File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
internal-packages/run-engine/src/engine/systems Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -366,6 +366,22 @@ export class WaitpointSystem {
366366
367367 /**
368368 * Prevents a run from continuing until the waitpoint is completed.
369+ *
370+ * This method uses two separate SQL statements intentionally:
371+ *
372+ * 1. A CTE that INSERTs TaskRunWaitpoint rows (blocking connections) and
373+ * _WaitpointRunConnections rows (historical connections).
374+ *
375+ * 2. A separate SELECT that checks if any of the requested waitpoints are still PENDING.
376+ *
377+ * These MUST be separate statements because of PostgreSQL MVCC in READ COMMITTED isolation:
378+ * each statement gets its own snapshot. If a concurrent `completeWaitpoint` commits between
379+ * the CTE starting and finishing, the CTE's snapshot won't see the COMPLETED status. By using
380+ * a separate SELECT, we get a fresh snapshot that reflects the latest committed state.
381+ *
382+ * The pending check queries ALL requested waitpoint IDs (not just the ones actually inserted
383+ * by the CTE). This is intentional: if a TaskRunWaitpoint row already existed (ON CONFLICT
384+ * DO NOTHING skipped the insert), a still-PENDING waitpoint should still count as blocking.
369385 */
370386 async blockRunWithWaitpoint ( {
371387 runId,
You can’t perform that action at this time.
0 commit comments