Skip to content

Commit 2160486

Browse files
committed
fix(run-store): reject an id-less or wrong-shard waitpoint co-located onto a gen-2 shard
1 parent 2869f6a commit 2160486

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

internal-packages/run-store/src/runOpsStore.shardMap.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,17 @@ describe("RoutingRunStore gen-2 shard refuses a co-located cuid waitpoint", () =
672672
router.createWaitpoint({ data: { id: "cuid_w1" } } as never, undefined, {
673673
coLocateWithRunId: "a:run_1",
674674
})
675-
).toThrow("cuid-shaped waitpoint");
675+
).toThrow('onto gen-2 shard "a"');
676+
expect(trace(log)).toEqual([]);
677+
});
678+
679+
it("throws when an id-less waitpoint is co-located onto a gen-2 shard", () => {
680+
// Prisma's @default(cuid()) would otherwise mint a cuid on the gen-2 shard AFTER the write,
681+
// leaving it unroutable for its own completion (CodeRabbit finding). Reject it up front.
682+
const { router, log } = coLocateRouter();
683+
expect(() =>
684+
router.createWaitpoint({ data: {} } as never, undefined, { coLocateWithRunId: "a:run_1" })
685+
).toThrow('onto gen-2 shard "a"');
676686
expect(trace(log)).toEqual([]);
677687
});
678688

internal-packages/run-store/src/runOpsStore.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,17 +1494,15 @@ export class RoutingRunStore implements RunStore {
14941494
): RunStore {
14951495
if (ownerId !== undefined) {
14961496
const key = this.#shardKeyOfSafe(ownerId);
1497-
// A gen-2 shard holds only shard-stamped ids. A cuid waitpoint co-located here would be
1498-
// unroutable for its own completion, so the blocked run would never resume. The mint layer
1499-
// must stamp the owner's shard onto the waitpoint id. Fail loud rather than write it.
1497+
// A gen-2 shard holds only ids stamped for that shard, because a waitpoint completes on the
1498+
// shard its own id names. Anything else stranded the blocked run: a cuid (routes to the gen-1
1499+
// pair on completion), an id for a DIFFERENT gen-2 shard, or NO id at all — Prisma's
1500+
// @default(cuid()) then mints a cuid on the gen-2 shard after the write. The mint layer must
1501+
// stamp the owner's shard onto the waitpoint id, so fail loud rather than write an orphan.
15001502
const isGen2 = key !== NEW_SHARD && key !== LEGACY_SHARD;
1501-
if (
1502-
isGen2 &&
1503-
typeof waitpointId === "string" &&
1504-
this.#shardKeyOfSafe(waitpointId) === LEGACY_SHARD
1505-
) {
1503+
if (isGen2 && (waitpointId === undefined || this.#shardKeyOfSafe(waitpointId) !== key)) {
15061504
throw new Error(
1507-
`RoutingRunStore: refusing to co-locate cuid-shaped waitpoint "${waitpointId}" onto gen-2 shard "${key}"`
1505+
`RoutingRunStore: refusing to co-locate waitpoint "${waitpointId ?? "<no id>"}" onto gen-2 shard "${key}"; its id must be stamped for that shard`
15081506
);
15091507
}
15101508
return this.#shardStore(key);

0 commit comments

Comments
 (0)