@@ -211,43 +211,34 @@ export class WaitpointSystem {
211211 completedAfter,
212212 idempotencyKey,
213213 idempotencyKeyExpiresAt,
214- tx,
215214 } : {
216215 runId ?: string ;
217216 projectId : string ;
218217 environmentId : string ;
219218 completedAfter : Date ;
220219 idempotencyKey ?: string ;
221220 idempotencyKeyExpiresAt ?: Date ;
222- tx ?: PrismaClientOrTransaction ;
223221 } ) {
224222 // Co-location invariant: a DATETIME wait waitpoint lives on the same run-ops DB as the run that
225223 // blocks on it (so the block edge's local `Waitpoint` join resolves and completion/resume stay
226224 // local). The minted waitpoint id is always a cuid, so without `coLocateWithRunId` the upsert
227225 // would always route to LEGACY and a run-ops run on NEW would hang. The (env,idempotencyKey) dedup
228226 // is within the owning run/tree (co-resident on one DB), so the dedup probe + rotation target the
229227 // SAME store. With no run id (a standalone token has no owning run yet) the lookup falls back to
230- // a cross-DB NEW-then-LEGACY scan and the upsert routes by id-shape. A caller-supplied tx pins a
231- // client (same physical DB as the control-plane tx → LEGACY), so it stays on direct prisma .
228+ // a cross-DB NEW-then-LEGACY scan and the upsert routes by id-shape. Always routed through the
229+ // run store (never a caller tx) so it can never bypass residency onto the wrong DB .
232230 const colocate = runId ? { coLocateWithRunId : runId } : undefined ;
233231 const existingWaitpoint = idempotencyKey
234- ? tx
235- ? await tx . waitpoint . findFirst ( {
232+ ? await this . $ . runStore . findWaitpoint (
233+ {
236234 where : {
237235 environmentId,
238236 idempotencyKey,
239237 } ,
240- } )
241- : await this . $ . runStore . findWaitpoint (
242- {
243- where : {
244- environmentId,
245- idempotencyKey,
246- } ,
247- } ,
248- undefined ,
249- colocate
250- )
238+ } ,
239+ undefined ,
240+ colocate
241+ )
251242 : undefined ;
252243
253244 if ( existingWaitpoint ) {
@@ -266,11 +257,7 @@ export class WaitpointSystem {
266257 inactiveIdempotencyKey : existingWaitpoint . idempotencyKey ,
267258 } ,
268259 } ;
269- if ( tx ) {
270- await tx . waitpoint . update ( rotateArgs ) ;
271- } else {
272- await this . $ . runStore . updateWaitpoint ( rotateArgs , undefined , colocate ) ;
273- }
260+ await this . $ . runStore . updateWaitpoint ( rotateArgs , undefined , colocate ) ;
274261
275262 //let it fall through to create a new waitpoint
276263 } else {
@@ -297,9 +284,7 @@ export class WaitpointSystem {
297284 } ,
298285 update : { } ,
299286 } ;
300- const waitpoint = tx
301- ? await tx . waitpoint . upsert ( upsertArgs )
302- : await this . $ . runStore . upsertWaitpoint ( upsertArgs , undefined , colocate ) ;
287+ const waitpoint = await this . $ . runStore . upsertWaitpoint ( upsertArgs , undefined , colocate ) ;
303288
304289 await this . $ . worker . enqueue ( {
305290 id : `finishWaitpoint.${ waitpoint . id } ` ,
0 commit comments