Skip to content

fix: sanitize tool_use_id in tool_result blocks to match API history#11131

Merged
mrubens merged 1 commit intomainfrom
feature/ext-711-fix-toolresultidmismatcherror-tool_result-ids-not-sanitized
Jan 31, 2026
Merged

fix: sanitize tool_use_id in tool_result blocks to match API history#11131
mrubens merged 1 commit intomainfrom
feature/ext-711-fix-toolresultidmismatcherror-tool_result-ids-not-sanitized

Conversation

@daniel-lxs
Copy link
Copy Markdown
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-v0
Copy link
Copy Markdown
Contributor

roomote-v0 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
Copilot AI added a commit to dreness/Roo-Code that referenced this pull request Feb 1, 2026
Copilot AI added a commit to dreness/Roo-Code that referenced this pull request Feb 1, 2026
- Traced bug introduction to v3.40.0 (Jan 13, 2026) via PR RooCodeInc#10649
- Bug persisted for 18 days across versions 3.40.x through 3.46.0
- Fixed in v3.46.1 (Jan 31, 2026) via PR RooCodeInc#11131
- Added detailed version timeline showing affected releases
- Documented that prior versions had no mismatch errors but had API validation errors instead

Co-authored-by: dreness <[email protected]>
mini2s referenced this pull request in zgsm-ai/costrict Feb 1, 2026
* feat(providers): add gpt-5.2-codex model to openai-native provider (#10731)

* feat(e2e): Enable E2E tests - 39 passing tests (#10720)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>

* Clear terminal output buffers to prevent memory leaks (#7666)

* feat: add OpenAI Codex provider with OAuth subscription authentication (#10736)

Co-authored-by: Roo Code <[email protected]>

* fix(litellm): inject dummy thought signatures on ALL tool calls for Gemini (#10743)

* fix(e2e): add alwaysAllow config for MCP time server tools (#10733)

* Release v3.41.0 (#10746)

* Changeset version bump (#10747)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* feat: clarify Slack and Linear are Cloud Team only features (#10748)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Matt Rubens <[email protected]>

* Release: v1.106.0 (#10749)

* refactor(chat): replace current task display with last user feedback

* style(chat): adjust feedback text width calculation

* fix: handle missing tool identity in OpenAI Native streams (#10719)

* Feat/issue 5376 aggregate subtask costs (#10757)

* feat(chat): add streaming state to task header interaction

* feat: add settings tab titles to search index (#10761)

Co-authored-by: Roo Code <[email protected]>

* fix: filter Ollama models without native tool support (#10735)

* fix: filter out empty text blocks from user messages for Gemini compatibility (#10728)

* fix: flatten top-level anyOf/oneOf/allOf in MCP tool schemas (#10726)

* fix: prevent duplicate tool_use IDs causing API 400 errors (#10760)

* fix: truncate call_id to 64 chars for OpenAI Responses API (#10763)

* fix: Gemini thought signature validation errors (#10694)

Co-authored-by: Roo Code <[email protected]>

* Release v3.41.1 (#10767)

* Changeset version bump (#10768)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* feat: add button to open markdown in VSCode preview (#10773)

Co-authored-by: Roo Code <[email protected]>

* fix(openai-codex): reset invalid model selection (#10777)

* fix: add openai-codex to providers that don't require API key (#10786)

Co-authored-by: Roo Code <[email protected]>

* fix(litellm): detect Gemini models with space-separated names for thought signature injection (#10787)

* Release v3.41.2 (#10788)

* Changeset version bump (#10790)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* Roo Code Router fixes for the cli (#10789)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>

* Revert "feat(e2e): Enable E2E tests - 39 passing tests" (#10794)

Co-authored-by: Hannes Rudolph <[email protected]>

* Claude-like cli flags, auth fixes (#10797)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
Co-authored-by: Roo Code <[email protected]>

* Release cli v0.0.47 (#10798)

* Use a redirect instead of a fetch for cli auth (#10799)

* chore(cli): prepare release v0.0.48 (#10800)

* Fix thinking block word-breaking to prevent horizontal scroll (#10806)

Co-authored-by: Roo Code <[email protected]>

* chore: add changeset for v3.41.3 (#10822)

* Removal of glm4 6 (#10815)

Co-authored-by: Matt Rubens <[email protected]>

* Changeset version bump (#10823)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* feat: warn users when too many MCP tools are enabled (#10772)

* feat: warn users when too many MCP tools are enabled

- Add WarningRow component for displaying generic warnings with icon, title, message, and optional docs link
- Add TooManyToolsWarning component that shows when users have more than 40 MCP tools enabled
- Add MAX_MCP_TOOLS_THRESHOLD constant (40)
- Add i18n translations for the warning message
- Integrate warning into ChatView to display after task header
- Add comprehensive tests for both components

Closes ROO-542

* Moves constant to the right place

* Move it to the backend

* i18n

* Add actionlink that takes you to MCP settings in this case

* Add to MCP settings too

* Bump max tools up to 60 since github itself has 50+

* DRY

* Fix test

---------

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Bruno Bergher <[email protected]>
Co-authored-by: Matt Rubens <[email protected]>

* Support different cli output formats: text, json, streaming json (#10812)

Co-authored-by: Roo Code <[email protected]>

* chore(cli): prepare release v0.0.49 (#10825)

* fix(cli): set integrationTest to true in ExtensionHost constructor (#10826)

* fix(cli): fix quiet mode tests by capturing console before host creation (#10827)

* refactor: unify user content tags to <user_message> (#10723)

Co-authored-by: Roo Code <[email protected]>

* feat(openai-codex): add ChatGPT subscription usage limits dashboard (#10813)

* perf(webview): avoid resending taskHistory in state updates (#10842)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>

* Fix broken link on pricing page (#10847)

* fix: update broken pricing link to /models page

* Update apps/web-roo-code/src/app/pricing/page.tsx

---------

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Bruno Bergher <[email protected]>

* Git worktree management (#10458)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Hannes Rudolph <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>

* feat: enable prompt caching for Cerebras zai-glm-4.7 model (#10670)

Co-authored-by: Roo Code <[email protected]>

* feat: add Kimi K2 thinking model to VertexAI provider (#9269)

Co-authored-by: Roo Code <[email protected]>

* feat: standardize model selectors across all providers (#10294)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
Co-authored-by: Roo Code <[email protected]>

* chore: remove XML tool calling support (#10841)

Co-authored-by: daniel-lxs <[email protected]>
Co-authored-by: Matt Rubens <[email protected]>

* Fix broken link on pricing page (#10847)

* fix: update broken pricing link to /models page

* Update apps/web-roo-code/src/app/pricing/page.tsx

---------

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Bruno Bergher <[email protected]>

* Pr 10853 (#10854)

Co-authored-by: Roo Code <[email protected]>

* Git worktree management (#10458)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Hannes Rudolph <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>

* feat: enable prompt caching for Cerebras zai-glm-4.7 model (#10670)

Co-authored-by: Roo Code <[email protected]>
(cherry picked from commit c7ce8aa)

* feat: add Kimi K2 thinking model to VertexAI provider (#9269)

Co-authored-by: Roo Code <[email protected]>
(cherry picked from commit a060915)

* feat: standardize model selectors across all providers (#10294)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
Co-authored-by: Roo Code <[email protected]>
(cherry picked from commit e356d05)

* fix: resolve race condition in context condensing prompt input (#10876)

* Copy: update /slack page messaging (#10869)

copy: update /slack page messaging

- Update trial CTA to 'Start a free 14 day Team trial'
- Replace 'humans' with 'your team' in value props subtitle
- Shorten value prop titles for consistent one-line display
- Improve Thread-aware and Open to all descriptions

* fix: Handle mode selector empty state on workspace switch (#9674)

* fix: handle mode selector empty state on workspace switch

When switching between VS Code workspaces, if the current mode from
workspace A is not available in workspace B, the mode selector would
show an empty string. This fix adds fallback logic to automatically
switch to the default "code" mode when the current mode is not found
in the available modes list.

Changes:
- Import defaultModeSlug from @roo/modes
- Add fallback logic in selectedMode useMemo to detect when current
  mode is not available and automatically switch to default mode
- Add tests to verify the fallback behavior works correctly
- Export defaultModeSlug in test mock for consistent behavior

* fix: prevent infinite loop by moving fallback notification to useEffect

* fix: prevent infinite loop by using ref to track notified invalid mode

* refactor: clean up comments in ModeSelector fallback logic

---------

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>

* Roo to main remove xml (#936)

* Fix broken link on pricing page (#10847)

* fix: update broken pricing link to /models page

* Update apps/web-roo-code/src/app/pricing/page.tsx

---------

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Bruno Bergher <[email protected]>

* Git worktree management (#10458)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Hannes Rudolph <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>

* feat: enable prompt caching for Cerebras zai-glm-4.7 model (#10670)

Co-authored-by: Roo Code <[email protected]>

* feat: add Kimi K2 thinking model to VertexAI provider (#9269)

Co-authored-by: Roo Code <[email protected]>

* feat: standardize model selectors across all providers (#10294)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
Co-authored-by: Roo Code <[email protected]>

* chore: remove XML tool calling support (#10841)

Co-authored-by: daniel-lxs <[email protected]>
Co-authored-by: Matt Rubens <[email protected]>

* Pr 10853 (#10854)

Co-authored-by: Roo Code <[email protected]>

* feat(commit): enhance git diff handling for new repositories

* feat(task): support fake_tool_call for Qwen model with XML tool call format

* feat(prompts): add snapshots for custom instructions and system prompt variations

---------

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Bruno Bergher <[email protected]>
Co-authored-by: Chris Estreich <[email protected]>
Co-authored-by: Hannes Rudolph <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>
Co-authored-by: Matt Rubens <[email protected]>
Co-authored-by: MP <[email protected]>

* feat: remove Claude