Skip to content

Conversation

@daniel-lxs
Copy link
Member

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

Summary

Fixes ToolResultIdMismatchError where tool_result IDs didn't match tool_use IDs in API conversation history.

Problem

PostHog reported 926 ToolResultIdMismatchError occurrences in v3.46.0 where tool_result IDs (e.g., functions.read_file:0) didn't match tool_use IDs (e.g., functions_read_file_0).

Root Cause

In Task.ts, when saving tool_use blocks to API conversation history, IDs were sanitized using sanitizeToolUseId(). However, in presentAssistantMessage.ts, when creating tool_result blocks, the original unsanitized toolCallId was used.

Solution

Updated presentAssistantMessage.ts to sanitize toolCallId using sanitizeToolUseId() when creating tool_result blocks, ensuring consistency with how tool_use IDs are stored in history.

Changes

  • Added import for sanitizeToolUseId in presentAssistantMessage.ts
  • Updated all 7 occurrences of tool_use_id: toolCallId to tool_use_id: sanitizeToolUseId(toolCallId)
  • Added test case for the exact pattern seen in PostHog

Testing

  • All existing tests pass (5317 tests)
  • Added test case verifying functions.read_file:0functions_read_file_0 sanitization

Linear Issue

Fixes EXT-711


Important

Fixes ToolResultIdMismatchError by sanitizing toolCallId in presentAssistantMessage.ts to ensure consistent ID format.

  • Behavior:
    • Fixes ToolResultIdMismatchError by sanitizing toolCallId in presentAssistantMessage.ts using sanitizeToolUseId().
    • Ensures tool_result IDs match tool_use IDs in API history.
  • Testing:
    • Adds test case in tool-id.spec.ts for sanitizing functions.read_file:0 to functions_read_file_0.
    • Confirms all existing tests pass (5317 tests).

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

Tool IDs from providers like Gemini/OpenRouter contain special characters
(e.g., 'functions.read_file:0') that are sanitized when saving tool_use
blocks to API history. However, tool_result blocks were using the original
unsanitized IDs, causing ToolResultIdMismatchError.

This fix ensures tool_result blocks use sanitizeToolUseId() to match the
sanitized tool_use IDs in conversation history.

Fixes EXT-711
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners January 31, 2026 04:02
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Jan 31, 2026
@roomote
Copy link
Contributor

roomote bot commented Jan 31, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The fix correctly addresses the ToolResultIdMismatchError by ensuring tool_result IDs are sanitized to match the sanitized tool_use IDs in API history. All 7 occurrences are updated consistently, and the test coverage is appropriate.

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

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 31, 2026
@mrubens mrubens merged commit 3400499 into main Jan 31, 2026
21 checks passed
@mrubens mrubens deleted the feature/ext-711-fix-toolresultidmismatcherror-tool_result-ids-not-sanitized branch January 31, 2026 04:15
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jan 31, 2026
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 size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants