fix(agent-loop): recover malformed tool arguments - #746
Open
imMamdouhaboammar wants to merge 1 commit into
Open
Conversation
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.
Problem
agent_runner_loop()parses model tool-call arguments before dispatch. Malformed JSON raisedJSONDecodeErrorand terminated the task before GenericAgent could ask the model to correct the call.A second edge case exists even when the JSON syntax is valid:
null, arrays, strings, numbers, and booleans decode successfully but violate GenericAgent's tool contract, which expects an argument object. Those values later crash_compact_tool_args()orBaseHandler.dispatch()instead of entering the retry flow.Review also identified a reliability edge: echoing the entire malformed argument payload into the retry prompt lets a very large invalid tool call inflate the next model request.
Fix
dict)bad_jsonrecovery pathVerification
TDD and review-driven regression work was performed before rebuilding this clean branch:
31165097818failed with the exactJSONDecodeErroratagent_loop.py:70before dispatch3116517065731165565545failed for all five targeted values:null,[], string, number, and boolean, while malformed-JSON recovery still passed31165676777: compile, malformed JSON coverage, all five non-object subcases, andgit diff --check31167984365kept the existing recovery tests green and failed only because a ~20k malformed payload produced a 20,112-character retry prompt31168074147passed compile, all three regression methods, andgit diff --checkwith a bounded preview that retains total length metadatamainas one clean commit using the exact production/test blobs from the last GREEN validationScope
main