Skip to content

fix: sweep closed sessions' localStorage on live slot lists - #31773

Merged
bolichen97 merged 1 commit into
mainfrom
crew/bug-resolve/31285-slots-gc
Nov 7, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
crew/bug-resolve/31285-slots-gc

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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 boot fetchSlots reply (website/src/shell/appShell.tsx:852-858). The close-time gcSessionStorage(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 the alreadyGone close arm keeps every per-session key (vc_heights_, vc_anchor3_, mc-panel-tabs: and the rest of SESSION_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.ts exists 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

  • Changing the boot sweep in appShell.tsx (it still reads an unlabelled GET /api/chat/slots reply with no hold check).
  • Per-key sweeps on slot_patch removals.
  • Changing how a key's session id is parsed (slot keys are colon-free; pinned in 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:

  • New website/src/utils/slotStorageSweep.ts: createSlotStorageSweep() returns a sweep that remembers the last complete frame's key set and runs gcOrphanedStorage only 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 way reconcileSlotResidue does: frame keys, the active slot, the safeKey() spelling of each (written with isUnsafeKey, since safeKey lives behind the store/chat facade), plus the keys the dashboard list still carries after the reducer (a session this tab just created). It skips a slotsPartial frame without moving its baseline, skips the empty frame a reconnect sends before the first snapshot, and spares keys named by slotListHoldTest(hold) (slotsHeldKeys, and channel keys under slotsHoldChannels). A slot key can contain ':' (a channel key such as slack:<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 way gcSessionStorage matches; it never decides liveness from the first ':' segment alone. It applies the same match after a leading pane:, side: or embed:, the host prefixes ChatPane, SideChat and ChatEmbed put before the slot in the transcript sessionId (their scroll anchors are vc_anchor3_pane:<slot> and so on).
  • website/src/hooks/websocket/slotList.ts: onSlots calls the sweep right after dispatch(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: gcOrphanedStorage takes an optional isKept(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 slots frame. 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-12 says the sweep exists to stop orphaned per-session keys overflowing the quota, and the issue (filed from #6807 review) asks for this sweep. Nothing in docs/decisions/ or the specs says closes made elsewhere should be kept until reload. On main, gcOrphanedStorage has one caller, website/src/shell/appShell.tsx:857, inside the boot useEffect.

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:A are written, then close A from tab 2. Tab 1 receives the slots frame without A: onSlots (website/src/hooks/websocket/slotList.ts) dispatches sseSlots and the in-memory reconcileSlotResidue evicts A's chat state, but nothing touches localStorage, and gcSessionStorage ran only in tab 2's deleteSlot. 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 runs gcSessionStorage.

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:

  • a closed session is removed on the next complete frame; frame sessions, the active slot, artifacts-gallery and mc-busy-send-mode:no-slot stay;
  • live, active and held slots whose key contains ':' (and their <slot>:tables1:… height keys) are kept, while a dropped one is removed;
  • a live slot's anchor under a pane:/side:/embed: host is kept, a dropped slot's is removed;
  • a key the dashboard list still carries is kept;
  • no walk when no key was lost;
  • a partial frame removes nothing and keeps the baseline, so a session closed during the restart is still collected on the next complete frame (red if the partial check is removed);
  • a slotsHeldKeys key and a channel key under slotsHoldChannels are spared (red if the hold test is not passed);
  • the pre-snapshot empty frame removes nothing (red if that guard is removed).

Proof: not provable -- frontend test (prove.py runs Python only)

Manual verification

N/A — unit coverage of the sweep's decisions is sufficient; the onSlots wiring is one call after sseSlots, 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 the gcOrphanedStorage signature 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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

@CrysisDeu
CrysisDeu requested review from a team and KiroCrewCaptain as code owners November 6, 2026 20:25
@CrysisDeu
CrysisDeu requested a review from Zedmor November 6, 2026 20:25
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 6, 2026
@CrysisDeu
CrysisDeu force-pushed the crew/bug-resolve/31285-slots-gc branch from ed9613e to ea779c2 Compare November 6, 2026 21:19
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of a637858c17c7900c13dd7e6f85b0ad762fa8e9aa — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of a637858c17c7900c13dd7e6f85b0ad762fa8e9aa — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • Item 4 — symptom-level (1 counted sibling): the sweep keeps live colon keys (slack:<thread>) and hosted anchors (pane:/side:/embed:) through isKept. The only other caller, gcOrphanedStorage(liveIds) (website/src/shell/appShell.tsx:857), still splits at the first : and does not pass isKept. So every reload still deletes the keys this sweep keeps; grepped gcOrphanedStorage( and found 2 call sites outside tests. The PR lists the boot sweep under ## Not a goal, so this gap is accepted and deferred. Subtraction: move the colon and host matching out of slotStorageSweep.ts into gcOrphanedStorage itself, replacing the split(':')[0] test, so there is one matcher and not two.

What this change ships

Inventory (5 items) — 4 justified

Intent: a dashboard tab left open drops a closed session's localStorage keys without a reload. This is a FIX.

  1. An open tab removes a closed session's stored keys on the next complete slot list — justified
  2. Partial lists, pre-snapshot empty lists and held keys never trigger deletion — justified
  3. Storage is walked only when a list has lost a key — justified
  4. Live colon-keyed slots and pane/side/embed scroll anchors survive the live sweep — symptom-level
  5. gcOrphanedStorage gains an optional isKept predicate — justified

[FIRST-PRINCIPLES-REVIEWED] a637858

Description read

[DESCRIPTION-READ] ff6a11a580d2c277c22f58108178b6c8bd502b33f566395a370bb68bd2e9bf5d

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of a637858c17c7900c13dd7e6f85b0ad762fa8e9aa — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • Two collectors now share one live-set rule, and only the live one knows about holds, colon keys and host prefixes. The boot sweep in appShell.tsx stays cruder (it reads the first : segment only). If the deferred follow-up happens, folding the boot path into this sweep would leave one rule instead of two that can drift.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed a637858c17c7900c13dd7e6f85b0ad762fa8e9aa — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] a637858

Verdict parsed from the review's SHA-scoped output markers for commit a637858c17c7900c13dd7e6f85b0ad762fa8e9aa.

False positive or not applicable? A repository writer can comment:
/ai-review override fable a637858c17c7900c13dd7e6f85b0ad762fa8e9aa false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)

GPT 6.1 flagged blocking issues on a637858c17c7900c13dd7e6f85b0ad762fa8e9aa; Opus 5.5 adjudication downgraded every one of them. Downgraded: the remedy each one needs is disproportionate to the harm it prevents. Adjudication downgraded all 1 blocking finding(s): the remedy each one requires is disproportionate to the harm it prevents.

This comment is updated in place on each push.

Review details

BLOCKING -- website/src/utils/slotStorageSweep.ts:38 -- Releasing a hold never retries collection of the omitted session

lastKeys = keys
if (!previous || ![...previous].some(key => !keys.has(key))) return 0
Trigger: A tab survives a restart; the next complete frame omits previously listed session A but holds it in slotsHeldKeys. The sweep preserves A’s storage and advances lastKeys. Deleting A from History calls release_deleted_slot_keys and push_slots_update; onSlots receives unchanged rows with A’s hold removed.
Outcome: The sweep returns before collection because no additional row disappeared. A’s orphaned localStorage entries remain until another session disappears or the page reloads; the History-delete thunk performs no separate storage cleanup.
Anchor: defect
Fix: Track deferred omissions and retry their collection when protection ends, while retaining the no-walk optimization for unchanged liveness and protection.
Sites: Bulk History deletion releases holds in src/kiro_crew/dashboard/handlers/sessions_parts/delete_routes.py:340; channel reconciliation publishes hold-only changes in src/kiro_crew/dashboard/channel_slots.py:1557. The same gate also ignores withdrawal of keptKeys and active-slot protection at website/src/utils/slotStorageSweep.ts:40 and website/src/utils/slotStorageSweep.ts:41.

[BLOCK-MERGE-DOWNGRADED] a637858
[GPT-REVIEWED] a637858

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 (website/src/utils/slotStorageSweep.ts:33-35). That frame advances lastKeys and walks, but the hold protects A (:38, :45-46). When the hold is lifted, the next frame shows no newly missing row, so the sweep returns early (:39).

Recovery: the entries get collected the next time any session disappears, or at the next page load, when the boot sweep runs gcOrphanedStorage (website/src/shell/appShell.tsx:852-857). Before this PR, a tab that stayed open never swept at all, so this is still an improvement over that. Nothing gets corrupted, nothing leaks to another user, and nothing that is still in use is lost.

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 :39-41 that every later reader has to follow. That cost is more than a temporary storage leak is worth.

[ADJUDICATION] a637858c17c7900c13dd7e6f85b0ad762fa8e9aa total=1 uphold=0 downgrade=1
DOWNGRADE F1 website/src/utils/slotStorageSweep.ts:38 reason=disproportionate-remedy
[GPT-ADJUDICATED] a637858c17c7900c13dd7e6f85b0ad762fa8e9aa

False positive or not applicable? A repository writer can comment:
/ai-review override gpt a637858c17c7900c13dd7e6f85b0ad762fa8e9aa false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@CrysisDeu
CrysisDeu force-pushed the crew/bug-resolve/31285-slots-gc branch from ea779c2 to 935382b Compare November 6, 2026 22:23
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Opus 5.5 BLOCK on ea779c236b (colon slot keys wiped by the sweep): fixed in 935382b579. The live sweep no longer decides liveness from the first ':' segment. It passes gcOrphanedStorage an isKept(scoped) predicate that matches the whole rest of a storage key, or any prefix of it ending at a ':', against the live and held sets, the same matching gcSessionStorage uses. So mc-panel-tabs:slack:<thread> and vc_heights_<slot>:tables1:… survive for a live, active or held slot. New test: keeps live, active and held slots whose key contains a colon. The boot sweep's parse is unchanged, which is what the Not a goal bullet refers to.

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 test_pull_request_target_allowlist.py::test_only_the_allowed_workflows_use_pull_request_target (sensitive-change-review.yml), a workflow-file check this frontend-only diff does not touch.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 6, 2026
@CrysisDeu
CrysisDeu force-pushed the crew/bug-resolve/31285-slots-gc branch from 935382b to 4f86d61 Compare November 6, 2026 23:24
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 7, 2026
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
@CrysisDeu
CrysisDeu force-pushed the crew/bug-resolve/31285-slots-gc branch from 4f86d61 to a637858 Compare November 7, 2026 00:15
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Opus 5.5 BLOCK on 4f86d6166f (host-prefixed anchors vc_anchor3_pane:<slot> wiped): fixed in a637858c17. The sweep's keep test now also matches after a leading pane:, side: or embed:, the three host prefixes ChatPane, SideChat and ChatEmbed put before the slot in the transcript sessionId. Swept every sessionId writer under website/src (git grep -nE "sessionId[:=] *[\'"{]|anchorSessionId:"): the remaining ones use the raw slot or are terminal ids outside SESSION_PREFIXES. New test: keeps a live slot anchor saved under a pane, side or embed host. The previous head's frontend shard red (chatSlice.ownership.test.ts`, a comment naming the store path) is also fixed.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 7, 2026
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 7, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving a637858. I read the full diff at this head.

  • A live slots frame now runs the same gcOrphanedStorage sweep 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.
  • createSlotStorageSweep applies the in-memory reconcile's rules: the active slot and both safeKey() 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.

@bolichen97
bolichen97 enabled auto-merge (squash) November 7, 2026 06:34
@bolichen97
bolichen97 merged commit e7bc65b into main Nov 7, 2026
155 of 166 checks passed
@bolichen97
bolichen97 deleted the crew/bug-resolve/31285-slots-gc branch November 7, 2026 06:34
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 7, 2026
bolichen97 pushed a commit that referenced this pull request Nov 9, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dashboard: collect a closed session's localStorage keys on the live slot list, not only at boot

2 participants