Skip to content

fix: synthesize tool_result placeholders for unanswered tool_use blocks#5

Merged
jeremydw merged 1 commit into
mainfrom
fix/repair-unanswered-tool-use
Jul 3, 2026
Merged

fix: synthesize tool_result placeholders for unanswered tool_use blocks#5
jeremydw merged 1 commit into
mainfrom
fix/repair-unanswered-tool-use

Conversation

@jeremydw

@jeremydw jeremydw commented Jul 3, 2026

Copy link
Copy Markdown
Member

Problem

When a turn dies mid-tool-call (network error, upstream failure, cancellation), VS Code's chat history keeps the assistant's tool_use but its tool_result never lands. Anthropic requires every tool_use to be answered by a matching tool_result in the immediately-following message, so every subsequent request built from that history was rejected with:

Vertex 400: messages.N: tool_use ids were found without tool_result blocks immediately after

Worse, each failed retry appends another dangling tool call, so the conversation wedges permanently. ef4c7bd fixed the trimming path and the reverse case (orphaned tool_result), but never repaired an unanswered tool_use.

Fix

Add a repairUnansweredToolUse pass in buildClaudeBody that synthesizes is_error placeholder tool_result blocks for any unanswered tool_use ids — completing a partial result turn in place, or inserting a new user result turn when the next message carries no results (or doesn't exist). Covers both the VS Code chat path and the CLI proxy path, since both build bodies here.

Tests

New pairing-invariant helper plus cases for: plain user turn after a failed tool call, partially-answered multi-tool turns, trailing dangling tool call, consecutive failed turns (the wedged-conversation repro), and untouched well-formed sequences. 84/84 passing; typecheck/lint/build green.

When a turn dies mid-tool-call (network error, upstream failure, user
cancellation), VS Code's chat history keeps the assistant's tool_use but
its tool_result never lands. Anthropic requires every tool_use to be
answered by a matching tool_result in the immediately-following message,
so every subsequent request built from that history was rejected with a
Vertex 400 ("tool_use ids were found without tool_result blocks
immediately after"), permanently wedging the conversation.

Add a repair pass in buildClaudeBody that synthesizes error placeholder
tool_result blocks for any unanswered tool_use ids: completing a partial
result turn in place, or inserting a new user result turn when the next
message carries no results (or doesn't exist). Covers both the VS Code
chat path and the CLI proxy path.
@jeremydw jeremydw merged commit 813ae9a into main Jul 3, 2026
1 check passed
@jeremydw jeremydw deleted the fix/repair-unanswered-tool-use branch July 3, 2026 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant