-
-
Notifications
You must be signed in to change notification settings - Fork 69.2k
Compaction deletes thinkingSignature, causing Anthropic API rejection #27504
Copy link
Copy link
Closed
Description
Summary
sanitizeHistoryContentBlock() in the compaction pipeline unconditionally deletes thinkingSignature from thinking blocks. When these blocks later appear as the latest assistant message in the Anthropic API request, the API rejects with:
messages.N.content.M: `thinking` or `redacted_thinking` blocks in the latest assistant message
cannot be modified. These blocks must remain as they were in the original response.
Steps to Reproduce
- Use Anthropic provider with extended thinking enabled (
thinkingLevel: lowor higher) - Have a long-running session that accumulates enough history to trigger compaction
- After compaction, send a new message through the same session
- API rejects because the latest assistant message's thinking blocks are missing
thinkingSignature
Root Cause
In pi-embedded (traced via dist), sanitizeHistoryContentBlock() contains:
if (type === "thinking") {
if ("thinkingSignature" in entry) {
delete entry.thinkingSignature; // ← deletes the cryptographic signature
truncated = true;
}
}The Anthropic API requires thinking blocks to be byte-identical to the original response, including the thinkingSignature field. Deleting it constitutes a modification.
Impact
- Any session with extended thinking + enough history for compaction becomes permanently broken
- The session cannot recover — every subsequent API call fails with the same error
- Only fix is clearing the session entirely (deleting the JSONL)
- Fresh sessions (e.g., WhatsApp messages that start new conversations) are unaffected
Observed Behaviour
- Error first appeared after session accumulated 1685 events across 3 compactions
- Error message index varies (messages.37, messages.79, messages.93) as compaction changes history length
- Error persists across gateway restarts — the damage is in the stored session data
- Tested on OpenClaw 2026.2.23 (b817600), Anthropic provider, claude-sonnet-4-6
Suggested Fix
Either:
- Preserve
thinkingSignatureduring compaction — it's needed for API round-tripping - Strip the entire thinking block instead of just the signature, if the goal is to save tokens
- Only strip
thinkingSignaturefrom non-latest assistant messages, since the API only validates the most recent one
Option 2 is probably safest — the thinking content is not useful after compaction, and removing the entire block avoids the signature mismatch entirely.
Environment
- OpenClaw: 2026.2.23 (b817600)
- Provider: Anthropic (claude-sonnet-4-6)
- OS: macOS Darwin 25.3.0
- Node: v22.22.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.