Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions apps/sim/lib/copilot/client-sse/run-tool-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,45 @@ async function reportCompletion(
data?: Record<string, unknown>
): Promise<void> {
try {
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({
toolCallId,
status,
message: message || (status === 'success' ? 'Tool completed' : 'Tool failed'),
...(data ? { data } : {}),
}),
body,
})
if (!res.ok) {
// 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) {
Comment thread
TheodoreSpeaks marked this conversation as resolved.
Outdated
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,
})
Comment thread
TheodoreSpeaks marked this conversation as resolved.
Outdated
const retryRes = 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: dataWithoutLogs,
}),
Comment thread
TheodoreSpeaks marked this conversation as resolved.
})
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) {
Expand Down
Loading