Skip to content

Commit 231bade

Browse files
committed
fix: prevent duplicate tool_result blocks in native tool protocol
1 parent ad1e9a8 commit 231bade

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ export async function presentAssistantMessage(cline: Task) {
277277
break
278278
}
279279

280+
// Track if we've already pushed a tool result for this tool call (native protocol only)
281+
let hasToolResult = false
282+
280283
const pushToolResult = (content: ToolResponse) => {
281284
// Check if we're using native tool protocol
282285
const toolProtocol = vscode.workspace
@@ -288,6 +291,14 @@ export async function presentAssistantMessage(cline: Task) {
288291
const toolCallId = (block as any).id
289292

290293
if (isNative && toolCallId) {
294+
// For native protocol, only allow ONE tool_result per tool call
295+
if (hasToolResult) {
296+
console.warn(
297+
`[presentAssistantMessage] Skipping duplicate tool_result for tool_use_id: ${toolCallId}`,
298+
)
299+
return
300+
}
301+
291302
// For native protocol, add as tool_result block
292303
let resultContent: string
293304
if (typeof content === "string") {
@@ -312,6 +323,8 @@ export async function presentAssistantMessage(cline: Task) {
312323
tool_use_id: toolCallId,
313324
content: resultContent,
314325
} as Anthropic.ToolResultBlockParam)
326+
327+
hasToolResult = true
315328
} else {
316329
// For XML protocol, add as text blocks (legacy behavior)
317330
cline.userMessageContent.push({ type: "text", text: `${toolDescription()} Result:` })

0 commit comments

Comments
 (0)