Skip to content

Commit 2f81c5f

Browse files
committed
fix: keep onboarding setup paths cold
1 parent 26b203e commit 2f81c5f

7 files changed

Lines changed: 251 additions & 22 deletions

File tree

‎CHANGELOG.md‎

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

2020
### Fixes
2121

22+
- Onboarding/setup: keep first-run config reads, plugin compatibility notices, and post-model sanity checks on cold metadata paths unless the user chooses to browse all models, avoiding full plugin/runtime catalog work between prompts. Thanks @shakkernerd.
2223
- Onboarding/models: keep skip-auth and provider-scoped model picker prompts off the full global model catalog path, and cache provider catalog hook resolution so setup no longer stalls after auth on large plugin registries. Thanks @shakkernerd.
2324
- Gateway/Bonjour: suppress known @homebridge/ciao cancellation and network assertion failures through scoped process handlers so malformed mDNS packets or restricted VPS networking disable/restart Bonjour instead of crashing the gateway. Fixes #67578. Thanks @zenassist26-create.
2425
- Discord: keep late clicks on already-resolved exec approval buttons quiet when elevated mode auto-resolved the request, while still surfacing real approval submission failures. Fixes #66906. Thanks @rlerikse.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
import type { OpenClawConfig } from "../config/types.openclaw.js";
3+
import { warnIfModelConfigLooksOff } from "./auth-choice.model-check.js";
4+
import { makePrompter } from "./setup/__tests__/test-utils.js";
5+
6+
const loadModelCatalog = vi.hoisted(() => vi.fn());
7+
vi.mock("../agents/model-catalog.js", () => ({
8+
loadModelCatalog,
9+
}));
10+
11+
const ensureAuthProfileStore = vi.hoisted(() => vi.fn(() => ({ version: 1, profiles: {} })));
12+
const listProfilesForProvider = vi.hoisted(() => vi.fn(() => []));
13+
vi.mock("../agents/auth-profiles.js", () => ({
14+
ensureAuthProfileStore,
15+
listProfilesForProvider,
16+
}));
17+
18+
const resolveEnvApiKey = vi.hoisted(() => vi.fn(() => undefined));
19+
const hasUsableCustomProviderApiKey = vi.hoisted(() => vi.fn(() => false));
20+
vi.mock("../agents/model-auth.js", () => ({
21+
resolveEnvApiKey,
22+
hasUsableCustomProviderApiKey,
23+
}));
24+
25+
describe("warnIfModelConfigLooksOff", () => {
26+
beforeEach(() => {
27+
vi.clearAllMocks();
28+
loadModelCatalog.mockResolvedValue([]);
29+
});
30+
31+
it("skips catalog validation when requested while keeping auth checks", async () => {
32+
const note = vi.fn(async () => {});
33+
const prompter = makePrompter({ note });
34+
const config = {
35+
agents: {
36+
defaults: {
37+
model: "openai-codex/gpt-5.5",
38+
},
39+
},
40+
} as OpenClawConfig;
41+
42+
await warnIfModelConfigLooksOff(config, prompter, { validateCatalog: false });
43+
44+
expect(loadModelCatalog).not.toHaveBeenCalled();
45+
expect(ensureAuthProfileStore).toHaveBeenCalledOnce();
46+
expect(listProfilesForProvider).toHaveBeenCalledWith(
47+
expect.objectContaining({ profiles: {} }),
48+
"openai-codex",
49+
);
50+
expect(note).toHaveBeenCalledWith(
51+
expect.stringContaining('No auth configured for provider "openai-codex"'),
52+
"Model check",
53+
);
54+
});
55+
56+
it("keeps full catalog validation enabled by default", async () => {
57+
const note = vi.fn(async () => {});
58+
const prompter = makePrompter({ note });
59+
const config = {
60+
agents: {
61+
defaults: {
62+
model: "openai-codex/gpt-5.5",
63+
},
64+
},
65+
} as OpenClawConfig;
66+
67+
await warnIfModelConfigLooksOff(config, prompter);
68+
69+
expect(loadModelCatalog).toHaveBeenCalledWith({
70+
config,
71+
useCache: false,
72+
});
73+
});
74+
});

