Repository navigation
[STALE: REBASE FROM NEW FORK] anthropic: retry once without history thinking blocks on invalid thinking signature (AGE-2004) - #23
Draft
vadymhimself wants to merge 1 commit into
Conversation
…gnature in thinking block' 400 (AGE-2004) Co-Authored-By: Claude Code <noreply@anthropic.com>
|
✅ Deterministic PR hygiene checks passed. |
⏳ DRAFT
What to do
Its title has been prefixed with |
Collaborator
Author
|
This PR is based on the superseded 2.65 gateway line. Rebuild the change from |
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.
What
Anthropic answers 400
messages.N.content.0: Invalid `signature` in `thinking` blockwhen a replayed thinking block was minted under a different model or account than the one now serving the call (AGE-2004, Мира aebc14d8: House Claude, rotated account/model mid-conversation). Today that 400 goes straight back to the agent and the turn is dead.Now the Anthropic adapter recovers once, inside the same call: on exactly that 400 it rebuilds the request with every
thinking/redacted_thinkingblock removed from the history and resends. Anthropic allows omitting history thinking. If the last assistant turn held atool_use(open tool loop), the dropped block would be required with thinking on, so that one resend goes withthinkingdisabled (or absent on models without explicit disable).messagesToAnthropicFormat) and the canonical raw source-replay lane (body cloned from the Claude client).thinkingReplayGuard); a second rejection is returned to the caller unchanged. Unrelated 400s are never resent. Match is the exact Anthropic message, a display-safe bounded body, adapteranthropic, status 400 only.anthropic-thinking-replay(causeciphertext-refusal, status 400) in the telemetry roster, failure model, attribution table, Logs page label and all 10 catalogs.Design note: why not carry the model in the envelope
The first plan was to stamp the minting model into the
ocxr1envelope and drop mismatches. The raw source-replay lane and raw client signatures (src/claude/outbound.ts,src/claude/inbound.ts:281-287) carry the signature raw, so the minting model cannot be attached there. A stateless retry on the real rejection covers both lanes and needs no stored state.Trade-off: while the client keeps sending the stale blocks, each turn costs one extra failed 400 before the resend (no extra billed tokens; the 400 is rejected before generation).
OPEN question
Does Anthropic reject the same model's signature across different accounts, or only across models? This fix recovers either way, so it does not need an answer; the recovery-kind counter in the request log will show how often it fires.
Agent's-eye text
No text the agent sees changes on success: the agent gets a normal answer and the turn continues. On a second rejection the agent receives the unchanged Anthropic 400 body (same as before this change).
Tests
tests/responses/responses-anthropic-thinking-replay.test.ts: closed turn resend drops blocks and keeps thinking; open tool loop resend turns thinking off and keeps the tool_use; unrelated 400 is not resent; second rejection returned after one resend. Roster, attribution, failure-stage and Logs label oracles pass (105 tests, 7 files).Eval added/updated: N/A deterministic (unit/integration test: tests/responses/responses-anthropic-thinking-replay.test.ts)
🤖 Generated with Claude Code