Skip to content

Commit 400c999

Browse files
steipeteErick Kinnee
andcommitted
fix(plugins): enforce agent-scoped live catalog discovery
Co-authored-by: Erick Kinnee <[email protected]>
1 parent f191bae commit 400c999

7 files changed

Lines changed: 114 additions & 9 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Docs: https://docs.openclaw.ai
6969

7070
### Fixes
7171

72+
- **Provider catalog isolation:** scope startup, live discovery, synthetic authentication, and catalog outcomes to each agent's selected providers, authenticated providers, and effective model-policy wildcards. (#129624) Thanks @ekinnee.
7273
- **Control UI terminal transcript settlement:** retire live commentary, tool, and streamed reply projections atomically when the matching durable terminal message arrives, preventing duplicated final responses and transient row overlap after steering. Fixes #127209. Thanks @shakkernerd.
7374
- **Control UI Codex compaction history:** preserve successful native context compactions as durable, model-excluded activity inside completed work traces after the composer status clears or the session reloads. Fixes #127206. Thanks @shakkernerd.
7475
- **Control UI Codex steering:** preserve pre-steer commentary and tool activity in durable transcript order, keep it visible while active, and collapse it before the steering message after completion. Fixes #126938. Thanks @shakkernerd.

‎src/agents/prepared-model-catalog.worker.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** Worker-thread entrypoint for complete model-catalog discovery. */
22
import { parentPort, workerData } from "node:worker_threads";
33
import { withPluginRuntimeGenerationScope } from "../plugins/runtime/generation-scope.js";
4+
import { resolveRuntimeSyntheticAuthProviderRefs } from "../plugins/synthetic-auth.runtime.js";
45
import {
56
resolveAgentCredentialMapFromStore,
67
resolveUsableAgentCredentialModes,
@@ -20,6 +21,7 @@ import {
2021
type PreparedModelWorkerRequest,
2122
type PreparedModelWorkerResult,
2223
} from "./prepared-model-catalog-worker.js";
24+
import { scopeSyntheticAuthProviderRefs } from "./prepared-model-runtime.synthetic-auth.js";
2325
import { AuthStorage } from "./sessions/auth-storage.js";
2426

2527
function refreshAuthStore(params: {
@@ -145,6 +147,10 @@ export async function runPreparedModelCatalogWorkerRequest(
145147
resolveAmbientAgentCredentialsForDiscovery({
146148
config: value.input.config,
147149
env: value.input.env,
150+
syntheticAuthProviderRefs: scopeSyntheticAuthProviderRefs(
151+
resolveRuntimeSyntheticAuthProviderRefs(),
152+
value.providerIds,
153+
),
148154
...(value.input.workspaceDir ? { workspaceDir: value.input.workspaceDir } : {}),
149155
}),
150156
);

‎src/agents/prepared-model-runtime.facts.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ import {
3030
loadBundledProviderStaticCatalogContextModels,
3131
} from "./embedded-agent-runner/model.static-catalog.js";
3232
import { createStaticModelIdMatcher } from "./embedded-agent-runner/model.static-id.js";
33-
import { buildConfiguredModelCatalog } from "./model-selection-shared.js";
33+
import {
34+
buildConfiguredModelCatalog,
35+
parseConfiguredModelVisibilityEntries,
36+
} from "./model-selection-shared.js";
3437
import { ensureOpenClawModelsJson, planOpenClawModelsJsonSource } from "./models-config.js";
3538
import { prepareImplicitProviderStaticCatalog } from "./models-config.providers.implicit.js";
3639
import {
@@ -131,6 +134,10 @@ function prepareAgentFacts(
131134
catalogMode === "live",
132135
configuredModelRefs,
133136
),
137+
...parseConfiguredModelVisibilityEntries({
138+
cfg: input.config,
139+
agentId: input.agentId,
140+
}).providerWildcards,
134141
...additionalProviderIds.map(normalizeProviderId).filter(Boolean),
135142
]),
136143
].toSorted((left, right) => left.localeCompare(right)),
@@ -236,6 +243,9 @@ export async function prepareWorkspaceBuildGroup(
236243
const configuredProviderIds = [
237244
...new Set([
238245
...collectPreparedModelRuntimeProviderIds(input.config, {}, false),
246+
...inputs.flatMap(({ config, agentId }) => [
247+
...parseConfiguredModelVisibilityEntries({ cfg: config, agentId }).providerWildcards,
248+
]),
239249
...(options.providerDiscoveryProviderIds ?? []).map(normalizeProviderId).filter(Boolean),
240250
]),
241251
].toSorted((left, right) => left.localeCompare(right));
@@ -282,7 +292,7 @@ export async function prepareWorkspaceBuildGroup(
282292
registryDiagnostics: pluginMetadataSnapshot.registryDiagnostics,
283293
...(input.workspaceDir ? { workspaceDir: input.workspaceDir } : {}),
284294
}),
285-
options.providerDiscoveryProviderIds,
295+
configuredProviderIds,
286296
),
287297
...(catalogMode === "static"
288298
? {
@@ -602,6 +612,7 @@ export async function prepareAgentCatalogSource(
602612
);
603613
const options = {
604614
pluginMetadataSnapshot: pluginGeneration.pluginMetadataSnapshot,
615+
providerDiscoveryProviderIds: sourceOptions.providerDiscoveryProviderIds ?? providerIds,
605616
...(pluginGeneration.preparedStaticProviderCatalog
606617
? { preparedStaticProviderCatalog: pluginGeneration.preparedStaticProviderCatalog }
607618
: {}),
@@ -610,13 +621,9 @@ export async function prepareAgentCatalogSource(
610621
...(catalogMode === "static"
611622
? {
612623
providerDiscoveryEntriesOnly: true as const,
613-
providerDiscoveryProviderIds: sourceOptions.providerDiscoveryProviderIds ?? providerIds,
614624
}
615625
: {
616626
providerDiscoveryTimeoutMs: MODEL_RUNTIME_PROVIDER_DISCOVERY_TIMEOUT_MS,
617-
...(sourceOptions.providerDiscoveryProviderIds
618-
? { providerDiscoveryProviderIds: sourceOptions.providerDiscoveryProviderIds }
619-
: {}),
620627
}),
621628
};
622629
if (!persist) {

‎src/agents/prepared-model-runtime.startup-static.test.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,12 @@ describe("prepared model runtime Gateway catalog mode", () => {
243243
beta: { api: "openai-completions" as const, baseUrl: "https://beta.invalid", models: [] },
244244
},
245245
},
246-
agents: { defaults: { model: { primary: "openai/gpt-5.5" } } },
246+
agents: {
247+
defaults: {
248+
model: { primary: "openai/gpt-5.5" },
249+
modelPolicy: { allow: ["vllm/*"] },
250+
},
251+
},
247252
};
248253

249254
await prepareScopedReadOnlyModelCatalog(
@@ -261,7 +266,7 @@ describe("prepared model runtime Gateway catalog mode", () => {
261266

262267
expect(mocks.prepareStaticCatalog).toHaveBeenCalledWith(
263268
expect.objectContaining({
264-
providerDiscoveryProviderIds: ["anthropic", "local-runtime", "openai"],
269+
providerDiscoveryProviderIds: ["anthropic", "local-runtime", "openai", "vllm"],
265270
staticCatalogProviderIds: ["anthropic", "local-runtime", "openai"],
266271
}),
267272
);
@@ -270,7 +275,7 @@ describe("prepared model runtime Gateway catalog mode", () => {
270275
"/tmp/prepared-static-agent",
271276
expect.objectContaining({
272277
providerDiscoveryEntriesOnly: true,
273-
providerDiscoveryProviderIds: ["anthropic", "local-runtime", "openai"],
278+
providerDiscoveryProviderIds: ["anthropic", "local-runtime", "openai", "vllm"],
274279
}),
275280
);
276281
expect(mocks.ensureOpenClawModelsJson).not.toHaveBeenCalled();

‎src/agents/prepared-model-runtime.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,46 @@ describe("prepared model runtime snapshots", () => {
335335
]);
336336
});
337337

338+
it("limits live discovery to the selected agent's models and authenticated providers", async () => {
339+
const config = {
340+
agents: {
341+
defaults: { model: { primary: "openai/gpt-5.6" } },
342+
list: [
343+
{
344+
id: "selected",
345+
model: { primary: "anthropic/claude-sonnet-5" },
346+
modelPolicy: { allow: ["vllm/*"] },
347+
},
348+
{
349+
id: "sibling",
350+
model: { primary: "ollama/sibling" },
351+
modelPolicy: { allow: ["sibling-only/*"] },
352+
},
353+
],
354+
},
355+
models: {
356+
providers: {
357+
unrelated: { baseUrl: "https://unrelated.example/v1", models: [] },
358+
vllm: { baseUrl: "https://vllm.example/v1", models: [] },
359+
},
360+
},
361+
} as OpenClawConfig;
362+
363+
await publishPreparedModelRuntimeSnapshot({
364+
agentId: "selected",
365+
config,
366+
agentDir: "/tmp/prepared-model-runtime-selected-provider-scope",
367+
});
368+
369+
expect(mocks.ensureOpenClawModelsJson).toHaveBeenCalledWith(
370+
config,
371+
"/tmp/prepared-model-runtime-selected-provider-scope",
372+
expect.objectContaining({
373+
providerDiscoveryProviderIds: ["anthropic", "custom", "openai", "vllm"],
374+
}),
375+
);
376+
});
377+
338378
it("captures static provider-hook rows in the same lifecycle generation", async () => {
339379
mocks.loadStaticCatalog.mockResolvedValueOnce([
340380
{

‎src/plugins/provider-discovery.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,44 @@ describe("runProviderCatalog", () => {
181181
{ provider: "openai", profileId: "openai:chatgpt", status: "auth-rejected" },
182182
]);
183183
});
184+
185+
it.each([
186+
{ providerIds: ["OPENAI"], expected: ["openai"] },
187+
{ providerIds: ["azure-openai"], expected: ["azure-openai"] },
188+
{ providerIds: [], expected: [] },
189+
])(
190+
"emits outcomes only for selected provider identities: $providerIds",
191+
async ({ providerIds, expected }) => {
192+
const outcomes: string[] = [];
193+
const provider: ProviderPlugin = {
194+
id: "openai",
195+
label: "OpenAI",
196+
auth: [],
197+
catalog: {
198+
run: async () => ({
199+
providers: {},
200+
outcomes: [
201+
{ provider: "openai", profileId: "openai:private", status: "auth-rejected" },
202+
{ provider: "azure-openai", profileId: "azure-openai:selected", status: "ready" },
203+
{ provider: "unrelated", status: "unavailable" },
204+
],
205+
}),
206+
},
207+
};
208+
209+
await runProviderCatalog({
210+
provider,
211+
providerIds,
212+
config: {},
213+
env: {},
214+
resolveProviderApiKey: () => ({ apiKey: undefined }),
215+
resolveProviderAuth: () => ({ apiKey: undefined, mode: "none", source: "none" }),
216+
reportCatalogOutcome: (outcome) => outcomes.push(outcome.provider),
217+
});
218+
219+
expect(outcomes).toEqual(expected);
220+
},
221+
);
184222
});
185223

186224
describe("normalizePluginDiscoveryResult", () => {

‎src/plugins/provider-discovery.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ export async function runProviderCatalog(params: {
181181
resolveProviderAuth: params.resolveProviderAuth,
182182
});
183183
for (const outcome of copyProviderCatalogOutcomes(result)) {
184+
if (
185+
params.providerIds !== undefined &&
186+
!params.providerIds.some(
187+
(providerId) => normalizeProviderId(providerId) === normalizeProviderId(outcome.provider),
188+
)
189+
) {
190+
continue;
191+
}
184192
params.reportCatalogOutcome?.(outcome);
185193
}
186194
return result;

0 commit comments

Comments
 (0)