diff --git a/doc/ui-internals.md b/doc/ui-internals.md index 21ad0050184..28bade0628e 100644 --- a/doc/ui-internals.md +++ b/doc/ui-internals.md @@ -151,7 +151,7 @@ Run `node scripts/check-query-error-rendering.mjs`. The guard now enforces acros The browser saves a small read cache in `paperclip:query-cache:v1:*` local storage records. It contains session display identity, health and shell preferences, company and sidebar data, agent/project lists, plugin UI contribution metadata, the first inbox page (including up to 100 rows per legacy Inbox query), and up to 20 recently opened tasks. Records belong to one user and company, expire 24 hours after each read, and are discarded when the build changes. Normal in-memory query garbage collection does not erase saved recent tasks or extend their expiry. Builds without a source commit stamp skip read-cache hydration and persistence, but still revoke and clear saved reads on sign-out. Plugin contributions use the existing instance-wide query inside the user's root record. Session tokens, bootstrap payloads, documents, comments, browser viewer capabilities, pairing data, other queries and mutations are excluded, with one exception for the saved recent tasks below. Task content in this allowlist remains on the browser until expiry or sign-out; use the normal sign-out action to clear it across tabs. -The first chat frame of each saved recent task is also saved, so a hard load of a task the user opened before shows its conversation before any server response. The owner approved saving recent comments for this on 2026-11-14. The saved reads are only the ones that first frame waits for: the recent comments window (at most 50 comments, the newest ones), their input facts, recent activity, the recent run window, interactions, attachment metadata (never file contents), live and active runs, work products and the plan document. They follow the 20-task limit and are stored in the task's own user and company record. Each task's saved chat is limited to 192 KiB and all saved chat to 1 MiB, newest tasks first. A record that storage refuses is saved again without its chat, so saved chat never displaces the rest of the cache. The other field exclusions (tokens, credentials, environment values and the like) still apply. Saved chat expires 24 hours after it was read, like every other entry. A 401, 403 or 404 on the task or on any of its chat reads removes the task and its saved chat from memory and storage at once. Restored reads are shown immediately and revalidated through the page's chat bootstrap; its answer replaces them, and they never replace newer data already in the page. Account changes also detach pending shared GETs so a new user cannot join the previous user’s private reads. Editors that need fields excluded from the display cache, including bulk agent settings, fetch complete current data before opening. +The first chat frame of each saved recent task is also saved, so a hard load of a task the user opened before shows its conversation before any server response. The owner approved saving recent comments for this on 2026-11-14. The saved reads are only the ones that first frame waits for: the recent comments window (at most 50 comments, the newest ones), their input facts, recent activity, the recent run window, interactions, attachment metadata (never file contents), live and active runs, work products and the plan document. They follow the 20-task limit and are stored in the task's own user and company record. Each task's saved chat is limited to 192 KiB and all saved chat to 1 MiB, newest tasks first. A record that storage refuses is saved again without its chat, so saved chat never displaces the rest of the cache. The other field exclusions (tokens, credentials, environment values and the like) still apply. Saved chat expires 24 hours after it was read, like every other entry. A 401 or 403 on the task or on any of its chat reads, or a 404 on the task or its comments, removes the task and its saved chat from memory and storage at once. A 404 on a plan, run or work-product read does not, because it does not mean the task is gone (a task without a plan answers 404). Restored reads are shown immediately and revalidated through the page's chat bootstrap; its answer replaces them, and they never replace newer data already in the page. Account changes also detach pending shared GETs so a new user cannot join the previous user’s private reads. Editors that need fields excluded from the display cache, including bulk agent settings, fetch complete current data before opening. Restored identity permits cached display only. Restored inline task drafts compare their saved base with a fresh field read before each replay; conflicting edits stay in the editor for review. Account-bound writes wait for a fresh server session and are cancelled if its user changes. A definitive session denial removes saved account reads. Service-worker updates reload hidden tabs only after connectivity is online and mutations, durable sends and autosaves have settled. Durable queues synchronously report each unresolved operation, including the intervals between online rate-limit retries. Sign-out revocation also works on plain-HTTP installs without `crypto.randomUUID`. diff --git a/ui/src/lib/persisted-query-cache.ts b/ui/src/lib/persisted-query-cache.ts index b50e2e841e3..2040505812c 100644 --- a/ui/src/lib/persisted-query-cache.ts +++ b/ui/src/lib/persisted-query-cache.ts @@ -564,7 +564,11 @@ export function startPersistedQueryCache(client: QueryClient, options: { blockedQueries.add(hashKey(event.query.queryKey)); const userId = owner ?? userIdOf(client.getQueryData(queryKeys.auth.session)); const saved = userId ? readSaved(userId) : []; - if ((issueDetail || chatRef !== null) && ["auth", "forbidden", "not_found"].includes(classifyError(event.action.error))) { + const refusal = classifyError(event.action.error); + const revokesTask = issueDetail + ? ["auth", "forbidden", "not_found"].includes(refusal) + : chatRef !== null && (["auth", "forbidden"].includes(refusal) || (refusal === "not_found" && event.query.queryKey[1] === "comments")); + if (revokesTask) { // A refused task read, or a refused read of its saved chat, removes the // task and its saved chat at once, from memory and from storage. const ids = new Set(issueDetail ? issueRefs(event.query) : [chatRef!.toLowerCase()]); diff --git a/ui/src/lib/saved-task-chat.test.ts b/ui/src/lib/saved-task-chat.test.ts index 139d93d5fe9..9b8fb975a3e 100644 --- a/ui/src/lib/saved-task-chat.test.ts +++ b/ui/src/lib/saved-task-chat.test.ts @@ -222,6 +222,19 @@ describe("saved first chat frame of a recently opened task", () => { expect(reloaded.getQueryData(commentsKey("ABC-2"))).toBeDefined(); }); + it.each([ + ["a missing plan", [...queryKeys.issues.documents(task(1).id), "plan"]], + ["a missing active run", queryKeys.issues.activeRun("ABC-1")], + ["missing work products", queryKeys.issues.workProducts("ABC-1")], + ])("keeps the task after a 404 for %s, which does not mean the task is gone", async (_name, key) => { + const storage = savedPage((client) => { openTask(client, 1); }); + const { client } = page(storage); + await client.fetchQuery({ queryKey: key as readonly unknown[], queryFn: async () => { throw new ApiError("Not found", 404, null); } }).catch(() => {}); + expect(client.getQueryData(coreKey("ABC-1"))).toBeDefined(); + expect(client.getQueryData(commentsKey("ABC-1"))).toBeDefined(); + expect(storage.text()).toContain("comment-1-0"); + }); + it("removes the saved chat when the task record itself is refused", async () => { const storage = savedPage((client) => { openTask(client, 1); }); const { client } = page(storage);