Skip to content

Commit d087c25

Browse files
d-csclaude
andcommitted
fix(run-ops split): make webapp assertEnvExists a no-op when split is OFF
With the split OFF there is a single DB, so a run and its environment are co-located and there is no cross-seam FK/check to replace (matches main). Skip the always-on hot-path read in that branch; the split-ON branch is unchanged (cache-first, throws on a genuinely missing env). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4119616 commit d087c25

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

apps/webapp/app/v3/runOpsMigration/controlPlaneResolver.server.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,8 @@ export class ControlPlaneResolver {
394394

395395
async assertEnvExists(environmentId: string): Promise<void> {
396396
if (!this.splitEnabled()) {
397-
const exists = await this.#queryEnvExists(this.controlPlanePrimary, environmentId);
398-
if (!exists) {
399-
throw new ControlPlaneReferenceError(
400-
`Referenced environment does not exist: ${environmentId}`
401-
);
402-
}
397+
// Split OFF = single DB, so run and env are co-located and there is no FK/check
398+
// to replace (matches main). Skip the hot-path read entirely.
403399
return;
404400
}
405401

apps/webapp/test/v3/runOpsMigration/controlPlaneResolver.server.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,21 +335,22 @@ heteroPostgresTest(
335335
);
336336

337337
heteroPostgresTest(
338-
"assertEnvExists passthrough (split OFF) still validates a real env",
338+
"assertEnvExists passthrough (split OFF) is a no-op: never reads, never throws",
339339
async ({ prisma14 }) => {
340340
const { environment } = await seedControlPlane(prisma14);
341-
const { client: counting } = countQueries(prisma14);
341+
const { client: counting, reads } = countQueries(prisma14);
342342
const resolver = new ControlPlaneResolver({
343343
controlPlaneReplica: counting,
344344
controlPlanePrimary: counting,
345345
cache: new ControlPlaneCache(),
346346
splitEnabled: () => false,
347347
});
348348

349+
// Split OFF = single DB, run and env co-located, so there is nothing to assert
350+
// and the hot-path read is skipped entirely — resolves for present and missing.
349351
await expect(resolver.assertEnvExists(environment.id)).resolves.toBeUndefined();
350-
await expect(resolver.assertEnvExists("env_missing")).rejects.toBeInstanceOf(
351-
ControlPlaneReferenceError
352-
);
352+
await expect(resolver.assertEnvExists("env_missing")).resolves.toBeUndefined();
353+
expect(reads()).toBe(0);
353354
}
354355
);
355356

apps/webapp/test/v3/runOpsMigration/runEngineControlPlaneResolver.server.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,14 @@ describe("RunEngineControlPlaneResolver adapter", () => {
205205
);
206206

207207
heteroPostgresTest(
208-
"assertEnvExists resolves for a present env, rejects for a missing one",
208+
"assertEnvExists (split ON) resolves for a present env, rejects for a missing one",
209209
async ({ prisma14 }) => {
210210
const { environment } = await seedEnv(prisma14, "PRODUCTION");
211-
const adapter = new RunEngineControlPlaneResolver(buildAppResolver(prisma14));
211+
// split ON: the only mode where assertEnvExists asserts (split OFF is a no-op,
212+
// covered in controlPlaneResolver.server.test.ts).
213+
const adapter = new RunEngineControlPlaneResolver(
214+
buildAppResolver(prisma14, { splitEnabled: true })
215+
);
212216

213217
await expect(adapter.assertEnvExists(environment.id)).resolves.toBeUndefined();
214218
await expect(adapter.assertEnvExists("env_missing")).rejects.toThrow();

0 commit comments

Comments
 (0)