Skip to content

[Bug] Session compaction causes tool_use_id mismatch in group chats #368

@msqai

Description

@msqai

Description

After session compaction in Telegram group chats, the LLM request fails with:

LLM request rejected: messages.X.content.1: unexpected tool_use_id found in tool_result blocks: toolu_XXXXX. 
Each tool_result block must have a corresponding tool_use block in the previous message.

Steps to Reproduce

  1. Add OpenClaw bot to a Telegram group
  2. Have extended conversations with tool calls
  3. Wait for auto-compaction to trigger (or manually /compact)
  4. Try to send a new message in the group

Expected Behavior

Compaction should maintain valid tool_use/tool_result pairs or remove both together.

Actual Behavior

Compaction removes tool_use blocks but leaves orphaned tool_result blocks, which violates Anthropic API requirements.

Environment

  • OpenClaw version: 2026.2.2-3
  • Compaction mode: safeguard
  • Channel: Telegram groups
  • Model: claude-opus-4-5

Workaround

Delete the corrupted session file:

rm /root/.openclaw/agents/main/sessions/<session-id>.jsonl

Suggested Fix

During compaction, ensure tool_use and tool_result blocks are either both kept or both removed together.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions