fix: skip incomplete tool calls with partialJson in session repair#5822
Conversation
When streaming is aborted mid-tool-call, the assistant message contains a toolCall with partialJson (incomplete arguments) instead of complete arguments. The repair logic was creating synthetic tool_results for these incomplete calls, but since the incomplete tool_use blocks are skipped during API conversion, this caused "unexpected tool_use_id" errors from the Anthropic API. This fix updates extractToolCallsFromAssistant() to skip tool calls that have partialJson but no arguments field, preventing synthetic results from being created for tool calls that won't be sent to the API. Co-Authored-By: Claude Opus 4.5 <[email protected]>
3 tasks
4 tasks
This was referenced Feb 13, 2026
This pull request was closed.
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
When streaming is aborted mid-tool-call, the assistant message contains a
toolCallwithpartialJson(incomplete arguments) instead of completearguments. The repair logic was creating synthetictool_resultsfor these incomplete calls, but since the incompletetool_useblocks are skipped during API conversion, this caused "unexpected tool_use_id" errors from the Anthropic API.Changes
extractToolCallsFromAssistant()to skip tool calls that havepartialJsonbut noargumentsfieldTest plan
Greptile Overview
Greptile Summary
This PR updates the session transcript repair logic to ignore incomplete streamed tool calls that contain
partialJsonbut noarguments. This prevents the repair step from inserting synthetictoolResultmessages for tool calls that will later be omitted during Anthropic API conversion, avoiding "unexpected tool_use_id" validation errors. Two Vitest cases were added to cover skipping incomplete tool calls and ensuring synthetic results are still generated for complete calls.Confidence Score: 5/5
(2/5) Greptile learns from your feedback when you react with thumbs up/down!
Context used:
dashboard- CLAUDE.md (source)dashboard- AGENTS.md (source)