Repository navigation
fix(anthropic): keep signatures per thinking block and keep redacted thinking - #816
Open
ardazeybek wants to merge 1 commit into
Open
ardazeybek wants to merge 1 commit into
ardazeybek wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
When Anthropic returns more than one thinking block in a turn (interleaved thinking around text or tool use), every
signature_deltawas appended to a single string. The finished message ended up with one thinking block carryingSIG1SIG2and the next one with no signature at all, so replaying that history to Anthropic fails signature validation.redacted_thinkingblocks were dropped completely, even thoughThinkingContent.redactedexists. Anthropic expects those blocks to be sent back unchanged on the next request, so a conversation that hit one could not continue correctly.What changed:
redacted_thinkingblock becomesThinkingContent(thinking="", redacted=True)with the encrypteddatastored inthinking_signature, and the request builder sends it back as{"type": "redacted_thinking", "data": ...}.ProviderThinkingDeltaEventgot anew_blockflag so the stream canonicalizer opens a new thinking block at each provider block boundary instead of merging adjacent ones. Empty deltas (used to mark a redacted block's position) do not emit aThinkingDeltaEvent.Checks:
tests/test_anthropic_sse.py: per-block signatures, and redacted thinking kept plus replayed in the next request body. Both fail without the change.uv run ruff check .anduv run ruff format --check .are clean; the full test suite passes locally.I did not test against the live API; the streams in the tests are hand-written from the documented event shapes.