Skip to content

Commit 6e4c0de

Browse files
d-csclaude
andcommitted
fix(run-ops split): align WaitpointPresenter single-DB fallback and repair read-side test shims
- WaitpointPresenter: default omitted read-through clients to the presenter's own replica instead of the global run-ops singletons, so single-DB/self-host reads hydrate the waitpoint and its connected runs from one DB. - SpanPresenter test: bind proxy-returned store methods to the target so private field access holds for all methods (e.g. findRunOnPrimary), not just findRun/findRuns. - ApiRetrieveRunPresenter read-route test: select scalar lockedToVersionId and fold the resolved lockedToVersion per node, matching the presenter's current shape. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 94eaef6 commit 6e4c0de

3 files changed

Lines changed: 23 additions & 16 deletions

File tree

apps/webapp/app/presenters/v3/WaitpointPresenter.server.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { isWaitpointOutputTimeout, prettyPrintPacket } from "@trigger.dev/core/v3";
2-
import {
3-
type PrismaClientOrTransaction,
4-
type PrismaReplicaClient,
5-
runOpsNewReplica,
6-
runOpsLegacyReplica,
7-
} from "~/db.server";
2+
import { type PrismaClientOrTransaction, type PrismaReplicaClient } from "~/db.server";
83
import { clickhouseFactory } from "~/services/clickhouse/clickhouseFactoryInstance.server";
94
import { generateHttpCallbackUrl } from "~/services/httpCallback.server";
105
import { logger } from "~/services/logger.server";
@@ -74,10 +69,11 @@ export class WaitpointPresenter extends BasePresenter {
7469
deps: {
7570
splitEnabled: this.readThroughDeps.splitEnabled,
7671
newClient:
77-
(this.readThroughDeps.newClient as PrismaReplicaClient | undefined) ?? runOpsNewReplica,
72+
(this.readThroughDeps.newClient as PrismaReplicaClient | undefined) ??
73+
(this._replica as unknown as PrismaReplicaClient),
7874
legacyReplica:
7975
(this.readThroughDeps.legacyReplica as PrismaReplicaClient | undefined) ??
80-
runOpsLegacyReplica,
76+
(this._replica as unknown as PrismaReplicaClient),
8177
},
8278
});
8379

apps/webapp/test/SpanPresenter.readthrough.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,16 @@ async function createRun(
157157
function ownDbStore(prisma: PrismaClient): RunStore {
158158
const inner = new PostgresRunStore({ prisma, readOnlyPrisma: prisma });
159159
return new Proxy(inner, {
160-
get(target, prop, receiver) {
160+
get(target, prop) {
161161
if (prop === "findRun" || prop === "findRuns") {
162162
return (...args: unknown[]) => {
163163
// Strip a trailing explicit `client` arg so the store reads from its own DB.
164164
const stripped = stripTrailingClient(prop, args);
165-
return (target[prop] as (...a: unknown[]) => unknown)(...stripped);
165+
return (target[prop] as (...a: unknown[]) => unknown).apply(target, stripped);
166166
};
167167
}
168-
return Reflect.get(target, prop, receiver);
168+
const value = Reflect.get(target, prop, target);
169+
return typeof value === "function" ? value.bind(target) : value;
169170
},
170171
}) as unknown as RunStore;
171172
}

apps/webapp/test/apiRetrieveRunPresenter.readroute.test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const commonRunSelect = {
6060
scheduleId: true,
6161
workerQueue: true,
6262
region: true,
63-
lockedToVersion: { select: { version: true } },
63+
lockedToVersionId: true,
6464
resumeParentOnCompletion: true,
6565
batch: { select: { id: true, friendlyId: true } },
6666
runTags: true,
@@ -84,18 +84,28 @@ const findRunSelect = {
8484
} satisfies Prisma.TaskRunSelect;
8585

8686
// Drive the read exactly as `findRun` does: the RunStore.findRun contract over
87-
// the given store with the presenter's where+select, mapping to FoundRun.
87+
// the given store with the presenter's where+select. The scalar `lockedToVersionId`
88+
// folds to a resolved `lockedToVersion` per node, matching the presenter's shape;
89+
// seeded runs carry no locked version, so every node resolves to null.
8890
async function readFoundRunViaStore(
8991
store: PostgresRunStore,
9092
friendlyId: string,
9193
runtimeEnvironmentId: string
9294
): Promise<FoundRun | null> {
93-
const pgRow = await store.findRun(
95+
const pgRow = (await store.findRun(
9496
{ friendlyId, runtimeEnvironmentId },
9597
{ select: findRunSelect }
96-
);
98+
)) as Record<string, any> | null;
9799
if (!pgRow) return null;
98-
return { ...(pgRow as Omit<FoundRun, "isBuffered">), isBuffered: false };
100+
const foldVersion = (run: Record<string, any>) => ({ ...run, lockedToVersion: null });
101+
return {
102+
...pgRow,
103+
lockedToVersion: null,
104+
parentTaskRun: pgRow.parentTaskRun ? foldVersion(pgRow.parentTaskRun) : null,
105+
rootTaskRun: pgRow.rootTaskRun ? foldVersion(pgRow.rootTaskRun) : null,
106+
childRuns: (pgRow.childRuns ?? []).map(foldVersion),
107+
isBuffered: false,
108+
} as FoundRun;
99109
}
100110

101111
async function seedOrgProjectEnv(prisma: PrismaClient, suffix: string) {

0 commit comments

Comments
 (0)