A local-first multi-agent app development platform, built on PenguinHarness
fix(web): keep the cost center's error notice read after a restart (#1118)
lmlihengb6fb40809bf4
diff --git a/changelog/unreleased/2026-10-15-error-read-status.md b/changelog/unreleased/2026-10-15-error-read-status.mdnew file mode 100644index 00000000..83cd2413--- /dev/null+++ b/changelog/unreleased/2026-10-15-error-read-status.md@@ -0,0 +1,19 @@+# Error notices stay read after a restart++- **Date:** 2026-10-15+- **Type:** fix+- **Scope:** `web`++[中文版](2026-10-15-error-read-status.zh.md)++Ported from upstream PenguinHarness (#1118, commit `591f091d`).++The Cost Center loaded the errors for the range on screen but marked the timestamp cached when the+app started as read, so an error that arrived while the app was open was marked read and raised the+notice again after a restart. Loading the Cost Center now refreshes the notice first, so both the+table and the read marker name the same newest error.++A read marker now hides the notice only once its preference write succeeds: a failed write reports+the API error and leaves the notice there to retry. Consecutive dismissals save in order, so an+earlier request cannot overwrite a later marker. The preference format is unchanged, and an error+newer than the saved timestamp still raises the notice.diff --git a/changelog/unreleased/2026-10-15-error-read-status.zh.md b/changelog/unreleased/2026-10-15-error-read-status.zh.mdnew file mode 100644index 00000000..1f386ec8--- /dev/null+++ b/changelog/unreleased/2026-10-15-error-read-status.zh.md@@ -0,0 +1,16 @@+# 重启后错误提醒的已读状态保留++- **Date:** 2026-10-15+- **Type:** fix+- **Scope:** `web`++[English](2026-10-15-error-read-status.md)++移植自上游 PenguinHarness(#1118,提交 `591f091d`)。++成本中心此前读的是屏幕上那一档范围里的错误,标记已读时写下的却是**应用启动时**缓存的那个时间戳 ——+于是应用打开之后到达的错误也被算作已读,重启后它又把提醒重新抬起来。现在成本中心加载时先刷新一次+提醒,表格与已读标记因此指的是同一条最新错误。++已读标记改为**写入成功后**才收起提醒:写入失败时显示接口报错,并留着这条提醒供重试。连续标记按顺序+保存,先发出的请求不会覆盖后写的标记。偏好项的格式一字未改,比已保存时间戳更新的错误仍会抬起提醒。diff --git a/packages/web/src/features/usage/usage-page.tsx b/packages/web/src/features/usage/usage-page.tsxindex f1b055e0..ecfcda4f 100644--- a/packages/web/src/features/usage/usage-page.tsx+++ b/packages/web/src/features/usage/usage-page.tsx@@ -195,6 +195,9 @@ export function UsagePage() {const load = useCallback(async () => {if (!projectId) return;+ // The notice must acknowledge the errors fetched for this visit, not the timestamp+ // cached when the app started; otherwise those errors return as unread after a reload.+ refreshProjectTodos(projectId);setError(null);try {// The trailing presets recompute their window at load time, so a reload@@ -455,11 +458,8 @@ export function UsagePage() {// Clearing the log is a Project-level management operation, gated on the owner// by the route; a member reads the panel without the action.canClear={currentProject?.role === "owner"}- // The badge and the notice above are gated on a probe cached per Project for the- // browser session, not on this response — without the re-probe an emptied table- // would sit under a dot still pointing at the rows that just went.+ // Reload both the table and its notice after clearing the log.onCleared={() => {- refreshProjectTodos(projectId);void load();}}/>diff --git a/packages/web/src/lib/todo-dismissals.ts b/packages/web/src/lib/todo-dismissals.tsindex 30b3c0c8..ece03a01 100644--- a/packages/web/src/lib/todo-dismissals.ts+++ b/packages/web/src/lib/todo-dismissals.ts@@ -24,7 +24,9 @@import { useEffect } from "react";import { createStore } from "zustand/vanilla";import { useStore } from "zustand/react";+import { toastError } from "@lmliheng/penguin-ui";import * as api from "../api/endpoints";+import { apiErrorText } from "./api-error";import type { TodoKey } from "./todo-badges";/** The `ui_prefs` key the whole map is stored under. */@@ -119,17 +121,23 @@ export function useTodoDismissals(projectId: string | null, eager = false): Todo);}-/** Dismisses one trail at the signature it is showing right now, and persists it (best-effort). */+// Each write carries the whole map. Serialize them so a slower earlier request cannot+// overwrite a later dismissal, and compose each map from the last successful write.+let saving: Promise<void> = Promise.resolve();++/** Dismisses the shown signature once saved; a failed write leaves it available to retry. */export function dismissTodo(projectId: string | null, key: TodoKey, signature: string): void {if (projectId === null) return;- const { map } = dismissStore.getState();// No markers means no dot was raised, so there is nothing to wave away — and writing now// would persist a map missing every Project this session never read.- if (map === null) return;- if (map[projectId]?.[key] === signature) return; // No-op: skip the write and the re-render.- const next = withDismissal(map, projectId, key, signature);- dismissStore.setState({ map: next });- // Fire-and-forget, the initial-password banner's pattern: a lost write only costs- // persistence, the dot is already down in this tab.- void api.putPrefs({ [TODO_PREFS_KEY]: next }).catch(() => undefined);+ if (dismissStore.getState().map === null) return;+ saving = saving+ .then(async () => {+ const map = dismissStore.getState().map!;+ if (map[projectId]?.[key] === signature) return;+ const next = withDismissal(map, projectId, key, signature);+ await api.putPrefs({ [TODO_PREFS_KEY]: next });+ dismissStore.setState({ map: next });+ })+ .catch((e: unknown) => toastError(apiErrorText(e)));}