Skip to content

sanitizeSurrogates() corrupts thinking block content before API replay #27825

@izaimza0-topbruv

Description

@izaimza0-topbruv

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

  1. Have a conversation that triggers extended thinking (thinking blocks in assistant messages)
  2. The thinking block content contains surrogate-like byte sequences (common in reasoning traces)
  3. On the next turn, when the conversation history is replayed to the Anthropic API, sanitizeSurrogates() mutates the thinking block content
  4. The Anthropic API receives thinking content that differs from what it originally generated
  5. 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 signature

Environment

  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked 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