fix(anthropic): drop thinking blocks when orphan-strip mutates an assistant turn#35855
Open
fesalfayed wants to merge 1 commit into
Open
fix(anthropic): drop thinking blocks when orphan-strip mutates an assistant turn#35855fesalfayed wants to merge 1 commit into
fesalfayed wants to merge 1 commit into
Conversation
…istant turn Stripping an orphaned tool_use invalidates the thinking-block signature on that turn (it was signed against the original content), so replaying it returns a non-retryable HTTP 400. Drop the now-stale thinking blocks from any turn whose tool_use set was trimmed.
Closed
9 tasks
Collaborator
9 tasks
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.
What does this PR do?
Extended-thinking Claude models sign each
thinkingblock against the full turn content. When_strip_orphaned_tool_blocksremoves atool_usewhosetool_resultnever arrived (interrupted parallel batch, compression, truncation), the turn's content changes and the signature no longer matches. Replaying it returns a non-retryable HTTP 400:Since the turn is rebuilt from the store every iteration, the gateway loops on it with no recovery.
_merge_consecutive_rolesalready drops thinking blocks for the same reason when it mutates a turn. This applies the identical treatment to the orphan-strip path: if a turn'stool_useset was trimmed, drop its thinking blocks too.Related Issue
Fixes #35847
Type of Change
Changes Made
agent/anthropic_adapter.py—_strip_orphaned_tool_blocks: when a turn'stool_useset is trimmed, drop itsthinking/redacted_thinkingblocks.tests/agent/test_anthropic_adapter.py— test covering a partially-answered parallel tool batch.How to Test
Checklist
Code
Documentation & Housekeeping