Skip to content

Anthropic thinking blocks with expired signatures cause crash loop on replay #88932

Closed

Description

@conini

Problem

When running with thinking=adaptive (or any thinking mode) against Anthropic models, extended thinking blocks with cryptographically signed replay signatures accumulate in the session transcript. These signatures are time-limited and single-use.

The current transcript hygiene strips thinking blocks with missing, empty, or blank signatures:

Thinking blocks with missing, empty, or blank replay signatures are stripped before provider conversion.

However, it does not strip thinking blocks where the signature is present but expired/invalid. When these are replayed to the Anthropic Messages API, the API rejects the entire request:

messages.9.content.6: Invalid signature in thinking block

This causes a cascade:

  1. Every subsequent LLM call fails because the full history is replayed
  2. The corrupted transcript is persisted to disk
  3. Container restarts reload the same bad transcript → crash loop
  4. No automatic recovery without manual session reset

Expected Behavior

Historical thinking blocks should be stripped from replay regardless of signature state. The Anthropic API uses signatures for single-use replay within the same conversation turn; there is no valid reason to replay thinking blocks from earlier turns. All type: "thinking" blocks in historical assistant messages should be removed before provider conversion.

Actual Behavior

Thinking blocks with expired but non-empty signatures pass through transcript hygiene and are sent to the Anthropic API, which rejects them.

Reproduction

  1. Run an agent with thinking=adaptive on Anthropic Claude
  2. Have a long-running session (10+ turns with thinking responses)
  3. Wait for signatures to expire (or restart the container after some time)
  4. Next LLM call fails with Invalid signature in thinking block
  5. All subsequent calls fail — session is bricked

Impact

  • Two production outages in our setup: 1.5h and 8h downtime
  • Only recoverable via manual session transcript deletion
  • Affects any long-running session using thinking mode with Anthropic

Suggested Fix

In the Anthropic provider adapter's transcript hygiene, change the stripping condition from "missing/empty/blank signature" to "all thinking blocks in historical turns":

// Before: only strips missing/blank
content.filter(b => !(b.type === 'thinking' && (!b.signature || b.signature.trim() === '')))

// After: strip ALL thinking blocks from historical assistant messages
content.filter(b => b.type !== 'thinking')

The current-turn thinking block (if any) should still be preserved for tool-call continuations within the same turn, per existing logic.

Environment

  • OpenClaw: 2026.5.27
  • Model: anthropic/claude-opus-4-6
  • Thinking mode: adaptive

Workaround

Manual session reset to delete all transcript files and restart the gateway.

Activity

  1. clawsweeper commented on Jun 1, 2026

    @clawsweeper
    Contributor

    Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

    Current main now detects the reported Anthropic invalid-signature thinking-block rejection and retries the provider call with thinking blocks stripped, so the session no longer hard-loops; the proof is current-main-only and is not in v2026.5.28.

    So I’m closing this as already implemented rather than keeping a duplicate issue open.

    Review details

    Best possible solution:

    Keep the current main preserve-then-recover implementation and ship it in the next release; reopen only if a current-main build still loops after replay-invalid recovery.

    Do we have a high-confidence way to reproduce the issue?

    Source-reproducible: v2026.5.28 lacks the replay-invalid thinking-signature classifier, while current main has classifier and recovery tests for the exact error shape. I did not run a live Anthropic session in this read-only review.

    Is this the best way to solve the issue?

    Yes. Current main preserves signed thinking where Anthropic requires it for tool-use/current-turn continuity, then recovers opaque invalid-signature rejections by retrying once without thinking blocks, which is narrower than removing all Claude 4.6+ historical thinking up front.

    Security review:

    Security review: Non-PR issue review; the report is an availability/session-state bug rather than a security-boundary issue.

    AGENTS.md: found and applied where relevant.

    What I checked:

    • Repository policy read: Root AGENTS.md and the scoped agent-runtime AGENTS.md were read and applied; this is core agent/session replay behavior requiring source, test, history, and release provenance. (AGENTS.md:1, 630f0d6938cd)
    • Invalid thinking signatures classified as replay-invalid: Current main adds a thinking-signature classifier and makes replay-invalid detection include invalid or expired signatures when the error also mentions thinking. (src/agents/embedded-agent-helpers/errors.ts:366, 630f0d6938cd)
    • Provider call recovery strips thinking blocks on retry: The Anthropic recovery wrapper retries a rejected request once with all thinking blocks stripped from the outbound context, replacing thinking-only assistant turns with omitted-reasoning text. (src/agents/embedded-agent-runner/thinking.ts:532, 630f0d6938cd)
    • Runtime installs recovery for signed-thinking policies: The agent attempt path wraps Anthropic signed-thinking streams with the recovery wrapper whenever signatures or thinking-block replay policy is active. (src/agents/embedded-agent-runner/run/attempt.ts:2613, 630f0d6938cd)
    • Regression coverage for the exact reported error: Tests cover the exact JSON-shaped Invalid signature in thinking block payload as replay_invalid and cover pre-content stream-error retry without thinking blocks. (src/agents/embedded-agent-helpers.isbillingerrormessage.test.ts:1566, 630f0d6938cd)
    • Dependency contract checked: Anthropic documents that Claude Sonnet 4.6+ preserves prior thinking blocks by default and that complete unmodified thinking blocks are required during tool use, which supports OpenClaw preserving signed blocks where needed and recovering opaque invalid-signature rejections rather than blanket-stripping every historical block first. (platform.claude.com)

    Likely related people:

    • Vincent Koc: Current blame for the classifier/recovery files points to Vincent, and earlier history includes the Anthropic thinking crash recovery commit. (role: recent area contributor and current implementation proof; confidence: high; commits: 76fa1b99c310, 9aa2ef273602, d49460b4173c; files: src/agents/embedded-agent-helpers/errors.ts, src/agents/embedded-agent-runner/thinking.ts, src/agents/embedded-agent-runner/run/attempt.ts)
    • Shakker: Recent history shows signed-thinking replay sanitization and tool-result trust work near the same session replay boundary. (role: adjacent signed-thinking replay contributor; confidence: medium; commits: 3cc9d53eb31f, 1e35eed2772e; files: src/agents/pi-embedded-runner/replay-history.ts, src/agents/session-transcript-repair.ts, src/agents/pi-embedded-runner/run/attempt.tool-call-normalization.ts)
    • Frank Yang: History shows the earlier Anthropic thinking-block drop-on-replay change that established part of this behavior family. (role: earlier Anthropic replay behavior contributor; confidence: medium; commits: 5ca0233db05f; files: src/agents/transcript-policy.ts, src/agents/pi-embedded-runner/run/attempt.ts)
    • Ayaan Zaidi: History shows the preservation change for Anthropic thinking replay that current main continues to respect for signed-thinking providers. (role: adjacent Anthropic thinking preservation contributor; confidence: medium; commits: c65e152b390a; files: src/agents/pi-embedded-runner/thinking.ts, src/agents/pi-embedded-runner/proxy-stream-wrappers.ts)

    Codex review notes: model gpt-5.5, reasoning high; reviewed against 630f0d6938cd; fix evidence: commit 76fa1b99c310, main fix timestamp 2026-06-01T05:17:27+02:00.

  2. added
    P1
    impact:crash-loop
    impact:session-state
    on Jun 1, 2026
  3. locked as resolved and limited conversation to collaborators on Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1impact:crash-loopimpact:session-state

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions