Skip to content

Commit 01ed7cc

Browse files
icecrasher321claude
andcommitted
improvement(logs): run the duplicate-execution probe and snapshot upsert concurrently
startWorkflowExecution's existing-log probe and createSnapshotWithDeduplication have no data dependency; running them in parallel cuts a serial round trip from every execution start. The duplicate-executionId path still returns the prior log and snapshot — the concurrent upsert is an idempotent no-op on an unchanged state hash, and a changed-hash orphan is reclaimed by cleanupOrphanedSnapshots. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 04e5bec commit 01ed7cc

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

apps/sim/lib/logs/execution/logger.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -651,12 +651,21 @@ export class ExecutionLogger implements IExecutionLoggerService {
651651

652652
execLog.debug('Starting workflow execution')
653653

654-
// Check if execution log already exists (idempotency check)
655-
const existingLog = await execDb
656-
.select()
657-
.from(workflowExecutionLogs)
658-
.where(eq(workflowExecutionLogs.executionId, executionId))
659-
.limit(1)
654+
/**
655+
* The duplicate-execution probe and the snapshot upsert have no data
656+
* dependency, so they run concurrently. On the duplicate path the extra
657+
* snapshot write is an idempotent no-op for an unchanged state hash (its
658+
* `(workflowId, stateHash)` conflict target), and an orphaned row from a
659+
* changed hash is reclaimed by `cleanupOrphanedSnapshots`.
660+
*/
661+
const [existingLog, snapshotResult] = await Promise.all([
662+
execDb
663+
.select()
664+
.from(workflowExecutionLogs)
665+
.where(eq(workflowExecutionLogs.executionId, executionId))
666+
.limit(1),
667+
snapshotService.createSnapshotWithDeduplication(workflowId, workflowState),
668+
])
660669

661670
if (existingLog.length > 0) {
662671
execLog.debug('Execution log already exists, skipping duplicate INSERT (idempotent)')
@@ -691,11 +700,6 @@ export class ExecutionLogger implements IExecutionLoggerService {
691700
}
692701
}
693702

694-
const snapshotResult = await snapshotService.createSnapshotWithDeduplication(
695-
workflowId,
696-
workflowState
697-
)
698-
699703
const startTime = new Date()
700704

701705
const [workflowLog] = await execDb

0 commit comments

Comments
 (0)