Skip to content

Bug: thinking/redacted_thinking blocks corrupted during context compaction (safeguard mode) #20039

@byungsker

Description

@byungsker

Description

When extended thinking (thinking=low or higher) is enabled and a session grows long enough to trigger context compaction (compaction.mode: safeguard), OpenClaw appears to modify or strip thinking/redacted_thinking blocks from the conversation history.

This causes subsequent API calls to fail 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.

The session then becomes permanently broken — every new message triggers the same error in a loop.

Steps to Reproduce

  1. Enable thinking mode (/reasoning or set thinking: low in config)
  2. Have a long conversation in a channel/thread session
  3. Wait until context compaction triggers (safeguard mode)
  4. Send another message — the error appears
  5. Every subsequent message in the same session produces the same error

Expected Behavior

Context compaction should either:

  • Preserve thinking/redacted_thinking blocks intact, OR
  • Remove the entire assistant turn (both thinking blocks AND text blocks together), never partially

Actual Behavior

Thinking blocks are stripped or modified during compaction, corrupting the conversation history. The session cannot recover — requires /new to reset.

Environment

  • OpenClaw version: 2026.2.9
  • Model: anthropic/claude-sonnet-4-5
  • Thinking: low
  • Compaction mode: safeguard
  • Channel: Discord (thread session)

Workaround

Use /new to reset the session. The session cannot self-recover.

Notes

Per Anthropic's API docs, thinking and redacted_thinking blocks must be passed back exactly as returned in multi-turn conversations. Any modification — including removal of thinking blocks while keeping text blocks — is rejected by the API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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