Skip to content

Feature Request: Auto-recovery for corrupted session transcripts (orphan tool_result) #7659

@rojasjuniore

Description

@rojasjuniore

Problem

When a session transcript becomes corrupted with an orphan tool_result block (missing corresponding tool_use), the session becomes permanently broken until manually cleared.

Error message:

400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.24.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."}}

This can happen when:

  • Context truncation removes a tool_use but keeps its tool_result
  • Network errors during tool execution
  • Other edge cases that corrupt the message history

Current Workaround

Manually delete the session transcript file:

rm /data/.clawdbot/agents/main/sessions/<session-id>.jsonl

Proposed Solution

Add an error handler that:

  1. Detects this specific error type when it occurs
  2. Auto-clears the corrupted transcript
  3. Notifies via configured channel (e.g., Slack #alerts)
  4. Retries the original message with a fresh session

This would make OpenClaw self-healing for this class of errors.

Alternative

At minimum, a CLI command to reset a specific session would help:

openclaw session reset <session-key>

Environment

  • OpenClaw version: 2026.2.1
  • Running on Railway
  • Multiple Slack channels as sessions

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions