fix: add explicit native toolProtocol check for parallel subtask queuing

This commit is contained in:
daniel-lxs 2025-12-02 14:58:19 -05:00
parent 7ada0df3af
commit 56f7be6c7f
No known key found for this signature in database
GPG key ID: 21C74479048B3AA6
2 changed files with 7 additions and 4 deletions

View file

@ -147,13 +147,16 @@ export class NewTaskTool extends BaseTool<"new_task"> {
task.checkpointSave(true)
}
// Queue this new_task if there are:
// Queue this new_task if using native tool protocol AND there are:
// 1. Multiple new_task blocks (to execute sequentially), OR
// 2. Any remaining tool blocks after this one (so they can execute before delegation)
// NOTE: XML protocol processes tools one at a time, so this condition is always false for XML.
// We add an explicit check for clarity and defensive safety.
const isNativeToolProtocol = toolProtocol === "native"
const newTaskBlockCount = countNewTaskBlocks(task)
const hasRemainingTools = hasRemainingToolBlocks(task)
if (newTaskBlockCount > 1 || hasRemainingTools) {
if (isNativeToolProtocol && (newTaskBlockCount > 1 || hasRemainingTools)) {
task.pendingSubtasks.push({
toolCallId: toolCallId ?? "",
message: unescapedMessage,

View file

@ -775,7 +775,7 @@ describe("newTaskTool parallel execution", () => {
handleError: vi.fn(),
pushToolResult: mockPushToolResult,
removeClosingTag: vi.fn((_: string, v?: string) => v ?? ""),
toolProtocol: "xml",
toolProtocol: "native", // Native protocol is required for parallel tool execution
toolCallId: "tool-1",
})
@ -802,7 +802,7 @@ describe("newTaskTool parallel execution", () => {
handleError: vi.fn(),
pushToolResult: mockPushToolResult,
removeClosingTag: vi.fn((_: string, v?: string) => v ?? ""),
toolProtocol: "xml",
toolProtocol: "native", // Native protocol is required for parallel tool execution
toolCallId: "tool-2",
})