Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(models): 删除模型的确认框只在写成功之后收起,被拒的模型留在页面上(条目 7.14)

lmliheng49d4c919154d
diff --git a/changelog/unreleased/2026-10-20-models-delete-model.md b/changelog/unreleased/2026-10-20-models-delete-model.md
new file mode 100644
index 00000000..4969b1b0
--- /dev/null
+++ b/changelog/unreleased/2026-10-20-models-delete-model.md
@@ -0,0 +1,34 @@
+# Delete model: the confirmation closes only after the delete lands
+
+- **Date:** 2026-10-20
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文版](2026-10-20-models-delete-model.zh.md)
+
+A model's config dialog asks before "Delete model", naming the model and saying its config and
+API key go with it. Both that confirmation and the config dialog behind it used to close as soon
+as the request left, **whether the delete had succeeded or not** — while `persist` keeps the
+attempted rows, which for a delete is a table *without* this model. A refused delete therefore
+took the model off the page while the server still held it, and the card that opens the config
+dialog went with it: there was nothing left to retry from, and the error toast was the only trace
+of the refusal.
+
+Now the delete is written before either dialog is dismissed, and a refused one leaves the card —
+and the row behind it — exactly where it was.
+
+## Details
+
+- Both dialogs stay open until the table write lands; on a refusal the sentence stays verbatim,
+ the error toast shows the server's own words, and the retry is that same confirmation.
+- A refused write leaves the table as it stood before the delete (rather than the attempted one),
+ so the card, its "Delete model" action and the dialog itself all survive the refusal — the
+ dialog is gated on its row still being in the table, so the attempted table would have
+ unmounted it mid-flow.
+- The confirmation is marked busy while the request is in flight: its buttons are disabled, so a
+ second click cannot start a second write.
+
+## Compatibility
+
+- No API, wire-format or dependency change: this is only the order of writing and dismissing.
diff --git a/changelog/unreleased/2026-10-20-models-delete-model.zh.md b/changelog/unreleased/2026-10-20-models-delete-model.zh.md
new file mode 100644
index 00000000..c645cb1f
--- /dev/null
+++ b/changelog/unreleased/2026-10-20-models-delete-model.zh.md
@@ -0,0 +1,27 @@
+# 删除模型:写成功才收起确认框,被拒的模型留在页面上
+
+- **Date:** 2026-10-20
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[English](2026-10-20-models-delete-model.md)
+
+模型的配置对话框里,「删除模型」会先问一句,说明要删的是哪个模型、它的配置与 API key 一起移除。
+而这张确认框和它背后的配置对话框此前在请求发出时就关闭,**不管删没删成**;同时 `persist` 会保留尝试
+中的表 —— 对一次删除来说,那就是一张**没有这个模型**的表。于是被拒的那次删除让模型从页面上消失,
+服务器却仍然留着它,而打开这张对话框的卡片也跟着没了:没有地方可以重试,只剩一句错误提示。
+
+现在删除把写入做完之后才收起这两张对话框,被拒时卡片与服务器那一行都原样留着。
+
+## 细节
+
+- 两张对话框一直开到表写入有结果为止;被拒时句子原样留着,错误提示照旧显示服务端那句话,重试就是
+ 同一张确认框。
+- 写入被拒时页面留在删除前的表上(而不是尝试中的那张):卡片、它的「删除模型」入口、以及对话框本身
+ 都还在 —— 对话框是按「它那一行仍在表里」才挂载的,尝试中的表会在半途中把它卸掉。
+- 请求在飞的时候确认框标为 busy(按钮禁用),连点不会发出第二次写入。
+
+## 兼容性
+
+- 没有接口、传输格式或依赖变化;只改了页面里写入与收起的先后。
diff --git a/packages/web/e2e/models-delete-model.spec.mjs b/packages/web/e2e/models-delete-model.spec.mjs
new file mode 100644
index 00000000..a6819f16
--- /dev/null
+++ b/packages/web/e2e/models-delete-model.spec.mjs
@@ -0,0 +1,196 @@
+/**
+ * Regression: "Delete model" dismisses its confirmation (and the config dialog behind it) only
+ * after the write landed, and a refused write leaves the card on the page.
+ *
+ * The confirmation names the model and says the config and API key go with it. It used to close
+ * on the way out of the request, success or not, and so did the config dialog — while `persist`
+ * keeps the attempted rows for a field edit the user is still holding, i.e. a table *without*
+ * this model. So a refused delete took the model off the page while the server still held it,
+ * and the card that opens this dialog went with it: nothing was left to retry from, and nothing
+ * said the row still existed except the toast. (Measured on the pre-fix build: no dialog, zero
+ * matches for the model's name on the page, the row still on the server, and a retry that had
+ * nowhere to start.)
+ *
+ * Both tests work on a hand-added model inside a user-defined group, seeded through the table PUT
+ * so nothing here depends on the built-in catalog.
+ */
+import { test, expect } from "@playwright/test";
+import { provisionAndLogin } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const P = "password123";
+
+/** The group and model both tests delete; unique enough to appear nowhere else. */
+const GROUP = "probesolo";
+const MODEL = "probe-solo";
+const NAME = "Probe Solo";
+
+/** The row the model is, as this file seeds it: a hand-added model of a user-defined group. */
+const ROW = {
+ provider: GROUP,
+ modelId: MODEL,
+ displayName: NAME,
+ contextWindow: 32000,
+ clientType: "openai-chat",
+ baseUrl: "http://127.0.0.1:9/v1",
+ maxTokens: 4096,
+};
+
+/** The table entry a `ModelInfo` came from: every field the response reports, sent back as-is. */
+function toEntry(m) {
+ const entry = { provider: m.provider, modelId: m.modelId };
+ for (const key of [
+ "displayName",
+ "contextWindow",
+ "clientType",
+ "vision",
+ "maxTokens",
+ "fastMode",
+ "pricing",
+ ]) {
+ if (m[key] !== undefined) entry[key] = m[key];
+ }
+ if (m.credential?.baseUrl !== undefined) entry.baseUrl = m.credential.baseUrl;
+ return entry;
+}
+
+/**
+ * Provision the user and make sure their Project holds the model (a second run on the same data
+ * root finds it already deleted or already seeded and leaves the table as it is).
+ */
+async function projectWithModel(page, userId) {
+ await provisionAndLogin(page.request, userId, P);
+ const { projects } = await (await page.request.get(`${BASE}/api/projects`)).json();
+ const projectId = projects[0].projectId;
+ const read = async () =>
+ (await page.request.get(`${BASE}/api/projects/${projectId}/models`)).json();
+ const has = (table) => table.models.some((m) => m.provider === GROUP && m.modelId === MODEL);
+
+ let table = await read();
+ if (!has(table)) {
+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {
+ data: {
+ defaultModel: table.defaultModel,
+ models: [...table.models.filter((m) => toEntry(m).provider !== GROUP).map(toEntry), ROW],
+ },
+ });
+ expect(put.ok(), "seed the model through the table PUT").toBeTruthy();
+ table = await read();
+ }
+ expect(has(table), "the Project holds the model").toBeTruthy();
+ return { read, has };
+}
+
+/** Refuse every table write with a code the app has no local copy for, so the server's words show. */
+async function refuseWrites(page, seen) {
+ await page.route("**/api/projects/*/models", async (route) => {
+ if (route.request().method() !== "PUT") return route.fallback();
+ seen.push(route.request().url());
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({
+ error: { code: "models_store_closed", message: "models store is closed" },
+ }),
+ });
+ });
+}
+
+/** Open the model's config dialog from its card, expanding the group first when it starts folded. */
+async function openModelDialog(page) {
+ const card = page.getByText(NAME, { exact: true }).first();
+ if (!(await card.isVisible().catch(() => false))) {
+ await page.getByText(GROUP, { exact: false }).first().click();
+ }
+ await expect(card).toBeVisible();
+ await card.click();
+ const dialog = page.getByRole("dialog");
+ await expect(dialog).toBeVisible();
+ await expect(page.getByRole("button", { name: "删除模型" })).toBeVisible();
+ return dialog;
+}
+
+/** The "Delete model" confirmation stacked on the config dialog. */
+function confirmation(page) {
+ return page.getByRole("dialog").filter({ hasText: "确定删除" });
+}
+
+test("a refused model delete keeps its dialog, its sentence and the card the server still backs", async ({
+ page,
+}) => {
+ const { read, has } = await projectWithModel(page, "r92refuse");
+
+ await page.goto("/models");
+ await openModelDialog(page);
+ await page.getByRole("button", { name: "删除模型" }).click();
+ const confirm = confirmation(page);
+ await expect(confirm).toBeVisible();
+ const sentence = await confirm.innerText();
+ expect(sentence).toContain(NAME);
+
+ const puts = [];
+ await refuseWrites(page, puts);
+ await confirm.getByRole("button", { name: "确认" }).click();
+
+ // The write was refused: the server's words show, and both dialogs are still exactly as they
+ // were — the same model, the same sentence.
+ await expect(page.getByText("models store is closed")).toBeVisible();
+ expect(puts).toHaveLength(1);
+ await expect(confirm).toBeVisible();
+ expect(await confirm.innerText()).toBe(sentence);
+ await expect(page.getByRole("button", { name: "删除模型" })).toBeVisible();
+
+ // The card is back on the page behind the dialog (the dialog's own title also carries the
+ // name, so both count): before the fix the refused delete took it away while the server kept
+ // the row, leaving nowhere to retry from.
+ await expect(page.getByText(NAME, { exact: true })).toHaveCount(2);
+
+ // And the server still holds the untouched row.
+ expect(has(await read())).toBeTruthy();
+
+ // Canceling the confirmation decides nothing: the config dialog stays, the row stays.
+ await confirm.getByRole("button", { name: "取消" }).click();
+ await expect(confirmation(page)).toHaveCount(0);
+ await expect(page.getByRole("button", { name: "删除模型" })).toBeVisible();
+ expect(has(await read())).toBeTruthy();
+});
+
+test("the retry after a refused model delete writes it, and only a written one closes both dialogs", async ({
+ page,
+}) => {
+ const { read, has } = await projectWithModel(page, "r92retry");
+
+ await page.goto("/models");
+ const puts = [];
+ let refuse = true;
+ await page.route("**/api/projects/*/models", async (route) => {
+ if (route.request().method() !== "PUT") return route.fallback();
+ puts.push(route.request().url());
+ if (!refuse) return route.fallback();
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({
+ error: { code: "models_store_closed", message: "models store is closed" },
+ }),
+ });
+ });
+
+ await openModelDialog(page);
+ await page.getByRole("button", { name: "删除模型" }).click();
+ const confirm = confirmation(page);
+ await confirm.getByRole("button", { name: "确认" }).click();
+ await expect(page.getByText("models store is closed")).toBeVisible();
+ await expect(confirm).toBeVisible();
+ expect(puts).toHaveLength(1);
+
+ // The retry is the same confirmation — no reopening the card, no second 删除模型 click.
+ refuse = false;
+ await confirm.getByRole("button", { name: "确认" }).click();
+ await expect(confirmation(page)).toHaveCount(0);
+ await expect(page.getByRole("button", { name: "删除模型" })).toHaveCount(0);
+ expect(puts).toHaveLength(2);
+ await expect(page.getByText(NAME, { exact: true })).toHaveCount(0);
+
+ expect(has(await read())).toBeFalsy();
+});
diff --git a/packages/web/src/features/models/models-page.tsx b/packages/web/src/features/models/models-page.tsx
index 7e23ef51..9011ee97 100644
--- a/packages/web/src/features/models/models-page.tsx
+++ b/packages/web/src/features/models/models-page.tsx
@@ -793,6 +793,16 @@ export function ModelsPage() {
const [editingMovedToCustom, setEditingMovedToCustom] = useState(false);
/** Target group (provider id) for adding a model: taken from the group header entry point, falling back to custom when empty. */
const [addingTo, setAddingTo] = useState<string | null>(null);
+ /**
+ * Close the config dialog. One helper because the remove action closes it from the write's
+ * outcome (see `onSubmit`) while cancel closes it on the way out — both must clear the
+ * three fields that say which entry point opened it.
+ */
+ const closeModelDialog = () => {
+ setEditing(null);
+ setEditingMovedToCustom(false);
+ setAddingTo(null);
+ };
const [query, setQuery] = useState("");
/**
* Expanded vendor groups — hydrated from this Project's persisted set (DeepSeek-only
@@ -901,6 +911,14 @@ export function ModelsPage() {
nextVision: ModelRefDto | undefined,
/** Success toast text (defaults to "saved"); on failure this function shows an error toast instead. */
successText?: string,
+ /**
+ * The table to leave on the page when the write is refused. Default: the attempted rows,
+ * which is right for a field edit the user is still holding. A delete passes the table as
+ * it stood instead — its attempted rows are a table without the model, and showing it for
+ * the instant before the caller restores them unmounts the config dialog, which is gated on
+ * its row still being in the table.
+ */
+ refusedRows?: RowState[],
): Promise<boolean> => {
if (!projectId) return false;
setBusy(true);
@@ -925,7 +943,7 @@ export function ModelsPage() {
toastSuccess(successText ?? S.common.saved);
return true;
} catch (e) {
- setRows(nextRows);
+ setRows(refusedRows ?? nextRows);
if (nextDefault !== undefined) setDefaultModel(nextDefault);
if (effectiveVision !== undefined) setVisionModel(effectiveVision);
toastError(apiErrorText(e));
@@ -1830,41 +1848,45 @@ export function ModelsPage() {
canEdit={isOwner}
isDefault={editingRow !== undefined && sameModelRef(rowRef(editingRow), defaultModel)}
isVisionModel={editingRow !== undefined && sameModelRef(rowRef(editingRow), visionModel)}
- onClose={() => {
- setEditing(null);
- setEditingMovedToCustom(false);
- setAddingTo(null);
- }}
+ onClose={closeModelDialog}
// The sync rewrites the very row this dialog was seeded from, so the dialog goes
// first and the merge runs against the table, not around an open form.
onSyncPresets={
isOwner
? () => {
- setEditing(null);
- setEditingMovedToCustom(false);
- setAddingTo(null);
+ closeModelDialog();
void syncPresets();
}
: undefined
}
onSubmit={(next, action) => {
const isNew = addingTo !== null;
- setEditing(null);
- setEditingMovedToCustom(false);
- setAddingTo(null);
if (action === "remove") {
// Filter by the **identity as loaded**: rows / pointers are both keyed by the
// paired reference as loaded. If the user edited identity fields before
// deleting, next's current reference wouldn't match any row -> nothing gets
// deleted while it still reports "saved".
const removed = next.original;
- void persist(
- rows.filter((r) => !sameModelRef(rowRef(r), removed)),
+ const before = rows;
+ // The dialog and its confirmation stay open until the delete is written: a
+ // refused one used to take the model off the page (persist keeps the attempted
+ // rows) while the server still held it, and the card that opens this dialog went
+ // with it, so the only way back to the retry was a reload (measured on a refused
+ // write: no dialog, zero matches for the model's name, the row still on the
+ // server). Keeping both means the retry is the same click against the same
+ // sentence, and the restored table matches what the server kept.
+ return persist(
+ before.filter((r) => !sameModelRef(rowRef(r), removed)),
sameModelRef(removed, defaultModel) ? undefined : defaultModel,
sameModelRef(removed, visionModel) ? undefined : visionModel,
- );
- return;
+ undefined,
+ before,
+ ).then((saved) => {
+ if (saved) closeModelDialog();
+ return saved;
+ });
}
+ closeModelDialog();
const nextRows = isNew
? [...rows, next]
: rows.map((r) => (sameModelRef(rowRef(r), editing) ? next : r));
@@ -2467,7 +2489,12 @@ function ModelDialog({
onClose: () => void;
/** Closes the dialog and runs the header's "sync presets" merge; absent for a member, who cannot write the config. */
onSyncPresets?: () => void;
- onSubmit: (row: RowState, action: DialogAction) => void;
+ /**
+ * Commit one action. The remove action reports whether its write landed (and keeps this
+ * dialog up until then); every other action closes on the way out as before, so they
+ * return nothing.
+ */
+ onSubmit: (row: RowState, action: DialogAction) => Promise<boolean> | void;
}) {
// Pricing input is displayed/entered in the current currency; converted back to USD storage on submit (RowState always stores USD).
const [form, setForm] = useState<RowState>(() => {
@@ -2536,6 +2563,8 @@ function ModelDialog({
* (Adding a new custom model isn't confirmed: opening the dialog is itself a clear intent.)
*/
const [confirming, setConfirming] = useState<DialogAction | null>(null);
+ /** The confirmed remove is on the wire: its confirmation waits for the answer instead of closing on the click. */
+ const [removing, setRemoving] = useState(false);
/** Fast mode is being switched ON and awaits the premium-billing warning's confirmation. */
const [confirmingFastMode, setConfirmingFastMode] = useState(false);
/** Protocol detection in progress (custom / user-defined groups only). */
@@ -2982,7 +3011,18 @@ function ModelDialog({
);
return;
}
- onSubmit(next, action);
+ const written = onSubmit(next, action);
+ if (written === undefined) return;
+ // Only the remove action reports back. A refused delete has to keep this dialog and its
+ // confirmation exactly as they are — the sentence names the model and what goes with it,
+ // and the retry is the same click — so the confirmation is dismissed here, once the write
+ // landed (on success the page closes this dialog too, which unmounts both).
+ setRemoving(true);
+ try {
+ if (await written) setConfirming(null);
+ } finally {
+ setRemoving(false);
+ }
};
// Provider info for the current group (updates live as the group dropdown
@@ -3766,10 +3806,13 @@ function ModelDialog({
open
title={CONFIRM_TITLE[confirming]()}
tone={confirming === "remove" ? "danger" : "primary"}
+ busy={confirming === "remove" && removing}
onClose={() => setConfirming(null)}
onConfirm={() => {
const action = confirming;
- setConfirming(null);
+ // The remove confirmation lives until its write lands (see `submit`): dismissed on
+ // the click it could only ever say nothing about a refusal.
+ if (action !== "remove") setConfirming(null);
void submit(action);
}}
confirmLabel={S.common.confirm}