Skip to content
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export async function executeWorkflowWithFullLogging(
}

const executionId = options.executionId || uuidv4()
const { addConsole, updateConsole } = useTerminalConsoleStore.getState()
const { addConsole, updateConsole, cancelRunningEntries } = useTerminalConsoleStore.getState()
const { setActiveBlocks, setBlockRunStatus, setEdgeRunStatus, setCurrentExecutionId } =
useExecutionStore.getState()
const wfId = targetWorkflowId
Expand All @@ -445,6 +445,7 @@ export async function executeWorkflowWithFullLogging(
const activeBlocksSet = new Set<string>()
const activeBlockRefCounts = new Map<string, number>()
const executionIdRef = { current: executionId }
const accumulatedBlockLogs: BlockLog[] = []

const blockHandlers = createBlockEventHandlers(
{
Expand All @@ -453,7 +454,7 @@ export async function executeWorkflowWithFullLogging(
workflowEdges,
activeBlocksSet,
activeBlockRefCounts,
accumulatedBlockLogs: [],
accumulatedBlockLogs,
accumulatedBlockStates: new Map(),
executedBlockIds: new Set(),
consoleMode: 'update',
Expand Down Expand Up @@ -490,7 +491,25 @@ export async function executeWorkflowWithFullLogging(

if (!response.ok) {
const error = await response.json()
throw new Error(error.error || 'Workflow execution failed')
const errorMessage = error.error || 'Workflow execution failed'
const isValidationError = response.status >= 400 && response.status < 500
const now = new Date().toISOString()
addConsole({
input: {},
output: {},
success: false,
error: errorMessage,
durationMs: 0,
startedAt: now,
executionOrder: 0,
endedAt: now,
workflowId: wfId,
blockId: isValidationError ? 'validation' : 'execution-error',
executionId,
blockName: isValidationError ? 'Workflow Validation' : 'Execution Error',
blockType: isValidationError ? 'validation' : 'error',
})
throw new Error(errorMessage)
}

if (!response.body) {
Expand Down Expand Up @@ -575,15 +594,49 @@ export async function executeWorkflowWithFullLogging(
}
break

case 'execution:error':
case 'execution:error': {
setCurrentExecutionId(wfId, null)
const errorMessage = event.data.error || 'Execution failed'
executionResult = {
success: false,
output: {},
error: event.data.error || 'Execution failed',
error: errorMessage,
logs: [],
}

cancelRunningEntries(wfId)

const isPreExecutionError = accumulatedBlockLogs.length === 0
const hasBlockError = accumulatedBlockLogs.some((log) => log.error)
if (isPreExecutionError || !hasBlockError) {
const isTimeout = errorMessage.toLowerCase().includes('timed out')
const now = new Date().toISOString()
addConsole({
input: {},
output: {},
success: false,
error: errorMessage,
durationMs: event.data.duration || 0,
startedAt: now,
executionOrder: isPreExecutionError ? 0 : Number.MAX_SAFE_INTEGER,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Number.MAX_SAFE_INTEGER as sentinel executionOrder

Using Number.MAX_SAFE_INTEGER (9,007,199,254,740,991) as the executionOrder for a non-pre-execution error entry is a rough sentinel that could cause unexpected sorting behavior if any downstream consumer adds to, compares, or serialises this value. A named constant or a derivation from the actual accumulated log count would be safer and clearer:

Suggested change
executionOrder: isPreExecutionError ? 0 : Number.MAX_SAFE_INTEGER,
executionOrder: accumulatedBlockLogs.length,

This naturally places the error entry after all completed block logs without relying on an extreme sentinel value.

endedAt: now,
workflowId: wfId,
blockId: isPreExecutionError
? 'validation'
: isTimeout
? 'timeout-error'
: 'execution-error',
executionId: executionIdRef.current,
blockName: isPreExecutionError
? 'Workflow Validation'
: isTimeout
? 'Timeout Error'
: 'Execution Error',
blockType: isPreExecutionError ? 'validation' : 'error',
})
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
}
break
}
}
}
}
Expand Down
Loading