From 23e96688efcf485d937d043ad9ea9fe1d54ddb7a Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan Date: Tue, 17 Mar 2026 13:13:46 -0700 Subject: [PATCH 1/2] Fix mothership tool scheduling --- .../orchestrator/sse/handlers/handlers.ts | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts b/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts index fcd6327224..7c6b30c7f1 100644 --- a/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts +++ b/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts @@ -396,16 +396,21 @@ export const sseHandlers: Record = { return } - // Auto-allowed client-executable tool: client runs it, we wait for completion. + // Client-executable tool: if the server can handle it, execute server-side. + // Otherwise wait for the client (React UI) to complete it. if (clientExecutable) { - toolCall.status = 'executing' - const completion = await waitForToolCompletion( - toolCallId, - options.timeout || STREAM_TIMEOUT_MS, - options.abortSignal - ) - handleClientCompletion(toolCall, toolCallId, completion) - await emitSyntheticToolResult(toolCallId, toolCall.name, completion, options) + if (isToolAvailableOnSimSide(toolName)) { + fireToolExecution() + } else { + toolCall.status = 'executing' + const completion = await waitForToolCompletion( + toolCallId, + options.timeout || STREAM_TIMEOUT_MS, + options.abortSignal + ) + handleClientCompletion(toolCall, toolCallId, completion) + await emitSyntheticToolResult(toolCallId, toolCall.name, completion, options) + } return } @@ -643,14 +648,18 @@ export const subAgentHandlers: Record = { } if (clientExecutable) { - toolCall.status = 'executing' - const completion = await waitForToolCompletion( - toolCallId, - options.timeout || STREAM_TIMEOUT_MS, - options.abortSignal - ) - handleClientCompletion(toolCall, toolCallId, completion) - await emitSyntheticToolResult(toolCallId, toolCall.name, completion, options) + if (isToolAvailableOnSimSide(toolName)) { + fireToolExecution() + } else { + toolCall.status = 'executing' + const completion = await waitForToolCompletion( + toolCallId, + options.timeout || STREAM_TIMEOUT_MS, + options.abortSignal + ) + handleClientCompletion(toolCall, toolCallId, completion) + await emitSyntheticToolResult(toolCallId, toolCall.name, completion, options) + } return } From d90de25bac78cf0aaf71305e1e9da95c33ef8a19 Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan Date: Tue, 17 Mar 2026 13:22:57 -0700 Subject: [PATCH 2/2] Fix --- .../sim/lib/copilot/orchestrator/sse/handlers/handlers.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts b/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts index 7c6b30c7f1..d0431b59cd 100644 --- a/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts +++ b/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts @@ -296,7 +296,7 @@ export const sseHandlers: Record = { return } - if (!isToolAvailableOnSimSide(toolName)) { + if (!isToolAvailableOnSimSide(toolName) && !clientExecutable) { return } @@ -396,8 +396,8 @@ export const sseHandlers: Record = { return } - // Client-executable tool: if the server can handle it, execute server-side. - // Otherwise wait for the client (React UI) to complete it. + // Client-executable tool: execute server-side if available, otherwise + // delegate to the client (React UI) and wait for completion. if (clientExecutable) { if (isToolAvailableOnSimSide(toolName)) { fireToolExecution() @@ -553,7 +553,7 @@ export const subAgentHandlers: Record = { return } - if (!isToolAvailableOnSimSide(toolName)) { + if (!isToolAvailableOnSimSide(toolName) && !clientExecutable) { return }