⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@daniel-lxs
Copy link
Member

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

Problem

After multiple condensations, tool_use blocks preserved in earlier summary messages can end up outside the bounded search window of N_MESSAGES_TO_KEEP (3 messages). This causes orphaned tool_result blocks that trigger 400 errors from the API:

messages.0.content.0: unexpected tool_use_id found in tool_result blocks

Root Cause

The bounded search in getKeepMessagesWithToolBlocks was too restrictive:

// Only searches 3 messages before the keep boundary
const searchStart = startIndex - 1
const searchEnd = Math.max(0, startIndex - N_MESSAGES_TO_KEEP)
const messagesToSearch = messages.slice(searchEnd, searchStart + 1)

After multiple condensations, tool_use blocks can be in earlier summary messages that are outside this window.

Solution

Changed the search to cover the entire condensed region:

// Search the entire condensed region (from index 0 to startIndex-1)
const messagesToSearch = messages.slice(0, startIndex)

Tests

Added two new tests:

  • should find tool_use even when it is far back in the message history (ROO-520 fix)
  • should find tool_use in previous summary message after multiple condensations (ROO-520)

Fixes: https://linear.app/roocode/issue/ROO-520


Important

Expands search range for tool_use blocks in condensed regions to prevent API errors, with new tests added.

  • Behavior:
    • Expands search range in getKeepMessagesWithToolBlocks to cover entire condensed region, preventing orphaned tool_result blocks.
    • Fixes API 400 errors due to unexpected tool_use_id in tool_result blocks.
  • Tests:
    • Adds test should find tool_use even when it is far back in the message history (ROO-520 fix).
    • Adds test should find tool_use in previous summary message after multiple condensations (ROO-520).
  • Misc:
    • Minor formatting changes in README.md and page.tsx.
    • Removes unused mocks in useMcpToolTool.spec.ts.

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

The bounded search window in getKeepMessagesWithToolBlocks was too
restrictive after multiple condensations. When tool_use blocks are
preserved in earlier summary messages, they can end up outside the
N_MESSAGES_TO_KEEP search window, causing orphaned tool_result blocks
that trigger 400 errors from the API.

Changed the search to cover the entire condensed region (from index 0
to startIndex-1) instead of just the last N_MESSAGES_TO_KEEP messages.

Fixes: https://linear.app/roocode/issue/ROO-520
@daniel-lxs daniel-lxs requested a review from jr as a code owner January 15, 2026 16:33
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jan 15, 2026
@roomote
Copy link
Contributor

roomote bot commented Jan 15, 2026

Rooviewer Clock   See task on Roo Cloud

Re-review complete for latest update. No issues found.

  • No issues found
Previous reviews

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 23, 2026
@mrubens
Copy link
Collaborator

mrubens commented Jan 24, 2026

@roomote can you fix the conflicts here?

@roomote
Copy link
Contributor

roomote bot commented Jan 24, 2026

Fixaroo Clock   See task on Roo Cloud

Resolved merge conflicts by accepting main's changes. The getKeepMessagesWithToolBlocks function was removed in main, making the ROO-520 fix obsolete. All local checks passed.

View commit | Revert commit

The getKeepMessagesWithToolBlocks function and related code were removed
in main, making the ROO-520 fix obsolete. Accepting main changes.

Also fixed type error in useMcpToolTool.spec.ts where invalid properties
were passed to ToolCallbacks.
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jan 24, 2026
@github-actions
Copy link
Contributor

🚀 Preview deployed!

Your changes have been deployed to Vercel:

Preview URL: https://roo-code-website-dal7uoh3u-roo-code.vercel.app

This preview will be updated automatically when you push new commits to this PR.

@mrubens mrubens closed this Jan 24, 2026
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jan 24, 2026
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jan 24, 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

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants