@@ -490,25 +490,19 @@ export class WaitpointSystem {
490490 this . $ . runStore
491491 ) ;
492492
493- // Insert the blocking + historical connections via the run-ops store, routed by the owning
494- // run id so the edge co-resides with the run. Never pinned to the caller's control-plane tx:
495- // that joined `Waitpoint` on the wrong DB and wrote 0 edges. The pending check stays a
496- // SEPARATE store call so it gets its own READ COMMITTED snapshot (see the doc comment above).
497- await this . $ . runStore . blockRunWithWaitpointEdges ( {
493+ // Insert the blocking + historical connections and re-check the pending count. The
494+ // coordinator keeps these as two separate store statements, in this order, for the READ
495+ // COMMITTED reason documented on the method and in the doc comment above.
496+ const { pendingCount } = await this . coordinator . registerBlocks ( {
498497 runId,
499498 waitpointIds : $waitpoints ,
500499 projectId,
501500 spanIdToComplete,
502501 batchId : batch ?. id ,
503502 batchIndex : batch ?. index ,
503+ client : prisma ,
504504 } ) ;
505505
506- // Check if the run is actually blocked using a separate query (see above). Pass the writer so the
507- // pending re-read is read-your-writes on the owning PRIMARY (a lagging replica can strand the run).
508- // Route by the blocked run id: its blocking waitpoints co-locate with the run, so the router
509- // counts on the run's store and only falls back to the other DB for a cross-tree token.
510- const pendingCount = await this . $ . runStore . countPendingWaitpoints ( $waitpoints , prisma , runId ) ;
511-
512506 const isRunBlocked = pendingCount > 0 ;
513507
514508 let newStatus : TaskRunExecutionStatus = "SUSPENDED" ;
@@ -606,10 +600,10 @@ export class WaitpointSystem {
606600 } ) : Promise < void > {
607601 const $waitpoints = typeof waitpoints === "string" ? [ waitpoints ] : waitpoints ;
608602
609- // Same routed edge write as blockRunWithWaitpoint, routed by the owning run id. No lock
610- // needed: ON CONFLICT DO NOTHING makes concurrent inserts safe, and the parent snapshot is
611- // already EXECUTING_WITH_WAITPOINTS from blockRunWithCreatedBatch.
612- await this . $ . runStore . blockRunWithWaitpointEdges ( {
603+ // Same routed edge write as blockRunWithWaitpoint. No lock needed: ON CONFLICT DO NOTHING
604+ // makes concurrent inserts safe, and the parent snapshot is already
605+ // EXECUTING_WITH_WAITPOINTS from blockRunWithCreatedBatch. No pending count here .
606+ await this . coordinator . registerBlocksLockless ( {
613607 runId,
614608 waitpointIds : $waitpoints ,
615609 projectId,
0 commit comments