-
-
Notifications
You must be signed in to change notification settings - Fork 69.4k
Compaction corrupts thinking/redacted_thinking blocks, breaking Anthropic API sessions #39887
Copy link
Copy link
Description
Bug Description
When a session uses extended thinking (thinking=adaptive or similar) with Anthropic models, and compaction runs on the conversation history, the compactor modifies thinking and/or redacted_thinking content blocks in assistant messages. The Anthropic API then rejects the next request with:
LLM request rejected: messages.N.content.N: thinking or redacted_thinking blocks
in the latest assistant message cannot be modified. These blocks must remain as
they were in the original response.
This permanently breaks the session since every subsequent API call fails with the same error.
Secondary Issue: Error Leakage to Chat
When the compaction-triggered API call fails:
- Error messages leak to the chat channel despite
suppressToolErrors: truebeing set in the agent config - Compaction failure sentinel messages (e.g. "Gateway: agents.defaults.compaction failed") also leak to the user's chat
- The session enters a loop of failed API calls with visible error messages
Steps to Reproduce
- Configure an agent with an Anthropic model that supports extended thinking (e.g.
claude-opus-4-6) - Enable thinking (e.g.
thinking: adaptive) - Set compaction mode to
safeguard - Have a long enough conversation to trigger compaction
- Compaction runs and modifies thinking blocks in the conversation history
- Next API call fails with the error above
- Session becomes unresponsive
Expected Behavior
- Compaction should preserve thinking blocks exactly as-is, or strip them entirely before resubmitting to the API. The Anthropic API requires these blocks to be unmodified.
- Compaction failures should NOT leak to the user's chat channel. The
suppressToolErrors: trueconfig should cover compaction-related errors as well. - Restart sentinel messages from compaction failures should be suppressed from the chat output.
Suggested Fix
When compacting conversation history that contains thinking or redacted_thinking blocks:
- Option A (preferred): Leave all
thinkingandredacted_thinkingblocks byte-identical to the original API response. Only compact/summarizetextandtool_use/tool_resultblocks. - Option B: Strip
thinkingandredacted_thinkingblocks entirely from messages being sent back to the API (Anthropic allows omitting them from non-latest messages). - Separately: Ensure compaction errors are caught by the
suppressToolErrorsmechanism and do not propagate to the chat channel.
Environment
- OpenClaw version: 2026.3.7
- Model: Anthropic Claude Opus 4-6
- Compaction mode: safeguard
- Thinking config: adaptive
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.