Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 6 additions & 12 deletions apps/sim/app/api/workflows/[id]/execute/route.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -919,8 +919,7 @@ async function handleExecutePost(
blockType: string,
executionOrder: number,
iterationContext?: IterationContext,
childWorkflowContext?: ChildWorkflowContext,
blockExecutionId?: string
childWorkflowContext?: ChildWorkflowContext
) => {
reqLogger.info('onBlockStart called', { blockId, blockName, blockType })
sendEvent({
Expand All@@ -946,7 +945,6 @@ async function handleExecutePost(
childWorkflowBlockId: childWorkflowContext.parentBlockId,
childWorkflowName: childWorkflowContext.workflowName,
}),
...(blockExecutionId && { blockExecutionId }),
},
})
}
Expand All@@ -957,8 +955,7 @@ async function handleExecutePost(
blockType: string,
callbackData: any,
iterationContext?: IterationContext,
childWorkflowContext?: ChildWorkflowContext,
blockExecutionId?: string
childWorkflowContext?: ChildWorkflowContext
) => {
const hasError = callbackData.output?.error
const childWorkflowData = childWorkflowContext
Expand All@@ -972,11 +969,6 @@ async function handleExecutePost(
? { childWorkflowInstanceId: callbackData.childWorkflowInstanceId }
: {}

const resolvedBlockExecutionId = blockExecutionId ?? callbackData.blockExecutionId
const blockExecData = resolvedBlockExecutionId
? { blockExecutionId: resolvedBlockExecutionId }
: {}

if (hasError) {
reqLogger.info('onBlockComplete (error) called', {
blockId,
Expand DownExpand Up@@ -1010,7 +1002,6 @@ async function handleExecutePost(
}),
...childWorkflowData,
...instanceData,
...blockExecData,
},
})
} else {
Expand DownExpand Up@@ -1045,7 +1036,6 @@ async function handleExecutePost(
}),
...childWorkflowData,
...instanceData,
...blockExecData,
},
})
}
Expand DownExpand Up@@ -1175,6 +1165,7 @@ async function handleExecutePost(
data: {
error: timeoutErrorMessage,
duration: result.metadata?.duration || 0,
finalBlockLogs: result.logs,
},
})
finalMetaStatus = 'error'
Expand All@@ -1188,6 +1179,7 @@ async function handleExecutePost(
workflowId,
data: {
duration: result.metadata?.duration || 0,
finalBlockLogs: result.logs,
},
})
finalMetaStatus = 'cancelled'
Expand DownExpand Up@@ -1228,6 +1220,7 @@ async function handleExecutePost(
duration: result.metadata?.duration || 0,
startTime: result.metadata?.startTime || startTime.toISOString(),
endTime: result.metadata?.endTime || new Date().toISOString(),
finalBlockLogs: result.logs,
},
})
}
Expand All@@ -1252,6 +1245,7 @@ async function handleExecutePost(
data: {
error: executionResult?.error || errorMessage,
duration: executionResult?.metadata?.duration || 0,
finalBlockLogs: executionResult?.logs,
Comment thread
waleedlatif1 marked this conversation as resolved.
},
})
finalMetaStatus = 'error'
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,7 @@ import {
addHttpErrorConsoleEntry,
type BlockEventHandlerConfig,
createBlockEventHandlers,
reconcileFinalBlockLogs,
addExecutionErrorConsoleEntry as sharedAddExecutionErrorConsoleEntry,
handleExecutionCancelledConsole as sharedHandleExecutionCancelledConsole,
handleExecutionErrorConsole as sharedHandleExecutionErrorConsole,
Expand DownExpand Up@@ -230,25 +231,31 @@ export function useWorkflowExecution() {
durationMs?: number
blockLogs: BlockLog[]
isPreExecutionError?: boolean
finalBlockLogs?: BlockLog[]
}) => {
if (!params.workflowId) return
sharedHandleExecutionErrorConsole(
{ addConsole, updateConsole },
{ addConsole, updateConsole, cancelRunningEntries },
{ ...params, workflowId: params.workflowId }
)
},
[addConsole, updateConsole]
[addConsole, cancelRunningEntries, updateConsole]
)

