From c0cbc3deee2cc1fdb137575b0327c50a4e1c0911 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Fri, 28 Nov 2025 08:40:18 +0000 Subject: [PATCH] fix: prevent duplicate responses when using native OpenAI tool format - Fixed issue where text content was being duplicated in responses when using native tool format - The problem occurred because text was accumulated in both assistantMessage and assistantMessageContent - Solution: For native protocol with text blocks, use only the text blocks from assistantMessageContent - For XML protocol or native without text blocks, use the accumulated assistantMessage as before Fixes #9669 --- src/core/task/Task.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index c4a52246aa..ded919f3dd 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -2924,8 +2924,23 @@ export class Task extends EventEmitter implements TaskLike { // Build the assistant message content array const assistantContent: Array = [] - // Add text content if present - if (assistantMessage) { + // For native protocol, check if we already have text blocks in assistantMessageContent + // to avoid duplication. For XML protocol, use the accumulated assistantMessage. + const hasTextBlocks = this.assistantMessageContent.some((block) => block.type === "text") + + if (!shouldUseXmlParser && hasTextBlocks) { + // Native protocol with text blocks - use the text blocks from assistantMessageContent + const textBlocks = this.assistantMessageContent.filter((block) => block.type === "text") + for (const block of textBlocks) { + if (block.type === "text" && block.content) { + assistantContent.push({ + type: "text" as const, + text: block.content, + }) + } + } + } else if (assistantMessage) { + // XML protocol or native protocol without text blocks - use accumulated assistantMessage assistantContent.push({ type: "text" as const, text: assistantMessage,