Repository navigation
fix: sweep closed sessions' localStorage on live slot lists - #31773
Conversation
ed9613e to
ea779c2
Compare
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The diff only clears stale localStorage entries in the background and adds no control, string or state a user sees. [UX-REVIEWED] a637858 Description read[DESCRIPTION-READ] bacff32bf030d91c80b706508a7067248c4631225ad01c1b3e7159da3e68e976 That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The defect is linked as #31285, and the sweep is placed in the frame handler, which is the right place. One note: the boot sweep still has the colon-key flaw that this sweep avoids. Notes
What this change shipsInventory (5 items) — 4 justifiedIntent: a dashboard tab left open drops a closed session's localStorage keys without a reload. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] a637858 Description read[DESCRIPTION-READ] ff6a11a580d2c277c22f58108178b6c8bd502b33f566395a370bb68bd2e9bf5d That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the live sweep keeps everything the boot sweep keeps, plus held, active, still-listed and host-prefixed keys. It runs only after a complete frame drops a key, so it deletes nothing that a reload would not delete. Notes
[DESIGN-REVIEWED] a637858 Description read[DESCRIPTION-READ] 8c9d523659d43e4243b2980ac543ddc6d89893f75617c2638623506caf2f541a That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)GPT 6.1 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- website/src/utils/slotStorageSweep.ts:38 -- Releasing a hold never retries collection of the omitted session
Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 is LOW harm. All it causes is leftover localStorage entries for a deleted session, which nobody sees. The conditions hold: a complete frame drops A's row while the gateway hold still covers A ( Recovery: the entries get collected the next time any session disappears, or at the next page load, when the boot sweep runs The real fix adds new state on the sweep: a set of deferred omissions, a retry when protection ends, and changes to the no-walk gate at False positive or not applicable? A repository writer can comment: |
ea779c2 to
935382b
Compare
|
Opus 5.5 BLOCK on GPT 6.1 findings (both downgraded on adjudication): a hold released with an unchanged key set, and an all-empty reconnect snapshot, each leave stale keys until the next key loss or reload. No live data is lost in either case, and the boot sweep collects them; left as is. Backend Tests (Windows) (7) failed on |
935382b to
4f86d61
Compare
The orphan sweep ran only at boot, so a long-open tab kept every session closed in another tab or device until a reload. Run it when a complete pushed slots frame drops a key, honouring the gateway's drain hold, the active slot and the pre-snapshot empty frame the way the in-memory reconcile does. Fixes #31285
4f86d61 to
a637858
Compare
|
Opus 5.5 BLOCK on |
bolichen97
left a comment
There was a problem hiding this comment.
Approving a637858. I read the full diff at this head.
- A live
slotsframe now runs the samegcOrphanedStoragesweep the boot path runs once per page load, so a tab left open drops the localStorage of sessions closed elsewhere (another tab, device or agent) without a reload. createSlotStorageSweepapplies the in-memory reconcile's rules: the active slot and bothsafeKey()spellings stay live, keys the list still keeps (such as a session this tab just created) are kept, and the gateway's drain hold protects every key it names. It runs only on a complete list, after a real snapshot was seen, and a storage error is swallowed.- The new test file covers those cases.
No regex, glob or case-blind matching is added. Every check on this head passes or has a newer passing run, and the UX, Design, First Principles, Opus and GPT lanes pass on this head.
The orphan sweep ran only at boot, so a long-open tab kept every session closed in another tab or device until a reload. Run it when a complete pushed slots frame drops a key, honouring the gateway's drain hold, the active slot and the pre-snapshot empty frame the way the in-memory reconcile does. Fixes #31285 Co-authored-by: Zezhen Xu <zezhexu@amazon.com> Backport note: release's useSlotListSync still returns an object literal from useMemo (main's block body came with perf #29360, not on release), so the sweep is created once per hook in a ref beside the other refs and called through it after sseSlots, instead of as a const inside the useMemo body. (cherry picked from commit e7bc65b)
Problem / Motivation
Goal: a dashboard tab left open drops a closed session's localStorage keys on the next complete slot list, without a reload.
The localStorage orphan sweep (
gcOrphanedStorage) runs once per page load, on the bootfetchSlotsreply (website/src/shell/appShell.tsx:852-858). The close-timegcSessionStorage(key)(website/src/store/chatSlice.ts:726) runs only in the tab that closed the session, and only on its success arm. So a session closed in another tab, on another device, by an agent, or through thealreadyGoneclose arm keeps every per-session key (vc_heights_,vc_anchor3_,mc-panel-tabs:and the rest ofSESSION_PREFIXES) in a long-open tab until that tab reloads. Open PR #6807 removes the close-time delete as well, which would make the boot sweep the only collector for every close.Why it matters
storageGc.tsexists because these keys can fill the ~5 MB origin quota and white-screen the dashboard. Heavy users keep one tab open for days and close many sessions per day, which is exactly the case the boot-only sweep misses.Not a goal
appShell.tsx(it still reads an unlabelledGET /api/chat/slotsreply with no hold check).slot_patchremovals.storageGc.test.ts).What changed (motivation → approach → change)
Symptom: closed sessions' keys stay until reload. Cause: the only list-driven sweep runs at boot. Change:
website/src/utils/slotStorageSweep.ts:createSlotStorageSweep()returns a sweep that remembers the last complete frame's key set and runsgcOrphanedStorageonly when a complete frame has lost a key since then, so the frequent same-keyed frames never walk localStorage. It builds the live set the wayreconcileSlotResiduedoes: frame keys, the active slot, thesafeKey()spelling of each (written withisUnsafeKey, sincesafeKeylives behind the store/chat facade), plus the keys the dashboard list still carries after the reducer (a session this tab just created). It skips aslotsPartialframe without moving its baseline, skips the empty frame a reconnect sends before the first snapshot, and spares keys named byslotListHoldTest(hold)(slotsHeldKeys, and channel keys underslotsHoldChannels). A slot key can contain ':' (a channel key such asslack:<thread>), so the sweep matches the whole rest of a storage key, or any prefix of it ending at a ':', against the live and held sets, the waygcSessionStoragematches; it never decides liveness from the first ':' segment alone. It applies the same match after a leadingpane:,side:orembed:, the host prefixes ChatPane, SideChat and ChatEmbed put before the slot in the transcriptsessionId(their scroll anchors arevc_anchor3_pane:<slot>and so on).website/src/hooks/websocket/slotList.ts:onSlotscalls the sweep right afterdispatch(sseSlots(data)), reading the hold fields the reducers just applied. localStorage is a side effect, so it lives in the handler, not the reducer. Wrapped best-effort so unavailable storage cannot break the frame handler.website/src/utils/storageGc.ts:gcOrphanedStoragetakes an optionalisKept(scoped)predicate over everything after the prefix (default: keep nothing extra), so the boot caller is unchanged.Other design, not taken: defer the boot sweep to the first complete
slotsframe. It would also close the boot path's restart window, but it changes the boot behaviour this issue does not require and leaves a tab whose socket never connects with no sweep at all. Kept as a possible follow-up.Intended? / Repro
Intended? No. The module header in
website/src/utils/storageGc.ts:1-12says the sweep exists to stop orphaned per-session keys overflowing the quota, and the issue (filed from #6807 review) asks for this sweep. Nothing indocs/decisions/or the specs says closes made elsewhere should be kept until reload. On main,gcOrphanedStoragehas one caller,website/src/shell/appShell.tsx:857, inside the bootuseEffect.Repro (main @ 39717a0, by reading code, no local tests per host rule): open the dashboard in tab 1 and tab 2. Open session A in tab 2 so
vc_heights_A/mc-panel-tabs:Aare written, then close A from tab 2. Tab 1 receives theslotsframe without A:onSlots(website/src/hooks/websocket/slotList.ts) dispatchessseSlotsand the in-memoryreconcileSlotResidueevicts A's chat state, but nothing touches localStorage, andgcSessionStorageran only in tab 2'sdeleteSlot. Tab 1 (same origin) keeps A's keys until a reload of any tab runs the boot sweep. Same for a close from another device or by an agent, where no tab runsgcSessionStorage.Backwards compatibility
Compatible:
gcOrphanedStorage's new parameter is optional and defaults to holding nothing, so the boot call behaves as before; the new sweep only removes keys the boot sweep would also remove on the next reload.Removes nothing: the sweep deletes the same orphaned keys the existing boot sweep already deletes, just without waiting for a reload; it spares everything that sweep spares plus held, active and still-listed keys.
Tests
website/src/utils/slotStorageSweep.test.ts:artifacts-galleryandmc-busy-send-mode:no-slotstay;<slot>:tables1:…height keys) are kept, while a dropped one is removed;pane:/side:/embed:host is kept, a dropped slot's is removed;slotsHeldKeyskey and a channel key underslotsHoldChannelsare spared (red if the hold test is not passed);Proof: not provable -- frontend test (prove.py runs Python only)
Manual verification
N/A — unit coverage of the sweep's decisions is sufficient; the
onSlotswiring is one call aftersseSlots, and tests run in CI only on this host.Screenshots / video
Why no screenshot: the change only removes stale localStorage entries in the background and renders nothing new.
Related Issues
Fixes #31285
Nearby change: open PR #6807 (not ours) also edits
website/src/utils/storageGc.ts; this PR changes only thegcOrphanedStoragesignature and header line there.Sibling sweep
Swept: git grep -n "gcOrphanedStorage|gcSessionStorage" -- website/src
Sibling: website/src/shell/appShell.tsx:857 -- not affected -- boot sweep keeps its behaviour, listed under Not a goal
Sibling: website/src/store/chatSlice.ts:726 -- not affected -- close-time per-key delete in the closing tab is unchanged
Pattern harvest
Not generalizable: a one-off missing trigger for one cache's garbage collector, not a repeatable code shape.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.