Skip to content

[Bug] Session reset when thinking blocks present in long sessions (thinkingSignature modified during compaction) #19524

@alexidentiq

Description

@alexidentiq

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

  1. Enable extended thinking (any level) on a session
  2. Have a long conversation (50+ messages with tool calls)
  3. Session grows large enough to trigger context compaction
  4. OpenClaw attempts to reconstruct message history for next API call
  5. Error fires and retries ~6 times
  6. 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

  1. Enable extended thinking on a session (any level: low/high)
  2. Have a long conversation with tool calls (exec, file reads, etc.)
  3. Let the session grow to ~50+ messages
  4. Wait for OpenClaw to trigger context compaction automatically
  5. 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:

  1. Extended thinking enabled (any level)
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions