Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Dec 11, 2025

Problem

Users are encountering the following error when the API is called:

ApiError: undefined: Expected toolResult blocks at messages.8.content for the following Ids: toolu_01HqaicajCMgEJ78exc2Wwmg, toolu_01RaoEkKUYn1rErRxepLQGZD

This error occurs when an assistant message contains tool_use blocks but the subsequent user message is missing the corresponding tool_result blocks entirely. This can happen during parallel tool execution scenarios (e.g., when the model tries to execute the new_task tool in parallel with other tools).

Root Cause

The existing validateAndFixToolResultIds() function only fixed ID mismatches between tool_result and tool_use blocks, but didn't handle the case where tool_result blocks are completely missing.

Solution

Enhanced validateAndFixToolResultIds() to:

  1. Detect missing tool_result blocks - Check if any tool_use IDs don't have corresponding tool_result blocks
  2. Report to telemetry - Added MissingToolResultError class for structured error tracking
  3. Auto-fix by adding placeholder blocks - Add missing tool_result blocks with content: "Tool execution was interrupted before completion."

Changes

src/core/task/validateToolResultIds.ts

  • Added new MissingToolResultError class for telemetry tracking
  • Enhanced validation logic to detect and add missing tool_result blocks
  • Added telemetry reporting for missing tool_results

src/core/task/__tests__/validateToolResultIds.spec.ts

  • Added comprehensive tests for:
    • Adding missing tool_result for single/multiple tool_use blocks
    • Partial missing (some exist, some don't)
    • Empty user content arrays
    • MissingToolResultError class
    • Telemetry for missing tool_result detection

Testing

  • All 23 unit tests pass
  • Full test suite passes (4625 tests)

Important

Enhance validateAndFixToolResultIds() to detect and add missing tool_result blocks, with comprehensive tests and telemetry reporting.

  • Behavior:
    • Enhanced validateAndFixToolResultIds() in validateToolResultIds.ts to detect and add missing tool_result blocks.
    • Adds placeholder tool_result blocks with content: "Tool execution was interrupted before completion."
    • Reports missing tool_result blocks using MissingToolResultError.
  • Testing:
    • Added tests in validateToolResultIds.spec.ts for scenarios with missing tool_result blocks, partial matches, and telemetry reporting.
    • Tests cover single/multiple missing tool_result blocks and empty user content arrays.
  • Telemetry:
    • Added MissingToolResultError class for structured error tracking.
    • Reports missing and mismatched tool_result blocks to telemetry.

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

When an assistant message contains tool_use blocks but the subsequent user message
is missing the corresponding tool_result blocks, the API returns a 400 error.

This fix enhances validateAndFixToolResultIds() to:
- Detect missing tool_result blocks (tool_use IDs without corresponding tool_results)
- Report missing tool_results to telemetry for monitoring
- Automatically add placeholder tool_result blocks for any missing tool_use IDs

This addresses the 'Expected toolResult blocks at messages.X.content' error
that can occur during parallel tool execution scenarios (e.g., new_task tool).
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Dec 11, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 11, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation correctly addresses the API error by detecting and adding missing tool_result blocks. The code is well-structured with proper telemetry tracking and comprehensive test coverage.

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 Dec 11, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Dec 11, 2025
@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Dec 11, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 11, 2025
@cte cte merged commit 8731709 into main Dec 11, 2025
24 checks passed
@cte cte deleted the fix/missing-tool-result-blocks branch December 11, 2025 20:02
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Dec 11, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Dec 11, 2025
@cte cte mentioned this pull request Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer PR - Needs Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants