Skip to content

Commit 58e86c5

Browse files
waleedlatif1claude
andcommitted
fix(terminal): correct error/cancel block status in logs panel
Three bugs in the workflow editor's terminal/logs panel where block status diverged from the engine's truth on error paths: 1. **Errored block shown as "canceled"** — when the SSE 'add' mode produced a duplicate entry on block error and `cancelRunningEntries` then swept the original placeholder. 2. **Upstream blocks stuck on "Running"** — terminal events arrived before the engine's last block events under reconnect/timeout, so the live panel never received the per-block terminal state. 3. **Phantom "Run Error" pseudo-row** — the failing block rendered as "canceled" while a synthetic row carried the real error text. Fixes: - **Fix B** (`addConsoleErrorEntry`): when a running placeholder exists for `(blockId, executionId)`, route through `updateConsoleErrorEntry` instead of creating a second entry. Aligns 'add' mode with the existing 'update' mode behavior. - **Fix C** (`reconcileFinalBlockLogs`): terminal SSE events now carry `finalBlockLogs` (server-authoritative snapshot). On execution:error / execution:cancelled, reconcile any still-running entries with their server-side terminal state. Recovers correctness on network drop, server timeout/abort, and reconnect-resume paths where individual block:* events may not have reached the client. - **Fix D** (`addExecutionErrorConsoleEntry`): cross-check `useTerminalConsoleStore` for entries with `error` set scoped to the executionId before emitting the synthetic "Run Error" row. Suppresses the phantom row when the failing block already carries the message. - **Signature refactor**: `handleExecutionErrorConsole` / `handleExecutionCancelledConsole` now take a typed `ExecutionConsoleDeps` object instead of stacking positional deps — matches the existing `createBlockEventHandlers(config, deps)` precedent in the same file. Tests: - 12 tests in `workflow-execution-utils.test.ts` covering Fix B/C/D and the deps-object signature refactor. - Centralized terminal-console store mock in `@sim/testing` so future tests can stub the store without per-file boilerplate. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 220f8c8 commit 58e86c5

9 files changed

Lines changed: 587 additions & 40 deletions

File tree

apps/sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,7 @@ async function handleExecutePost(
11651165
data: {
11661166
error: timeoutErrorMessage,
11671167
duration: result.metadata?.duration || 0,
1168+
finalBlockLogs: result.logs,
11681169
},
11691170
})
11701171
finalMetaStatus = 'error'
@@ -1178,6 +1179,7 @@ async function handleExecutePost(
11781179
workflowId,
11791180
data: {
11801181
duration: result.metadata?.duration || 0,
1182+
finalBlockLogs: result.logs,
11811183
},
11821184
})
11831185
finalMetaStatus = 'cancelled'
@@ -1242,6 +1244,7 @@ async function handleExecutePost(
12421244
data: {
12431245
error: executionResult?.error || errorMessage,
12441246
duration: executionResult?.metadata?.duration || 0,
1247+
finalBlockLogs: executionResult?.logs,
12451248
},
12461249
})
12471250
finalMetaStatus = 'error'

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,25 +216,31 @@ export function useWorkflowExecution() {
216216
durationMs?: number
217217
blockLogs: BlockLog[]
218218
isPreExecutionError?: boolean
219+
finalBlockLogs?: BlockLog[]
219220
}) => {
220221
if (!params.workflowId) return
221-
sharedHandleExecutionErrorConsole(addConsole, cancelRunningEntries, {
222-
...params,
223-
workflowId: params.workflowId,
224-
})
222+
sharedHandleExecutionErrorConsole(
223+
{ addConsole, updateConsole, cancelRunningEntries },
224+
{ ...params, workflowId: params.workflowId }
225+
)
225226
},
226-
[addConsole, cancelRunningEntries]
227+
[addConsole, cancelRunningEntries, updateConsole]
227228
)
228229

229230
const handleExecutionCancelledConsole = useCallback(
230-
(params: { workflowId?: string; executionId?: string; durationMs?: number }) => {
231+
(params: {
232+
workflowId?: string
233+
executionId?: string
234+
durationMs?: number
235+
finalBlockLogs?: BlockLog[]
236+
}) => {
231237
if (!params.workflowId) return
232-
sharedHandleExecutionCancelledConsole(addConsole, cancelRunningEntries, {
233-
...params,
234-
workflowId: params.workflowId,
235-
})
238+
sharedHandleExecutionCancelledConsole(
239+
{ addConsole, updateConsole, cancelRunningEntries },
240+
{ ...params, workflowId: params.workflowId }
241+
)
236242
},
237-
[addConsole, cancelRunningEntries]
243+
[addConsole, cancelRunningEntries, updateConsole]
238244
)
239245

240246
const buildBlockEventHandlers = useCallback(
@@ -1226,6 +1232,7 @@ export function useWorkflowExecution() {
12261232
durationMs: data.duration,
12271233
blockLogs: accumulatedBlockLogs,
12281234
isPreExecutionError,
1235+
finalBlockLogs: data.finalBlockLogs,
12291236
})
12301237

12311238
if (activeWorkflowId && !isExecutingFromChat) {
@@ -1252,6 +1259,7 @@ export function useWorkflowExecution() {
12521259
workflowId: activeWorkflowId,
12531260
executionId: executionIdRef.current,
12541261
durationMs: data?.duration,
1262+
finalBlockLogs: data?.finalBlockLogs,
12551263
})
12561264

12571265
if (activeWorkflowId && !isExecutingFromChat) {
@@ -1739,6 +1747,7 @@ export function useWorkflowExecution() {
17391747
error: data.error,
17401748
durationMs: data.duration,
17411749
blockLogs: accumulatedBlockLogs,
1750+
finalBlockLogs: data.finalBlockLogs,
17421751
})
17431752

17441753
setCurrentExecutionId(workflowId, null)
@@ -1751,6 +1760,7 @@ export function useWorkflowExecution() {
17511760
workflowId,
17521761
executionId: executionIdRef.current,
17531762
durationMs: data?.duration,
1763+
finalBlockLogs: data?.finalBlockLogs,
17541764
})
17551765

17561766
setCurrentExecutionId(workflowId, null)
@@ -1999,9 +2009,10 @@ export function useWorkflowExecution() {
19992009
executionId: capturedExecutionId,
20002010
error: data.error,
20012011
blockLogs: accumulatedBlockLogs,
2012+
finalBlockLogs: data.finalBlockLogs,
20022013
})
20032014
},
2004-
onExecutionCancelled: () => {
2015+
onExecutionCancelled: (data) => {
20052016
reconnectionComplete = true
20062017
activeReconnections.delete(reconnectWorkflowId)
20072018
if (!activated) {
@@ -2018,6 +2029,7 @@ export function useWorkflowExecution() {
20182029
handleExecutionCancelledConsole({
20192030
workflowId: reconnectWorkflowId,
20202031
executionId: capturedExecutionId,
2032+
finalBlockLogs: data?.finalBlockLogs,
20212033
})
20222034
},
20232035
},

0 commit comments

Comments
 (0)