Skip to content

[Bug]: [Bug] Synthetic error repair creates malformed tool_use/tool_result pairs - session permanently broken #8264

@imranrashiddk-oss

Description

@imranrashiddk-oss

OpenClaw's transcript repair mechanism attempts to fix missing tool results by inserting synthetic errors, but creates a tool_use/tool_result ID mismatch that permanently breaks the session. Even openclaw session reset cannot recover - only manual deletion of session files works.

Steps to reproduce

  1. Experience a tool result loss (network interruption, gateway restart, or timing issue during tool execution)
  2. OpenClaw detects missing result and logs: [openclaw] missing tool result in session history; inserted synthetic error result for transcript repair.
  3. Send any new message to the session
  4. Observe: Every request fails with 400 error about unexpected tool_use_id
    Expected behavior

When inserting synthetic error results, OpenClaw should:

• Verify the corresponding tool_use block exists in the previous message
• Skip synthetic insertion if tool_use is missing (fail gracefully)
• OR reconstruct the full tool_use/tool_result pair correctly
• Validate the repair before persisting to session file
Actual behavior

  1. Synthetic repair creates tool_result referencing a tool_use_id that doesn't exist in the previous message
  2. Session becomes permanently broken
  3. Every subsequent request (including openclaw session reset) fails with same error:
    HTTP 400 invalid_request_error: messages.254.content.1: unexpected tool_use_id found in tool_result blocks: toolu_01H4RzKvgMZxs7diWx2VX9FS. Each tool_result block must have a corresponding tool_use block in the previous message.
  4. Only fix is nuclear: rm -rf ~/.openclaw/sessions/main
    Environment

• OpenClaw version: 2026.2.3 (latest)
• OS: macOS Darwin 25.2.0 (arm64)
• Install method: npm global install
• Node: v22.22.0
• Model: anthropic/claude-sonnet-4-5
• Session: main (webchat)
Logs or screenshots

Session Log Pattern:
🛠️ Exec {} [openclaw] missing tool result in session history; inserted synthetic error result for transcript repair.
terminated
Error (repeated on every message):
HTTP 400 invalid_request_error: messages.254.content.1: unexpected tool_use_id found in tool_result blocks: toolu_01H4RzKvgMZxs7diWx2VX9FS. Each tool_result block must have a corresponding tool_use block in the previous message. (request_id: req_011CXm7oRsUVsBoVoKoAmqW8)
Workaround:

Backup first (CRITICAL)

cp -r ~/.openclaw/sessions ~/.openclaw/sessions_backup_$(date +%Y%m%d_%H%M%S)

Nuclear option - clear the corrupted session

rm -rf ~/.openclaw/sessions/main

Restart gateway

openclaw gateway restart
Related Issues

#7659 - Feature Request: Auto-recovery for corrupted session transcripts
#5430 - Session Corruption Bug: Terminated Tool Calls
#5857 - Malformed tool_use blocks corrupt session history
This is a variant where the repair mechanism itself creates corruption.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions