Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 30, 2026

Fixes the issue where the message queue sends messages prematurely during parallel tool execution.

Problem

When multiple parallel tools are being executed, the message queue was sending messages before all tool results were complete. The userMessageContentReady flag was set to true when reaching the last content block, before all tool_result blocks were pushed to userMessageContent.

Root Cause

In presentAssistantMessage.ts, the userMessageContentReady flag was set to true based only on whether we had reached the last content block index. This happened before all parallel tools had completed their pushToolResult() calls.

Solution

Added a helper function areAllToolResultsCollected() that:

  • Counts tool_use and mcp_tool_use blocks in assistantMessageContent
  • Counts tool_result blocks in userMessageContent
  • Returns true only when all tool_use IDs have matching tool_result IDs

The userMessageContentReady flag is now only set to true when:

  1. All content blocks are complete (no partial blocks)
  2. All tool_use blocks have corresponding tool_result blocks
  3. AND the stream is complete or aborted

Testing

  • Added comprehensive test suite in presentAssistantMessage-parallel-tools.spec.ts
  • All 39 existing tests pass
  • TypeScript type checking passes

Files Changed

  • src/core/assistant-message/presentAssistantMessage.ts - Added areAllToolResultsCollected() helper and updated the three locations where userMessageContentReady is set
  • src/core/assistant-message/__tests__/presentAssistantMessage-parallel-tools.spec.ts - New test file for parallel tool execution timing

View task on Roo Code Cloud


Important

Fixes premature message sending by ensuring all tool results are collected before setting userMessageContentReady during parallel tool execution.

  • Behavior:
    • Fixes premature message sending during parallel tool execution by ensuring all tool results are collected before setting userMessageContentReady.
    • Introduces areAllToolResultsCollected() in presentAssistantMessage.ts to verify tool results collection.
  • Testing:
    • Adds presentAssistantMessage-parallel-tools.spec.ts to test parallel tool execution timing.
    • Verifies userMessageContentReady is only set when all conditions are met.
  • Files Changed:
    • presentAssistantMessage.ts: Adds areAllToolResultsCollected() and updates userMessageContentReady logic.
    • presentAssistantMessage-parallel-tools.spec.ts: New test file for parallel tool execution.

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

… (EXT-693)

When multiple parallel tools are executed, the message queue was
proceeding prematurely because userMessageContentReady was set to true
when reaching the last content block, before all tool_result blocks
were pushed to userMessageContent.

This fix adds a helper function areAllToolResultsCollected() that:
- Counts tool_use and mcp_tool_use blocks in assistantMessageContent
- Counts tool_result blocks in userMessageContent
- Only returns true when all tool_use IDs have matching tool_result IDs

The userMessageContentReady flag is now only set to true when:
1. All content blocks are complete (no partial blocks)
2. All tool_use blocks have corresponding tool_result blocks
3. AND the stream is complete or aborted

This prevents the message queue from sending messages before all parallel
tool results are collected.
@roomote
Copy link
Contributor Author

roomote bot commented Jan 30, 2026

Rooviewer Clock   See task on Roo Cloud

Review completed. All previously flagged issues have been addressed.

  • Missing didCompleteReadingStream check at line 1032 in presentAssistantMessage.ts - inconsistent with other locations and PR description
  • Test "should not set userMessageContentReady if stream is not complete" lacks an assertion to verify the expected behavior
Previous reviews

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

// CRITICAL: For parallel tool execution, we must verify all tool results
// are collected before signaling ready. Without this check, the message
// queue could proceed before all tool_result blocks are in userMessageContent.
if (areAllToolResultsCollected(cline)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description states that userMessageContentReady should only be set when the stream is complete or aborted (condition 3). However, this line only checks areAllToolResultsCollected(cline) without also checking didCompleteReadingStream, unlike lines 120 and 1052 which correctly check both conditions. This inconsistency could lead to premature signaling if we're at the last currently-known block and all tool results are collected, but the stream is still active and more tool_use blocks are incoming.

Suggested change
if (areAllToolResultsCollected(cline)) {
if (cline.didCompleteReadingStream && areAllToolResultsCollected(cline)) {

Fix it with Roo Code or mention @roomote and request a fix.

Comment on lines 237 to 240
// Even if the tool executed, userMessageContentReady should NOT be true
// because the stream hasn't completed yet (more content may arrive)
// Note: The fix specifically checks both conditions
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test describes the expected behavior in comments but lacks an actual assertion. The comment says "userMessageContentReady should NOT be true because the stream hasn't completed yet" but the test never verifies this. Without an assertion, this test will always pass regardless of the actual implementation behavior.

Suggested change
// Even if the tool executed, userMessageContentReady should NOT be true
// because the stream hasn't completed yet (more content may arrive)
// Note: The fix specifically checks both conditions
})
// Even if the tool executed, userMessageContentReady should NOT be true
// because the stream hasn't completed yet (more content may arrive)
// Note: The fix specifically checks both conditions
expect(mockTask.userMessageContentReady).toBe(false)

Fix it with Roo Code or mention @roomote and request a fix.

@roomote
Copy link
Contributor Author

roomote bot commented Jan 30, 2026

Fixaroo Clock   See task on Roo Cloud

Fixed the reported issues. All local checks passed.

View commit | Revert commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant