Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/core/task/__tests__/Task.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1967,3 +1967,40 @@ describe("Queued message processing after condense", () => {
expect(taskB.messageQueueService.isEmpty()).toBe(true)
})
})

describe("Partial tool_use blocks at stream end", () => {
/**
* Regression test for: https://github.com/RooCodeInc/Roo-Code/pull/9758
*
* The bug: malformed native tool calls leave partial=true, causing infinite hang.
*
* The fix at Task.ts line ~2947 must be:
* if (partialBlocks.length > 0) { presentAssistantMessage(this) }
*
* THE BROKEN CONDITION (causes infinite hang):
* if (partialBlocks.length > 0 && partialBlocks.some(block => block.type !== "tool_use"))
*
* This test reads the actual Task.ts source code and verifies the fix is correct.
*/
it("Task.ts must NOT filter out tool_use blocks when calling presentAssistantMessage", async () => {
const fs = await import("fs")
const path = await import("path")

// Read Task.ts source
const taskTsPath = path.join(__dirname, "..", "Task.ts")
const taskSource = fs.readFileSync(taskTsPath, "utf-8")

// The BROKEN pattern we must NOT have:
const hasBrokenCondition = taskSource.includes('partialBlocks.some((block) => block.type !== "tool_use")')

// The CORRECT pattern we MUST have:
const hasCorrectCondition = taskSource.includes(
Copy link
Contributor

Choose a reason for hiding this comment

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

The check for the correct condition relies on an exact string (with specific newline and tab characters), which could be brittle if formatting changes. Consider using a regex that ignores whitespace differences.

"if (partialBlocks.length > 0) {\n\t\t\t\t\t// If there is content to update",
)
Comment on lines +1997 to +1999
Copy link
Contributor

Choose a reason for hiding this comment

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

The test's string matching for the correct condition is brittle because it relies on exact whitespace and comment text. The test checks for "if (partialBlocks.length > 0) {\n\t\t\t\t\t// If there is content to update" but this will fail if: 1) the code is reformatted with different indentation (tabs vs spaces, or different tab count), 2) the comment text is modified or extended, or 3) code formatting tools normalize the whitespace. Consider using a regex pattern that's more flexible about whitespace, such as /if\s*\(\s*partialBlocks\.length\s*>\s*0\s*\)/ to match just the conditional logic without depending on exact formatting.

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


// The code MUST NOT use the broken condition (filtering out tool_use)
expect(hasBrokenCondition).toBe(false)
// The code MUST use the correct condition (simple length check)
expect(hasCorrectCondition).toBe(true)
})
})
Loading