openclaw - 💡(How to fix) Fix lossless-claw: orphaned tool_use blocks in lcm.db after model switch cause permanent Anthropic API failures [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#58924Fetched 2026-04-08 02:31:08
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0

When switching from a non-Anthropic model (e.g. MiniMax M2.7) to an Anthropic model (e.g. Claude Sonnet) mid-conversation, an orphaned `tool_use` block gets written to `lcm.db` without a corresponding `tool_result`. Every subsequent Anthropic API request for that channel then fails permanently with:

``` LLM request rejected: messages.N: tool_use ids were found without tool_result blocks immediately after: <id>. Each tool_use block must have a corresponding tool_result block in the next message. ```

Error Message

  1. Switch back or restart — the error now appears on every Anthropic request for that channel

Root Cause

  • The orphaned block persists in `lcm.db` across gateway restarts, session file deletion, and `sessions.json` cleanup — because lossless-claw assembles context from `lcm.db`, not from `.jsonl` files
  • `repairToolUseResultPairing()` exists in `session-transcript-repair.ts` and is referenced in `TranscriptPolicy`, but does not appear to run on lossless-claw assembled context before Anthropic API calls
  • The only workaround is manually deleting all records for the affected `conversation_id` from `lcm.db` across all tables (`context_items`, `message_parts`, `messages`, `conversations`, etc.) and retiring the `.jsonl` session file

Fix Action

Fix / Workaround

  • The orphaned block persists in `lcm.db` across gateway restarts, session file deletion, and `sessions.json` cleanup — because lossless-claw assembles context from `lcm.db`, not from `.jsonl` files
  • `repairToolUseResultPairing()` exists in `session-transcript-repair.ts` and is referenced in `TranscriptPolicy`, but does not appear to run on lossless-claw assembled context before Anthropic API calls
  • The only workaround is manually deleting all records for the affected `conversation_id` from `lcm.db` across all tables (`context_items`, `message_parts`, `messages`, `conversations`, etc.) and retiring the `.jsonl` session file
RAW_BUFFERClick to expand / collapse

Summary

When switching from a non-Anthropic model (e.g. MiniMax M2.7) to an Anthropic model (e.g. Claude Sonnet) mid-conversation, an orphaned `tool_use` block gets written to `lcm.db` without a corresponding `tool_result`. Every subsequent Anthropic API request for that channel then fails permanently with:

``` LLM request rejected: messages.N: tool_use ids were found without tool_result blocks immediately after: <id>. Each tool_use block must have a corresponding tool_result block in the next message. ```

Steps to Reproduce

  1. Have an agent running on lossless-claw with a non-Anthropic model as primary (e.g. MiniMax)
  2. Switch to an Anthropic model mid-conversation while a tool call is in flight or just completed
  3. Gateway freezes or the switch interrupts the tool_use/tool_result sequence
  4. Switch back or restart — the error now appears on every Anthropic request for that channel

Key Details

  • The orphaned block persists in `lcm.db` across gateway restarts, session file deletion, and `sessions.json` cleanup — because lossless-claw assembles context from `lcm.db`, not from `.jsonl` files
  • `repairToolUseResultPairing()` exists in `session-transcript-repair.ts` and is referenced in `TranscriptPolicy`, but does not appear to run on lossless-claw assembled context before Anthropic API calls
  • The only workaround is manually deleting all records for the affected `conversation_id` from `lcm.db` across all tables (`context_items`, `message_parts`, `messages`, `conversations`, etc.) and retiring the `.jsonl` session file

Expected Behaviour

`repairToolUseResultPairing()` should run on the context assembled by lossless-claw before it's sent to any Anthropic endpoint, inserting synthetic `tool_result` blocks for any orphaned `tool_use` blocks.

Environment

  • OpenClaw: 2026.3.31
  • Plugin: lossless-claw (extensions/lossless-claw)
  • Affected channel: Discord
  • Primary model: minimax/MiniMax-M2.7
  • Failing model: anthropic/claude-sonnet-4-6

extent analysis

TL;DR

Run repairToolUseResultPairing() on the context assembled by lossless-claw before sending it to any Anthropic endpoint to insert synthetic tool_result blocks for orphaned tool_use blocks.

Guidance

  • Verify that repairToolUseResultPairing() is correctly implemented in session-transcript-repair.ts and referenced in TranscriptPolicy.
  • Check if the function is being called before Anthropic API requests, and if not, modify the code to ensure it runs before sending the context to the Anthropic endpoint.
  • Consider adding error handling to prevent similar issues in the future, such as checking for orphaned tool_use blocks before switching models.
  • Manually deleting records for the affected conversation_id from lcm.db and retiring the .jsonl session file can be used as a temporary workaround.

Example

No code snippet is provided as the issue does not contain sufficient information to create a specific example.

Notes

The provided information suggests that the issue is specific to the lossless-claw plugin and the Anthropic model. The workaround of manually deleting records from lcm.db and retiring the .jsonl session file may not be feasible in all scenarios, and a more robust solution would be to ensure repairToolUseResultPairing() is correctly implemented and called.

Recommendation

Apply the workaround of manually deleting records for the affected conversation_id from lcm.db and retiring the .jsonl session file, as a permanent fix would require modifying the code to correctly call repairToolUseResultPairing() before Anthropic API requests.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING