Skip to content

Commit df2c47a

Browse files
TheodoreSpeaksTheodore Li
andauthored
fix(copilot): fix copilot running workflow stuck on 10mb error (#3999)
* fix(copilot): fix copilot running workflow stuck on 10mb error * Use correct try catch * Add const * Strip only logs on payload too large * Fix threshold --------- Co-authored-by: Theodore Li <theo@sim.ai>
1 parent 25b4a3f commit df2c47a

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

apps/sim/lib/copilot/client-sse/run-tool-execution.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,46 @@ async function reportCompletion(
320320
data?: Record<string, unknown>
321321
): Promise<void> {
322322
try {
323+
const body = JSON.stringify({
324+
toolCallId,
325+
status,
326+
message: message || (status === 'success' ? 'Tool completed' : 'Tool failed'),
327+
...(data ? { data } : {}),
328+
})
323329
const res = await fetch(COPILOT_CONFIRM_API_PATH, {
324330
method: 'POST',
325331
headers: { 'Content-Type': 'application/json' },
326-
body: JSON.stringify({
327-
toolCallId,
328-
status,
329-
message: message || (status === 'success' ? 'Tool completed' : 'Tool failed'),
330-
...(data ? { data } : {}),
331-
}),
332+
body,
332333
})
333-
if (!res.ok) {
334+
// Next.js silently truncates request bodies beyond its body size limit (default 10MB),
335+
// corrupting the JSON and causing a server-side parse error (500). When the request fails
336+
// and the payload is large, retry without logs (the largest field) to fit under the limit.
337+
const LARGE_PAYLOAD_THRESHOLD = 10 * 1024 * 1024
338+
const bodySize = new Blob([body]).size
339+
if (!res.ok && data && bodySize > LARGE_PAYLOAD_THRESHOLD) {
340+
const { logs: _logs, ...dataWithoutLogs } = data
341+
logger.warn('[RunTool] reportCompletion failed with large payload, retrying without logs', {
342+
toolCallId,
343+
status: res.status,
344+
bodySize,
345+
})
346+
const retryRes = await fetch(COPILOT_CONFIRM_API_PATH, {
347+
method: 'POST',
348+
headers: { 'Content-Type': 'application/json' },
349+
body: JSON.stringify({
350+
toolCallId,
351+
status,
352+
message: message || (status === 'success' ? 'Tool completed' : 'Tool failed'),
353+
data: dataWithoutLogs,
354+
}),
355+
})
356+
if (!retryRes.ok) {
357+
logger.warn('[RunTool] reportCompletion retry also failed', {
358+
toolCallId,
359+
status: retryRes.status,
360+
})
361+
}
362+
} else if (!res.ok) {
334363
logger.warn('[RunTool] reportCompletion failed', { toolCallId, status: res.status })
335364
}
336365
} catch (err) {

0 commit comments

Comments
 (0)