Skip to content

Commit ec69d07

Browse files
committed
fix(logs): let the ledger-order reader observe every finished run
1 parent dca0465 commit ec69d07

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎apps/sim/lib/logs/execution/completion-ledger-order.integration.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,20 @@ describe('completeWorkflowExecution', () => {
121121
const executionId = generateId()
122122
await startExecution(executionId)
123123

124-
/** The ledger only grows, so the first read that finds the run finished is the one that counts. */
124+
/**
125+
* The ledger only grows, so the first read that finds the run finished is the one that
126+
* counts. Settlement is captured before each read, so a read already in flight when the
127+
* completion lands cannot end the loop before the finished run is observed.
128+
*/
125129
let completing = true
126130
const reader = (async () => {
127-
while (completing) {
128-
if ((await logRow(executionId))?.status !== 'completed') continue
129-
if ((await buildCostLedger(executionId)) === null) finishedWithoutLedger++
130-
return
131+
for (;;) {
132+
const settledBeforeRead = !completing
133+
if ((await logRow(executionId))?.status === 'completed') {
134+
if ((await buildCostLedger(executionId)) === null) finishedWithoutLedger++
135+
return
136+
}
137+
if (settledBeforeRead) return
131138
}
132139
})()
133140

0 commit comments

Comments
 (0)