Skip to content

Session compaction corrupts thinking blocks, breaking all subsequent requests until session restart #85717

Closed

Description

@brainmonger

Bug Report

Summary

When extended thinking (reasoning) is enabled, session compaction corrupts thinking blocks in conversation history. Once a corrupted block is in history, every subsequent API call fails with:

LLM request rejected: messages.N.content.N: Invalid `signature` in `thinking` block

The session is then unrecoverable until restarted.

Reproduction

  1. Enable reasoning (/reasoning or thinkingDefault: high)
  2. Run a long session until compaction triggers
  3. Observe: all subsequent requests fail with the signature error above
  4. New session resolves it immediately

Root Cause

Anthropics API requires thinking blocks to be either:

  1. Preserved exactly as-is (signature must match content — no truncation, no modification)
  2. Dropped entirely from historical messages (recommended — past thinking blocks are not needed for context)

The compaction path appears to be partially truncating thinking blocks instead of dropping them cleanly. A mangled thinking block with a broken signature is worse than no thinking block at all.

Expected Behavior

During compaction, thinking blocks in historical messages should be stripped entirely, not truncated. Only the most recent assistant turn needs thinking blocks preserved intact.

Anthropic Docs

From Anthropic extended thinking docs: when replaying conversation history, thinking blocks from prior turns can be omitted. The signature validation only applies to blocks that are included — so the safe path is to drop them during compaction rather than truncate.

Workaround

  • Disabling reasoning keeps thinking blocks out of history entirely
  • Enabling truncateAfterCompaction: true helps somewhat (rotates the transcript after compaction so old blocks are archived, not replayed)

Environment

  • OpenClaw 2026.5.19 (a185ca2)
  • Model: anthropic/claude-sonnet-4-6
  • thinkingDefault: high
  • compaction.mode: safeguard

Activity

  1. clawsweeper commented on May 23, 2026

    @clawsweeper
    Contributor

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

    Close: current main now handles the reported signed-thinking replay failure by preserving latest assistant thinking, stripping invalid historical thinking when compaction appends a new prompt, and retrying Anthropic-style invalid-signature rejections once without thinking replay. The fix is on main only after the latest release.

    I found the merged PR that appears to have closed this: #85579: fix(agents): preserve latest thinking replay signatures.

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

    Review details

    Best possible solution:

    Keep the current-main signed-thinking replay fix and close this report; any fresh failure should come back with a redacted current-main transcript showing which provider replay path still preserves an invalid nonblank signature.

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

    Yes, source-level: the historical sanitizer/recovery path matched the signed-thinking invalid-signature failure, and current main has targeted tests for compaction opt-out and invalid-signature retry. I did not run live Anthropic credentials in this read-only review.

    Is this the best way to solve the issue?

    Yes: the merged current-main fix is narrower than dropping all historical thinking, because it preserves latest assistant thinking where Anthropic requires it, strips invalid historical replay when compaction adds a prompt, and retries provider-side invalid-signature rejections once without thinking.

    Security review:

    Security review: Non-PR issue triage; no patch security review applies.

    What I checked:

    Likely related people:

    • giodl73-repo: Authored the merged signed-thinking replay fix that added latest-assistant preservation, compaction opt-out, recovery broadening, and focused tests. (role: fix author; confidence: high; commits: 56108ac481fe, af765100ffa7; files: src/agents/pi-embedded-runner/thinking.ts, src/agents/pi-embedded-runner/compact.ts, src/agents/pi-embedded-runner/replay-history.ts)
    • steipete: Committed follow-up signed-thinking replay hardening on current main and earlier worked on the invalid-signature sanitizer path. (role: recent adjacent contributor; confidence: high; commits: 791ad0864aca, 906476af0c0b, d6c9387c0fbb; files: src/agents/pi-embedded-runner/thinking.ts, src/agents/pi-embedded-runner/replay-history.ts, src/agents/transcript-policy.ts)
    • NianJiuZst: Authored current-main follow-up work to strip invalid thinking signatures for signed-thinking providers. (role: follow-up hardening author; confidence: medium; commits: 41329c0e1489; files: src/agents/pi-embedded-runner/replay-history.ts, src/agents/pi-embedded-runner.sanitize-session-history.test.ts)
    • vincentkoc: Earlier history added Anthropic thinking-error recovery helpers and tests in the same replay failure family. (role: prior recovery contributor; confidence: medium; commits: 9aa2ef273602, 707f5485b967; files: src/agents/pi-embedded-runner/thinking.ts, src/agents/pi-embedded-runner/run/attempt.ts, src/agents/pi-embedded-runner/thinking.test.ts)

    Codex review notes: model gpt-5.5, reasoning high; reviewed against 5be62e779b2e; fix evidence: merged PR #85579, commit af765100ffa7, main fix timestamp 2026-05-24T03:41:57Z.

  2. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.
    on May 23, 2026
  3. locked as resolved and limited conversation to collaborators on May 27, 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

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions