From 28bf52c33d1025aca2cc284343f527b6eb0f28cf Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Mon, 6 Apr 2026 16:35:38 -0700 Subject: [PATCH 1/5] fix(copilot): fix copilot running workflow stuck on 10mb error --- .../copilot/client-sse/run-tool-execution.ts | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/apps/sim/lib/copilot/client-sse/run-tool-execution.ts b/apps/sim/lib/copilot/client-sse/run-tool-execution.ts index 7c80d159840..eef80f97729 100644 --- a/apps/sim/lib/copilot/client-sse/run-tool-execution.ts +++ b/apps/sim/lib/copilot/client-sse/run-tool-execution.ts @@ -290,7 +290,6 @@ function buildResultData(result: unknown): Record | undefined { return { success: r.success, output: r.output, - logs: r.logs, error: r.error, } } @@ -300,7 +299,6 @@ function buildResultData(result: unknown): Record | undefined { return { success: exec.success, output: exec.output, - logs: exec.logs, error: exec.error, } } @@ -320,17 +318,37 @@ async function reportCompletion( data?: Record ): Promise { try { + const payload = { + toolCallId, + status, + message: message || (status === 'success' ? 'Tool completed' : 'Tool failed'), + ...(data ? { data } : {}), + } const res = await fetch(COPILOT_CONFIRM_API_PATH, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - toolCallId, - status, - message: message || (status === 'success' ? 'Tool completed' : 'Tool failed'), - ...(data ? { data } : {}), - }), + body: JSON.stringify(payload), }) - if (!res.ok) { + if (res.status === 413 && data) { + logger.warn('[RunTool] reportCompletion payload too large, retrying without data', { + toolCallId, + }) + const retryRes = await fetch(COPILOT_CONFIRM_API_PATH, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + toolCallId, + status: 'error', + message: 'Workflow execution failed: payload too large', + }), + }) + if (!retryRes.ok) { + logger.warn('[RunTool] reportCompletion retry also failed', { + toolCallId, + status: retryRes.status, + }) + } + } else if (!res.ok) { logger.warn('[RunTool] reportCompletion failed', { toolCallId, status: res.status }) } } catch (err) { From f31181d7b1b614f698186b0149fa1f74246476ba Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Mon, 6 Apr 2026 17:04:07 -0700 Subject: [PATCH 2/5] Use correct try catch --- .../lib/copilot/client-sse/run-tool-execution.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/sim/lib/copilot/client-sse/run-tool-execution.ts b/apps/sim/lib/copilot/client-sse/run-tool-execution.ts index eef80f97729..40ea7cb0e76 100644 --- a/apps/sim/lib/copilot/client-sse/run-tool-execution.ts +++ b/apps/sim/lib/copilot/client-sse/run-tool-execution.ts @@ -290,6 +290,7 @@ function buildResultData(result: unknown): Record | undefined { return { success: r.success, output: r.output, + logs: r.logs, error: r.error, } } @@ -299,6 +300,7 @@ function buildResultData(result: unknown): Record | undefined { return { success: exec.success, output: exec.output, + logs: exec.logs, error: exec.error, } } @@ -318,20 +320,22 @@ async function reportCompletion( data?: Record ): Promise { try { - const payload = { + const body = JSON.stringify({ toolCallId, status, message: message || (status === 'success' ? 'Tool completed' : 'Tool failed'), ...(data ? { data } : {}), - } + }) const res = await fetch(COPILOT_CONFIRM_API_PATH, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(payload), + body, }) - if (res.status === 413 && data) { - logger.warn('[RunTool] reportCompletion payload too large, retrying without data', { + if (!res.ok && data && new Blob([body]).size > 1024 * 1024) { + logger.warn('[RunTool] reportCompletion failed with large payload, retrying without data', { toolCallId, + status: res.status, + bodySize: new Blob([body]).size, }) const retryRes = await fetch(COPILOT_CONFIRM_API_PATH, { method: 'POST', @@ -339,7 +343,7 @@ async function reportCompletion( body: JSON.stringify({ toolCallId, status: 'error', - message: 'Workflow execution failed: payload too large', + message: 'Workflow execution failed: result payload too large', }), }) if (!retryRes.ok) { From 38d46e65c6c66c82aeffbf7ee6c489d9e41ad136 Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Mon, 6 Apr 2026 17:11:07 -0700 Subject: [PATCH 3/5] Add const --- apps/sim/lib/copilot/client-sse/run-tool-execution.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/sim/lib/copilot/client-sse/run-tool-execution.ts b/apps/sim/lib/copilot/client-sse/run-tool-execution.ts index 40ea7cb0e76..f0c88e59e5b 100644 --- a/apps/sim/lib/copilot/client-sse/run-tool-execution.ts +++ b/apps/sim/lib/copilot/client-sse/run-tool-execution.ts @@ -331,7 +331,11 @@ async function reportCompletion( headers: { 'Content-Type': 'application/json' }, body, }) - if (!res.ok && data && new Blob([body]).size > 1024 * 1024) { + // Next.js silently truncates request bodies beyond its body size limit (default 10MB), + // corrupting the JSON and causing a server-side parse error (500). When the request fails + // and the payload is large, retry without the data to unblock the server-side waiter. + const LARGE_PAYLOAD_THRESHOLD = 1024 * 1024 + if (!res.ok && data && new Blob([body]).size > LARGE_PAYLOAD_THRESHOLD) { logger.warn('[RunTool] reportCompletion failed with large payload, retrying without data', { toolCallId, status: res.status, From 9c99c3a7d124804bfab8543800031001f2bb486a Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Mon, 6 Apr 2026 17:17:29 -0700 Subject: [PATCH 4/5] Strip only logs on payload too large --- apps/sim/lib/copilot/client-sse/run-tool-execution.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/sim/lib/copilot/client-sse/run-tool-execution.ts b/apps/sim/lib/copilot/client-sse/run-tool-execution.ts index f0c88e59e5b..059d383167b 100644 --- a/apps/sim/lib/copilot/client-sse/run-tool-execution.ts +++ b/apps/sim/lib/copilot/client-sse/run-tool-execution.ts @@ -333,10 +333,11 @@ async function reportCompletion( }) // Next.js silently truncates request bodies beyond its body size limit (default 10MB), // corrupting the JSON and causing a server-side parse error (500). When the request fails - // and the payload is large, retry without the data to unblock the server-side waiter. + // and the payload is large, retry without logs (the largest field) to fit under the limit. const LARGE_PAYLOAD_THRESHOLD = 1024 * 1024 if (!res.ok && data && new Blob([body]).size > LARGE_PAYLOAD_THRESHOLD) { - logger.warn('[RunTool] reportCompletion failed with large payload, retrying without data', { + const { logs: _logs, ...dataWithoutLogs } = data + logger.warn('[RunTool] reportCompletion failed with large payload, retrying without logs', { toolCallId, status: res.status, bodySize: new Blob([body]).size, @@ -346,8 +347,9 @@ async function reportCompletion( headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ toolCallId, - status: 'error', - message: 'Workflow execution failed: result payload too large', + status, + message: message || (status === 'success' ? 'Tool completed' : 'Tool failed'), + data: dataWithoutLogs, }), }) if (!retryRes.ok) { From 80640908cfd938a1dcacdfe107b46368ce158da5 Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Mon, 6 Apr 2026 18:00:32 -0700 Subject: [PATCH 5/5] Fix threshold --- apps/sim/lib/copilot/client-sse/run-tool-execution.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/sim/lib/copilot/client-sse/run-tool-execution.ts b/apps/sim/lib/copilot/client-sse/run-tool-execution.ts index 059d383167b..2e22fcf6a78 100644 --- a/apps/sim/lib/copilot/client-sse/run-tool-execution.ts +++ b/apps/sim/lib/copilot/client-sse/run-tool-execution.ts @@ -334,13 +334,14 @@ async function reportCompletion( // Next.js silently truncates request bodies beyond its body size limit (default 10MB), // corrupting the JSON and causing a server-side parse error (500). When the request fails // and the payload is large, retry without logs (the largest field) to fit under the limit. - const LARGE_PAYLOAD_THRESHOLD = 1024 * 1024 - if (!res.ok && data && new Blob([body]).size > LARGE_PAYLOAD_THRESHOLD) { + const LARGE_PAYLOAD_THRESHOLD = 10 * 1024 * 1024 + const bodySize = new Blob([body]).size + if (!res.ok && data && bodySize > LARGE_PAYLOAD_THRESHOLD) { const { logs: _logs, ...dataWithoutLogs } = data logger.warn('[RunTool] reportCompletion failed with large payload, retrying without logs', { toolCallId, status: res.status, - bodySize: new Blob([body]).size, + bodySize, }) const retryRes = await fetch(COPILOT_CONFIRM_API_PATH, { method: 'POST',