Skip to content

Commit a80466a

Browse files
committed
fix(run-engine): stop createDateTimeWaitpoint bypassing residency routing
The tx branch wrote the waitpoint directly on the caller's connection, which could strand a run-ops-resident run's DATETIME waitpoint on the wrong database and hang it. No caller supplied tx; drop the parameter so it always routes through the run store, matching createManualWaitpoint.
1 parent d243c41 commit a80466a

2 files changed

Lines changed: 10 additions & 28 deletions

File tree

internal-packages/run-engine/src/engine/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,6 @@ export class RunEngine {
16551655
completedAfter,
16561656
idempotencyKey,
16571657
idempotencyKeyExpiresAt,
1658-
tx,
16591658
}: {
16601659
/** The run that will block on this waitpoint. Co-locates the waitpoint with the run's DB. */
16611660
runId?: string;
@@ -1664,7 +1663,6 @@ export class RunEngine {
16641663
completedAfter: Date;
16651664
idempotencyKey?: string;
16661665
idempotencyKeyExpiresAt?: Date;
1667-
tx?: PrismaClientOrTransaction;
16681666
}) {
16691667
return this.waitpointSystem.createDateTimeWaitpoint({
16701668
runId,
@@ -1673,7 +1671,6 @@ export class RunEngine {
16731671
completedAfter,
16741672
idempotencyKey,
16751673
idempotencyKeyExpiresAt,
1676-
tx,
16771674
});
16781675
}
16791676

internal-packages/run-engine/src/engine/systems/waitpointSystem.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)