‎src/commands/auth-choice.model-check.ts‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,27 @@ import { buildProviderAuthRecoveryHint } from "./provider-auth-guidance.js";
99
export async function warnIfModelConfigLooksOff(
1010
config: OpenClawConfig,
1111
prompter: WizardPrompter,
12-
options?: { agentId?: string; agentDir?: string },
12+
options?: { agentId?: string; agentDir?: string; validateCatalog?: boolean },
1313
) {
1414
const ref = resolveDefaultModelForAgent({
1515
cfg: config,
1616
agentId: options?.agentId,
1717
});
1818
const warnings: string[] = [];
19-
const catalog = await loadModelCatalog({
20-
config,
21-
useCache: false,
22-
});
23-
if (catalog.length > 0) {
24-
const known = catalog.some(
25-
(entry) => entry.provider === ref.provider && entry.id === ref.model,
26-
);
27-
if (!known) {
28-
warnings.push(
29-
`Model not found: ${ref.provider}/${ref.model}. Update agents.defaults.model or run /models list.`,
19+
if (options?.validateCatalog !== false) {
20+
const catalog = await loadModelCatalog({
21+
config,
22+
useCache: false,
23+
});
24+
if (catalog.length > 0) {
25+
const known = catalog.some(
26+
(entry) => entry.provider === ref.provider && entry.id === ref.model,
3027
);
28+
if (!known) {
29+
warnings.push(
30+
`Model not found: ${ref.provider}/${ref.model}. Update agents.defaults.model or run /models list.`,
31+
);
32+
}
3133
}
3234
}
3335

‎src/commands/model-picker.test.ts‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,87 @@ describe("promptDefaultModel", () => {
233233
);
234234
});
235235

236+
it("keeps current preferred-provider models cold until browsing is requested", async () => {
237+
const select = vi.fn(async (params) => params.initialValue as never);
238+
const prompter = makePrompter({ select });
239+
const config = {
240+
agents: {
241+
defaults: {
242+
model: "openai-codex/gpt-5.5",
243+
},
244+
},
245+
} as OpenClawConfig;
246+
247+
const result = await promptDefaultModel({
248+
config,
249+
prompter,
250+
allowKeep: true,
251+
includeManual: true,
252+
ignoreAllowlist: true,
253+
preferredProvider: "openai-codex",
254+
browseCatalogOnDemand: true,
255+
});
256+
257+
expect(result).toEqual({});
258+
expect(loadModelCatalog).not.toHaveBeenCalled();
259+
expect(select.mock.calls[0]?.[0]).toMatchObject({
260+
searchable: false,
261+
initialValue: "__keep__",
262+
});
263+
expect(select.mock.calls[0]?.[0]?.options).toEqual([
264+
expect.objectContaining({ value: "__keep__" }),
265+
expect.objectContaining({ value: "__manual__" }),
266+
expect.objectContaining({ value: "__browse__" }),
267+
]);
268+
});
269+
270+
it("loads the full model catalog when the user chooses to browse", async () => {
271+
loadModelCatalog.mockResolvedValue([
272+
{
273+
provider: "openai-codex",
274+
id: "gpt-5.5",
275+
name: "GPT-5.5",
276+
},
277+
{
278+
provider: "openai-codex",
279+
id: "gpt-5.5-pro",
280+
name: "GPT-5.5 Pro",
281+
},
282+
]);
283+
const select = vi
284+
.fn()
285+
.mockResolvedValueOnce("__browse__")
286+
.mockImplementationOnce(async (params) => {
287+
const option = params.options.find(
288+
(entry: { value: string }) => entry.value === "openai-codex/gpt-5.5-pro",
289+
);
290+
return option?.value ?? params.initialValue;
291+
});
292+
const prompter = makePrompter({ select });
293+
const config = {
294+
agents: {
295+
defaults: {
296+
model: "openai-codex/gpt-5.5",
297+
},
298+
},
299+
} as OpenClawConfig;
300+
301+
const result = await promptDefaultModel({
302+
config,
303+
prompter,
304+
allowKeep: true,
305+
includeManual: true,
306+
ignoreAllowlist: true,
307+
preferredProvider: "openai-codex",
308+
browseCatalogOnDemand: true,
309+
});
310+
311+
expect(result.model).toBe("openai-codex/gpt-5.5-pro");
312+
expect(loadModelCatalog).toHaveBeenCalledOnce();
313+
expect(select).toHaveBeenCalledTimes(2);
314+
expect(select.mock.calls[1]?.[0]?.searchable).toBe(true);
315+
});
316+
236317
it("supports configuring vLLM during setup", async () => {
237318
loadModelCatalog.mockResolvedValue([
238319
{

‎src/flows/model-picker.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export { applyPrimaryModel } from "../plugins/provider-model-primary.js";
3333

3434
const KEEP_VALUE = "__keep__";
3535
const MANUAL_VALUE = "__manual__";
36+
const BROWSE_VALUE = "__browse__";
3637
const PROVIDER_FILTER_THRESHOLD = 30;
3738

3839
// Internal router models are valid defaults during auth/setup but not manual API targets.
@@ -46,6 +47,7 @@ export type PromptDefaultModelParams = {
4647
includeProviderPluginSetups?: boolean;
4748
ignoreAllowlist?: boolean;
4849
loadCatalog?: boolean;
50+
browseCatalogOnDemand?: boolean;
4951
preferredProvider?: string;
5052
agentDir?: string;
5153
workspaceDir?: string;
@@ -508,20 +510,70 @@ export async function promptDefaultModel(
508510
const includeManual = params.includeManual ?? true;
509511
const includeProviderPluginSetups = params.includeProviderPluginSetups ?? false;
510512
const loadCatalog = params.loadCatalog ?? true;
513+
const browseCatalogOnDemand = params.browseCatalogOnDemand ?? false;
511514
const ignoreAllowlist = params.ignoreAllowlist ?? false;
512515
const preferredProviderRaw = normalizeOptionalString(params.preferredProvider);
513516
const preferredProvider = preferredProviderRaw
514517
? normalizeProviderId(preferredProviderRaw)
515518
: undefined;
516519
const configuredRaw = resolveConfiguredModelRaw(cfg);
520+
const useStaticModelNormalization = !loadCatalog || browseCatalogOnDemand;
517521
const resolved = resolveConfiguredModelRef({
518522
cfg,
519523
defaultProvider: DEFAULT_PROVIDER,
520524
defaultModel: DEFAULT_MODEL,
525+
allowPluginNormalization: useStaticModelNormalization ? false : undefined,
521526
});
522527
const resolvedKey = modelKey(resolved.provider, resolved.model);
523528
const configuredKey = configuredRaw ? resolvedKey : "";
524529

530+
if (
531+
loadCatalog &&
532+
browseCatalogOnDemand &&
533+
preferredProvider &&
534+
allowKeep &&
535+
normalizeProviderId(resolved.provider) === preferredProvider
536+
) {
537+
const options: WizardSelectOption[] = [
538+
{
539+
value: KEEP_VALUE,
540+
label: configuredRaw
541+
? `Keep current (${configuredRaw})`
542+
: `Keep current (default: ${resolvedKey})`,
543+
hint:
544+
configuredRaw && configuredRaw !== resolvedKey ? `resolves to ${resolvedKey}` : undefined,
545+
},
546+
];
547+
if (includeManual) {
548+
options.push({ value: MANUAL_VALUE, label: "Enter model manually" });
549+
}
550+
options.push({
551+
value: BROWSE_VALUE,
552+
label: "Browse all models",
553+
hint: "loads provider catalogs",
554+
});
555+
556+
const selection = await params.prompter.select({
557+
message: params.message ?? "Default model",
558+
options,
559+
initialValue: KEEP_VALUE,
560+
searchable: false,
561+
});
562+
if (selection === KEEP_VALUE) {
563+
return {};
564+
}
565+
if (selection === MANUAL_VALUE) {
566+
return promptManualModel({
567+
prompter: params.prompter,
568+
allowBlank: false,
569+
initialValue: configuredRaw || resolvedKey || undefined,
570+
});
571+
}
572+
if (selection !== BROWSE_VALUE) {
573+
return { model: selection };
574+
}
575+
}
576+
525577
if (!loadCatalog) {
526578
const options: WizardSelectOption[] = [];
527579
if (allowKeep) {

‎src/wizard/setup.test.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,18 @@ const readConfigFileSnapshot = vi.hoisted(() =>
118118
legacyIssues: [] as Array<{ path: string; message: string }>,
119119
})),
120120
);
121+
const createConfigIO = vi.hoisted(() =>
122+
vi.fn(() => ({
123+
readConfigFileSnapshot,
124+
})),
125+
);
121126
const ensureSystemdUserLingerInteractive = vi.hoisted(() => vi.fn(async () => {}));
122127
const isSystemdUserServiceAvailable = vi.hoisted(() => vi.fn(async () => true));
123128
const ensureControlUiAssetsBuilt = vi.hoisted(() => vi.fn(async () => ({ ok: true })));
124129
const runTui = vi.hoisted(() => vi.fn(async (_options: unknown) => {}));
125130
const setupWizardShellCompletion = vi.hoisted(() => vi.fn(async () => {}));
126131
const probeGatewayReachable = vi.hoisted(() => vi.fn(async () => ({ ok: true })));
127-
const buildPluginCompatibilityNotices = vi.hoisted(() =>
132+
const buildPluginCompatibilitySnapshotNotices = vi.hoisted(() =>
128133
vi.fn((): PluginCompatibilityNotice[] => []),
129134
);
130135
const formatPluginCompatibilityNotice = vi.hoisted(() =>
@@ -185,8 +190,8 @@ vi.mock("../commands/onboard-hooks.js", () => ({
185190

186191
vi.mock("../config/config.js", () => ({
187192
DEFAULT_GATEWAY_PORT: 18789,
193+
createConfigIO,
188194
resolveGatewayPort,
189-
readConfigFileSnapshot,
190195
writeConfigFile,
191196
}));
192197

@@ -228,7 +233,7 @@ vi.mock("../infra/control-ui-assets.js", () => ({
228233
}));
229234

230235
vi.mock("../plugins/status.js", () => ({
231-
buildPluginCompatibilityNotices,
236+
buildPluginCompatibilitySnapshotNotices,
232237
formatPluginCompatibilityNotice,
233238
}));
234239

@@ -405,6 +410,7 @@ describe("runSetupWizard", () => {
405410
const multiselect: WizardPrompter["multiselect"] = vi.fn(async () => []);
406411
const prompter = buildWizardPrompter({ select, multiselect });
407412
const runtime = createRuntime({ throwsOnExit: true });
413+
createConfigIO.mockClear();
408414
ensureAuthProfileStore.mockClear();
409415

410416
await runSetupWizard(
@@ -423,6 +429,7 @@ describe("runSetupWizard", () => {
423429
prompter,
424430
);
425431

432+
expect(createConfigIO).toHaveBeenCalledWith({ pluginValidation: "skip" });
426433
expect(select).not.toHaveBeenCalled();
427434
expect(ensureAuthProfileStore).not.toHaveBeenCalled();
428435
expect(setupChannels).not.toHaveBeenCalled();
@@ -623,6 +630,7 @@ describe("runSetupWizard", () => {
623630

624631
it("prompts for a model during explicit interactive Ollama setup", async () => {
625632
promptDefaultModel.mockClear();
633+
warnIfModelConfigLooksOff.mockClear();
626634
resolveProviderPluginChoice.mockReturnValue({
627635
provider: {
628636
id: "ollama",
@@ -671,8 +679,14 @@ describe("runSetupWizard", () => {
671679
expect(promptDefaultModel).toHaveBeenCalledWith(
672680
expect.objectContaining({
673681
allowKeep: false,
682+
browseCatalogOnDemand: true,
674683
}),
675684
);
685+
expect(warnIfModelConfigLooksOff).toHaveBeenCalledWith(
686+
expect.anything(),
687+
expect.anything(),
688+
expect.objectContaining({ validateCatalog: false }),
689+
);
676690
});
677691

678692
it("re-prompts for auth when applyAuthChoice requests retry selection", async () => {
@@ -744,7 +758,7 @@ describe("runSetupWizard", () => {
744758
});
745759

746760
it("shows plugin compatibility notices for an existing valid config", async () => {
747-
buildPluginCompatibilityNotices.mockReturnValue([
761+
buildPluginCompatibilitySnapshotNotices.mockReturnValue([
748762
{
749763
pluginId: "legacy-plugin",
750764
code: "legacy-before-agent-start",

0 commit comments

Comments
 (0)