A local-first multi-agent app development platform, built on PenguinHarness
fix(web): the error center's two cards keep a refused write's reason
lmlihenge84167aa4412
diff --git a/changelog/unreleased/2026-11-12-errors-card-refusal.md b/changelog/unreleased/2026-11-12-errors-card-refusal.mdnew file mode 100644index 00000000..6cfe425c--- /dev/null+++ b/changelog/unreleased/2026-11-12-errors-card-refusal.md@@ -0,0 +1,48 @@+# Both confirmation cards in the error center keep a refused write's reason inside the card++- **Date:** 2026-11-12+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文版](2026-11-12-errors-card-refusal.zh.md)++The cost center's error panel has two cards that ask before they write: 清空 deletes every record in+the range, and 忽略这类异常 adds a rule that hides a class of them. Both closed on success and stayed+open on failure — correctly — but the reason for the failure was only a notification that dismissed+itself after six seconds. The card then read exactly as it had before the attempt: on the delete card+that is a question about deleting records that were refused, waiting to be answered again; on the+ignore card it is a class that is still in the table with nothing saying why.++Each card now carries the refusal itself, in the shared card's `refusal` slot — `操作被拒绝:<reason>`+under the sentence that was refused, beside the button that retries it. The sentence above is+untouched (a refused write changed nothing), the toast is gone, and the reason is cleared when the+next attempt starts or the card is closed, so reopening it starts clean.++## Details++- `packages/web/src/features/usage/errors-panel.tsx`: a `clearRefusal` state on the delete card and an+ `ignoreRefusal` state on the ignore card. Both are filled from `apiErrorText` only when the write is+ refused, emptied at the start of every attempt and when the card closes; the delete card is also+ emptied when it is opened (its sentence is about a count that has just been re-read). The two+ `toastError` calls they replace are gone — the card is the whole account of the refusal, which is+ the app-wide rule.+- Nothing else about either card moved: what they name, when they close, what they delete or silence,+ and the retry being the same button.++## Tests++- `packages/web/e2e/cost-center-clear.spec.mjs`: the refused-delete test now reads the reason inside+ the card, checks the notification region holds nothing, and that the card still reads as it did —+ the prior sentences plus the one line; it then closes the card, reopens it, and sees a clean card+ before letting the retry through.+- `packages/web/e2e/errors-ignore.spec.mjs`: a new refused-ignore test — the card stays open on the+ class it named with the reason inside it and nothing in the notification region; the row is still+ in the table, no notice to undo, no rule on the Project; the card reopens clean and the retry lands+ a rule.+- Both run on a real server, the repository's mock model and a real browser.++## Compatibility++No wire change, no new dependency, no Project config change, no new copy: the sentence is the+existing app-wide `操作被拒绝:<reason>`. Successful writes and every other notification are untouched.diff --git a/changelog/unreleased/2026-11-12-errors-card-refusal.zh.md b/changelog/unreleased/2026-11-12-errors-card-refusal.zh.mdnew file mode 100644index 00000000..e0c590ff--- /dev/null+++ b/changelog/unreleased/2026-11-12-errors-card-refusal.zh.md@@ -0,0 +1,38 @@+# 错误中心的两个确认框被拒时,原因留在卡片里++- **日期:** 2026-11-12+- **类型:** 修复+- **范围:** `web`+- **破坏性变更:** 否++[English](2026-11-12-errors-card-refusal.md)++成本中心的异常面板里有两个「先问再写」的卡片:**清空**要删掉这一范围内的每一条记录,**忽略这类异常**要加一条+把某一类藏起来的规则。成功时关掉、被拒时留着 —— 这两点本来都对,但被拒的原因只活在一条六秒后自己消失的通知里。+于是卡片读起来和没点之前一模一样:在删除那张上,那是「删掉已被拒的记录」这句话又在等人确认一次;在忽略那张上,+是那一类仍在表里,而屏幕上没有一个字说为什么。++现在两张卡片各自带着这次拒绝,走共享卡片的 `refusal` 槽 —— `操作被拒绝:<原因>` 画在被拒的那句话下面、重试它的+那个按钮旁边。上面那句原样不动(被拒的写什么都没改),通知不再另弹,句子在下次尝试开始或卡片关闭时清掉,所以+重新打开是一张干净的卡片。++## 细节++- `packages/web/src/features/usage/errors-panel.tsx`:删除卡片新增 `clearRefusal`、忽略卡片新增 `ignoreRefusal`。+ 两者都只在写入被拒时由 `apiErrorText` 填上,每次尝试开始与卡片关闭时清掉;删除卡片在**打开**时也清一次+ (它那句话说的是一次刚刚重新读过的计数)。被它们替掉的两处 `toastError` 一并删掉 —— 卡片就是这次拒绝的全部+ 交代,与全应用的规则一致。+- 两张卡片的其余部分一处未动:它们说什么、什么时候关、删掉或藏起什么、以及「同一个按钮就是重试」。++## 测试++- `packages/web/e2e/cost-center-clear.spec.mjs`:被拒删除那条改成读**卡片里**的原因、断言通知区是空的、卡片+ 除了这一行之外与之前逐字相同;随后关掉卡片、重新打开、确认是一张干净的卡片,再让重试落地。+- `packages/web/e2e/errors-ignore.spec.mjs`:新增一条被拒忽略的用例 —— 卡片留在他点名的那一类上、原因在卡片里、+ 通知区没有东西;那一行仍在表里、没有可撤销的提示、Project 上没有规则;重新打开是干净的,重试落下一条规则。+- 两条都跑在真服务端、仓库自带的 mock 模型与真浏览器上。++## 兼容性++线上接口没变、没有新依赖、Project 配置没变、没有新文案:那句话就是全应用既有的 `操作被拒绝:<原因>`。成功的+写入与其余通知一字未改。diff --git a/packages/web/e2e/cost-center-clear.spec.mjs b/packages/web/e2e/cost-center-clear.spec.mjsindex ca039dd6..f130b793 100644--- a/packages/web/e2e/cost-center-clear.spec.mjs+++ b/packages/web/e2e/cost-center-clear.spec.mjs@@ -238,13 +238,24 @@ test("a refused delete keeps the dialog and the rows, and a retry clears them",const sentence = await dialog.innerText();await dialog.getByRole("button", { name: "清空" }).click();- await expect(page.getByText(/errors store is closed/)).toBeVisible();+ await expect(dialog.getByText(/errors store is closed/)).toBeVisible();await expect(dialog).toBeVisible();- // The sentence is still the one that was being confirmed: the refused write changed nothing.- expect(await dialog.innerText()).toBe(sentence);+ // 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 before plus the one line (the sentence+ // is still the one that was being confirmed — the refused write changed nothing).+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);+ expect((await dialog.innerText()).replace(/\n操作被拒绝:[^\n]*/, "")).toBe(sentence);await expect(page.getByText(/^已删除 \d+ 条错误记录$/)).toHaveCount(0);expect((await seen.read()).total).toBe(before.total);+ // Closing the card decides nothing, and reopening it does not carry the old reason.+ await dialog.getByRole("button", { name: "取消", exact: true }).click();+ await expect(dialog).toHaveCount(0);+ await page.getByRole("button", { name: "清空", exact: true }).click();+ await expect(dialog).toBeVisible();+ await expect(dialog.getByText(/errors store is closed/)).toHaveCount(0);+ expect(await dialog.innerText()).toBe(sentence);+// Let the delete through: the retry closes the dialog, reports, and empties the table.await page.unroute("**/api/projects/*/usage/errors*");await dialog.getByRole("button", { name: "清空" }).click();diff --git a/packages/web/e2e/errors-ignore.spec.mjs b/packages/web/e2e/errors-ignore.spec.mjsindex c54e8a6a..55b93f2d 100644--- a/packages/web/e2e/errors-ignore.spec.mjs+++ b/packages/web/e2e/errors-ignore.spec.mjs@@ -232,3 +232,61 @@ test("the ignored view names the rules, and 取消忽略 re-exposes every recordfunction row(page, target) {return page.locator("tbody tr").filter({ hasText: target.code });}++test("a refused ignore keeps the card, its sentence and every record", async ({ page }) => {+ test.setTimeout(120_000);+ // A fresh account per run: the rules are the Project's, so a rerun on the same data root would+ // otherwise find the rule a previous run left behind and start from a table with no such row.+ const user = `ignorerefuse_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`;+ const { projectId, sessionId } = await prepare(page, user);+ const target = await seedError(page, projectId, sessionId);++ await page.goto("/usage");+ await expect(page.locator("tbody tr").first()).toBeVisible();++ const REFUSAL = { code: "errors_store_closed", message: "ignore store is closed" };+ await page.route("**/api/projects/*/usage/errors/ignores*", async (route) => {+ if (route.request().method() !== "POST") return route.fallback();+ await route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ });+ });++ const targetRow = row(page, target).first();+ await expect(targetRow).toBeVisible();+ await targetRow.getByRole("button", { name: "忽略这类异常", exact: true }).click();+ const dialog = page.getByRole("dialog");+ await expect(dialog).toBeVisible();+ const sentence = await dialog.innerText();+ await dialog.getByRole("button", { name: "忽略", exact: true }).click();++ // The reason is in the card that asked — the card stays open on the class it named — and it is+ // not a toast: the notification region holds no dismissible button, and the card reads exactly+ // as before plus the one line.+ await expect(dialog.getByText(REFUSAL.message)).toBeVisible();+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);+ await expect(dialog).toBeVisible();+ expect((await dialog.innerText()).replace(/\n操作被拒绝:[^\n]*/, "")).toBe(sentence);++ // Nothing was silenced: the row is still in the table, there is no notice to undo, and the+ // Project has no rule — the records were never in question.+ await expect(targetRow).toBeVisible();+ await expect(page.locator("[data-ignore-notice]")).toHaveCount(0);+ expect(await readRules(page, projectId)).toHaveLength(0);++ // Reopening the card starts clean, and letting the write through lands exactly as the plain+ // path does: the class leaves the table and one rule takes its place.+ await dialog.getByRole("button", { name: "取消", exact: true }).click();+ await expect(dialog).toHaveCount(0);+ await targetRow.getByRole("button", { name: "忽略这类异常", exact: true }).click();+ await expect(dialog).toBeVisible();+ await expect(dialog.getByText(REFUSAL.message)).toHaveCount(0);+ expect(await dialog.innerText()).toBe(sentence);+ await page.unroute("**/api/projects/*/usage/errors/ignores*");+ await dialog.getByRole("button", { name: "忽略", exact: true }).click();+ await expect(dialog).toHaveCount(0);+ await expect(row(page, target)).toHaveCount(0);+ expect(await readRules(page, projectId)).toHaveLength(1);+});diff --git a/packages/web/src/features/usage/errors-panel.tsx b/packages/web/src/features/usage/errors-panel.tsxindex ba307f60..e54d4ac4 100644--- a/packages/web/src/features/usage/errors-panel.tsx+++ b/packages/web/src/features/usage/errors-panel.tsx@@ -456,6 +456,11 @@ export function ErrorsPanel({until: string;} | null>(null);const [counting, setCounting] = useState(false);+ // Why the delete the card asked for did not land. It sits in the card, not in a toast: the+ // card is still open on the sentence that was refused, and a deletion whose reason dismissed+ // itself after six seconds reads as "nothing happened" — with the same sentence waiting to be+ // confirmed again. Cleared when the attempt starts and when the card closes.+ const [clearRefusal, setClearRefusal] = useState<string | null>(null);/*** Reads the count the dialog will name, then opens it. `limit: 1` is all it needs: `total`@@ -463,6 +468,9 @@ export function ErrorsPanel({*/const openClear = async () => {setCounting(true);+ // A card that closed on a refusal and is being opened again starts clean: its sentence was+ // about the previous count, which this read has just replaced.+ setClearRefusal(null);try {const res = await api.getUsageErrors(projectId, { offset: 0, limit: 1, ...activeFilters });const newest = res.items[0]?.ts;@@ -490,6 +498,7 @@ export function ErrorsPanel({const runClear = async () => {if (confirmTarget === null) return;setClearing(true);+ setClearRefusal(null);try {const res = await api.clearUsageErrors(projectId, {...activeFilters,@@ -501,7 +510,7 @@ export function ErrorsPanel({// refetched rather than patched here; that also restores page 0 from the new snapshot.onReload();} catch (e) {- toastError(apiErrorText(e));+ setClearRefusal(apiErrorText(e));} finally {setClearing(false);}@@ -517,6 +526,10 @@ export function ErrorsPanel({const [ignoreTarget, setIgnoreTarget] = useState<UsageErrorItem | null>(null);const [ignoreFragment, setIgnoreFragment] = useState("");const [ignoring, setIgnoring] = useState(false);+ // Same rule as the clear's card: the rule this card asked for did not land, so the reason stays+ // in the card that asked — the row's dialog is the only place that knows which class it was+ // about, and the notice that would carry an undo only appears when the write succeeds.+ const [ignoreRefusal, setIgnoreRefusal] = useState<string | null>(null);// The rule just made, kept so the panel can offer the undo in place: the row it stood for is// already gone from the table below, so a notice floating elsewhere would point at nothing. The// count is the answer the write carried, not the stats above — those are still the dashboard's@@ -565,6 +578,7 @@ export function ErrorsPanel({if (ignoreTarget === null) return;const { source, code } = ignoreTarget;setIgnoring(true);+ setIgnoreRefusal(null);try {const added = await api.ignoreUsageErrors(projectId,@@ -581,7 +595,7 @@ export function ErrorsPanel({// refetched: the ignored count and the table's own first page both move with this.onReload();} catch (e) {- toastError(apiErrorText(e));+ setIgnoreRefusal(apiErrorText(e));} finally {setIgnoring(false);}@@ -804,6 +818,9 @@ export function ErrorsPanel({onClick={() => {setIgnoreTarget(e);setIgnoreFragment("");+ // A different class: the previous card's refusal named the class it+ // was about, not this one.+ setIgnoreRefusal(null);}}className="inline-flex size-5 items-center justify-center rounded-sm text-fg-subtle transition-colors duration-150 hover:bg-surface-muted hover:text-fg-muted">@@ -869,7 +886,11 @@ export function ErrorsPanel({confirmLabel={S.usage.errorsClear}cancelLabel={S.common.cancel}busy={clearing}- onClose={() => setConfirmingClear(false)}+ refusal={clearRefusal === null ? undefined : S.common.refused(clearRefusal)}+ onClose={() => {+ setConfirmingClear(false);+ setClearRefusal(null);+ }}onConfirm={() => void runClear()}><div className="space-y-1.5 text-sm text-gray-700 dark:text-gray-300">@@ -905,9 +926,11 @@ export function ErrorsPanel({confirmLabel={S.usage.errorsIgnore}cancelLabel={S.common.cancel}busy={ignoring}+ refusal={ignoreRefusal === null ? undefined : S.common.refused(ignoreRefusal)}onClose={() => {setIgnoreTarget(null);setIgnoreFragment("");+ setIgnoreRefusal(null);}}onConfirm={() => void runIgnore()}>