fix: prevent duplicated tool call rendering in parallel execution

Explicitly marks all tool_use blocks as non-partial after finalization
to prevent race conditions where tools might still have partial=true.

Fixes EXT-634
This commit is contained in:
daniel-lxs 2026-01-27 00:59:22 -05:00 committed by Hannes Rudolph
parent 6e08ae4bfd
commit 6eafee94b7

View file

@ -3283,6 +3283,17 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
}
}
// CRITICAL FIX: Explicitly mark ALL tool_use blocks as non-partial after finalization.
// This prevents race conditions where tools might still have partial=true if:
// - toolUseIndex was undefined during finalization (tool already removed from tracking)
// - finalizeStreamingToolCall returned null but tool exists in assistantMessageContent
// Without this, the first tool in a parallel batch could be presented twice.
for (const block of this.assistantMessageContent) {
if ((block.type === "tool_use" || block.type === "mcp_tool_use") && block.partial) {
block.partial = false
}
}
// IMPORTANT: Capture partialBlocks AFTER finalizeRawChunks() to avoid double-presentation.
// Tools finalized above are already presented, so we only want blocks still partial after finalization.
const partialBlocks = this.assistantMessageContent.filter((block) => block.partial)