fix: prevent duplicate tool results by adding existence check (#7419)

* fix: prevent duplicate tool results by adding existence check

Add a check in ToolResultUtils to skip adding a tool result if one already exists for the same tool_use_id, logging a warning to avoid redundant entries in userMessageContent and maintain message integrity. Introduces Logger import for warning output.

* add changeset
This commit is contained in:
Bee authored and GitHub committed 2025-11-11 21:37:11 -08:00
1 parent 87c6708fbe
commit 3be3ffae4c
2 files changed
+14

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"claude-dev": patch
---
Prevents adding multiple tool results by adding existence check
@@ -3,6 +3,7 @@ import { ToolUse } from "@core/assistant-message"
import { formatResponse } from "@core/prompts/responses"
import { ToolResponse } from "@core/task"
import { processFilesIntoText } from "@/integrations/misc/extract-text"
import { Logger } from "@/services/logging/Logger"
import { ClineAsk } from "@/shared/ExtensionMessage"
import type { ToolExecutorCoordinator } from "../ToolExecutorCoordinator"
import { TaskConfig } from "../types/TaskConfig"
@@ -38,6 +39,14 @@ export class ToolResultUtils {
// Get tool_use_id from map, or use "cline" as fallback for backward compatibility
const toolUseId = toolUseIdMap?.get(block.name) || "cline"
// If we have already added a tool result for this tool use, skip adding another one
if (
userMessageContent.some((item) => item.type === "tool_result" && item.tool_use_id === toolUseId && item.content)
) {
Logger.warn(`ToolResultUtils: Tool result for tool_use_id ${toolUseId} already exists. Skipping duplicate.`)
return
}
// Create ToolResultBlockParam with description and result
userMessageContent.push(ToolResultUtils.createToolResultBlock(`${description} Result:\n${resultText}`, toolUseId))
} else {