From c090c821be74b1bc1d0d666f16ba951311ed3389 Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Mon, 16 Mar 2026 17:44:29 -0700 Subject: [PATCH] fix(mothership): add promptForToolApproval to prevent tool hang in mothership chat (#3616) Tools with requiresConfirmation (e.g. user_table) blocked indefinitely in mothership because the frontend has no approval UI. Added a new promptForToolApproval orchestrator option so mothership auto-executes these tools while copilot continues to prompt for user approval. Made-with: Cursor Co-authored-by: Theodore Li --- apps/sim/app/api/copilot/chat/route.ts | 2 ++ apps/sim/app/api/mothership/chat/route.ts | 1 + apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts | 4 ++-- apps/sim/lib/copilot/orchestrator/types.ts | 7 +++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/sim/app/api/copilot/chat/route.ts b/apps/sim/app/api/copilot/chat/route.ts index 57e6575d6c..305280b8f0 100644 --- a/apps/sim/app/api/copilot/chat/route.ts +++ b/apps/sim/app/api/copilot/chat/route.ts @@ -302,6 +302,7 @@ export async function POST(req: NextRequest) { goRoute: '/api/copilot', autoExecuteTools: true, interactive: true, + promptForToolApproval: true, }, }) @@ -315,6 +316,7 @@ export async function POST(req: NextRequest) { goRoute: '/api/copilot', autoExecuteTools: true, interactive: true, + promptForToolApproval: true, }) const responseData = { diff --git a/apps/sim/app/api/mothership/chat/route.ts b/apps/sim/app/api/mothership/chat/route.ts index 8cd9d40cc4..eee1f4c2e0 100644 --- a/apps/sim/app/api/mothership/chat/route.ts +++ b/apps/sim/app/api/mothership/chat/route.ts @@ -262,6 +262,7 @@ export async function POST(req: NextRequest) { goRoute: '/api/mothership', autoExecuteTools: true, interactive: true, + promptForToolApproval: false, onComplete: async (result: OrchestratorResult) => { if (!actualChatId) return diff --git a/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts b/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts index 04c779c08b..fcd6327224 100644 --- a/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts +++ b/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts @@ -320,7 +320,7 @@ export const sseHandlers: Record = { return } - if (requiresConfirmation) { + if (requiresConfirmation && options.promptForToolApproval) { const decision = await waitForToolDecision( toolCallId, options.timeout || STREAM_TIMEOUT_MS, @@ -569,7 +569,7 @@ export const subAgentHandlers: Record = { return } - if (requiresConfirmation) { + if (requiresConfirmation && options.promptForToolApproval) { const decision = await waitForToolDecision( toolCallId, options.timeout || STREAM_TIMEOUT_MS, diff --git a/apps/sim/lib/copilot/orchestrator/types.ts b/apps/sim/lib/copilot/orchestrator/types.ts index 4f912dc498..130666c81e 100644 --- a/apps/sim/lib/copilot/orchestrator/types.ts +++ b/apps/sim/lib/copilot/orchestrator/types.ts @@ -139,6 +139,13 @@ export interface OrchestratorOptions { onError?: (error: Error) => void | Promise abortSignal?: AbortSignal interactive?: boolean + /** + * When true, tools with `requiresConfirmation` will block until the client + * explicitly approves or rejects. When false (e.g. Mothership chat), those + * tools are auto-executed without waiting for user approval. + * Defaults to false. + */ + promptForToolApproval?: boolean } export interface OrchestratorResult {