Skip to content

Commit bb5cf6d

Browse files
committed
docs(run-store): correct the single-DB claim in the RoutingRunStore docstring
The docstring said "In single-DB both stores are the same, so routing is a no-op passthrough". That has not been true since the injecting seam started returning a bare PostgresRunStore when the split is off — this class is not constructed at all in single-DB. The stale sentence made the counting fan-outs look like they could double count one store. State the actual invariant instead: every shard is a distinct database, enforced by the seam and by the fail-closed boot sentinel, and two keys resolving to one store would double count. Comment-only. Also re-anchors the line references in runOpsStore.mixedResidency.test.ts, which the docstring shifted.
1 parent 48ec39b commit bb5cf6d

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

‎internal-packages/run-store/src/runOpsStore.mixedResidency.test.ts‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ async function seedSharedEnv(prisma14: PrismaClient, suffix: string) {
195195
}
196196

197197
describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id #new coexisting)", () => {
198-
// ── Case 1: findRuns by a MIXED bounded id-set (#findRunsByIdSet, runOpsStore.ts:449) ──
198+
// ── Case 1: findRuns by a MIXED bounded id-set (#findRunsByIdSet, runOpsStore.ts:453) ──
199199
// A list-hydrate id set spans cuid (legacy) + run-ops id (new) ids plus a run-ops id absent from legacy.
200200
// Both resident runs returned; take/skip applied GLOBALLY post-merge; orderBy honored; the absent
201-
// run-ops id short-circuits (never probed on LEGACY, #fanOutPartitioned, :165).
201+
// run-ops id short-circuits (never probed on LEGACY, #fanOutPartitioned, :169).
202202
heteroRunOpsPostgresTest(
203203
"case 1: findRuns by a mixed id-set returns both DBs' runs, ordered, take/skip global",
204204
async ({ prisma14, prisma17 }) => {
@@ -306,7 +306,7 @@ describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id
306306
}
307307
);
308308

309-
// ── Case 2: findRuns by an OPEN predicate (#findRunsOpen, runOpsStore.ts:464) ──
309+
// ── Case 2: findRuns by an OPEN predicate (#findRunsOpen, runOpsStore.ts:468) ──
310310
// No id set → query BOTH stores, union, dedup by id (NEW wins). Filter by a shared scalar
311311
// (runtimeEnvironmentId + status) that matches rows on both DBs.
312312
heteroRunOpsPostgresTest(
@@ -355,7 +355,7 @@ describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id
355355
}
356356
);
357357

358-
// ── Case 3: expireRunsBatch with a MIXED id list (runOpsStore.ts:723) ──
358+
// ── Case 3: expireRunsBatch with a MIXED id list (runOpsStore.ts:727) ──
359359
// Partitions run-ops id→NEW / cuid→LEGACY; each leg called only when non-empty; counts summed; each row
360360
// updated on its OWN DB only.
361361
heteroRunOpsPostgresTest(
@@ -388,7 +388,7 @@ describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id
388388
}
389389
);
390390

391-
// ── Case 4: clearIdempotencyKey fan-out arm (byFriendlyIds, runOpsStore.ts:590) ──
391+
// ── Case 4: clearIdempotencyKey fan-out arm (byFriendlyIds, runOpsStore.ts:594) ──
392392
// byFriendlyIds spans mixed residency → fan out to both, sum the count, each row cleared on its home.
393393
heteroRunOpsPostgresTest(
394394
"case 4: clearIdempotencyKey byFriendlyIds clears across both DBs and sums the count",
@@ -429,7 +429,7 @@ describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id
429429
}
430430
);
431431

432-
// ── Case 5: countPendingWaitpoints scattered across both DBs (runOpsStore.ts:1146) ──
432+
// ── Case 5: countPendingWaitpoints scattered across both DBs (runOpsStore.ts:1150) ──
433433
// A run's pending waitpoints can be split across both stores mid-drain → count on each and sum.
434434
heteroRunOpsPostgresTest(
435435
"case 5: countPendingWaitpoints sums PENDING waitpoints scattered across both DBs",
@@ -465,7 +465,7 @@ describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id
465465
}
466466
);
467467

468-
// ── Case 6: findManyWaitpoints { id: { in: [...mixed...] } } (runOpsStore.ts:1326) ──
468+
// ── Case 6: findManyWaitpoints { id: { in: [...mixed...] } } (runOpsStore.ts:1330) ──
469469
// Merge waitpoints from both DBs for a mixed id set.
470470
heteroRunOpsPostgresTest(
471471
"case 6: findManyWaitpoints merges a mixed id set from both DBs",
@@ -495,7 +495,7 @@ describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id
495495

496496
// ── Case 8: findExecutionSnapshot / findManyExecutionSnapshots OPEN (no runId) where ──
497497
// A by-snapshot-id-only lookup (snapshot ids are non-classifiable cuids) must fan out NEW→LEGACY
498-
// (findExecutionSnapshot, :1008) / merge both (findManyExecutionSnapshots, :1023). Seed a snapshot on
498+
// (findExecutionSnapshot, :1012) / merge both (findManyExecutionSnapshots, :1027). Seed a snapshot on
499499
// EACH DB (one run-ops run on #new, one cuid run on #legacy) and read with a no-runId where.
500500
heteroRunOpsPostgresTest(
501501
"case 8: findExecutionSnapshot/findManyExecutionSnapshots with an open where reach both DBs",
@@ -544,7 +544,7 @@ describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id
544544
}
545545
);
546546

