Skip to content

Commit c6013b8

Browse files
d-csTrigger.dev RepoOps
authored andcommitted
refactor(run-store): remove findRunOrThrowOnPrimary and read the owning primary through findRunOrThrow
Removes an internal run store read method that nothing outside the store used. Mono-RevId: 125b9d8e7163809f00fee48cb24e38bab7c34c1d
1 parent 84f35ba commit c6013b8

8 files changed

Lines changed: 95 additions & 75 deletions

File tree

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,22 +1739,6 @@ export class PostgresRunStore implements RunStore {
17391739
return this.#findTaskRunWithSelect(this.prisma, "findFirst", where, args ?? {});
17401740
}
17411741

1742-
findRunOrThrowOnPrimary<S extends Prisma.TaskRunSelect>(
1743-
where: Prisma.TaskRunWhereInput,
1744-
args: { select: S }
1745-
): Promise<Prisma.TaskRunGetPayload<{ select: S }>>;
1746-
findRunOrThrowOnPrimary<I extends Prisma.TaskRunInclude>(
1747-
where: Prisma.TaskRunWhereInput,
1748-
args: { include: I }
1749-
): Promise<Prisma.TaskRunGetPayload<{ include: I }>>;
1750-
findRunOrThrowOnPrimary(where: Prisma.TaskRunWhereInput): Promise<TaskRun>;
1751-
async findRunOrThrowOnPrimary(
1752-
where: Prisma.TaskRunWhereInput,
1753-
args?: { select?: Prisma.TaskRunSelect; include?: Prisma.TaskRunInclude }
1754-
): Promise<unknown> {
1755-
return this.#findTaskRunWithSelect(this.prisma, "findFirstOrThrow", where, args ?? {});
1756-
}
1757-
17581742
findRuns<S extends Prisma.TaskRunSelect>(
17591743
args: {
17601744
where: Prisma.TaskRunWhereInput;

‎internal-packages/run-store/src/delegatingRunStore.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
// Three things remain invisible to the compiler, and they are what is left here.
1212
//
13-
// First, the six overloaded members. TypeScript cannot express one body that satisfies an overload
13+
// First, the five overloaded members. TypeScript cannot express one body that satisfies an overload
1414
// set, so their single implementation forwards through a cast, and the cast is exactly where a
1515
// wrong-member forward would stop being a type error.
1616
//
@@ -35,7 +35,6 @@ const OVERLOADED_MEMBERS = [
3535
"findRun",
3636
"findRunOrThrow",
3737
"findRunOnPrimary",
38-
"findRunOrThrowOnPrimary",
3938
"findRuns",
4039
"findRunsByIds",
4140
] as const;

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// argument, does not compile. That is the whole point of the shape. An untyped forwarder would let
88
// both mistakes through, because a pass-through has no other behaviour to catch them.
99
//
10-
// Six members are overloaded. Their overloads are declared so callers keep the full contract, and
10+
// Five members are overloaded. Their overloads are declared so callers keep the full contract, and
1111
// their single implementation signature is the one place a cast appears: TypeScript cannot express
1212
// one body that satisfies an overload set without it.
1313
//
@@ -371,22 +371,6 @@ export class DelegatingRunStore implements RunStore {
371371
);
372372
}
373373

374-
findRunOrThrowOnPrimary<S extends Prisma.TaskRunSelect>(
375-
where: Prisma.TaskRunWhereInput,
376-
args: { select: S }
377-
): Promise<Prisma.TaskRunGetPayload<{ select: S }>>;
378-
findRunOrThrowOnPrimary<I extends Prisma.TaskRunInclude>(
379-
where: Prisma.TaskRunWhereInput,
380-
args: { include: I }
381-
): Promise<Prisma.TaskRunGetPayload<{ include: I }>>;
382-
findRunOrThrowOnPrimary(where: Prisma.TaskRunWhereInput): Promise<TaskRun>;
383-
findRunOrThrowOnPrimary(...args: unknown[]): unknown {
384-
return (this.delegate.findRunOrThrowOnPrimary as (...a: unknown[]) => unknown).apply(
385-
this.delegate,
386-
args
387-
);
388-
}
389-
390374
findRuns<S extends Prisma.TaskRunSelect>(
391375
args: {
392376
where: Prisma.TaskRunWhereInput;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ export const READ_ONLY_METHODS: readonly string[] = [
202202
"findRun",
203203
"findRunOrThrow",
204204
"findRunOnPrimary",
205-
"findRunOrThrowOnPrimary",
206205
"findRuns",
207206
"findRunsByIds",
208207
"findRunsByIdempotencyKeys",

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,4 +474,83 @@ describe("run-ops split — read-after-write reads the OWNING store's WRITER, no
474474
expect(hits()).toEqual({ ...none, newWriter: true, legacyWriter: true });
475475
}
476476
);
477+
478+
// Catches: a dropped field list, a client with no field list reading a replica, or a branded replica reaching a writer.
479+
heteroRunOpsPostgresTest(
480+
"findRunOrThrow with a caller client keeps the field list or reads the whole row, and a branded replica fans out over the replicas",
481+
async ({ prisma14, prisma17 }) => {
482+
const dedicated = seedEnvironmentDedicated("ort_rows_new");
483+
const legacy = await seedEnvironmentLegacy(prisma14, "ort_rows_leg");
484+
const newRunId = `run_${NEW_ID_26}`;
485+
const legacyRunId = `run_${CUID_25}`;
486+
await prisma17.taskRun.create({
487+
data: taskRunData({
488+
id: newRunId,
489+
friendlyId: "run_rows_new",
490+
organizationId: dedicated.organization.id,
491+
projectId: dedicated.project.id,
492+
runtimeEnvironmentId: dedicated.environment.id,
493+
}),
494+
});
495+
await prisma14.taskRun.create({
496+
data: {
497+
...taskRunData({
498+
id: legacyRunId,
499+
friendlyId: "run_rows_leg",
500+
organizationId: legacy.organization.id,
501+
projectId: legacy.project.id,
502+
runtimeEnvironmentId: legacy.environment.id,
503+
}),
504+
spanId: "span_rows_legacy",
505+
},
506+
});
507+
508+
// 1. Run id with a field list → only the selected field (plus `id`, which the run-ops
509+
// schema's select always keeps), from the NEW writer.
510+
const selected = makeLaggingRouter(prisma14, prisma17);
511+
expect(
512+
await selected.router.findRunOrThrow(
513+
{ id: newRunId },
514+
{ select: { friendlyId: true } },
515+
prisma14
516+
)
517+
).toEqual({ friendlyId: "run_rows_new", id: newRunId });
518+
expect(selected.hits()).toEqual({ ...none, newWriter: true });
519+
520+
// 2. Run id, client and no field list → the whole row, from the NEW writer.
521+
const wholeRow = makeLaggingRouter(prisma14, prisma17);
522+
const row = await wholeRow.router.findRunOrThrow({ id: newRunId }, prisma14);
523+
expect(row).toMatchObject({ friendlyId: "run_rows_new", taskIdentifier: "my-task" });
524+
expect(wholeRow.hits()).toEqual({ ...none, newWriter: true });
525+
526+
// 3. No run id with a field list → only the selected field, from the LEGACY writer.
527+
const fanSelected = makeLaggingRouter(prisma14, prisma17);
528+
expect(
529+
await fanSelected.router.findRunOrThrow(
530+
{ spanId: "span_rows_legacy" },
531+
{ select: { id: true } },
532+
prisma14
533+
)
534+
).toEqual({ id: legacyRunId });
535+
expect(fanSelected.hits()).toEqual({ ...none, newWriter: true, legacyWriter: true });
536+
537+
// 4. No run id, client and no field list, every database misses → P2025 from the LEGACY writer.
538+
const fanMissing = makeLaggingRouter(prisma14, prisma17);
539+
await expect(
540+
fanMissing.router.findRunOrThrow({ spanId: "span_rows_nowhere" }, prisma14)
541+
).rejects.toMatchObject(notFound);
542+
expect(fanMissing.hits()).toEqual({ ...none, newWriter: true, legacyWriter: true });
543+
544+
// 5. No run id and a branded replica → both replicas, no writer.
545+
const fanReplica = makeLaggingRouter(prisma14, prisma17);
546+
await expect(
547+
fanReplica.router.findRunOrThrow(
548+
{ spanId: "span_rows_legacy" },
549+
{ select: { id: true } },
550+
markReadReplicaClient({}) as never
551+
)
552+
).rejects.toThrow("lagging replica");
553+
expect(fanReplica.hits()).toEqual({ ...none, newReplica: true, legacyReplica: true });
554+
}
555+
);
477556
});

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

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,8 +1166,12 @@ export class RoutingRunStore implements RunStore {
11661166
if (id !== undefined) {
11671167
// Residency-classifiable (id/friendlyId): route to the owning store and let it throw on miss.
11681168
const store = this.#routeOrNew(id);
1169-
const method = onPrimary ? "findRunOrThrowOnPrimary" : "findRunOrThrow";
1170-
return (store[method] as (...rest: unknown[]) => Promise<unknown>)(where, args);
1169+
// The client goes second when there is no field list: the Postgres store reads it from there.
1170+
return (store.findRunOrThrow as (...rest: unknown[]) => Promise<unknown>)(
1171+
where,
1172+
...(args === undefined ? [] : [args]),
1173+
onPrimary ? store.primaryReadClient : undefined
1174+
);
11711175
}
11721176
// Unclassifiable where (e.g. spanId): the run may live on either DB, so fan out NEW-first then
11731177
// LEGACY rather than defaulting to NEW — defaulting silently misses legacy-resident runs and
@@ -1182,9 +1186,15 @@ export class RoutingRunStore implements RunStore {
11821186
): Promise<unknown> {
11831187
const probe = onPrimary ? "findRunOnPrimary" : "findRun";
11841188
// The last probe leg owns the canonical not-found throw when every shard misses.
1185-
const throwMethod = onPrimary ? "findRunOrThrowOnPrimary" : "findRunOrThrow";
11861189
return this.#probeFirst((store, _key, isLast) =>
1187-
(store[isLast ? throwMethod : probe] as (...rest: unknown[]) => Promise<unknown>)(where, args)
1190+
isLast
1191+
? // The client goes second when there is no field list: the Postgres store reads it from there.
1192+
(store.findRunOrThrow as (...rest: unknown[]) => Promise<unknown>)(
1193+
where,
1194+
...(args === undefined ? [] : [args]),
1195+
onPrimary ? store.primaryReadClient : undefined
1196+
)
1197+
: (store[probe] as (...rest: unknown[]) => Promise<unknown>)(where, args)
11881198
);
11891199
}
11901200

@@ -1213,30 +1223,6 @@ export class RoutingRunStore implements RunStore {
12131223
return this.#findRunUnrouted(where, args, true);
12141224
}
12151225

1216-
findRunOrThrowOnPrimary<S extends Prisma.TaskRunSelect>(
1217-
where: Prisma.TaskRunWhereInput,
1218-
args: { select: S }
1219-
): Promise<Prisma.TaskRunGetPayload<{ select: S }>>;
1220-
findRunOrThrowOnPrimary<I extends Prisma.TaskRunInclude>(
1221-
where: Prisma.TaskRunWhereInput,
1222-
args: { include: I }
1223-
): Promise<Prisma.TaskRunGetPayload<{ include: I }>>;
1224-
findRunOrThrowOnPrimary(where: Prisma.TaskRunWhereInput): Promise<TaskRun>;
1225-
findRunOrThrowOnPrimary(
1226-
where: Prisma.TaskRunWhereInput,
1227-
args?: { select?: unknown; include?: unknown }
1228-
): Promise<unknown> {
1229-
const id = idFromWhere(where);
1230-
if (id !== undefined) {
1231-
const store = this.#routeOrNew(id);
1232-
return (store.findRunOrThrowOnPrimary as (...rest: unknown[]) => Promise<unknown>)(
1233-
where,
1234-
args
1235-
);
1236-
}
1237-
return this.#findRunOrThrowUnrouted(where, args, true);
1238-
}
1239-
12401226
// ---------------------------------------------------------------------------
12411227
// run-ops persistence (snapshots / waitpoints / implicit joins / dependents / attempts /
12421228
// checkpoints). Mechanical residency-routing delegates so `implements RunStore` is satisfied.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export const RUN_STORE_METHOD_NAMES = [
4242
"findRun",
4343
"findRunOrThrow",
4444
"findRunOnPrimary",
45-
"findRunOrThrowOnPrimary",
4645
"findRuns",
4746
"findRunsByIds",
4847
"findRunsByIdempotencyKeys",

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -735,16 +735,6 @@ export interface RunStore {
735735
): Promise<Prisma.TaskRunGetPayload<{ include: I }> | null>;
736736
findRunOnPrimary(where: Prisma.TaskRunWhereInput): Promise<TaskRun | null>;
737737

738-
findRunOrThrowOnPrimary<S extends Prisma.TaskRunSelect>(
739-
where: Prisma.TaskRunWhereInput,
740-
args: { select: S }
741-
): Promise<Prisma.TaskRunGetPayload<{ select: S }>>;
742-
findRunOrThrowOnPrimary<I extends Prisma.TaskRunInclude>(
743-
where: Prisma.TaskRunWhereInput,
744-
args: { include: I }
745-
): Promise<Prisma.TaskRunGetPayload<{ include: I }>>;
746-
findRunOrThrowOnPrimary(where: Prisma.TaskRunWhereInput): Promise<TaskRun>;
747-
748738
findRuns<S extends Prisma.TaskRunSelect>(
749739
args: {
750740
where: Prisma.TaskRunWhereInput;

0 commit comments

Comments
 (0)