From 214627c64cf5dbc24ef5c6945dcfe368a3a9eaae Mon Sep 17 00:00:00 2001 From: Logan Yang Date: Mon, 15 Dec 2025 21:28:20 -0800 Subject: [PATCH] Fix background tool handling to prevent orphaned spinners in agent conversation (#2072) --- .../chainRunner/AutonomousAgentChainRunner.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/LLMProviders/chainRunner/AutonomousAgentChainRunner.ts b/src/LLMProviders/chainRunner/AutonomousAgentChainRunner.ts index b6b01893..ab8fcea4 100644 --- a/src/LLMProviders/chainRunner/AutonomousAgentChainRunner.ts +++ b/src/LLMProviders/chainRunner/AutonomousAgentChainRunner.ts @@ -766,6 +766,19 @@ ${params} loopDeps.availableTools.filter((tool) => tool.isBackground).map((tool) => tool.name) ); + // Remove any accidental background-tool markers to avoid orphaned spinners + if (currentIterationToolCallMessages.length > 0 && backgroundToolNames.size > 0) { + const backgroundPrefixes = Array.from(backgroundToolNames).map( + (name) => `temporary-tool-call-id-${name}-` + ); + for (let i = currentIterationToolCallMessages.length - 1; i >= 0; i -= 1) { + const message = currentIterationToolCallMessages[i]; + if (backgroundPrefixes.some((prefix) => message.includes(prefix))) { + currentIterationToolCallMessages.splice(i, 1); + } + } + } + const visibleToolNames: string[] = []; toolCalls.forEach((toolCall) => { if (!backgroundToolNames.has(toolCall.name)) { @@ -777,7 +790,9 @@ ${params} if (partialToolName) { const lastToolNameIndex = fullMessage.lastIndexOf(partialToolName); if (fullMessage.length - lastToolNameIndex > STREAMING_TRUNCATE_THRESHOLD) { - visibleToolNames.push(partialToolName); + if (!backgroundToolNames.has(partialToolName)) { + visibleToolNames.push(partialToolName); + } } }