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 @@ -364,6 +364,22 @@ export class WaitpointSystem {
364364
365365 /**
366366 * Prevents a run from continuing until the waitpoint is completed.
367+ *
368+ * This method uses two separate SQL statements intentionally:
369+ *
370+ * 1. A CTE that INSERTs TaskRunWaitpoint rows (blocking connections) and
371+ * _WaitpointRunConnections rows (historical connections).
372+ *
373+ * 2. A separate SELECT that checks if any of the requested waitpoints are still PENDING.
374+ *
375+ * These MUST be separate statements because of PostgreSQL MVCC in READ COMMITTED isolation:
376+ * each statement gets its own snapshot. If a concurrent `completeWaitpoint` commits between
377+ * the CTE starting and finishing, the CTE's snapshot won't see the COMPLETED status. By using
378+ * a separate SELECT, we get a fresh snapshot that reflects the latest committed state.
379+ *
380+ * The pending check queries ALL requested waitpoint IDs (not just the ones actually inserted
381+ * by the CTE). This is intentional: if a TaskRunWaitpoint row already existed (ON CONFLICT
382+ * DO NOTHING skipped the insert), a still-PENDING waitpoint should still count as blocking.
367383 */
368384 async blockRunWithWaitpoint ( {
369385 runId,
You can’t perform that action at this time.
0 commit comments