Repository navigation
fix(openai_agents): keep raw input when function span input is not parseable JSON - #3365
Open
BlueX888 wants to merge 1 commit into
Conversation
…rseable JSON
The agents SDK types FunctionSpanData.input as str | None and emits
function spans with input=None (custom tools / apply_patch, where
with_tool_function_span never sets it) and input="" (a computer call
with no actions, where _serialize_trace_payload(None) returns "").
Both made json.loads raise inside Observer.__exit__ — after the span
was added to trace_manager but before remove_span ran — so the
ToolSpan leaked in active_spans under its placeholder "NA" name, and
the SDK provider swallowed the exception so nothing surfaced.
Fall back to the raw value when parsing raises, matching what the
existing `or {"input": ...}` fallback already did for falsy parse
results.
|
@BlueX888 is attempting to deploy a commit to the Confident AI Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Function spans from the OpenAI Agents SDK whose
inputis not parseable JSON crashedDeepEvalTracingProcessor. The SDK emits such spans on real code paths:input=Nonefor custom tools and apply_patch (both run throughwith_tool_function_span, which never sets input), andinput=""for a computer call with no actions (_serialize_trace_payload(None)returns""). The crash fired insideObserver.__exit__— after the span had been added totrace_managerbut beforeremove_spanran — so theToolSpanleaked inactive_spansunder its placeholder"NA"name. The SDK's trace provider catches and logs processor exceptions, so nothing surfaced beyond the corrupted trace.Why
deepeval/openai_agents/extractors.py:192(before this change):The SDK types
FunctionSpanData.inputasstr | None(agents/tracing/span_data.py).json.loads(None)raisesTypeErrorandjson.loads("")raisesjson.JSONDecodeError. The call happens inObserver.__exit__(deepeval/tracing/tracing.py:1272) — aftertrace_manager.add_span(deepeval/tracing/tracing.py:1212) and beforetrace_manager.remove_span(deepeval/tracing/tracing.py:1303) — so the exception aborted span finalization and left the span inactive_spans.DefaultTraceProvider.on_span_endswallows processor exceptions, so the failure was silent.Changes
deepeval/openai_agents/extractors.py— fall back to the raw input whenjson.loadsraises, matching what the existingor {"input": ...}fallback already did for falsy parse results (e.g."null").tests/test_integrations/test_openai_agents/test_function_span_input.py— regression tests driving the sameObserverwiringDeepEvalTracingProcessoruses, plus direct extractor-level fallback tests. All offline (no API key, no network).Testing
New test file on the unpatched tree (the regression):
test_input_none_does_not_raisefails withTypeError: the JSON object must be str, bytes or bytearray, not NoneTypeatextractors.py:192; the empty-string and non-JSON cases fail withjson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0).With this change:
Existing module tests:
The 15 failures are byte-identical with and without this change and all fail with
openai.OpenAIError: Missing credentials— these tests call the live OpenAI API (CONTRIBUTING.md notes they only fully run internally).Note: verified with openai-agents 0.22.3. With the version pinned in
poetry.lock(0.3.3),deepeval.openai_agentsalready fails to import on currentmain(deepeval/openai_agents/patch.pyimportsagents.run_internal, which does not exist in 0.3.3), so no test in this directory can run against the locked version — pre-existing and untouched by this change.