Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(async): preserve outcomes during cleanup
Keep execution finalization cleanup best-effort so cancellation cleanup failures do not overwrite successful or failed outcomes. Restore webhook processor formatting to the repository Biome style to avoid noisy formatter churn.
  • Loading branch information
PlaneInABottle authored and test committed Mar 13, 2026
commit 285d2d73451f59156fa5c0b1dd02f1a601be6f5a
38 changes: 38 additions & 0 deletions apps/sim/lib/workflows/executor/execution-core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,42 @@ describe('executeWorkflowCore terminal finalization sequencing', () => {
})
)
})

it('does not replace a successful outcome when cancellation cleanup fails', async () => {
executorExecuteMock.mockResolvedValue({
success: true,
status: 'completed',
output: { done: true },
logs: [],
metadata: { duration: 123, startTime: 'start', endTime: 'end' },
})

clearExecutionCancellationMock.mockRejectedValue(new Error('cleanup failed'))

await expect(
executeWorkflowCore({
snapshot: createSnapshot() as any,
callbacks: {},
loggingSession: loggingSession as any,
})
).resolves.toMatchObject({ status: 'completed', success: true })

expect(safeCompleteWithErrorMock).not.toHaveBeenCalled()
})

it('does not replace the original error when cancellation cleanup fails', async () => {
const error = new Error('engine failed')
executorExecuteMock.mockRejectedValue(error)
clearExecutionCancellationMock.mockRejectedValue(new Error('cleanup failed'))

await expect(
executeWorkflowCore({
snapshot: createSnapshot() as any,
callbacks: {},
loggingSession: loggingSession as any,
})
).rejects.toBe(error)

expect(safeCompleteWithErrorMock).toHaveBeenCalledTimes(1)
})
})
19 changes: 16 additions & 3 deletions apps/sim/lib/workflows/executor/execution-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ function rememberFinalizedExecutionId(executionId: string): void {
finalizedExecutionIds.set(executionId, now + FINALIZED_EXECUTION_ID_TTL_MS)
}

async function clearExecutionCancellationSafely(
executionId: string,
requestId: string
): Promise<void> {
try {
await clearExecutionCancellation(executionId)
} catch (error) {
logger.error(`[${requestId}] Failed to clear execution cancellation`, { error, executionId })
}
}

function markExecutionFinalizedByCore(error: unknown, executionId: string): void {
rememberFinalizedExecutionId(executionId)

Expand All @@ -162,9 +173,10 @@ async function finalizeExecutionOutcome(params: {
result: ExecutionResult
loggingSession: LoggingSession
executionId: string
requestId: string
workflowInput: unknown
}): Promise<void> {
const { result, loggingSession, executionId, workflowInput } = params
const { result, loggingSession, executionId, requestId, workflowInput } = params
const { traceSpans, totalDuration } = buildTraceSpans(result)
const endedAt = new Date().toISOString()

Expand Down Expand Up @@ -197,7 +209,7 @@ async function finalizeExecutionOutcome(params: {
executionState: result.executionState,
})
} finally {
await clearExecutionCancellation(executionId)
await clearExecutionCancellationSafely(executionId, requestId)
}
Comment thread
cursor[bot] marked this conversation as resolved.
}

Expand Down Expand Up @@ -229,7 +241,7 @@ async function finalizeExecutionError(params: {
})
return false
} finally {
await clearExecutionCancellation(executionId)
await clearExecutionCancellationSafely(executionId, requestId)
}
}
Comment thread
PlaneInABottle marked this conversation as resolved.

Expand Down Expand Up @@ -486,6 +498,7 @@ export async function executeWorkflowCore(
result,
loggingSession,
executionId,
requestId,
workflowInput: processedInput,
})

Expand Down