fix(agents): malformed tool-call JSON no longer kills the rollout#480
Open
mariobrajkovski wants to merge 1 commit into
Open
fix(agents): malformed tool-call JSON no longer kills the rollout#480mariobrajkovski wants to merge 1 commit into
mariobrajkovski wants to merge 1 commit into
Conversation
A completion truncated at the output-token limit mid-arguments (e.g. Qwen
emitting '{"command": "' and stopping) raised JSONDecodeError from the bare
json.loads in get_response, which escaped the agent loop and errored the whole
trace with 'Unterminated string starting at: line 1 column 13'.
Parse failures now produce the tool call with a sentinel argument
(MALFORMED_TOOL_ARGS_KEY); the dispatcher returns an isError tool result for
that call id without executing anything, so the provider contract holds
(every call id gets a result) and the model can re-issue the call instead of
the rollout dying. Applied to both the chat.completions and Responses parse
sites.
73dfcf2 to
b02daeb
Compare
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.
A completion truncated at the output-token limit mid-arguments (e.g. Qwen emitting
{"command": "and stopping) raised JSONDecodeError from the bare json.loads in get_response, which escaped the agent loop and errored the whole trace with "Unterminated string starting at: line 1 column 13".Parse failures now produce the tool call with a sentinel argument (MALFORMED_TOOL_ARGS_KEY); the dispatcher returns an isError tool result for that call id without executing anything, so the provider contract holds (every call id gets a result) and the model can re-issue the call instead of the rollout dying. Applied to both the chat.completions and Responses parse sites.
Side effect: the Responses path previously crashed on valid-but-non-dict arguments; it now coerces to
{}, matching the chat.completions path.Note
Medium Risk
Changes shared tool parsing and dispatch on the core ToolAgent loop used by OpenAI agents; behavior is defensive but affects every rollout when arguments are malformed.
Overview
Truncated or invalid tool-call argument JSON (e.g. output cut mid-string at the token limit) used to raise
JSONDecodeErrorduringget_response, which aborted the whole agent rollout.parse_tool_argumentsintool_agentnow catches parse failures and attaches a sentinel key (MALFORMED_TOOL_ARGS_KEY) instead of crashing. Both chat.completions and Responses agents use this helper instead of barejson.loads._dispatch_calldetects that sentinel and returns anisErrortool result for the call id without running the tool, so the provider contract is satisfied and the model can retry with complete JSON.Non-dict JSON on the Responses path is coerced to
{}, matching chat.completions. Tests cover malformedget_responseparsing and dispatch error text.Reviewed by Cursor Bugbot for commit b02daeb. Bugbot is set up for automated code reviews on this repo. Configure here.