Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(settings): preserve selected default model when saving providers

yuxinoc19f70742aa3
diff --git a/apps/desktop/src/components/settings/ModelConfigPage.tsx b/apps/desktop/src/components/settings/ModelConfigPage.tsx
index 6807d6c01..dc9a342ca 100644
--- a/apps/desktop/src/components/settings/ModelConfigPage.tsx
+++ b/apps/desktop/src/components/settings/ModelConfigPage.tsx
@@ -4,7 +4,7 @@
*
* The default picker lists each configured model, while provider rows use
* `models[0]` as the provider's quick default. Editing the default provider
- * re-syncs `settings.defaultModelId` when that first model changes.
+ * preserves `settings.defaultModelId` while that model remains configured.
*/
import { useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
@@ -159,8 +159,7 @@ export function ModelConfigPage() {
};
/**
- * A saved provider that is also the global default may have changed its first
- * model, which is what `settings.defaultModelId` points at.
+ * Preserve the selected app default unless it was removed from the provider.
*/
const afterSaved = async (saved: ProviderPublic, models: ModelBinding[]) => {
const firstModelId = models[0]?.id;
@@ -175,7 +174,10 @@ export function ModelConfigPage() {
});
showToast(t("settings.providerSaved"), { variant: "success" });
} else {
- if (settings.defaultProviderId === saved.id && firstModelId) {
+ if (
+ settings.defaultProviderId === saved.id && firstModelId &&
+ !models.some((model) => modelIdsMatch(model.id, settings.defaultModelId ?? ""))
+ ) {
await api.setSettings({ ...settings, defaultModelId: firstModelId });
}
showToast(t("settings.providerUpdated"), { variant: "success" });
diff --git a/docs/spec/03-runtime/13-model-catalog-and-selection.md b/docs/spec/03-runtime/13-model-catalog-and-selection.md
index b1cac92e6..f39bc4ec0 100644
--- a/docs/spec/03-runtime/13-model-catalog-and-selection.md
+++ b/docs/spec/03-runtime/13-model-catalog-and-selection.md
@@ -368,6 +368,7 @@ use the configured model alias or published model name.
App-level default:
- first successfully tested provider + its default/recommended model
- the Settings default-model picker lists every configured model under its provider; selecting an entry persists both the owning provider and that exact model ID
+- saving that provider preserves the selected app-default model while it remains configured; removing it falls back to the first remaining binding
- the picker supports local search across provider name and model ID; its result list scrolls within the floating surface and shows an explicit empty state when no model matches
- the picker uses concise settings-specific search copy; each result gives visual priority to the model ID and keeps the provider as secondary metadata
- results are grouped by provider so a provider name is shown once per group rather than repeated on every model row
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index bb5ad75e3..81a1b03d2 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -501,8 +501,8 @@ identify the platform validation still needed.
#### E2E-005A: Edit provider model bindings and migrate a legacy model
- **Preconditions**: One provider saved with two model bindings; one fixture provider row exists with only the legacy `default_model_id` and no `config_json.models`; one fixture row carries an unknown or legacy `apiStyle` string.
-- **Steps**: 1) Reopen the saved provider; confirm the single form opens with its cached model list painted immediately, and that the API key field explains an unchanged key is kept. 2) Confirm the live probe then refreshes that list without a retyped key, because the stored secret is reused. 3) Confirm both existing bindings are still chosen and check-marked, with their limits, thinking chips and defaults intact. 4) Enable a level the fixture catalog does not publish, edit one row's limits and save. 5) Reopen the fixture provider and confirm its legacy model appears as one chosen row with 128,000 context, 8,192 max output and all seven thinking choices available but unselected. 6) Reopen the unknown-style fixture and confirm the editor renders with Chat Completions selected instead of an error boundary; save it and confirm the repaired style is persisted. 7) Save the fixture provider without changing the model. 8) Make the edited provider the global default, reopen it, remove its first model so a different binding becomes the head, and save. 9) Take the service offline or revoke the key, reopen the provider, and confirm the cached rows stay visible with a compact classified discovery error rather than an empty list or a raw host dump.
-- **Expected**: Editing never drops an unmodified binding. An explicitly enabled level remains saved even when the catalog does not publish it, so the Composer reads the same binding rather than silently narrowing it; a binding whose model discovery is unavailable keeps its stored levels untouched. Legacy read materializes one binding without losing the old model ID; the subsequent write stores `config_json.models` and keeps `defaultModelId` equal to the first binding for older readers. An unknown or legacy `apiStyle` is treated as a compatibility input: the editor falls back to Chat Completions, remains usable, and repairs the stored value on save. When the edited provider is the global default and its first model changed, `settings.defaultModelId` is re-synced to the new head binding. A failed live probe degrades to the cached list plus a compact classified error, never to a blank picker or a raw HTTP/JSON dump, and a catalog fallback is never written into the model cache.
+- **Steps**: 1) Reopen the saved provider; confirm the single form opens with its cached model list painted immediately, and that the API key field explains an unchanged key is kept. 2) Confirm the live probe then refreshes that list without a retyped key, because the stored secret is reused. 3) Confirm both existing bindings are still chosen and check-marked, with their limits, thinking chips and defaults intact. 4) Enable a level the fixture catalog does not publish, edit one row's limits and save. 5) Reopen the fixture provider and confirm its legacy model appears as one chosen row with 128,000 context, 8,192 max output and all seven thinking choices available but unselected. 6) Reopen the unknown-style fixture and confirm the editor renders with Chat Completions selected instead of an error boundary; save it and confirm the repaired style is persisted. 7) Save the fixture provider without changing the model. 8) Select the second binding as the app default, reopen the provider and save unchanged; confirm the app default stays on that binding. Save another provider and confirm the app default is unchanged. Reopen the default provider, remove the selected binding, and save; confirm the app default falls back to the first remaining binding. 9) Take the service offline or revoke the key, reopen the provider, and confirm the cached rows stay visible with a compact classified discovery error rather than an empty list or a raw host dump.
+- **Expected**: Editing never drops an unmodified binding. An explicitly enabled level remains saved even when the catalog does not publish it, so the Composer reads the same binding rather than silently narrowing it; a binding whose model discovery is unavailable keeps its stored levels untouched. Legacy read materializes one binding without losing the old model ID; the subsequent write stores `config_json.models` and keeps `defaultModelId` equal to the first binding for older readers. An unknown or legacy `apiStyle` is treated as a compatibility input: the editor falls back to Chat Completions, remains usable, and repairs the stored value on save. Saving the default provider preserves `settings.defaultModelId` while the selected model remains configured; only removal of that model falls back to the first remaining binding. Editing another provider never changes the app default. A failed live probe degrades to the cached list plus a compact classified error, never to a blank picker or a raw HTTP/JSON dump, and a catalog fallback is never written into the model cache.
- **Specs linked**: `03-runtime/11-provider-model-system.md`, `03-runtime/12-provider-config-schema.md`, `03-runtime/13-model-catalog-and-selection.md`, ADR 0114
- **Acceptance**: F (provider persistence and migration)
- **Milestone**: M2
diff --git a/scripts/e2e-provider-order.mjs b/scripts/e2e-provider-order.mjs
index 0b6ae36b7..eb5383c97 100644
--- a/scripts/e2e-provider-order.mjs
+++ b/scripts/e2e-provider-order.mjs
@@ -51,7 +51,14 @@ app.whenReady().then(async () => {
await host.start();
const fixtures = [];
for (const name of ["A", "B", "C"]) {
- const { provider } = await host.call("providers.create", { name, authKind: "none", defaultModelId: "model-" + name });
+ const { provider } = await host.call("providers.create", {
+ name, authKind: "none", baseUrl: "http://127.0.0.1:9/v1",
+ apiStyle: "chat_completions", defaultModelId: "model-" + name,
+ models: name === "A" ? ["deepseek-chat", "deepseek-reasoner"].map(id => ({
+ id, contextWindow: 128000, maxTokens: 8192,
+ thinkingLevels: ["off"], defaultThinkingLevel: "off",
+ })) : undefined,
+ });
fixtures.push(provider);
}
await host.call("settings.set", { defaultProviderId: fixtures[0].id, defaultModelId: fixtures[0].defaultModelId });
@@ -86,6 +93,7 @@ app.whenReady().then(async () => {
bindingForModel: (provider, modelId) => provider.models?.find((model) => model.id === modelId),
});
registrar.handle(IPC.invoke.settingsGet, () => host.call("settings.get"));
+ registrar.handle(IPC.invoke.settingsSet, (settings) => host.call("settings.set", settings));
registrar.handle(IPC.invoke.sessionList, () => host.call("session.list"));
registrar.handle(IPC.invoke.appGetOnboarding, async () => ({ dismissed: true }));
window = new BrowserWindow({ show: false, width: 1000, height: 1000, webPreferences: {
diff --git a/scripts/e2e/provider-order.tsx b/scripts/e2e/provider-order.tsx
index c1a6b7af5..543484b3b 100644
--- a/scripts/e2e/provider-order.tsx
+++ b/scripts/e2e/provider-order.tsx
@@ -164,16 +164,59 @@ globalThis.providerOrderProbe = async (restart = false) => {
host.scrollTop = 0;
await painted();
+ // Saving a provider must preserve the exact app default picked by the user.
+ const click = (element: HTMLButtonElement | null) => {
+ assert(element, "missing provider action");
+ flushSync(() => {
+ element!.dispatchEvent(new PointerEvent("pointerdown", { pointerId: 5, button: 0, bubbles: true }));
+ element!.click();
+ });
+ };
+ click(host.querySelector(".model-default-row button"));
+ await until(() => !!document.querySelector('[aria-label="A · deepseek-reasoner"]'), "second model missing from default picker");
+ click(document.querySelector('[aria-label="A · deepseek-reasoner"]'));
+ await until(() => useAppStore.getState().settings?.defaultModelId === "deepseek-reasoner",
+ "default picker did not select the second model");
+ const edit = async (name: string) => {
+ const selector = `[aria-label="${i18n.t("settings.editProvider")}"]`;
+ await until(() => !row(name).querySelector<HTMLButtonElement>(selector)?.disabled,
+ "provider is still saving");
+ click(row(name).querySelector(selector));
+ await until(() => !!document.querySelector(".provider-setup-dialog"), "provider editor did not open");
+ };
+ const save = async () => {
+ click([...document.querySelectorAll<HTMLButtonElement>("button")]
+ .find((button) => button.textContent?.trim() === i18n.t("settings.saveProvider"))!);
+ await until(() => !document.querySelector(".provider-setup-dialog"), "provider editor did not close");
+ await useAppStore.getState().refreshProviders();
+ };
+ await edit("A");
+ await save();
+ assert(useAppStore.getState().settings?.defaultModelId === "deepseek-reasoner",
+ "unchanged provider save reset the selected default model");
+ assert(host.querySelector(".model-default-model")?.textContent === "deepseek-reasoner",
+ "saved default model summary changed");
+ await edit("B");
+ await save();
+ assert(useAppStore.getState().settings?.defaultModelId === "deepseek-reasoner",
+ "editing another provider changed the app default");
+ await edit("A");
+ click([...document.querySelectorAll<HTMLElement>(".provider-chosen-row")]
+ .find((entry) => entry.querySelector(".provider-chosen-row-id")?.textContent === "deepseek-reasoner")!
+ .querySelector(".provider-chosen-remove"));
+ await save();
+ assert(useAppStore.getState().settings?.defaultModelId === "deepseek-chat",
+ "removing the selected default must fall back to the first remaining model");
+
await i18n.changeLanguage("zh-CN");
- await painted();
- assert(row("B").getAttribute("aria-label")?.includes("拖动"), "card reorder instruction must follow the interface language");
+ await until(() => !!row("B").getAttribute("aria-label")?.includes("拖动"), "card reorder instruction must follow the interface language");
flushSync(() => host.querySelector<HTMLButtonElement>(".composer-model-thinking-chip")!.click());
flushSync(() => document.querySelector<HTMLButtonElement>(".composer-menu-entry")!.click());
await until(() => document.querySelectorAll(".composer-model-group").length === 3, "model menu groups missing");
const groups = Array.from(document.querySelectorAll(".composer-model-group"), (group) => group.getAttribute("aria-label"));
assert(groups.join(",") === "B,C,A", `composer model menu did not follow provider order: ${groups}`);
assert(errors.length === 0, `render errors: ${errors.map(String)}`);
- return { ok: true, drag: true, keyboard: true, cancelledDrag: true, failedSave: true, staleRefresh: true, modelMenu: true };
+ return { ok: true, drag: true, keyboard: true, cancelledDrag: true, failedSave: true, staleRefresh: true, modelMenu: true, defaultModelPreserved: true, removedDefaultFallback: true };
} finally {
api.reorderProviders = realReorder;
api.listProviders = realList;