A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 批量删除被拒时,确认框留着,原因与没删掉的那几条也留着(7.25)
lmliheng0b844d220df5
diff --git a/changelog/unreleased/2026-10-22-session-batch-delete-refusal.md b/changelog/unreleased/2026-10-22-session-batch-delete-refusal.mdnew file mode 100644index 00000000..15b76ed1--- /dev/null+++ b/changelog/unreleased/2026-10-22-session-batch-delete-refusal.md@@ -0,0 +1,39 @@+# A refused batch delete keeps its confirmation and the reason in it++- **Date:** 2026-10-22+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文版](2026-10-22-session-batch-delete-refusal.zh.md)++The sidebar's batch delete goes out **one conversation at a time** (the server has no bulk route), so it can land+halfway. That batch used to run over `Promise.all`: the first refused row threw away every other row's outcome, the+card stayed open but the reason was a toast that dismissed itself after six seconds above it, and every row was+still ticked while the list and the server already disagreed — there was no telling which conversations had really+gone.++Now each row's outcome is kept: the ones that went leave the list and the ticks, the refused ones **stay ticked**+(so the card's own count is exactly what a retry would act on), and the card stays open with the server's words+under its sentence, so the retry is the same button. Only a batch where nothing was refused closes it.++## Details++- The rule follows the model library, scheduled tasks, evaluation center, plugin market, conversation and plugin+ settings rounds (`ConfirmModal`'s `refusal` slot): the reason is drawn inside the card that asked.+- `components/layout/sidebar.tsx`: `confirmBatchDelete` collects per-row outcomes with `Promise.allSettled` — rows+ that landed go to `forgetDeletedSessions` and leave the ticks, refused rows keep theirs; the card closes only when+ nothing was refused, otherwise "N of the selected chats were not deleted: <the server's words>" goes to a new+ `batchDeleteRefusal` state. The conversation on screen is only left for when it actually went away. Opening the+ card from the batch bar clears the previous reason first.+- Copy: `chat.batchDeleteRefused` (one line in each dictionary).+- New browser spec `e2e/session-batch-delete-refusal.spec.mjs` (two tests): a batch refused in part — card, sentence+ and the server's words all stay, the landed row is gone from the list while the refused one is still ticked and+ the card's count drops to 1, no toast, and the retry closes the card and really deletes; a batch refused whole —+ both rows and both ticks stay, the count is unchanged, and reopening the card after Cancel carries no old reason.++## Compatibility++- No API, wire-format or dependency change: this is only how a batch's outcomes are remembered and where the reason+ is drawn.+- Batch archive / unarchive are a different path (`Promise.all` + toast) and were left alone.diff --git a/changelog/unreleased/2026-10-22-session-batch-delete-refusal.zh.md b/changelog/unreleased/2026-10-22-session-batch-delete-refusal.zh.mdnew file mode 100644index 00000000..c9d123f9--- /dev/null+++ b/changelog/unreleased/2026-10-22-session-batch-delete-refusal.zh.md@@ -0,0 +1,33 @@+# 批量删除被拒时,确认框留着,原因也留在框里++- **Date:** 2026-10-22+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[English](2026-10-22-session-batch-delete-refusal.md)++侧栏的批量删除是**逐条**发出去的(服务端没有批量路由),所以它可能只成了一半。过去这一批用的是+`Promise.all`:第一条被拒就把别的行到底删没删掉全丢了,框虽留着,原因却是一条六秒后自己消失、还浮在框上方的+toast;所有行都还勾着,列表与服务端已经对不上 —— 再看一眼根本分不清哪些已经没了。++现在每一条的结果都收下来:删掉的行离开发列表与勾选,被拒的行**留着勾**(所以卡片里的条数正好是「重试会动到+的那几条」),框留着,并把服务端的原话画在句子下面,重试就是同一个按钮。整批都删掉了才关框。++## 细节++- 规则沿用模型库、定时任务、评估中心、插件市场、删除对话与插件设置那几轮(`ConfirmModal` 的 `refusal` 槽):+ 原因画在发起它的那张卡片里。+- `components/layout/sidebar.tsx`:`confirmBatchDelete` 改用 `Promise.allSettled` 逐条收结果 —— 落地的行交给+ `forgetDeletedSessions` 并从勾选里去掉,被拒的行留下勾选;只有「一条都没被拒」才关框,否则把+ 「还有 N 个对话没有删除:<服务端原话>」交给新状态 `batchDeleteRefusal`。当前打开的那个对话只有在**真的删掉**+ 时才跳走。从批量栏打开卡片时先清掉上一次的原因。+- 文案 `chat.batchDeleteRefused`(中英各一条)。+- 新增浏览器用例 `e2e/session-batch-delete-refusal.spec.mjs`(两条):一半被拒 —— 框、句子与服务端原话都在,+ 落地的行从列表消失、被拒的行仍勾着且卡片改数成 1,不弹 toast,重试那一次才关框并且真的删掉;整批被拒 ——+ 两条行与两个勾都还在,卡片计数不变,取消后重开不带旧原因。++## 兼容性++- 没有接口、传输格式或依赖变化;只改了「一批里的成败怎么记」与「原因画在哪」。+- 批量归档 / 批量取消归档走的是另一条路(`Promise.all` + toast),本次没动。diff --git a/packages/web/e2e/session-batch-delete-refusal.spec.mjs b/packages/web/e2e/session-batch-delete-refusal.spec.mjsnew file mode 100644index 00000000..22c58a99--- /dev/null+++ b/packages/web/e2e/session-batch-delete-refusal.spec.mjs@@ -0,0 +1,192 @@+/**+ * Regression: a batch delete is N writes, so it can land halfway — and the card that asked must+ * say so instead of leaving a six-second toast behind.+ *+ * Before: `confirmBatchDelete` ran `Promise.all`, so the first refused DELETE threw away every+ * other row's outcome. The card stayed open (it closes only on a landed batch) but the reason was+ * a toast above it, all rows stayed ticked even though some were already gone, and the list could+ * not be told apart from the server. Now the outcomes are collected per row (`allSettled`): the+ * landed rows leave the list and the ticks, the refused ones stay ticked, and the card keeps the+ * count of what is still left to delete plus the server's words in its `refusal` slot — so the+ * retry is the same button, on exactly the rows that did not go.+ *+ * 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 contract (what closes, what stays, what is still ticked) 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" };++/** 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 per conversation id: `state.refuseFor` holds the ids that are refused and+ * every attempt is recorded; anything else falls through to the real server (so a retry deletes+ * for real — and a landed row in the same batch is a real deletion too).+ */+async function stubDelete(page, state) {+ await page.route("**/api/sessions/*", async (route) => {+ const req = route.request();+ if (req.method() !== "DELETE") return route.fallback();+ const id = new URL(req.url()).pathname.split("/").pop();+ state.deletes.push(id);+ if (!state.refuseFor.has(id)) return route.fallback();+ return route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ });+ });+}++/** Tick the given conversations and ask for the batch delete — the card is left open. */+async function askBatchDelete(page, titles) {+ const sidebar = page.getByRole("complementary");+ await sidebar.getByRole("button", { name: "批量处理" }).click();+ for (const title of titles) {+ const box = sidebar.getByRole("checkbox", { name: `选中「${title}」` });+ await expect(box).toBeVisible();+ await box.check();+ }+ await page.getByRole("button", { name: "批量删除", exact: true }).click();+ const dialog = page.getByRole("dialog");+ await expect(dialog).toBeVisible();+ return dialog;+}++/** The card's text with its refusal line dropped — the only thing a refusal may change. */+async function cardText(dialog) {+ return (await dialog.innerText()).replace(/\n还有 \d+ 个对话没有删除:[^\n]*/, "");+}++test("a batch refused in part keeps the card, the reason and exactly the rows that did not go", 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 stamp = Date.now();+ const kept = `e2e batch kept ${stamp}`;+ const gone = `e2e batch gone ${stamp}`;+ const keptId = await seedSession(page, projectId, kept);+ const goneId = await seedSession(page, projectId, gone);+ const state = { deletes: [], refuseFor: new Set([keptId]) };+ await stubDelete(page, state);++ await page.goto("/chat");+ const sidebar = page.getByRole("complementary");+ await expect(sidebar.locator("li", { hasText: gone }).first()).toBeVisible();+ const dialog = await askBatchDelete(page, [kept, gone]);+ const before = await cardText(dialog);+ expect(before).toContain("确定删除选中的 2 个对话");++ await dialog.getByRole("button", { name: "删除", exact: true }).click();++ // The reason is inside the card that asked, and the card is not reporting through a toast.+ await expect(dialog.getByText(REFUSAL.message)).toBeVisible();+ await expect(dialog.getByText(/还有 1 个对话没有删除/)).toBeVisible();+ await expect(dialog).toBeVisible();+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);+ expect(state.deletes.sort()).toEqual([keptId, goneId].sort());++ // The half that landed is gone from the list; the refused row is still there — and the card now+ // counts exactly that row, which is what makes the retry act on it and nothing else.+ await expect(sidebar.locator("li", { hasText: gone })).toHaveCount(0);+ await expect(sidebar.locator("li", { hasText: kept }).first()).toBeVisible();+ await expect(dialog.getByText("确定删除选中的 1 个对话")).toBeVisible();+ await expect(sidebar.getByRole("checkbox", { name: `选中「${kept}」` })).toBeChecked();+ await expect(sidebar.getByRole("checkbox", { name: `选中「${gone}」` })).toHaveCount(0);++ // The same button retries: this time the row lands, so the card closes and the row goes.+ state.refuseFor.clear();+ await dialog.getByRole("button", { name: "删除", exact: true }).click();+ await expect(dialog).toHaveCount(0);+ await expect(sidebar.locator("li", { hasText: kept })).toHaveCount(0);+ expect(state.deletes.filter((id) => id === keptId)).toHaveLength(2);+ expect(state.deletes.filter((id) => id === goneId)).toHaveLength(1);++ // Both are really gone: the landed row from the first attempt, the retried one on the second.+ expect((await page.request.get(`${BASE}/api/sessions/${goneId}`)).status()).toBe(404);+ expect((await page.request.get(`${BASE}/api/sessions/${keptId}`)).status()).toBe(404);+});++test("a batch refused whole keeps every tick, and reopening the card drops the old reason", 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 stamp = Date.now();+ const first = `e2e batch refused 1 ${stamp}`;+ const second = `e2e batch refused 2 ${stamp}`;+ const firstId = await seedSession(page, projectId, first);+ const secondId = await seedSession(page, projectId, second);+ const state = { deletes: [], refuseFor: new Set([firstId, secondId]) };+ await stubDelete(page, state);++ await page.goto("/chat");+ const sidebar = page.getByRole("complementary");+ const dialog = await askBatchDelete(page, [first, second]);+ const before = await cardText(dialog);++ await dialog.getByRole("button", { name: "删除", exact: true }).click();++ await expect(dialog.getByText(REFUSAL.message)).toBeVisible();+ await expect(dialog.getByText("还有 2 个对话没有删除:session store is read-only")).toBeVisible();+ await expect(dialog).toBeVisible();+ expect(await cardText(dialog)).toBe(before);+ expect(state.deletes).toHaveLength(2);+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);++ // Nothing went: both rows and both ticks are still there.+ await expect(sidebar.locator("li", { hasText: first }).first()).toBeVisible();+ await expect(sidebar.locator("li", { hasText: second }).first()).toBeVisible();+ await expect(sidebar.getByRole("checkbox", { name: `选中「${first}」` })).toBeChecked();+ await expect(sidebar.getByRole("checkbox", { name: `选中「${second}」` })).toBeChecked();++ // Closing decides nothing; asking again starts without the last attempt's reason.+ await dialog.getByRole("button", { name: "取消" }).click();+ await expect(dialog).toHaveCount(0);+ await page.getByRole("button", { name: "批量删除", exact: true }).click();+ const reopened = page.getByRole("dialog");+ await expect(reopened).toBeVisible();+ await expect(reopened.getByText(REFUSAL.message)).toHaveCount(0);+ await expect(reopened.getByText("确定删除选中的 2 个对话")).toBeVisible();+});diff --git a/packages/web/src/components/layout/sidebar.tsx b/packages/web/src/components/layout/sidebar.tsxindex ec421363..6396a185 100644--- a/packages/web/src/components/layout/sidebar.tsx+++ b/packages/web/src/components/layout/sidebar.tsx@@ -648,6 +648,13 @@ export function Sidebar({const [batchSelected, setBatchSelected] = useState<ReadonlySet<string>>(new Set());const [batchBusy, setBatchBusy] = useState(false);const [batchConfirmDelete, setBatchConfirmDelete] = useState(false);+ /**+ * Why the last confirmed batch delete did not finish — the server's own words with the number of+ * rows it refused. Same rule as the single delete above (the reason belongs beside the button+ * that retries it), and a batch needs it even more: its refusal is partial, and what is left+ * ticked is exactly what did not go.+ */+ const [batchDeleteRefusal, setBatchDeleteRefusal] = useState<string | null>(null);/** Parked draft conversation pending delete confirmation (null = none). */const [deletingDraft, setDeletingDraft] = useState<DraftSessionEntry | null>(null);/** Parked draft conversations of this user × Project, newest first (reactive module store). */@@ -1437,26 +1444,52 @@ export function Sidebar({* 批量删除: the row delete's own confirmation, asked once for the whole selection, then the same* DELETE per row. Deleting the conversation on screen leaves for the next one of its Agent, as the* single delete does — the others are gone from the list, not from what the reader is looking at.+ *+ * A batch is N writes, not one, so the outcomes are collected per row (`allSettled`): some can+ * land while another is refused. The landed rows leave the list and the ticks; the refused ones+ * stay ticked — that is what makes the card's own count name the rows a retry would act on — and+ * the card stays open with the server's words in it (a toast would dismiss itself above the+ * card the person is still looking at, and it could not say that the rest went through).*/const confirmBatchDelete = async () => {const targets = batchTargets();if (targets.length === 0) return;setBatchBusy(true);+ setBatchDeleteRefusal(null);try {- await Promise.all(targets.map((s) => api.deleteSession(s.sessionId)));- forgetDeletedSessions(targets);- setBatchConfirmDelete(false);- setBatchSelected(new Set());- const openOne = targets.find((s) => s.sessionId === activeSessionId);+ const results = await Promise.allSettled(targets.map((s) => api.deleteSession(s.sessionId)));+ const landed: SessionInfo[] = [];+ const refused: SessionInfo[] = [];+ // The card shows ONE reason under its sentence, so the first refusal's words are the ones+ // kept — the rows themselves say which of them is still there to retry.+ let firstReason: unknown;+ results.forEach((result, i) => {+ const target = targets[i];+ if (target === undefined) return;+ if (result.status === "fulfilled") {+ landed.push(target);+ return;+ }+ if (refused.length === 0) firstReason = result.reason;+ refused.push(target);+ });+ forgetDeletedSessions(landed);+ setBatchSelected(new Set(refused.map((s) => s.sessionId)));+ if (refused.length === 0) {+ setBatchConfirmDelete(false);+ } else {+ setBatchDeleteRefusal(S.chat.batchDeleteRefused(refused.length, apiErrorText(firstReason)));+ }+ // Only a conversation that actually went away is left for: when the open one was one of the+ // refused rows it is still on screen, so there is nowhere to go.+ const openOne = landed.find((s) => s.sessionId === activeSessionId);if (openOne !== undefined) {- const deleted = new Set(targets.map((s) => s.sessionId));+ const deleted = new Set(landed.map((s) => s.sessionId));const rest = (byAgent.get(openOne.agentId) ?? []).filter((s) => !deleted.has(s.sessionId) && sessionCategory(s) === "active",);navigate(rest[0] ? `/chat/${rest[0].sessionId}` : "/chat");}- } catch (e) {- toastError(apiErrorText(e));} finally {setBatchBusy(false);}@@ -2310,7 +2343,8 @@ export function Sidebar({</ConfirmModal>{/* Batch delete confirmation: the same shared ConfirmModal as the row's own, asked once for- the whole selection instead of once per row. */}+ the whole selection instead of once per row. A partially refused batch keeps the card:+ its count and the ticks are then exactly the rows still left to delete. */}<ConfirmModalopen={batchConfirmDelete}title={S.chat.batchDeleteTitle}@@ -2319,6 +2353,7 @@ export function Sidebar({busy={batchBusy}onClose={() => (batchBusy ? undefined : setBatchConfirmDelete(false))}onConfirm={() => void confirmBatchDelete()}+ refusal={batchDeleteRefusal === null ? undefined : batchDeleteRefusal}><p className="text-sm text-gray-600 dark:text-gray-300">{S.chat.batchDeleteConfirm(batchSelected.size)}@@ -2742,7 +2777,11 @@ export function Sidebar({size="xs"variant="danger"disabled={batchBusy}- onClick={() => setBatchConfirmDelete(true)}+ onClick={() => {+ // One attempt, one reason: opening the card again never carries the last one over.+ setBatchDeleteRefusal(null);+ setBatchConfirmDelete(true);+ }}>{S.chat.batchDelete}</Button>diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex 01f3adcc..5713bb8c 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -3607,6 +3607,13 @@ export const en: Strings = {batchDeleteTitle: "Delete selected chats",batchDeleteConfirm: (n: number) =>`Delete the ${n} selected chats? Their messages and Trace will be removed permanently.`,+ /**+ * A batch delete the server refused (wholly or in part): how many of the ticked chats did not+ * go, then the server's words. The rest of the batch did land and has already left the list, so+ * the card counts only what a retry would still act on.+ */+ batchDeleteRefused: (n: number, reason: string) =>+ `${n} of the selected chats were not deleted: ${reason}`,/** Per-row ellipsis overflow menu (pin / rename / archive / delete live inside it) and the row-level pin. */pinSession: "Pin",unpinSession: "Unpin",diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex 948d52d9..cf66e4c0 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -3655,6 +3655,12 @@ export const zh = {batchDeleteTitle: "删除选中的对话",batchDeleteConfirm: (n: number) =>`确定删除选中的 ${n} 个对话?其消息与 Trace 将被移除,且不可恢复。`,+ /**+ * A batch delete the server refused (wholly or in part): how many of the ticked conversations+ * did not go, then the server's words. The rest of the batch did land and has already left the+ * list, so the card counts only what a retry would still act on.+ */+ batchDeleteRefused: (n: number, reason: string) => `还有 ${n} 个对话没有删除:${reason}`,/** Per-row ellipsis overflow menu (pin / rename / archive / delete live inside it) and the row-level pin. */pinSession: "置顶",unpinSession: "取消置顶",diff --git a/packages/web/test/sidebar-batch-sessions.test.ts b/packages/web/test/sidebar-batch-sessions.test.tsindex 50d12f4f..4aafcbb5 100644--- a/packages/web/test/sidebar-batch-sessions.test.ts+++ b/packages/web/test/sidebar-batch-sessions.test.ts@@ -60,6 +60,15 @@ describe("the batch bar's words", () => {expect(en.chat.batchDeleteConfirm(3)).toContain("permanently");});+ it("says how many of a refused batch did not go, before the server's words", () => {+ expect(zh.chat.batchDeleteRefused(2, "session store is read-only")).toBe(+ "还有 2 个对话没有删除:session store is read-only",+ );+ expect(en.chat.batchDeleteRefused(1, "session store is read-only")).toBe(+ "1 of the selected chats were not deleted: session store is read-only",+ );+ });+it("names each row's box after the conversation it stands for", () => {expect(zh.chat.batchSelectRow("修构建")).toBe("选中「修构建」");expect(en.chat.batchSelectRow("Fix the build")).toBe('Select "Fix the build"');@@ -107,21 +116,33 @@ describe("the batch wiring", () => {expect(SIDEBAR).toContain("targets.map((s) => api.deleteSession(s.sessionId))");// Both the single delete and the batch leave through the one cleanup.expect(SIDEBAR).toContain("forgetDeletedSessions([target]);");- expect(SIDEBAR).toContain("forgetDeletedSessions(targets);");+ // A batch is N writes, so its outcomes are read per row — `all` would drop the rows that did+ // land, and only the landed ones may be forgotten.+ expect(SIDEBAR).toContain("await Promise.allSettled(");+ expect(SIDEBAR).toContain("forgetDeletedSessions(landed);");});it("keeps the delete's confirmation, asked once for the whole selection", () => {expect(SIDEBAR).toContain("title={S.chat.batchDeleteTitle}");expect(SIDEBAR).toContain("onConfirm={() => void confirmBatchDelete()}");expect(SIDEBAR).toContain("S.chat.batchDeleteConfirm(batchSelected.size)");+ // A partially refused batch keeps the card, and the reason goes in it (not in a toast).+ expect(SIDEBAR).toContain(+ "refusal={batchDeleteRefusal === null ? undefined : batchDeleteRefusal}",+ );+ expect(SIDEBAR).toContain(+ "S.chat.batchDeleteRefused(refused.length, apiErrorText(firstReason))",+ );});it("drops the ticks when the mode is left, and clears them after an action lands", () => {expect(TOGGLE).toContain("setBatchMode(false)");expect(TOGGLE).toContain("setBatchSelected(new Set())");expect(SIDEBAR).toContain("const clearBatchSelection = () => setBatchSelected(new Set());");- // Archived and deleted rows are no longer the ones the reader picked.- expect(SIDEBAR.match(/setBatchSelected\(new Set\(\)\)/g)?.length).toBeGreaterThanOrEqual(4);+ // Archived rows are no longer the ones the reader picked, and a delete clears a fully landed+ // batch — but a refused one keeps exactly the rows that did not go ticked for the retry.+ expect(SIDEBAR.match(/setBatchSelected\(new Set\(\)\)/g)?.length).toBeGreaterThanOrEqual(3);+ expect(SIDEBAR).toContain("setBatchSelected(new Set(refused.map((s) => s.sessionId)));");});it("stops reordering rows while they are being picked", () => {