const handleExecutionCancelledConsole = useCallback(
(params: { workflowId?: string; executionId?: string; durationMs?: number }) => {
(params: {
workflowId?: string
executionId?: string
durationMs?: number
finalBlockLogs?: BlockLog[]
}) => {
if (!params.workflowId) return
sharedHandleExecutionCancelledConsole(
{ addConsole, updateConsole },
{ addConsole, updateConsole, cancelRunningEntries },
{ ...params, workflowId: params.workflowId }
)
},
[addConsole, updateConsole]
[addConsole, cancelRunningEntries, updateConsole]
)

const buildBlockEventHandlers = useCallback(
Expand DownExpand Up@@ -1030,6 +1037,7 @@ export function useWorkflowExecution() {
accumulatedBlockLogs,
accumulatedBlockStates,
executedBlockIds,
includeStartConsoleEntry: true,
onBlockCompleteCallback: onBlockComplete,
})

Expand DownExpand Up@@ -1123,6 +1131,13 @@ export function useWorkflowExecution() {

if (activeWorkflowId) {
setCurrentExecutionId(activeWorkflowId, null)
reconcileFinalBlockLogs(
updateConsole,
activeWorkflowId,
executionIdRef.current,
data.finalBlockLogs
)
cancelRunningEntries(activeWorkflowId)
}

executionResult = {
Expand DownExpand Up@@ -1232,6 +1247,7 @@ export function useWorkflowExecution() {
durationMs: data.duration,
blockLogs: accumulatedBlockLogs,
isPreExecutionError,
finalBlockLogs: data.finalBlockLogs,
})

if (activeWorkflowId && !isExecutingFromChat) {
Expand All@@ -1258,6 +1274,7 @@ export function useWorkflowExecution() {
workflowId: activeWorkflowId,
executionId: executionIdRef.current,
durationMs: data?.duration,
finalBlockLogs: data?.finalBlockLogs,
})

if (activeWorkflowId && !isExecutingFromChat) {
Expand DownExpand Up@@ -1674,6 +1691,7 @@ export function useWorkflowExecution() {
accumulatedBlockLogs,
accumulatedBlockStates,
executedBlockIds,
includeStartConsoleEntry: true,
})

await executionStream.executeFromBlock({
Expand All@@ -1692,6 +1710,14 @@ export function useWorkflowExecution() {
onBlockChildWorkflowStarted: blockHandlers.onBlockChildWorkflowStarted,

onExecutionCompleted: (data) => {
reconcileFinalBlockLogs(
updateConsole,
workflowId,
executionIdRef.current,
data.finalBlockLogs
)
cancelRunningEntries(workflowId)

if (data.success) {
executedBlockIds.add(blockId)

Expand DownExpand Up@@ -1743,6 +1769,7 @@ export function useWorkflowExecution() {
error: data.error,
durationMs: data.duration,
blockLogs: accumulatedBlockLogs,
finalBlockLogs: data.finalBlockLogs,
})

setCurrentExecutionId(workflowId, null)
Expand All@@ -1755,6 +1782,7 @@ export function useWorkflowExecution() {
workflowId,
executionId: executionIdRef.current,
durationMs: data?.duration,
finalBlockLogs: data?.finalBlockLogs,
})

setCurrentExecutionId(workflowId, null)
Expand DownExpand Up@@ -1901,6 +1929,7 @@ export function useWorkflowExecution() {
accumulatedBlockLogs,
accumulatedBlockStates,
executedBlockIds,
includeStartConsoleEntry: true,
})

const capturedExecutionId = executionId
Expand DownExpand Up@@ -1967,7 +1996,7 @@ export function useWorkflowExecution() {
onBlockCompleted: wrapHandler(handlers.onBlockCompleted),
onBlockError: wrapHandler(handlers.onBlockError),
onBlockChildWorkflowStarted: wrapHandler(handlers.onBlockChildWorkflowStarted),
onExecutionCompleted: () => {
onExecutionCompleted: (data) => {
reconnectionComplete = true
activeReconnections.delete(reconnectWorkflowId)
if (!activated) {
Expand All@@ -1981,6 +2010,13 @@ export function useWorkflowExecution() {
setCurrentExecutionId(reconnectWorkflowId, null)
setIsExecuting(reconnectWorkflowId, false)
setActiveBlocks(reconnectWorkflowId, new Set())
reconcileFinalBlockLogs(
updateConsole,
reconnectWorkflowId,
capturedExecutionId,
data?.finalBlockLogs
)
cancelRunningEntries(reconnectWorkflowId)
},
onExecutionError: (data) => {
reconnectionComplete = true
Expand All@@ -2001,6 +2037,7 @@ export function useWorkflowExecution() {
executionId: capturedExecutionId,
error: data.error,
blockLogs: accumulatedBlockLogs,
finalBlockLogs: data.finalBlockLogs,
})
},
onExecutionCancelled: (data) => {
Expand All@@ -2021,6 +2058,7 @@ export function useWorkflowExecution() {
workflowId: reconnectWorkflowId,
executionId: capturedExecutionId,
durationMs: data?.duration,
finalBlockLogs: data?.finalBlockLogs,
})
},
},
Expand Down
Loading
Loading