Skip to content

Commit a391203

Browse files
committed
fix: use loadAll()[0] fallback for AmbiguousScopeError
The previous fallback tried load(dbId, 'app') which fails when the test infrastructure provisions modules with non-'app' scopes (e.g. 'platform' + 'org'). Using loadAll()[0] picks the first available instance without assuming a specific scope name. Also fixes worker.test.ts: invalidateAll() → invalidate() to match the ModuleLoader API.
1 parent d32776a commit a391203

8 files changed

Lines changed: 19 additions & 9 deletions

File tree

job/compute-worker/src/compute-log.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ export class ComputeLogTracker {
4747
return;
4848
}
4949
if (err instanceof AmbiguousScopeError) {
50-
cfg = await this.loader.computeLog.load(this.databaseId, 'app');
50+
const all = await this.loader.computeLog.loadAll(this.databaseId);
51+
cfg = all[0];
5152
} else {
5253
throw err;
5354
}
5455
}
56+
if (!cfg) return;
5557

5658
const qualifiedTable = `"${cfg.publicSchema}"."${cfg.computeLogTable}"`;
5759
try {
@@ -91,11 +93,13 @@ export class ComputeLogTracker {
9193
return 0;
9294
}
9395
if (err instanceof AmbiguousScopeError) {
94-
cfg = await this.loader.computeLog.load(this.databaseId, 'app');
96+
const all = await this.loader.computeLog.loadAll(this.databaseId);
97+
cfg = all[0];
9598
} else {
9699
throw err;
97100
}
98101
}
102+
if (!cfg) return 0;
99103

100104
try {
101105
const result = await this.pool.query(

job/compute-worker/src/discovery.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export class FunctionDiscovery {
3939
return await this.loader.function.load(this.databaseId, null);
4040
} catch (err) {
4141
if (err instanceof AmbiguousScopeError) {
42-
return await this.loader.function.load(this.databaseId, 'app');
42+
const all = await this.loader.function.loadAll(this.databaseId);
43+
return all[0];
4344
}
4445
throw err;
4546
}

job/compute-worker/src/invocation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export class InvocationTracker {
4040
} catch (err) {
4141
if (err instanceof ModuleNotProvisionedError) return null;
4242
if (err instanceof AmbiguousScopeError) {
43-
return await this.loader.invocation.load(dbId, 'app');
43+
const all = await this.loader.invocation.loadAll(dbId);
44+
return all[0] ?? null;
4445
}
4546
throw err;
4647
}

job/worker/src/compute-meter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export function logComputeUsage(pool: Pool, entry: MeterEntry): string {
5252
return await loader.invocation.load(databaseId, entry.scope ?? null);
5353
} catch (err) {
5454
if (err instanceof AmbiguousScopeError) {
55-
return await loader.invocation.load(databaseId, 'app');
55+
const all = await loader.invocation.loadAll(databaseId);
56+
return all[0];
5657
}
5758
throw err;
5859
}

job/worker/src/graph-complete.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ async function resolveGraph(pool: Pool, databaseId: string, scope?: string | nul
2727
return await getLoader(pool).graph.load(databaseId, scope ?? null);
2828
} catch (err) {
2929
if (err instanceof AmbiguousScopeError) {
30-
return await getLoader(pool).graph.load(databaseId, 'app');
30+
const all = await getLoader(pool).graph.loadAll(databaseId);
31+
return all[0];
3132
}
3233
throw err;
3334
}

job/worker/src/storage-meter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ async function resolveComputeLog(pool: Pool, databaseId: string, scope: string |
3636
return await getLoader(pool).computeLog.load(databaseId, scope);
3737
} catch (err) {
3838
if (err instanceof AmbiguousScopeError) {
39-
return await getLoader(pool).computeLog.load(databaseId, 'app');
39+
const all = await getLoader(pool).computeLog.loadAll(databaseId);
40+
return all[0];
4041
}
4142
throw err;
4243
}

packages/agentic-server/src/inference-meter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ async function resolveComputeLog(pool: Pool, databaseId: string, scope: string |
4646
return await getLoader(pool).computeLog.load(databaseId, scope);
4747
} catch (err) {
4848
if (err instanceof AmbiguousScopeError) {
49-
return await getLoader(pool).computeLog.load(databaseId, 'app');
49+
const all = await getLoader(pool).computeLog.loadAll(databaseId);
50+
return all[0];
5051
}
5152
throw err;
5253
}

packages/functions-test/__tests__/worker.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ beforeEach(async () => {
6565
await conn.db.beforeEach();
6666
mockServer.reset();
6767
// Invalidate caches so each test gets fresh module config
68-
worker.loader.invalidateAll();
68+
worker.loader.invalidate();
6969
worker.discovery.invalidateAll();
7070
});
7171

0 commit comments

Comments
 (0)