Repository navigation
[STALE: REBASE FROM NEW FORK] anthropic: retry once without history thinking blocks on invalid thinking signature (AGE-2004) - #23
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 |
|
This PR is based on the superseded 2.65 gateway line. Rebuild the change from |
|
Trial evidence: before the merge the build ran 30.5 h on the laptop gateway and 24 h on the personal Mac Mini gateway, both with For new work:
Before opening a PR, use pinned Bun 1.4.4 with an isolated
Hosted-only behavior needs For this PR: not carried (no entry in 🤖 Generated with Claude Code |
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