Repository navigation
Description
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
- Enable reasoning (
/reasoningorthinkingDefault: high) - Run a long session until compaction triggers
- Observe: all subsequent requests fail with the signature error above
- New session resolves it immediately
Root Cause
Anthropics API requires thinking blocks to be either:
- Preserved exactly as-is (signature must match content — no truncation, no modification)
- 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: truehelps 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: highcompaction.mode: safeguard
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon May 23, 2026
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:
src/agents/pi-embedded-runner/compact.ts:1136, 5be62e779b2e)src/agents/pi-embedded-runner/thinking.ts:11, 5be62e779b2e)src/agents/pi-embedded-runner.sanitize-session-history.test.ts:1537, 5be62e779b2e)src/agents/pi-embedded-runner/thinking.test.ts:557, 5be62e779b2e)src/agents/pi-embedded-runner/thinking.ts:11, af765100ffa7)Likely related people:
src/agents/pi-embedded-runner/thinking.ts,src/agents/pi-embedded-runner/compact.ts,src/agents/pi-embedded-runner/replay-history.ts)src/agents/pi-embedded-runner/thinking.ts,src/agents/pi-embedded-runner/replay-history.ts,src/agents/transcript-policy.ts)src/agents/pi-embedded-runner/replay-history.ts,src/agents/pi-embedded-runner.sanitize-session-history.test.ts)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.