Skip to content

fix: prevent tool_use/tool_result pairing issues + add diagnostics#3130

Closed
kastrah wants to merge 5 commits intoopenclaw:mainfrom
kastrah:fix/tool-use-result-pairing
Closed

fix: prevent tool_use/tool_result pairing issues + add diagnostics#3130
kastrah wants to merge 5 commits intoopenclaw:mainfrom
kastrah:fix/tool-use-result-pairing

Conversation

@kastrah
Copy link

@kastrah kastrah commented Jan 28, 2026

Summary

Fixes 'tool id not found' errors (MiniMax error 2013) by:

  1. Fix history truncation bug - When dmHistoryLimit truncates conversation history, matching tool_use + tool_result pairs are now preserved together.

  2. Move sanitizer to common path - The sanitizeToolUseResultPairing function now runs for all providers (Google, Anthropic, MiniMax), not just Google.

  3. Add session health diagnostics:

    • diagnoseSessionHealth() - detects orphaned tool results, unmatched calls, duplicates
    • logSessionDiagnostics() - human-readable diagnostic output
  4. Add CLI diagnostic command:

    • moltbot sessions health - check sessions for tool pairing issues
    • moltbot sessions health --verbose - show detailed diagnostics
    • moltbot sessions health --session-id - check specific session
  5. Documentation - Added troubleshooting guide for tool id not found errors.

Testing

  • All existing tests pass
  • Manual verification: sessions cleared and gateway restarted successfully

Breaking changes

None.

Checklist

  • Tests pass
  • Lint clean
  • Build succeeds

- Fix limitHistoryTurns to include matching tool_use when truncating tool_result
- Move sanitizeToolUseResultPairing to attempt.ts for all providers
- Prevents 'tool id not found' error when dmHistoryLimit truncates sessions
- Add diagnoseSessionHealth() function to detect orphaned tool results
- Add logSessionDiagnostics() for human-readable diagnostic output
- Add 'sessions health' CLI command to check all sessions or specific ones
- Commands: moltbot sessions health [--verbose] [--session-id XYZ]
@openclaw-barnacle openclaw-barnacle bot added docs Improvements or additions to documentation cli CLI command changes commands Command implementations agents Agent runtime and tooling labels Jan 28, 2026
@kastrah kastrah closed this Jan 31, 2026
@kastrah kastrah deleted the fix/tool-use-result-pairing branch January 31, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes commands Command implementations docs Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant