fix: append diagram-state context after tool_result blocks, not before - #79
Merged
Merged
Conversation
Anthropic rejects a tool-result turn with a 400 ("tool_use ids were found
without tool_result blocks immediately after") when anything precedes the
tool_result block(s) that answer the prior round's tool_use. The rolling
diagram-state snapshot (PR #78) was being prepended to each round's
outgoing turn, which broke every multi-round Forge run against the real
API. Append it after the turn's own content instead — round 1's plain
prompt is unaffected either way, and round 2+'s tool_result blocks now
stay first.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
HTTP 400: tool_use ids were found without tool_result blocks immediately after.withLeadingText), ahead of thetool_resultblocks that answer the previous round'stool_usecalls. Anthropic requirestool_resultto be the first content in that turn — a block in front of it breaks the pairing and the request is rejected outright.withTrailingText). Round 1's plain prompt is unaffected either way; round 2+'stool_resultblocks now stay first, as required.Test plan
npm run typecheckcleannpm run test— 370 passing, including updatedaiRunner.test.tsassertions that now explicitly checkcontent[0].type === 'tool_result'on a tool-result turn (this is exactly the check that would have caught the original bug) and that the context snapshot lands atcontent.at(-1)instead🤖 Generated with Claude Code