Skip to content

Context corruption exposes raw API errors to chat surface #11038

@choutos

Description

@choutos

Summary

When a session transcript becomes corrupted (orphaned tool_result without matching tool_use), the raw Anthropic API error is delivered directly to the chat surface instead of being handled gracefully.

Reproduction

  1. A session accumulates tool calls over time
  2. Context compaction or a crash leaves a tool_result block without its corresponding tool_use
  3. Every subsequent message to that session fails with:
    LLM request rejected: messages.144.content.1: unexpected tool_use_id found in tool_result blocks: toolu_01HjX9c7NLJaBLDzyBasSkKw. Each tool_result block must have a corresponding tool_use block in the previous message.
    
  4. This error is sent to the Telegram group (or other surface) on every message — effectively spamming the channel

Observed behavior

  • Session: agent:main:telegram:group:-1003892537872:topic:37
  • Transcript: 3bd7214b-ada2-42fa-b07e-8ad3d15fd308.jsonl (84 entries)
  • Error referenced message index 144 (API-side count after expansion)

Expected behavior

  1. Don't expose raw API errors to users — log them, maybe notify the admin, but don't spam the chat
  2. Self-heal when possible — detect orphaned tool_results and either:
    • Prune them from context before sending
    • Or reset the session automatically with a single notice
  3. Prevent corruption — ensure compaction never orphans tool_result blocks

Workaround

Manual fix: delete/move the corrupted session transcript. Next message starts fresh.

mv ~/.openclaw/agents/main/sessions/<session-id>.jsonl ~/.Trash/

Environment

  • OpenClaw 2026.2.1 (ed4529e)
  • Model: claude-opus-4-5
  • Surface: Telegram group with topics

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