-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: prevent duplicate tool_result blocks in native protocol mode for read_file #9272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… read_file When read_file encountered errors (e.g., file not found), it would call handleError() which internally calls pushToolResult(), then continue to call pushToolResult() again with the final XML. In native protocol mode, this created two tool_result blocks with the same tool_call_id, causing 400 errors on subsequent API calls. This fix replaces handleError() with task.say() for error notifications. The agent still receives error details through the XML in the single final pushToolResult() call. This change works for both protocols: - Native: Only one tool_result per tool_call_id (fixes duplicate issue) - XML: Only one text block with complete XML (cleaner than before) Agent visibility preserved: Errors are included in the XML response sent to the agent via pushToolResult(). Tests: All 44 tests passing. Updated test to verify say() is called.
Review complete. No issues found. The changes correctly address the duplicate tool_result issue in native protocol mode by replacing Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
Problem
When using native tool protocol, if
read_fileencountered an error (e.g., file not found), it would create two tool_result blocks with the same tool_call_id:handleError()internally callspushToolResult()→ tool_result Add options to always approve write and execute operations #1pushToolResult()with XML → tool_result Fix vscode compatibility issue #2This violates the native protocol requirement of exactly one tool_result per tool_use_id, causing 400 errors on subsequent API calls.
Solution
Replace
handleError()withtask.say("error", ...)in error paths within ReadFileTool.Agent still receives error details through the XML in the single final
pushToolResult()call:Why This Doesn't Break Anything
Native Protocol
pushToolResult()call = only ONE tool_result per tool_call_id<error>Error reading file: ...</error>task.say()XML Protocol
task.say()(same as before)Both protocols: Agent error visibility is preserved through XML in the tool result.
Testing
say()is called with error messages