Skip to content

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

fix(settings): reconcile image bindings after model removal

Jack3d9e8b542281
diff --git a/apps/desktop/src/components/settings/ModelConfigPage.tsx b/apps/desktop/src/components/settings/ModelConfigPage.tsx
index dc065c016..b117253af 100644
--- a/apps/desktop/src/components/settings/ModelConfigPage.tsx
+++ b/apps/desktop/src/components/settings/ModelConfigPage.tsx
@@ -192,6 +192,11 @@ export function ModelConfigPage() {
imageModelIds?: string[],
) => {
const firstModelId = models[0]?.id;
+ const replacementChatModelId =
+ settings.defaultProviderId === saved.id && firstModelId &&
+ !models.some((model) => modelIdsMatch(model.id, settings.defaultModelId ?? ""))
+ ? firstModelId
+ : undefined;
try {
if (imageModelIds !== undefined) {
const current = await api.getSettings();
@@ -201,7 +206,11 @@ export function ModelConfigPage() {
imageModelIds,
[...providers.filter((provider) => provider.id !== saved.id), saved],
);
- const nextSettings = { ...current, ...plan };
+ const nextSettings = {
+ ...current,
+ ...plan,
+ ...(replacementChatModelId ? { defaultModelId: replacementChatModelId } : {}),
+ };
await api.setSettings(nextSettings);
useAppStore.setState({ settings: nextSettings });
showToast(t("settings.imageModelSelected"), { variant: "success" });
@@ -226,11 +235,8 @@ export function ModelConfigPage() {
}
showToast(t("settings.providerSaved"), { variant: "success" });
} else {
- if (
- settings.defaultProviderId === saved.id && firstModelId &&
- !models.some((model) => modelIdsMatch(model.id, settings.defaultModelId ?? ""))
- ) {
- await api.setSettings({ ...settings, defaultModelId: firstModelId });
+ if (replacementChatModelId) {
+ await api.setSettings({ ...settings, defaultModelId: replacementChatModelId });
}
showToast(t("settings.providerUpdated"), { variant: "success" });
}
diff --git a/apps/desktop/src/components/settings/ProviderSetupDialog.tsx b/apps/desktop/src/components/settings/ProviderSetupDialog.tsx
index 0b5d715cf..633d46f70 100644
--- a/apps/desktop/src/components/settings/ProviderSetupDialog.tsx
+++ b/apps/desktop/src/components/settings/ProviderSetupDialog.tsx
@@ -262,9 +262,17 @@ export function ProviderSetupDialog({
return;
}
const persisted = selection.bindingsToPersist;
- const imageModelIdsToSave = imageModelDraft?.filter((imageModelId) =>
+ // Removing a configured model releases its image binding even when the
+ // capability checkbox was untouched. Ordinary provider edits keep their
+ // existing save path when the image selection did not change.
+ const imageSelection = imageModelDraft ?? imageModelIds;
+ const remainingImageModels = imageSelection?.filter((imageModelId) =>
persisted.some((model) => model.id === imageModelId),
);
+ const imageModelIdsToSave = imageModelDraft !== undefined ||
+ remainingImageModels?.length !== imageSelection?.length
+ ? remainingImageModels
+ : undefined;
setSaving(true);
setError("");
try {
diff --git a/docs/spec/03-runtime/21-image-generation.md b/docs/spec/03-runtime/21-image-generation.md
index 174e8997b..d620fd43d 100644
--- a/docs/spec/03-runtime/21-image-generation.md
+++ b/docs/spec/03-runtime/21-image-generation.md
@@ -7,6 +7,18 @@ The desktop exposes `AppSettings.imageGeneration` as the current default image-g
Model Advanced exposes **Set as image model** alongside the image and document attachment capabilities in the model capability group, not as a separate control row. The checkbox is multi-select: saving a provider persists every checked model in `imageGenerationModels`; Cancel leaves settings unchanged. Saving candidates does not replace the default conversation model. Unchecking the current image model and saving removes its default binding: the first remaining runnable candidate becomes the default, or the default becomes null if none remains. The unmarked model is available for chat again after saving and reopening settings. Saving another provider preserves a still-runnable image default. Below the default model row in the same defaults panel, **Image generation model** shows the current default and offers a menu to choose one from all marked candidates. When no candidate is configured, the summary row is hidden. An existing candidate that is missing, disabled, credential-less or removed displays only **Currently unavailable**. OAuth accounts are not eligible; there is no fallback.
All marked provider/model pairs are excluded from the default conversation picker, provider quick-default action, and Composer model menu. Other providers with the same model ID remain independent. Existing conversation bindings and history are preserved; a conversation still pinned to any image candidate must select a chat model before sending. Runtime launch rejects every marked image model before inference.
+### Provider model removal
+
+Saving a provider after explicitly removing a configured model also removes
+that model's image candidate, even if the image capability checkbox was not
+touched. If it was the active image default, select the first remaining
+runnable candidate or clear the default when none remains. Cancel preserves
+both the provider models and the image settings. Legacy single bindings follow
+the same rule. Unchanged image selections retain the ordinary provider-save
+path. External provider changes can still leave an unavailable binding visible.
+The existing chat-default repair still runs if the saved provider no longer
+contains its selected chat model; otherwise the chat default is preserved.
+
## Agent contract
`GenerateImages({items: [{prompt, count?, images?}]})` is an Agent-mode tool.
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 9d95e4860..eb416c57d 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -8,6 +8,21 @@
## 1. Goals
+### E2E-IMAGES-remove-configured-model
+
+- **Preconditions:** API-boundary fixture with an image-marked model and another
+ configured model on its provider; repeat with legacy single binding and with
+ an additional runnable image candidate on another provider.
+- **Steps:** Remove the marked model in the provider editor without toggling its
+ image checkbox. Cancel once, repeat and Save, then reopen settings and editor.
+- **Expected:** Cancel preserves both configurations. Save removes the model and
+ its image candidate; the image default clears or switches to the remaining
+ runnable candidate. An unaffected chat default stays unchanged; a removed chat
+ default still falls back to the first configured model. Reload preserves results.
+- **Specs:** 03-runtime/21-image-generation. **Acceptance:** B.
+- **Milestone:** Maintenance. **Status:** Automated in English and Chinese by
+ `scripts/e2e-image-generation-ui.mjs`.
+
### E2E-IMAGES-desktop-conversation
- **Preconditions:** Isolated desktop profile and workspace, built image feature,
diff --git a/docs/zh-CN/spec/03-runtime/21-image-generation.md b/docs/zh-CN/spec/03-runtime/21-image-generation.md
index ac47fe1b3..295dc5af1 100644
--- a/docs/zh-CN/spec/03-runtime/21-image-generation.md
+++ b/docs/zh-CN/spec/03-runtime/21-image-generation.md
@@ -9,6 +9,16 @@
模型高级设置将“设为生图模型”与图片、文档附件能力放在同一能力组中,不再单独占一行;复选框支持多选,保存服务商表单后把所有勾选模型写入 `imageGenerationModels`,取消不会改变设置。保存候选不会替换默认对话模型。取消勾选当前生图模型并保存后,默认生图绑定改为剩余的第一个可用候选;没有可用候选时清空。取消标记的模型恢复为可选对话模型,重新打开设置后仍保持这一状态。保存其他服务商时保留仍可用的默认生图模型。默认模型下方同一面板中的“生图模型”显示当前默认,并提供菜单从所有已标记候选中选择一个。没有候选时隐藏摘要行;已存在但服务商停用、缺少凭据或模型移除的候选仅显示“暂不可用”。OAuth 账户不适用,也不会自动回退。
所有已标记的服务商/模型组合都会从默认对话模型选择器、服务商快速设为默认操作和 Composer 模型菜单中排除。其他服务商的同名模型独立保留。已有会话绑定和历史不改写;仍绑定任一生图候选的会话必须选择对话模型才能发送,运行时也会在推理前拒绝所有已标记生图模型。
+### 移除服务商模型
+
+在服务商编辑器中主动移除已配置模型并保存时,即使没有操作生图能力复选框,
+也会清除该模型的生图候选。如果它是当前默认生图模型,则选择剩余的第一个
+可用候选;没有可用候选时清空默认值。取消编辑保留模型列表和生图设置。
+旧版单绑定配置遵循相同规则。生图选择未改变时保留原有服务商保存流程。
+服务商的外部变化仍可能留下显示为“暂不可用”的绑定。
+若当前聊天默认模型也被移除,仍按原有规则选择服务商的第一个剩余模型;
+否则保留聊天默认值。
+
## Agent 合约
`GenerateImages({items: [{prompt, count?, images?}]})` 仅供 Agent 模式使用。`count` 默认为 1,支持不同提示词和同一提示词的多个变体,总输出为 1–10 张。每项可通过 `images` 提供 1–4 张本地参考图,之前生成的路径可用于迭代编辑。提示词最多 32,000 个字符;不支持或超限输入直接拒绝,不截断。Plan 和 Goal 不得执行此工具。
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index a52de6b78..95d0fe918 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -8330,6 +8330,19 @@ the latest destination. These assertions measure work counts, not device FPS.
default.
- **Status:** Contract-covered; no end-to-end driver waits out a real 70s call.
+### E2E-IMAGES-remove-configured-model
+
+- **前提:** API 边界 fixture,服务商包含已标记的生图模型及另一个模型;
+ 分别测试旧版单绑定和另一服务商仍有可用生图候选的情况。
+- **步骤:** 不操作生图复选框,直接移除已标记模型;先取消,再重复并保存,
+ 重新打开设置和编辑器。
+- **预期:** 取消保留配置;保存清除已移除模型的生图候选,默认值清空或切换
+ 至剩余可用候选;保留仍存在的聊天默认模型,被移除的聊天默认模型按原有
+ 规则改为第一个剩余模型,重新打开后状态保持。
+- **规格:** 03-runtime/21-image-generation。**验收:** B。
+- **里程碑:** 维护。**状态:** `scripts/e2e-image-generation-ui.mjs`
+ 使用中英文自动覆盖。
+
### E2E-IMAGES-desktop-conversation
- **Preconditions:** Isolated desktop profile and workspace, built image feature,
diff --git a/scripts/e2e/image-generation-ui.tsx b/scripts/e2e/image-generation-ui.tsx
index 6da30e75a..98d4e8650 100644
--- a/scripts/e2e/image-generation-ui.tsx
+++ b/scripts/e2e/image-generation-ui.tsx
@@ -80,7 +80,12 @@ globalThis.imageGenerationProbe = async () => {
providerCount: 1,
modelCount: 2,
});
- api.updateProvider = async (input) => ({ provider: providers.find((entry) => entry.id === input.id)! });
+ api.updateProvider = async (input) => {
+ const index = providers.findIndex((entry) => entry.id === input.id);
+ const saved = { ...providers[index], models: structuredClone(input.models ?? providers[index].models) };
+ providers[index] = saved;
+ return { provider: saved };
+ };
api.fsReadImageDataUrl = async () => ({
kind: "image",
dataUrl:
@@ -281,6 +286,60 @@ globalThis.imageGenerationProbe = async () => {
providers.splice(0, providers.length, provider, alternate, chatProvider);
flushSync(() => useAppStore.setState({ providers: [...providers] }));
+ // Removing a configured model is also an explicit release of its image
+ // binding, even when the capability checkbox was never touched.
+ for (const remaining of [false, true]) {
+ providers.splice(0, providers.length, provider, alternate, chatProvider);
+ const original = { providerId: "p", modelId: "image-one" };
+ const other = { providerId: "q", modelId: "image-two" };
+ settings = {
+ ...settings,
+ imageGeneration: original,
+ imageGenerationModels: remaining ? [original, other] : undefined,
+ defaultProviderId: remaining ? "chat" : "p",
+ defaultModelId: remaining ? "chat-model" : "image-one",
+ };
+ flushSync(() => useAppStore.setState({ settings, providers: [...providers] }));
+ const editImages = () => click(container.querySelector<HTMLButtonElement>(
+ 'button[aria-label="' + i18n.t("settings.editProvider") + '"]',
+ ));
+ const removeImage = async () => {
+ await until(() => !!document.querySelector(".provider-chosen-row"), "chosen models missing");
+ const chosen = [...document.querySelectorAll<HTMLElement>(".provider-chosen-row")]
+ .find((element) => element.querySelector(".provider-chosen-row-id")?.textContent === "image-one");
+ click(chosen?.querySelector<HTMLButtonElement>(".provider-chosen-remove"));
+ };
+ editImages();
+ await removeImage();
+ click(button(i18n.t("settings.cancel")));
+ assert(settings.imageGeneration?.modelId === original.modelId, "cancel removed the image default");
+ assert(providers[0].models.length === 2, "cancel persisted provider model removal");
+ editImages();
+ await removeImage();
+ click(button(i18n.t("settings.saveProvider")));
+ await until(() => !document.querySelector(".provider-setup-dialog"), "model removal save did not finish");
+ assert(!providers[0].models.some((model) => model.id === "image-one"), "model was not removed");
+ assert(settings.imageGeneration?.providerId === (remaining ? "q" : undefined),
+ "removed provider model kept the image default");
+ assert(settings.imageGenerationModels?.length === (remaining ? 1 : 0),
+ "removed provider model kept an image candidate");
+ assert(settings.defaultProviderId === (remaining ? "chat" : "p") &&
+ settings.defaultModelId === (remaining ? "chat-model" : "image-two"),
+ "model removal did not preserve the existing chat-default repair");
+ flushSync(() => root.render(null));
+ flushSync(() => useAppStore.setState({ settings: structuredClone(settings) }));
+ render();
+ assert(!!container.querySelector(".model-image-row") === remaining,
+ "image summary did not reflect the saved candidates after reopen");
+ editImages();
+ await until(() => !!document.querySelector(".provider-chosen-row"), "saved provider did not reopen");
+ assert(![...document.querySelectorAll(".provider-chosen-row-id")]
+ .some((element) => element.textContent === "image-one"), "removed model returned after reopen");
+ click(button(i18n.t("settings.cancel")));
+ }
+ providers.splice(0, providers.length, provider, alternate, chatProvider);
+ flushSync(() => useAppStore.setState({ providers: [...providers] }));
+
}
const message = {
id: "image",
@@ -329,6 +388,7 @@ globalThis.imageGenerationProbe = async () => {
ok: true,
locales: ["en", "zh-CN"],
scenarios: [
+ "remove-marked-model-cancel-save-reopen-and-fallback",
"advanced-save-cancel",
"unmark-only-image-model-save-reopen-chat-selection",
"advanced-provider-switch",