-
-
Notifications
You must be signed in to change notification settings - Fork 69.5k
[Bug] Session reset when thinking blocks present in long sessions (thinkingSignature modified during compaction) #19524
Description
Summary
Description
When a session uses extended thinking (thinking: low/high) and grows long enough
to trigger context compaction, OpenClaw fails to reconstruct the message history
correctly, causing repeated API errors and eventual session reset.
Error
400 {"type":"error","error":{"type":"invalid_request_error",
"message":"messages.45.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."}}
Steps to Reproduce
- Enable extended thinking (any level) on a session
- Have a long conversation (50+ messages with tool calls)
- Session grows large enough to trigger context compaction
- OpenClaw attempts to reconstruct message history for next API call
- Error fires and retries ~6 times
- Session forcibly resets
Root Cause (suspected)
During context compaction, OpenClaw reconstructs the message array but
modifies thinking/redacted_thinking blocks from historical assistant messages.
Anthropic's API requires these blocks to remain byte-for-byte identical
to the original response — any modification (including stripping thinkingSignature)
results in a 400 rejection.
Suggested Fix
When compacting session history, either:
- (A) Strip thinking blocks entirely from historical assistant messages (safest)
- (B) Preserve them exactly as-is including full
thinkingSignature
Currently neither is happening — blocks are included but modified.
Contributing Factor
Reading session JSONL files via exec embeds raw thinking block JSON into
toolResult content, which accelerates context overflow and may confuse
the reconstruction parser. Workaround: never read session JSONL files via exec.
Environment
- OpenClaw: latest (Feb 2026)
- Model: claude-sonnet-4-5
- Thinking: enabled (low)
- Channel: Telegram
- Session length at failure: ~230 messages in JSONL
Steps to reproduce
- Enable extended thinking on a session (any level: low/high)
- Have a long conversation with tool calls (exec, file reads, etc.)
- Let the session grow to ~50+ messages
- Wait for OpenClaw to trigger context compaction automatically
- Observe repeated 400 errors in session logs
Expected behavior
Session continues normally. When compacting history, thinking/redacted_thinking
blocks from historical assistant messages are either:
(a) stripped entirely, OR
(b) preserved byte-for-byte including thinkingSignature
No 400 error, no session reset.
Actual behavior
After session grows long (~230 messages), every API call returns:
400 {"type":"error","error":{"type":"invalid_request_error",
"message":"messages.45.content.1: thinking or redacted_thinking
blocks in the latest assistant message cannot be modified."}}
OpenClaw retries ~6 times (all fail), then forcibly resets the session.
All conversation context is lost.
OpenClaw version
2026.2.13
Operating system
macOS 15.4 (Darwin 25.3.0, arm64)
Install method
npm global
Logs, screenshots, and evidence
Error (repeated 6 times, ~10 min apart):
400 {"type":"error","error":{"type":"invalid_request_error",
"message":"messages.45.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."},
"request_id":"req_011CYENb4e3tubW6vx1U9WLU"}
Session JSONL had ~237 lines. Extended thinking was enabled (low).
After 6 consecutive failures, session was forcibly reset.Impact and severity
Affected: Any user running long sessions with extended thinking enabled
Severity: High — causes complete session reset and loss of all conversation context
Frequency: Deterministic (reproducible when session reaches ~230+ messages)
Consequence: All in-progress work and context is lost; agent must restart from scratch
Additional information
The bug is triggered specifically by the combination of:
- Extended thinking enabled (any level)
- Session length sufficient to trigger context compaction
Workaround: Keep sessions shorter or disable extended thinking.
The issue is NOT a recent regression — likely present in any version
that supports extended thinking with session compaction.
Note: Reading session JSONL files via exec tool accelerates the issue
by rapidly increasing session size.