-
-
Notifications
You must be signed in to change notification settings - Fork 69.8k
sanitizeSurrogates() corrupts thinking block content before API replay #27825
Description
Bug Summary
sanitizeSurrogates() modifies the content of thinking blocks when replaying conversation history to the Anthropic API. This corrupts the API signature integrity and causes session stalls (the API rejects or mishandles the modified thinking content).
Steps to Reproduce
- Have a conversation that triggers extended thinking (thinking blocks in assistant messages)
- The thinking block content contains surrogate-like byte sequences (common in reasoning traces)
- On the next turn, when the conversation history is replayed to the Anthropic API,
sanitizeSurrogates()mutates the thinking block content - The Anthropic API receives thinking content that differs from what it originally generated
- Session becomes stuck / errors out
Expected Behaviour
sanitizeSurrogates() should skip thinking blocks entirely when sanitising conversation history. Thinking blocks are opaque to the client and must be replayed byte-for-byte as received from the API.
Actual Behaviour
Thinking block content is passed through sanitizeSurrogates(), which strips/replaces surrogate pairs, altering the content. This breaks the API contract for thinking block replay.
Suggested Fix
Add a guard in the sanitisation pass to skip any content block where type === "thinking":
if (block.type === "thinking") return block; // preserve API signatureEnvironment
- OpenClaw v2026.2.25
- Anthropic API (Claude with extended thinking enabled)
- Observed on: Telegram channel session replay
Impact
Session-breaking — requires manual session reset to recover. Affects any channel where extended thinking is enabled and conversation history contains thinking blocks with surrogate-adjacent byte sequences.