Skip to content

[Bug]: OpenClaw adapter: compaction corrupts Anthropic thinking/redacted_thinking blocks #191

@Ge0metryAI

Description

@Ge0metryAI

Platform

OpenClaw / Pi Agent

context-mode version

1.0.53

Full doctor output (REQUIRED)

## context-mode doctor

- [x] Runtimes: 8/11 (73%) — javascript, shell, typescript, python, ruby, go, php, perl
- [x] Performance: FAST (Bun)
- [x] Server test: PASS
- [x] FTS5 / SQLite: PASS — native module works
- [x] Hook script: PASS — hooks/pretooluse.mjs
- [x] Version: v1.0.53

Exact prompt that triggered the bug (REQUIRED)

No specific prompt triggers it — it occurs when the conversation is long enough to trigger compaction. The compaction hook fires, OpenClaw truncates conversation history, and the next API call to Anthropic fails because `thinking` / `redacted_thinking` blocks in the truncated history were modified.

Typical trigger: a session with 15+ tool calls using Anthropic `claude-opus-4-6` with extended thinking enabled. After compaction, the next user message triggers the error.

Full error output (REQUIRED)

LLM request rejected: messages.13.content.10: 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 (REQUIRED)

  1. Install context-mode v1.0.53 as OpenClaw native plugin (npm run install:openclaw)
  2. Configure OpenClaw with an Anthropic model that has extended thinking enabled (e.g. claude-opus-4-6 with thinkingDefault: "xhigh")
  3. Start a conversation and make many tool calls (15+) to grow the context window
  4. Wait for compaction to trigger (context-mode's before_compaction hook fires)
  5. Send another message after compaction
  6. Anthropic API rejects the request with the thinking block validation error above

What have you tried to fix it?

  • Verified OpenClaw is on v2026.3.24 which includes the fix for a similar issue in a different code path (#52961: "preserve latest assistant thinking and redacted-thinking block ordering during transcript image sanitization")
  • Searched context-mode source code: git log --all --oneline --grep='thinking' returns 0 results, rg 'thinking|redacted_thinking' src/ build/ returns 0 matches — there is zero handling of thinking blocks anywhere in the codebase
  • The compaction logic (compact() returning firstKeptEntryId) has no awareness of Anthropic's thinking block constraints
  • Using /new to reset the session before compaction triggers is a workaround but not a fix

Pre-submission checklist

  • I am on the LATEST version (ran ctx-upgrade)
  • I searched existing issues and this is not a duplicate
  • I tried to debug this myself (read source, ran hooks manually, etc.)
  • I understand that PRs are preferred and issues don't guarantee a fix

Operating System

Linux (Ubuntu/Debian)

JS Runtime

node v22.21.0, bun 1.3.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions