Bug Description
When using Anthropic models with extended thinking enabled, the following error occurs intermittently:
LLM request rejected: messages.7.content.1: `thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified. These blocks must remain as they were in the original response.
Root Cause Analysis
Anthropic's API requires that thinking / redacted_thinking blocks in the latest assistant message remain exactly as they were in the original response. Any modification triggers a rejection.
OpenClaw's compaction and context pruning pipelines do not currently have special protection for thinking blocks in the latest assistant message:
-
compaction.ts: No thinking-aware logic. When compaction replaces old messages with a summary, the latest assistant message's thinking blocks may be lost or altered.
-
context-pruning/pruner.ts: Only touches toolResult messages (not assistant messages), so unlikely the direct cause. However, it counts thinking block chars for window estimation.
-
transcript-policy.ts: dropThinkingBlocks is only enabled for GitHub Copilot Claude (isCopilotClaude), not for direct Anthropic API usage — correct behavior. But there's no complementary "preserve latest assistant thinking blocks" guard for Anthropic.
Expected Behavior
The latest assistant message's thinking / redacted_thinking blocks should be preserved exactly as-is through compaction, pruning, and session restore operations when targeting Anthropic's API.
Suggested Fix
Add a guard in the compaction and/or session sanitization pipeline that:
- Identifies the last assistant message in the transcript
- Ensures its
thinking / redacted_thinking blocks are never modified or dropped
- Applies this guard specifically when the target provider is Anthropic
Environment
- OpenClaw version: 2026.2.27 (dev channel)
- Model:
anthropic/claude-opus-4-6
- Thinking: enabled (low)
- Compaction mode: default
- Context pruning: cache-ttl (20m)
Reproduction
- Use Anthropic model with thinking enabled
- Have a long session that triggers compaction or context pruning
- Send a follow-up message after compaction runs
- Error occurs when the compacted transcript is sent to Anthropic with modified thinking blocks
Bug Description
When using Anthropic models with extended thinking enabled, the following error occurs intermittently:
Root Cause Analysis
Anthropic's API requires that
thinking/redacted_thinkingblocks in the latest assistant message remain exactly as they were in the original response. Any modification triggers a rejection.OpenClaw's compaction and context pruning pipelines do not currently have special protection for thinking blocks in the latest assistant message:
compaction.ts: No thinking-aware logic. When compaction replaces old messages with a summary, the latest assistant message's thinking blocks may be lost or altered.context-pruning/pruner.ts: Only touchestoolResultmessages (not assistant messages), so unlikely the direct cause. However, it counts thinking block chars for window estimation.transcript-policy.ts:dropThinkingBlocksis only enabled for GitHub Copilot Claude (isCopilotClaude), not for direct Anthropic API usage — correct behavior. But there's no complementary "preserve latest assistant thinking blocks" guard for Anthropic.Expected Behavior
The latest assistant message's
thinking/redacted_thinkingblocks should be preserved exactly as-is through compaction, pruning, and session restore operations when targeting Anthropic's API.Suggested Fix
Add a guard in the compaction and/or session sanitization pipeline that:
thinking/redacted_thinkingblocks are never modified or droppedEnvironment
anthropic/claude-opus-4-6Reproduction