547-
// ── Case 9a: findRun with an UNCLASSIFIABLE where (spanId) on a #legacy run (#findRunUnrouted, :365) ──
547+
// ── Case 9a: findRun with an UNCLASSIFIABLE where (spanId) on a #legacy run (#findRunUnrouted, :369) ──
548548
// A run-ops run on #new and a cuid run on #legacy each carry a distinct spanId. A spanId where can't
549549
// be id-classified → fan out NEW-first then LEGACY. The legacy-resident run must be found.
550550
heteroRunOpsPostgresTest(
@@ -586,7 +586,7 @@ describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id
586586
}
587587
);
588588

589-
// ── Case 9b: findRunOrThrow with an UNCLASSIFIABLE where (spanId) on a #legacy run (#findRunOrThrowUnrouted, :864) ──
589+
// ── Case 9b: findRunOrThrow with an UNCLASSIFIABLE where (spanId) on a #legacy run (#findRunOrThrowUnrouted, :868) ──
590590
// The throwing twin must match findRun's fan-out: an unclassifiable where whose only matching run
591591
// lives on #legacy must NOT throw. A NEW-only fallback would miss the legacy run and throw.
592592
heteroRunOpsPostgresTest(
@@ -628,7 +628,7 @@ describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id
628628
}
629629
);
630630

631-
// ── Case 7: findManyTaskRunWaitpoints with edges whose relations STRADDLE DBs (runOpsStore.ts:1573) ──
631+
// ── Case 7: findManyTaskRunWaitpoints with edges whose relations STRADDLE DBs (runOpsStore.ts:1577) ──
632632
// An edge co-locates with its RUN, but its `waitpoint`/`taskRun` relations can live on the OTHER DB
633633
// (a cuid token blocking a run-ops run, and vice versa). The per-leg scalar query is stripped of the
634634
// relation keys; the router re-hydrates `waitpoint`/`taskRun` across BOTH DBs. Exercises BOTH
@@ -721,7 +721,7 @@ describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id
721721
}
722722
);
723723

724-
// ── Case 7b: the "blocking waitpoint not found on either DB" HARD ERROR (#hydrateEdgeWaitpointsCrossDb, runOpsStore.ts:1637) ──
724+
// ── Case 7b: the "blocking waitpoint not found on either DB" HARD ERROR (#hydrateEdgeWaitpointsCrossDb, runOpsStore.ts:1641) ──
725725
// An edge whose `waitpointId` resolves on NEITHER DB must throw rather than leave a null status that
726726
// would strand (hang) or wrongly unblock the run.
727727
heteroRunOpsPostgresTest(
@@ -748,7 +748,7 @@ describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id
748748
}
749749
);
750750

751-
// ── Case 10: findBatchTaskRunById / findBatchTaskRunByFriendlyId NEW-then-LEGACY probe (:1755, :1768) ──
751+
// ── Case 10: findBatchTaskRunById / findBatchTaskRunByFriendlyId NEW-then-LEGACY probe (:1759, :1772) ──
752752
// A batch resident on #legacy AND a run-ops-id batch landed on #new (the control-plane window mints
753753
// cuid ids, but a run-ops batch resides on #new) are BOTH found via the probe, regardless of id-shape.
754754
heteroRunOpsPostgresTest(
@@ -792,7 +792,7 @@ describe("RoutingRunStore — mixed-residency matrix (cuid #legacy + run-ops id
792792
}
793793
);
794794

795-
// ── Case 11a: updateManyWaitpoints with a NO-ID (batch) where fans out to both and sums (:1518) ──
795+
// ── Case 11a: updateManyWaitpoints with a NO-ID (batch) where fans out to both and sums (:1522) ──
796796
// A batch where (no single routable id, e.g. completedByTaskRunId IS NULL + status PENDING) must
797797
// apply on BOTH DBs and sum the count.
798798
heteroRunOpsPostgresTest(

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ const LEGACY_SHARD: ShardKey = "legacy";
4545
* map from shard key to store, selecting one by the residency classifier (`ownerEngine`: run-ops
4646
* id→NEW, cuid→LEGACY). The compat constructor holds the two gen-1 shards — a NEW store (the
4747
* dedicated run-ops DB, where new runs are born) and a LEGACY store (the control-plane DB).
48-
* In single-DB both stores are the same, so routing is a no-op passthrough. Inert until the
49-
* injecting seam wires it in under `isSplitEnabled()`; reads no flag here.
48+
* Inert until the injecting seam wires it in under `isSplitEnabled()`; reads no flag here.
49+
*
50+
* Every shard MUST be a distinct database. Single-DB does not construct this class at all — the
51+
* injecting seam returns a bare PostgresRunStore — and split mode requires two configured run-ops
52+
* URLs whose distinctness the boot sentinel enforces fail-closed. Two shard keys that resolve to
53+
* ONE store would make the sum sites (#sumCounts, the counting fan-outs) count that store twice.
5054
*
5155
* Three policies are held as data rather than implied by statement order: {@link #probeOrder} for a
5256
* lookup with no routable id, {@link #precedence} for a merge, and the two id-less fallbacks. A

0 commit comments

Comments
 (0)