Skip to content

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

fix(web): 删除对话被拒时,确认框留着,原因也留在框里(7.23)

lmlihengee2e3f144693
diff --git a/changelog/unreleased/2026-10-21-session-delete-refusal.md b/changelog/unreleased/2026-10-21-session-delete-refusal.md
new file mode 100644
index 00000000..88714936
--- /dev/null
+++ b/changelog/unreleased/2026-10-21-session-delete-refusal.md
@@ -0,0 +1,34 @@
+# A refused conversation delete keeps its confirmation and the reason in it
+
+- **Date:** 2026-10-21
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文版](2026-10-21-session-delete-refusal.zh.md)
+
+Deleting a conversation from the sidebar asks first, and that card already stayed open when the delete was
+refused — but the reason did not: it arrived as a toast that dismissed itself after six seconds and floated
+over the card the person was still looking at. The conversation was still in the list, and the only thing to
+do next was press the same button again without anything telling them why.
+
+The card now draws the server's own words under its sentence, where the retry is, and a new attempt starts
+without the previous attempt's reason. The same column's rename dialog has always answered a refused rename
+that way; the delete card now matches it.
+
+## Details
+
+- The rule follows the model library, scheduled tasks, evaluation center and plugin market rounds
+ (`ConfirmModal`'s `refusal` slot): the reason is drawn inside the card that asked for the write.
+- `components/layout/sidebar.tsx`: the `catch` of `confirmDeleteSession` hands the server's words to a new
+ `deleteRefusal` state instead of a toast; opening the card from the row menu clears the previous reason
+ first, and a retry clears it as it starts.
+- New browser spec `e2e/session-delete-refusal.spec.mjs` (two tests): a refused delete keeps the card, its
+ sentence and the row, raises no toast and deletes nothing; the retry deletes for real, and only a landed
+ delete closes the card.
+
+## Compatibility
+
+- No API, wire-format or dependency change: this is only where a refused delete's reason is drawn.
+- The batch delete (the multi-row confirmation) still reports a refusal as a toast — it is not a
+ success-or-failure write (some rows may land, some may not), and the ledger records it under "what is left".
diff --git a/changelog/unreleased/2026-10-21-session-delete-refusal.zh.md b/changelog/unreleased/2026-10-21-session-delete-refusal.zh.md
new file mode 100644
index 00000000..1075a887
--- /dev/null
+++ b/changelog/unreleased/2026-10-21-session-delete-refusal.zh.md
@@ -0,0 +1,30 @@
+# 删除对话被拒时,确认框留着,原因也留在框里
+
+- **Date:** 2026-10-21
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[English](2026-10-21-session-delete-refusal.md)
+
+侧栏删除一个对话要先确认,而那张卡片在删除被拒时本来就留着 —— 没留住的是原因:它作为一条 toast 出现,
+六秒后自己消失,还浮在用户正看着的那张卡片上方。对话仍在列表里,而唯一要做的下一件事是再按一次同一个
+按钮,却没有任何东西告诉他为什么。
+
+现在卡片把服务端的原话画在它那句话下面、重试按钮旁边,而下一次尝试从干净的状态开始,不带上一次的原因。
+同一列里的重命名对话框一直就是这么回答被拒的重命名的,删除这张卡片现在与它一致。
+
+## 细节
+
+- 规则沿用模型库、定时任务、评估中心与插件市场那几轮(`ConfirmModal` 的 `refusal` 槽):原因画在发起写入
+ 的那张卡片里。
+- `components/layout/sidebar.tsx`:`confirmDeleteSession` 的 `catch` 把服务端的原话交给新的 `deleteRefusal`
+ 状态,不再弹 toast;从行菜单打开卡片时先撤掉上一次的原因,重试开始的那一刻也把它清掉。
+- 新增浏览器用例 `e2e/session-delete-refusal.spec.mjs`(两条):被拒的删除留着卡片、句子与那一行,不弹
+ toast、什么都没删;重试真的删掉,而只有删成功的那一次才关框。
+
+## 兼容性
+
+- 没有接口、传输格式或依赖变化;只改了被拒删除的原因画在哪。
+- 批量删除(多行共用的那张确认框)仍用 toast 报拒绝 —— 它不是「成败二选一」的写入(可能有的删掉了、有的
+ 没有),台账把它记在「还差什么」里。
diff --git a/packages/web/e2e/session-delete-refusal.spec.mjs b/packages/web/e2e/session-delete-refusal.spec.mjs
new file mode 100644
index 00000000..e67f70dc
--- /dev/null
+++ b/packages/web/e2e/session-delete-refusal.spec.mjs
@@ -0,0 +1,177 @@
+/**
+ * Regression: deleting a conversation from the sidebar asks first, and a refused delete keeps that
+ * question — with the server's words inside it — instead of leaving only a toast behind.
+ *
+ * The card itself already stayed open on a refusal (it closes on a landed DELETE only); what was
+ * missing was the reason: it arrived as a toast that dismissed itself after six seconds and sat
+ * above the card the person was still looking at. The same column's rename dialog answers a
+ * refused write by keeping the dialog and showing the error inside it, so the delete card now does
+ * the same through `ConfirmModal`'s `refusal` slot, and the retry is the same button.
+ *
+ * Both tests run against the real server; only the DELETE is taken over, because a refusal has to
+ * be produced and the rest of the card's contract (what stays, what closes and when) is what is
+ * measured.
+ */
+import { test, expect } from "@playwright/test";
+import { login, ADMIN_ID, ADMIN_PASSWORD } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const MOCK = process.env.MOCK_URL;
+
+/** The delete call the page makes; a 500 with its own words proves the reason came back. */
+const REFUSAL = { code: "session_store_read_only", message: "session store is read-only" };
+
+/**
+ * Run one action from a Session row's "更多" menu. The trigger is a hover-revealed icon sitting
+ * over the row's own clickable surface: when the click lands a frame before the row has re-laid
+ * itself out, it hits the row (which navigates) and the menu never opens. So the open is retried
+ * and verified — the same helper chat.spec.mjs uses for the same menu.
+ */
+async function pickRowAction(page, row, name) {
+ for (let attempt = 0; attempt < 4; attempt += 1) {
+ await row.hover();
+ await row.getByRole("button", { name: "更多" }).click();
+ const item = page.getByRole("button", { name, exact: true });
+ if (await item.count()) {
+ await item.first().click();
+ return;
+ }
+ await page.keyboard.press("Escape");
+ }
+ throw new Error(`the row menu never offered "${name}"`);
+}
+
+/** Configure the mock model and create one titled conversation; returns its id. */
+async function seedSession(page, projectId, title) {
+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {
+ data: {
+ defaultModel: { provider: "custom", modelId: "claude-4-8" },
+ models: [
+ {
+ provider: "custom",
+ modelId: "claude-4-8",
+ apiKey: "sk-mock",
+ baseUrl: MOCK,
+ contextWindow: 200000,
+ pricing: { cacheRead: 1, cacheWrite: 5, output: 10 },
+ },
+ ],
+ },
+ });
+ expect(put.ok(), "put models").toBeTruthy();
+
+ const created = await page.request.post(
+ `${BASE}/api/projects/${projectId}/agents/default_agent/sessions`,
+ { data: { provider: "custom", modelId: "claude-4-8" } },
+ );
+ expect(created.ok(), "create session").toBeTruthy();
+ const sessionId = (await created.json()).session.sessionId;
+
+ const renamed = await page.request.patch(`${BASE}/api/sessions/${sessionId}`, {
+ data: { title },
+ });
+ expect(renamed.ok(), "rename session").toBeTruthy();
+ return sessionId;
+}
+
+/**
+ * Take over the DELETE: `state.refuse` produces the refusal and records the attempt, anything else
+ * falls through to the real server (so the retry test deletes for real).
+ */
+async function stubDelete(page, state) {
+ await page.route("**/api/sessions/*", async (route) => {
+ const req = route.request();
+ if (req.method() !== "DELETE") return route.fallback();
+ state.deletes.push(new URL(req.url()).pathname.split("/").pop());
+ if (!state.refuse) return route.fallback();
+ return route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+}
+
+/** The row's own card text with the refusal line dropped — the only thing a refusal may change. */
+async function cardText(dialog) {
+ return (await dialog.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");
+}
+
+test("a refused delete keeps the question, the reason and the row", async ({ page }) => {
+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);
+ const projects = await (await page.request.get(`${BASE}/api/projects`)).json();
+ const projectId = projects.projects[0].projectId;
+ const title = `e2e refused delete ${Date.now()}`;
+ await seedSession(page, projectId, title);
+ const state = { deletes: [], refuse: true };
+ await stubDelete(page, state);
+
+ await page.goto("/chat");
+ const sidebar = page.getByRole("complementary");
+ const row = sidebar.locator("li", { hasText: title }).first();
+ await expect(row).toBeVisible();
+
+ await pickRowAction(page, row, "删除对话");
+ const dialog = page.getByRole("dialog");
+ await expect(dialog).toBeVisible();
+ const sentence = await cardText(dialog);
+
+ await dialog.getByRole("button", { name: "删除", exact: true }).click();
+
+ // The reason is in the card that asked, and it is not a toast: the notification region holds no
+ // dismissible button, and the card reads exactly as it did before the attempt plus one line.
+ await expect(dialog.getByText(REFUSAL.message)).toBeVisible();
+ expect(state.deletes).toHaveLength(1);
+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);
+ await expect(dialog).toBeVisible();
+ expect(await cardText(dialog)).toBe(sentence);
+
+ // Nothing was deleted anywhere: the row is still in the list.
+ await expect(row).toBeVisible();
+
+ // Closing the card decides nothing, and opening it again does not carry the old reason over.
+ await dialog.getByRole("button", { name: "取消" }).click();
+ await expect(dialog).toHaveCount(0);
+ await expect(row).toBeVisible();
+ await pickRowAction(page, row, "删除对话");
+ const reopened = page.getByRole("dialog");
+ await expect(reopened).toBeVisible();
+ await expect(reopened.getByText(REFUSAL.message)).toHaveCount(0);
+});
+
+test("the retry after a refused delete deletes, and only a landed delete closes the card", async ({
+ page,
+}) => {
+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);
+ const projects = await (await page.request.get(`${BASE}/api/projects`)).json();
+ const projectId = projects.projects[0].projectId;
+ const title = `e2e retried delete ${Date.now()}`;
+ const sessionId = await seedSession(page, projectId, title);
+ const state = { deletes: [], refuse: true };
+ await stubDelete(page, state);
+
+ await page.goto("/chat");
+ const sidebar = page.getByRole("complementary");
+ const row = sidebar.locator("li", { hasText: title }).first();
+ await expect(row).toBeVisible();
+
+ await pickRowAction(page, row, "删除对话");
+ const dialog = page.getByRole("dialog");
+ await expect(dialog).toBeVisible();
+ await dialog.getByRole("button", { name: "删除", exact: true }).click();
+ await expect(dialog.getByText(REFUSAL.message)).toBeVisible();
+ await expect(dialog).toBeVisible();
+ expect(state.deletes).toEqual([sessionId]);
+
+ // The retry is the same card, and this time the delete lands: the card closes and the row is
+ // gone from the list.
+ state.refuse = false;
+ await dialog.getByRole("button", { name: "删除", exact: true }).click();
+ await expect(dialog).toHaveCount(0);
+ expect(state.deletes).toEqual([sessionId, sessionId]);
+ await expect(sidebar.getByText(title)).toHaveCount(0);
+
+ // The server really deleted it on the retry (the refusal was ours; this one went through).
+ const read = await page.request.get(`${BASE}/api/sessions/${sessionId}`);
+ expect(read.status()).toBe(404);
+});
diff --git a/packages/web/src/components/layout/sidebar.tsx b/packages/web/src/components/layout/sidebar.tsx
index 4e5aed9a..ec421363 100644
--- a/packages/web/src/components/layout/sidebar.tsx
+++ b/packages/web/src/components/layout/sidebar.tsx
@@ -630,6 +630,13 @@ export function Sidebar({
/** Session pending delete confirmation (null = none). */
const [deletingSession, setDeletingSession] = useState<SessionInfo | null>(null);
const [deletingBusy, setDeletingBusy] = useState(false);
+ /**
+ * Why the last confirmed deletion was refused, in the server's own words. It belongs to the
+ * dialog, not to a toast: nothing was deleted, so the conversation is still there and the only
+ * next step is the same button again — the rename dialog above answers a refused write the very
+ * same way.
+ */
+ const [deleteRefusal, setDeleteRefusal] = useState<string | null>(null);
/**
* Batch processing (the header control beside 搜索会话): while it is on every row is a picker and
* the bar above the list acts on the ticked ones. Both are transient — leaving the mode drops the
@@ -1335,6 +1342,7 @@ export function Sidebar({
const confirmDeleteSession = async () => {
if (!deletingSession) return;
setDeletingBusy(true);
+ setDeleteRefusal(null);
const target = deletingSession;
try {
await api.deleteSession(target.sessionId);
@@ -1352,7 +1360,9 @@ export function Sidebar({
navigate(rest[0] ? `/chat/${rest[0].sessionId}` : "/chat");
}
} catch (e) {
- toastError(apiErrorText(e));
+ // The dialog stays open (it only closes on a landed DELETE) and says why: a toast would
+ // dismiss itself above a card the person is still looking at.
+ setDeleteRefusal(apiErrorText(e));
} finally {
setDeletingBusy(false);
}
@@ -1740,7 +1750,11 @@ export function Sidebar({
setRenamingSession(x);
}}
onMessaging={(x) => setMessagingSession(x)}
- onDelete={(x) => setDeletingSession(x)}
+ onDelete={(x) => {
+ // The dialog first, then the last attempt's reason: one attempt carries one reason.
+ setDeletingSession(x);
+ setDeleteRefusal(null);
+ }}
onToggleArchive={(x) => void toggleArchive(x)}
{...(batchMode
? {
@@ -2286,6 +2300,7 @@ export function Sidebar({
busy={deletingBusy}
onClose={() => (deletingBusy ? undefined : setDeletingSession(null))}
onConfirm={() => void confirmDeleteSession()}
+ refusal={deleteRefusal === null ? undefined : S.common.refused(deleteRefusal)}
>
<p className="text-sm text-gray-600 dark:text-gray-300">
{deletingSession