Skip to content

Commit 910a51a

Browse files
committed
fix(executor): reconcile finalBlockLogs on execution:completed
block:completed callbacks fire-and-forget; the last block's event can arrive after execution:completed, leaving its console entry stuck isRunning. Mirror the error/cancelled paths: emit finalBlockLogs on execution:completed and reconcile + sweep on the client.
1 parent f396975 commit 910a51a

6 files changed

Lines changed: 31 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ async function handleExecutePost(
12201220
duration: result.metadata?.duration || 0,
12211221
startTime: result.metadata?.startTime || startTime.toISOString(),
12221222
endTime: result.metadata?.endTime || new Date().toISOString(),
1223+
finalBlockLogs: result.logs,
12231224
},
12241225
})
12251226
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
addHttpErrorConsoleEntry,
2626
type BlockEventHandlerConfig,
2727
createBlockEventHandlers,
28+
reconcileFinalBlockLogs,
2829
addExecutionErrorConsoleEntry as sharedAddExecutionErrorConsoleEntry,
2930
handleExecutionCancelledConsole as sharedHandleExecutionCancelledConsole,
3031
handleExecutionErrorConsole as sharedHandleExecutionErrorConsole,
@@ -1130,6 +1131,13 @@ export function useWorkflowExecution() {
11301131

11311132
if (activeWorkflowId) {
11321133
setCurrentExecutionId(activeWorkflowId, null)
1134+
reconcileFinalBlockLogs(
1135+
updateConsole,
1136+
activeWorkflowId,
1137+
executionIdRef.current,
1138+
data.finalBlockLogs
1139+
)
1140+
cancelRunningEntries(activeWorkflowId)
11331141
}
11341142

11351143
executionResult = {
@@ -1702,6 +1710,14 @@ export function useWorkflowExecution() {
17021710
onBlockChildWorkflowStarted: blockHandlers.onBlockChildWorkflowStarted,
17031711

17041712
onExecutionCompleted: (data) => {
1713+
reconcileFinalBlockLogs(
1714+
updateConsole,
1715+
workflowId,
1716+
executionIdRef.current,
1717+
data.finalBlockLogs
1718+
)
1719+
cancelRunningEntries(workflowId)
1720+
17051721
if (data.success) {
17061722
executedBlockIds.add(blockId)
17071723

@@ -1980,7 +1996,7 @@ export function useWorkflowExecution() {
19801996
onBlockCompleted: wrapHandler(handlers.onBlockCompleted),
19811997
onBlockError: wrapHandler(handlers.onBlockError),
19821998
onBlockChildWorkflowStarted: wrapHandler(handlers.onBlockChildWorkflowStarted),
1983-
onExecutionCompleted: () => {
1999+
onExecutionCompleted: (data) => {
19842000
reconnectionComplete = true
19852001
activeReconnections.delete(reconnectWorkflowId)
19862002
if (!activated) {
@@ -1994,6 +2010,13 @@ export function useWorkflowExecution() {
19942010
setCurrentExecutionId(reconnectWorkflowId, null)
19952011
setIsExecuting(reconnectWorkflowId, false)
19962012
setActiveBlocks(reconnectWorkflowId, new Set())
2013+
reconcileFinalBlockLogs(
2014+
updateConsole,
2015+
reconnectWorkflowId,
2016+
capturedExecutionId,
2017+
data?.finalBlockLogs
2018+
)
2019+
cancelRunningEntries(reconnectWorkflowId)
19972020
},
19982021
onExecutionError: (data) => {
19992022
reconnectionComplete = true

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ export async function executeWorkflowWithFullLogging(
731731

732732
onExecutionCompleted: (data) => {
733733
setCurrentExecutionId(wfId, null)
734+
reconcileFinalBlockLogs(updateConsole, wfId, executionIdRef.current, data.finalBlockLogs)
735+
cancelRunningEntries(wfId)
734736
executionResult = {
735737
success: data.success,
736738
output: data.output,

apps/sim/lib/workflows/executor/execution-events.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export interface ExecutionCompletedEvent extends BaseExecutionEvent {
5252
duration: number
5353
startTime: string
5454
endTime: string
55+
/** Authoritative per-block terminal states from the server's blockLogs. */
56+
finalBlockLogs?: BlockLog[]
5557
}
5658
}
5759

apps/sim/lib/workflows/executor/human-in-the-loop-manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ export class PauseResumeManager {
10771077
duration: result.metadata?.duration || 0,
10781078
startTime: result.metadata?.startTime || new Date().toISOString(),
10791079
endTime: result.metadata?.endTime || new Date().toISOString(),
1080+
finalBlockLogs: result.logs,
10801081
},
10811082
} as ExecutionEvent)
10821083
finalMetaStatus = 'complete'

apps/sim/lib/workflows/executor/queued-workflow-execution.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ export async function executeQueuedWorkflowJob(
243243
duration: result.metadata?.duration || 0,
244244
startTime: result.metadata?.startTime || metadata.startTime,
245245
endTime: result.metadata?.endTime || new Date().toISOString(),
246+
finalBlockLogs: result.logs,
246247
},
247248
})
248249
await setExecutionMeta(executionId, { status: 'complete' })

0 commit comments

Comments
 (0)