Skip to content

Commit 52498f7

Browse files
committed
fix(agents): carry the primary model's auth profile onto the derived utility default
A primary like openai/gpt-5.5@work previously reached utility tasks via the profiled fallback; the derived default shares the provider, so its trailing auth profile carries over instead of silently switching to default credentials (Codex review). Gates on Testbox: oxfmt, check:test-types, tests.
1 parent 9601834 commit 52498f7

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/agents/utility-model.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ describe("resolveUtilityModelRefForAgent", () => {
118118
);
119119
});
120120

121+
it("carries the primary model's auth profile onto the derived default", () => {
122+
const cfg = {
123+
agents: { defaults: { model: "openai/gpt-5.5@work" } },
124+
} as OpenClawConfig;
125+
126+
expect(resolveUtilityModelRefForAgent({ cfg, agentId: "main", metadataSnapshot })).toBe(
127+
"openai/gpt-5.6-luna@work",
128+
);
129+
});
130+
121131
it("prefers a caller-resolved primary provider over re-derivation", () => {
122132
expect(
123133
resolveUtilityModelRefForAgent({

src/agents/utility-model.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import type { OpenClawConfig } from "../config/types.openclaw.js";
55
import { getCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-snapshot.js";
66
import type { PluginMetadataSnapshot } from "../plugins/plugin-metadata-snapshot.types.js";
7-
import { resolveAgentConfig } from "./agent-scope.js";
7+
import { resolveAgentConfig, resolveAgentEffectiveModelPrimary } from "./agent-scope.js";
8+
import { splitTrailingAuthProfile } from "./model-ref-profile.js";
89
import { resolveDefaultModelForAgent } from "./model-selection.js";
910

1011
export type UtilityModelSetting =
@@ -87,9 +88,18 @@ export function resolveUtilityModelRefForAgent(params: {
8788
if (!provider) {
8889
return undefined;
8990
}
90-
return resolveProviderDefaultUtilityModelRef({
91+
const derived = resolveProviderDefaultUtilityModelRef({
9192
cfg: params.cfg,
9293
provider,
9394
metadataSnapshot: params.metadataSnapshot,
9495
});
96+
if (!derived) {
97+
return undefined;
98+
}
99+
// The derived default shares the primary's provider, so a trailing auth
100+
// profile on the primary ref must carry over; otherwise profile-isolated
101+
// setups would route utility calls through default credentials.
102+
const primaryRef = resolveAgentEffectiveModelPrimary(params.cfg, params.agentId) ?? "";
103+
const primaryProfile = primaryRef ? splitTrailingAuthProfile(primaryRef)?.profile : undefined;
104+
return primaryProfile ? `${derived}@${primaryProfile}` : derived;
95105
}

0 commit comments

Comments
 (0)