Skip to content

[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
release/2.65.0-vadymhimself.15from
be-low-r11/thinking-sig-retry
Draft

vadymhimself wants to merge 1 commit into
release/2.65.0-vadymhimself.15from
be-low-r11/thinking-sig-retry

Conversation

@vadymhimself

Copy link
Copy Markdown
Collaborator

What

Anthropic answers 400 messages.N.content.0: Invalid `signature` in `thinking` block when 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_thinking block removed from the history and resends. Anthropic allows omitting history thinking. If the last assistant turn held a tool_use (open tool loop), the dropped block would be required with thinking on, so that one resend goes with thinking disabled (or absent on models without explicit disable).

  • Both request lanes are covered: the translated lane (messagesToAnthropicFormat) and the canonical raw source-replay lane (body cloned from the Claude client).
  • One resend per request (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, adapter anthropic, status 400 only.
  • New recovery kind anthropic-thinking-replay (cause ciphertext-refusal, status 400) in the telemetry roster, failure model, attribution table, Logs page label and all 10 catalogs.
  • No client protocol change, no change to inbound guards, no envelope change.

Design note: why not carry the model in the envelope

The first plan was to stamp the minting model into the ocxr1 envelope 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

…gnature in thinking block' 400 (AGE-2004)

Co-Authored-By: Claude Code <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot changed the title anthropic: retry once without history thinking blocks on invalid thinking signature (AGE-2004) [WRONG BRANCH] anthropic: retry once without history thinking blocks on invalid thinking signature (AGE-2004) Nov 13, 2026
@github-actions

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (release/2.65.0-vadymhimself.15); retarget to dev. UI screenshot required.

What to do

  • Retarget this PR to dev — all contributions go to dev.
  • Add a screenshot of the UI change to the PR description.

Its title has been prefixed with [WRONG BRANCH].
This pull request is being kept as a draft automatically. Once every issue above is resolved, it will be marked ready for review again.

@github-actions
github-actions Bot marked this pull request as draft November 13, 2026 11:07
@vadymhimself vadymhimself changed the title [WRONG BRANCH] anthropic: retry once without history thinking blocks on invalid thinking signature (AGE-2004) [STALE: REBASE FROM NEW FORK] anthropic: retry once without history thinking blocks on invalid thinking signature (AGE-2004) Nov 18, 2026
@vadymhimself

Copy link
Copy Markdown
Collaborator Author

This PR is based on the superseded 2.65 gateway line. Rebuild the change from port/ar-on-upstream-2026-11-18 (upstream-derived 2.100 AR overlay, PR #46): #46 . Do not rebase onto or merge the old release line. Preserve the new gateway quota/cache gate and re-run the affected regressions. The candidate is not deployed; do not publish or replace a running gateway without explicit approval.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant