Skip to content

Commit f74dde8

Browse files
leilei3167obviyus
andauthored
fix: preserve canonical Claude model after Model Setup
Model Setup now keeps the Claude CLI probe identity separate from the saved model identity. The saved route uses the plugin-owned canonical Anthropic provider and pins that model to the Claude CLI runtime. Existing canonical model-map entries and aliases remain unchanged, and setup no longer adds an empty `claude-cli/*` key. Closes #134379. Co-authored-by: Ayaan Zaidi <[email protected]>
1 parent 0a37673 commit f74dde8

5 files changed

Lines changed: 75 additions & 16 deletions

File tree

‎src/system-agent/setup-inference-activate-persist.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export async function persistActivatedSetupInference(input: {
194194
if (
195195
!sameDefaultInferenceRoute(initialRoute, verifiedRoute) ||
196196
!resolvedRoute ||
197-
resolvedRoute.modelLabel !== plan.modelRef ||
197+
resolvedRoute.modelLabel !== (plan.persistModelRef ?? plan.modelRef) ||
198198
resolvedRoute.authProfileId !== plan.authProfileId
199199
) {
200200
throw new Error(
@@ -282,7 +282,7 @@ export async function persistActivatedSetupInference(input: {
282282
const resolvedRoute = await resolveRoute(stagedRuntime);
283283
if (
284284
!resolvedRoute ||
285-
resolvedRoute.modelLabel !== plan.modelRef ||
285+
resolvedRoute.modelLabel !== (plan.persistModelRef ?? plan.modelRef) ||
286286
(plan.authProfileId && resolvedRoute.authProfileId !== plan.authProfileId)
287287
) {
288288
throw new Error(
@@ -310,7 +310,7 @@ export async function persistActivatedSetupInference(input: {
310310
if (
311311
!sameDefaultInferenceRoute(nextRouteProjection, expectedSourceCandidateRoute) ||
312312
!nextResolvedRoute ||
313-
nextResolvedRoute.modelLabel !== plan.modelRef ||
313+
nextResolvedRoute.modelLabel !== (plan.persistModelRef ?? plan.modelRef) ||
314314
(plan.authProfileId && nextResolvedRoute.authProfileId !== plan.authProfileId)
315315
) {
316316
throw new Error(

‎src/system-agent/setup-inference-activate.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ async function activateSetupInferenceUnredacted(
375375
stagedRoute.runner !== testPlan.runner ||
376376
stagedRoute.provider !== testPlan.provider ||
377377
stagedRoute.model !== testPlan.model ||
378-
stagedRoute.modelLabel !== plan.modelRef ||
378+
stagedRoute.modelLabel !== (plan.persistModelRef ?? plan.modelRef) ||
379379
(plan.authProfileId && stagedRoute.authProfileId !== plan.authProfileId)
380380
) {
381381
return {

‎src/system-agent/setup-inference-plan-helpers.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ export function projectSetupTargetModelMetadata(
238238
export function resolveSetupAgentRuntimeId(
239239
kind: ActivateSetupInferenceParams["kind"],
240240
): string | undefined {
241+
if (kind === "claude-cli") {
242+
return "claude-cli";
243+
}
241244
if (kind === "codex-cli") {
242245
return "codex";
243246
}

‎src/system-agent/setup-inference-plan.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { resolveAmbientOwnerAgentId } from "../agents/agent-scope-config.js";
2+
import { resolveCliRuntimeCanonicalProvider } from "../agents/cli-backends.js";
23
import type { CodexCliApiKeyCredential } from "../agents/cli-credentials.js";
34
import { CliExecutionAuthProfileError } from "../agents/cli-execution-auth.js";
45
import { normalizeProviderId } from "../agents/model-selection.js";
@@ -310,14 +311,23 @@ export async function buildTestPlan(params: {
310311
return modelRef;
311312
}
312313
const ref = parseRef(modelRef);
314+
// Backend metadata owns whether a CLI runtime aliases a canonical provider.
315+
// Standalone CLI backends keep their runtime provider as the durable key.
316+
const persistProvider =
317+
resolveCliRuntimeCanonicalProvider({
318+
runtime: ref.provider,
319+
config: cfg,
320+
env: process.env,
321+
includeSetupRegistry: true,
322+
}) ?? ref.provider;
313323
return {
314324
runner: "cli",
315325
...ref,
316326
modelRef,
317327
config: cfg,
318328
agentId: "openclaw",
319329
routeAgentId,
320-
persistModelRef: modelRef,
330+
persistModelRef: `${persistProvider}/${ref.model}`,
321331
};
322332
}
323333
case "gemini-cli": {

‎src/system-agent/setup-inference.test.ts‎

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,7 @@ describe("activateSetupInference", () => {
17821782
defaults: { systemAgent: { agentId: "ops" } },
17831783
entries: {
17841784
ops: { model: "openai/gpt-5.5" },
1785-
research: { model: "claude-cli/claude-opus-5" },
1785+
research: { model: "anthropic/claude-opus-5" },
17861786
},
17871787
});
17881788
});
@@ -1896,7 +1896,12 @@ describe("activateSetupInference", () => {
18961896
sourceConfig,
18971897
runtimeConfig: {
18981898
...sourceConfig,
1899-
agents: { ...sourceConfig.agents, entries: { main: { default: true } } },
1899+
agents: {
1900+
...sourceConfig.agents,
1901+
entries: {
1902+
main: { default: true, ...sourceConfig.agents?.entries?.main },
1903+
},
1904+
},
19001905
},
19011906
};
19021907
});
@@ -1932,7 +1937,7 @@ describe("activateSetupInference", () => {
19321937
});
19331938

19341939
expect(result).toMatchObject({ ok: true, modelRef: "claude-cli/claude-opus-5" });
1935-
expect(committedConfig?.agents?.defaults?.model).toBe("claude-cli/claude-opus-5");
1940+
expect(committedConfig?.agents?.defaults?.model).toBe("anthropic/claude-opus-5");
19361941
});
19371942

19381943
it("persists only the verified model before OpenClaw configures the rest", async () => {
@@ -1954,7 +1959,7 @@ describe("activateSetupInference", () => {
19541959
lines: ["Inference verified: claude-cli/claude-opus-5"],
19551960
});
19561961
const persistedConfig = configHarness.current();
1957-
expect(persistedConfig.agents?.defaults?.model).toBe("claude-cli/claude-opus-5");
1962+
expect(persistedConfig.agents?.defaults?.model).toBe("anthropic/claude-opus-5");
19581963
expect(persistedConfig.agents?.defaults?.workspace).toBeUndefined();
19591964
expect(persistedConfig.gateway).toBeUndefined();
19601965
});
@@ -1987,7 +1992,7 @@ describe("activateSetupInference", () => {
19871992
expect(onCommitStarted).toHaveBeenCalledWith(lockedConfig);
19881993
expect(configHarness.current()).toMatchObject({
19891994
wizard: { securityAcknowledgedAt: "2026-08-03T00:00:00.000Z" },
1990-
agents: { defaults: { model: "claude-cli/claude-opus-5" } },
1995+
agents: { defaults: { model: "anthropic/claude-opus-5" } },
19911996
});
19921997
});
19931998

@@ -2045,7 +2050,7 @@ describe("activateSetupInference", () => {
20452050
expect(result).toMatchObject({ ok: true, modelRef: "claude-cli/claude-opus-5" });
20462051
expect(configHarness.current()).toMatchObject({
20472052
agents: {
2048-
defaults: { model: "claude-cli/claude-opus-5" },
2053+
defaults: { model: "anthropic/claude-opus-5" },
20492054
entries: { main: { default: true } },
20502055
},
20512056
});
@@ -2201,9 +2206,9 @@ describe("activateSetupInference", () => {
22012206
expect(persistedConfig.agents?.entries).toEqual({
22022207
work: {
22032208
default: true,
2204-
model: "claude-cli/claude-opus-5",
2209+
model: "anthropic/claude-opus-5",
22052210
name: "edited during probe",
2206-
models: { "claude-cli/claude-opus-5": {} },
2211+
models: { "anthropic/claude-opus-5": { agentRuntime: { id: "claude-cli" } } },
22072212
},
22082213
"new-agent": { model: "anthropic/claude-opus-5" },
22092214
});
@@ -2465,7 +2470,7 @@ describe("activateSetupInference", () => {
24652470

24662471
expect(result).toMatchObject({ ok: true });
24672472
expect(resolveCliRuntimeOwnerFingerprint).toHaveBeenCalledOnce();
2468-
expect(configHarness.current().agents?.defaults?.model).toBe("claude-cli/claude-opus-5");
2473+
expect(configHarness.current().agents?.defaults?.model).toBe("anthropic/claude-opus-5");
24692474
});
24702475

24712476
it("rejects a CLI owner drift on an existing route before handoff", async () => {
@@ -2567,11 +2572,52 @@ describe("activateSetupInference", () => {
25672572
expect(refreshPluginRegistry).not.toHaveBeenCalled();
25682573
expect(configHarness.transform).toHaveBeenCalledOnce();
25692574
expect(configHarness.current()).toMatchObject({
2570-
agents: { defaults: { model: "claude-cli/claude-opus-5" } },
2575+
agents: { defaults: { model: "anthropic/claude-opus-5" } },
25712576
});
25722577
expect(configHarness.current().plugins?.entries?.codex).toBeUndefined();
25732578
});
25742579

2580+
it("does not persist a legacy claude-cli key beside an existing canonical Anthropic CLI route", async () => {
2581+
const initialConfig = {
2582+
agents: {
2583+
defaults: {
2584+
models: {
2585+
"anthropic/claude-fable-5": {},
2586+
"anthropic/claude-opus-5": {
2587+
alias: "Claude Code · Opus 5",
2588+
agentRuntime: { id: "claude-cli" },
2589+
},
2590+
},
2591+
},
2592+
},
2593+
} satisfies OpenClawConfig;
2594+
const configHarness = createConfigTransformHarness(initialConfig);
2595+
const runCliAgent = vi.fn(successfulRunner("claude-cli", "claude-opus-5"));
2596+
2597+
const result = await activateSetupInference({
2598+
kind: "claude-cli",
2599+
deps: {
2600+
readConfigFileSnapshot: mockConfigSnapshot(initialConfig),
2601+
runCliAgent: runCliAgent as never,
2602+
transformConfigWithPendingPluginInstalls: configHarness.transform as never,
2603+
},
2604+
});
2605+
2606+
expect(result).toMatchObject({ ok: true, modelRef: "claude-cli/claude-opus-5" });
2607+
expect(runCliAgent).toHaveBeenCalledWith(
2608+
expect.objectContaining({ provider: "claude-cli", model: "claude-opus-5" }),
2609+
);
2610+
const persisted = configHarness.current();
2611+
expect(persisted.agents?.defaults?.models).toEqual(initialConfig.agents.defaults.models);
2612+
expect(persisted.agents?.defaults?.model).toBe("anthropic/claude-opus-5");
2613+
expect(persisted.agents?.entries?.main).toMatchObject({
2614+
default: true,
2615+
models: {
2616+
"anthropic/claude-opus-5": { agentRuntime: { id: "claude-cli" } },
2617+
},
2618+
});
2619+
});
2620+
25752621
it.each([
25762622
[
25772623
"an explicitly disabled Codex plugin",
@@ -2605,7 +2651,7 @@ describe("activateSetupInference", () => {
26052651
expect(configHarness.transform).toHaveBeenCalledOnce();
26062652
expect(configHarness.current()).toMatchObject(config);
26072653
expect(configHarness.current()).toMatchObject({
2608-
agents: { defaults: { model: "claude-cli/claude-opus-5" } },
2654+
agents: { defaults: { model: "anthropic/claude-opus-5" } },
26092655
});
26102656
});
26112657

0 commit comments

Comments
 (0)