Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Jan 5, 2026

Summary

Fixes vscode-lm provider 400 error where tool_result blocks reference condensed-away tool_use blocks.

Error:

"messages.0.content.0: unexpected `tool_use_id` found in `tool_result` blocks: toolu_vrtx_017zoz78rZkfhPsVf1SJkx1k. Each `tool_result` block must have a corresponding `tool_use` block in the previous message."

Root Cause

  1. validateAndFixToolResultIds() runs when messages are added to history
  2. Condensation happens later - tagging messages with condenseParent
  3. getEffectiveApiHistory() filters out condensed messages
  4. tool_results now reference non-existent tool_uses → 400 error

Solution

Add validation directly in getEffectiveApiHistory() after condensation filtering:

  1. Find the last assistant message using findLast()
  2. Get tool_use blocks from that assistant message
  3. Get tool_results from the following user message
  4. Validate that all tool_result IDs match valid tool_use IDs
  5. If mismatches detected:
    • Report to telemetry with context
    • Fix IDs by position-based matching
    • Remove orphaned tool_results that can't be matched

Efficiency

  • 8 early exit points for fast path when no issues
  • Only processes last 2 messages, not entire history
  • Uses Set for O(1) ID lookups
  • Only creates new arrays when mismatches detected

Test Coverage

  • 18 new tests covering all scenarios
  • Tests include exact bug scenario simulation with condensation
  • All existing condense tests (83) and task tests (124) pass

Linear Issue

Closes ROO-380


Important

Adds validation in getEffectiveApiHistory() to ensure tool_result IDs match existing tool_use IDs after condensation filtering, fixing mismatches and removing orphans.

  • Behavior:
    • Adds validation in getEffectiveApiHistory() to ensure tool_result IDs match existing tool_use IDs after condensation filtering.
    • Fixes mismatched IDs by position-based matching and removes orphaned tool_results.
    • Reports mismatches to telemetry.
  • Efficiency:
    • Early exits for fast path when no issues.
    • Processes only the last 2 messages.
    • Uses Set for O(1) ID lookups.
  • Test Coverage:
    • 18 new tests in getEffectiveApiHistory-tool-validation.spec.ts.
    • Tests cover scenarios including condensation and ID mismatches.
  • Misc:
    • Uses findLast() from array module in index.ts.

This description was created by Ellipsis for 1b6e1a3. You can customize this summary. It will automatically update as commits are pushed.

Fixes vscode-lm provider 400 error where tool_result blocks reference
condensed-away tool_use blocks.

Root cause: validateAndFixToolResultIds() runs when messages are ADDED,
but condensation happens LATER. When getEffectiveApiHistory() filters out
condensed messages, tool_results can reference non-existent tool_uses.

Solution: Add validation directly in getEffectiveApiHistory() after
condensation filtering to fix mismatched IDs by position-based matching.

- 8 early exit points for fast path when no issues
- Only processes last 2 messages, not entire history
- Uses Set for O(1) ID lookups
- Reports mismatches to telemetry

Closes ROO-380
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners January 5, 2026 20:03
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. bug Something isn't working labels Jan 5, 2026
@roomote
Copy link
Contributor

roomote bot commented Jan 5, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation correctly addresses the vscode-lm provider 400 error by validating tool_result IDs after condensation filtering. The code is well-structured with 8 early exit points for performance, comprehensive error handling, and thorough test coverage (18 new tests, all passing).

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jan 5, 2026
@daniel-lxs daniel-lxs closed this Jan 5, 2026
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jan 5, 2026
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jan 5, 2026
@daniel-lxs daniel-lxs deleted the feature/roo-380-fix-vscode-lm-tool-id-mismatch branch January 5, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants