Skip to content

Commit d07ba5f

Browse files
committed
fix(providers): avoid custom provider runtime fanout
1 parent f789081 commit d07ba5f

10 files changed

Lines changed: 271 additions & 16 deletions

‎CHANGELOG.md‎

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

4646
### Fixes
4747

48+
- Agents/providers: avoid loading owner plugin runtimes for explicitly configured custom provider models during OpenAI-compatible transport setup.
4849
- Release/CI/E2E: fail early when Crabbox sparse-sync full checkouts do not have enough local disk, with guidance for moving the sync root.
4950
- Build: render independent CLI startup metadata help snapshots concurrently to cut cold build-all metadata time.
5051
- Plugins: stop timed-out package-boundary prep steps by process group so descendant TypeScript/helper processes do not survive local check cleanup.

‎src/agents/agent-model-discovery.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export function normalizeDiscoveredAgentModel<T>(value: T, agentDir: string): T
5555
const pluginNormalized =
5656
normalizeProviderResolvedModelWithPlugin({
5757
provider: model.provider,
58+
modelId: model.id,
5859
context: {
5960
provider: model.provider,
6061
modelId: model.id,
@@ -65,6 +66,7 @@ export function normalizeDiscoveredAgentModel<T>(value: T, agentDir: string): T
6566
const transportNormalized =
6667
applyProviderResolvedTransportWithPlugin({
6768
provider: model.provider,
69+
modelId: model.id,
6870
context: {
6971
provider: model.provider,
7072
modelId: model.id,

‎src/agents/embedded-agent-runner/model.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,12 @@ function applyResolvedTransportFallback(params: {
187187
provider: params.provider,
188188
config: params.cfg,
189189
workspaceDir: params.workspaceDir,
190+
modelId: params.model.id,
190191
context: {
191192
config: params.cfg,
192193
workspaceDir: params.workspaceDir,
193194
provider: params.provider,
195+
modelId: params.model.id,
194196
api: params.model.api,
195197
baseUrl: params.model.baseUrl,
196198
},
@@ -309,6 +311,7 @@ function normalizeResolvedModel(params: {
309311

310312
function resolveProviderTransport(params: {
311313
provider: string;
314+
modelId?: string;
312315
api?: Api | null;
313316
baseUrl?: string;
314317
cfg?: OpenClawConfig;
@@ -321,12 +324,14 @@ function resolveProviderTransport(params: {
321324
const runtimeHooks = params.runtimeHooks ?? DEFAULT_PROVIDER_RUNTIME_HOOKS;
322325
const normalized = runtimeHooks.normalizeProviderTransportWithPlugin({
323326
provider: params.provider,
327+
...(params.modelId ? { modelId: params.modelId } : {}),
324328
config: params.cfg,
325329
workspaceDir: params.workspaceDir,
326330
context: {
327331
config: params.cfg,
328332
workspaceDir: params.workspaceDir,
329333
provider: params.provider,
334+
...(params.modelId ? { modelId: params.modelId } : {}),
330335
api: params.api,
331336
baseUrl: params.baseUrl,
332337
},
@@ -696,6 +701,7 @@ function applyConfiguredProviderOverrides(params: {
696701

697702
const resolvedTransport = resolveProviderTransport({
698703
provider: params.provider,
704+
modelId: discoveredModel.id,
699705
api: resolvedTransportApi,
700706
baseUrl: resolvedTransportBaseUrl,
701707
cfg: params.cfg,
@@ -1060,6 +1066,7 @@ function resolveConfiguredFallbackModel(params: {
10601066
});
10611067
const fallbackTransport = resolveProviderTransport({
10621068
provider,
1069+
modelId,
10631070
api:
10641071
normalizeResolvedTransportApi(configuredModel?.api) ??
10651072
resolveConfiguredProviderDefaultApi({
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { describe, expect, it } from "vitest";
2+
import type { OpenClawConfig } from "../config/types.openclaw.js";
3+
import { resolveModelCatalogScope } from "./model-catalog-scope.js";
4+
5+
describe("resolveModelCatalogScope", () => {
6+
it("keeps explicit custom provider models scoped to that provider", () => {
7+
const cfg = {
8+
models: {
9+
providers: {
10+
"tui-pty-mock": {
11+
api: "openai-responses",
12+
baseUrl: "http://127.0.0.1:64087/v1",
13+
models: [
14+
{
15+
id: "gpt-5.5",
16+
name: "gpt-5.5",
17+
reasoning: true,
18+
input: ["text"],
19+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
20+
contextWindow: 128_000,
21+
maxTokens: 8_192,
22+
},
23+
],
24+
},
25+
},
26+
},
27+
} as OpenClawConfig;
28+
29+
expect(
30+
resolveModelCatalogScope({
31+
cfg,
32+
provider: "tui-pty-mock",
33+
model: "gpt-5.5",
34+
}).modelRefs,
35+
).toEqual(["tui-pty-mock/gpt-5.5"]);
36+
});
37+
38+
it("keeps bare model refs for manifest-owned model lookup", () => {
39+
expect(
40+
resolveModelCatalogScope({
41+
cfg: {},
42+
provider: "openai",
43+
model: "gpt-5.4",
44+
}).modelRefs,
45+
).toEqual(["openai/gpt-5.4", "gpt-5.4"]);
46+
});
47+
});

‎src/agents/model-catalog-scope.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ function providerFromModelRef(value: string | undefined): string | undefined {
2222
return provider || undefined;
2323
}
2424

25+
function providerConfigDeclaresModel(
26+
providerConfig: { models?: readonly { id?: string }[] } | undefined,
27+
model: string,
28+
): boolean {
29+
const trimmedModel = model.trim();
30+
return Boolean(
31+
trimmedModel &&
32+
providerConfig?.models?.some((candidate) => candidate.id?.trim() === trimmedModel),
33+
);
34+
}
35+
2536
export function resolveModelCatalogScope(params: {
2637
cfg?: OpenClawConfig;
2738
provider: string;
@@ -30,9 +41,12 @@ export function resolveModelCatalogScope(params: {
3041
const provider = params.provider.trim();
3142
const model = params.model.trim();
3243
const providerConfig = findNormalizedProviderValue(params.cfg?.models?.providers, provider);
44+
const modelRefs = providerConfigDeclaresModel(providerConfig, model)
45+
? [provider && model ? `${provider}/${model}` : model]
46+
: [provider && model ? `${provider}/${model}` : model, model];
3347
return {
3448
providerRefs: dedupeCatalogScopeRefs([provider, providerConfig?.api]),
35-
modelRefs: dedupeCatalogScopeRefs([provider && model ? `${provider}/${model}` : model, model]),
49+
modelRefs: dedupeCatalogScopeRefs(modelRefs),
3650
};
3751
}
3852

‎src/agents/openai-transport-stream.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,8 +1807,15 @@ function resolveProviderTransportTurnState(
18071807
transport: "stream" | "websocket";
18081808
},
18091809
) {
1810+
const normalizedProvider = model.provider.trim().toLowerCase();
1811+
const allowRuntimePluginLoad =
1812+
normalizedProvider === "openai" ||
1813+
normalizedProvider === "azure-openai" ||
1814+
normalizedProvider === "azure-openai-responses";
18101815
return resolveProviderTransportTurnStateWithPlugin({
18111816
provider: model.provider,
1817+
modelId: model.id,
1818+
allowRuntimePluginLoad,
18121819
context: {
18131820
provider: model.provider,
18141821
modelId: model.id,

‎src/plugins/provider-hook-runtime.ts‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id";
1+
import {
2+
findNormalizedProviderValue,
3+
normalizeProviderId,
4+
} from "@openclaw/model-catalog-core/provider-id";
25
import {
36
normalizeLowercaseStringOrEmpty,
47
normalizeOptionalString,
@@ -189,6 +192,15 @@ function findProviderRuntimePluginInRegistry(params: {
189192
});
190193
}
191194

195+
function hasConfiguredModelProvider(params: {
196+
provider: string;
197+
config?: OpenClawConfig;
198+
}): boolean {
199+
return (
200+
findNormalizedProviderValue(params.config?.models?.providers, params.provider) !== undefined
201+
);
202+
}
203+
192204
export function resolveProviderPluginsForHooks(params: {
193205
config?: OpenClawConfig;
194206
workspaceDir?: string;
@@ -306,18 +318,23 @@ export function resolveLoadedProviderRuntimePlugin(
306318

307319
export function resolveProviderHookPlugin(params: {
308320
provider: string;
321+
modelId?: string | null;
309322
config?: OpenClawConfig;
310323
workspaceDir?: string;
311324
env?: NodeJS.ProcessEnv;
312325
}): ProviderPlugin | undefined {
313-
return (
314-
resolveProviderRuntimePlugin(params) ??
315-
resolveProviderPluginsForHooks({
316-
config: params.config,
317-
workspaceDir: params.workspaceDir,
318-
env: params.env,
319-
}).find((candidate) => matchesProviderId(candidate, params.provider))
320-
);
326+
const runtimePlugin = resolveProviderRuntimePlugin(params);
327+
if (runtimePlugin) {
328+
return runtimePlugin;
329+
}
330+
if (hasConfiguredModelProvider(params)) {
331+
return undefined;
332+
}
333+
return resolveProviderPluginsForHooks({
334+
config: params.config,
335+
workspaceDir: params.workspaceDir,
336+
env: params.env,
337+
}).find((candidate) => matchesProviderId(candidate, params.provider));
321338
}
322339

323340
export function resolveProviderRuntimePluginHandle(

0 commit comments

Comments
 (0)