From 95b17ff8209161c7bf7cedd2296326b06c8abf12 Mon Sep 17 00:00:00 2001 From: waleed Date: Tue, 17 Mar 2026 15:58:55 -0700 Subject: [PATCH] fix(copilot): abort in-progress tools when stream ends Calls abortAllInProgressTools in the stream_end handler so tools stuck in generating/executing state are resolved when the stream closes, regardless of whether a done event was received. Co-Authored-By: Claude Sonnet 4.6 --- apps/sim/lib/copilot/client-sse/handlers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/sim/lib/copilot/client-sse/handlers.ts b/apps/sim/lib/copilot/client-sse/handlers.ts index 0330853d69c..7705e1cf3dd 100644 --- a/apps/sim/lib/copilot/client-sse/handlers.ts +++ b/apps/sim/lib/copilot/client-sse/handlers.ts @@ -3,6 +3,7 @@ import { STREAM_STORAGE_KEY } from '@/lib/copilot/constants' import { asRecord } from '@/lib/copilot/orchestrator/sse/utils' import type { SSEEvent } from '@/lib/copilot/orchestrator/types' import { + abortAllInProgressTools, isBackgroundState, isRejectedState, isReviewState, @@ -956,7 +957,7 @@ export const sseHandlers: Record = { })) context.streamComplete = true }, - stream_end: (_data, context, _get, set) => { + stream_end: (_data, context, get, set) => { if (context.pendingContent) { if (context.isInThinkingBlock && context.currentThinkingBlock) { appendThinkingContent(context, context.pendingContent) @@ -967,6 +968,7 @@ export const sseHandlers: Record = { } finalizeThinkingBlock(context) updateStreamingMessage(set, context) + abortAllInProgressTools(set, get) }, default: () => {}, }