Repository navigation
Conversation
The Files tree mirrors its expansion to localStorage so a reload does not start fully collapsed. That mirror wrote with a raw setItem inside a bare catch, which discards a QuotaExceededError outright. `utils/safeStorage` exists for exactly this write: on a quota error it drops one tier of disposable cache -- the per-session virtualizer height caches, which accumulate across every chat ever opened and are the documented reason the origin fills up -- and retries. Bypassing it meant the mirror quietly stopped persisting while megabytes of re-derivable cache sat next to it, and nothing recovered it. The read had a second dead end. `readStore` returned null when localStorage was unusable so a doomed write could be skipped, but a value that merely failed JSON.parse took the same branch. One corrupt string therefore blocked every later write and left the bad value in place, so expansion never persisted again for the life of the profile. With safeSetItem making a doomed write harmless, that channel has no remaining purpose: the read now falls back to an empty record, and the next expansion overwrites the corrupt value. Storage that is unusable rather than full still degrades to session-only memory and never throws, which the third test pins. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
UX Review (Fable 5, fork) — ✅ PASSUX-level review of The diff touches only UX-Verdict: PASS Pure storage-layer fix with no rendered surface; the only user-visible effect is the file tree correctly staying expanded across reloads. [UX-REVIEWED] 58cb985 |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Right fix at the right layer: the shared quota-reclaiming helper replaces the hand-rolled guard that caused both failure modes, with the degradation contract pinned. The removal of the [DESIGN-REVIEWED] 58cb985 |
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of Both defects are verifiable directly in the base code ( First-Principles-Verdict: PASS Only unrunnable claim is the red-before/green-after test run — CI's vitest job settles it; both defects themselves are verifiable by reading base. What this change shipsInventory (5 items) — 5 justifiedIntent: keep the file tree's expansion state surviving a page reload when localStorage is full or holds a corrupt value — a FIX (both defects readable in base code; a prior review residual, not a new capability).
The rewritten docstring pin ("full quota degrades to session-only memory") is retired with evidence: the same catch demonstrably conflated corrupt values with broken storage in base. The declined sibling residual ( [FIRST-PRINCIPLES-REVIEWED] 58cb985 |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed Review detailsI've independently reconstructed the post-diff behavior and verified it against the The candidate list contains no candidates. My own falsification of the change confirms it is a sound defensive refactor:
No behavioral defect, security boundary, or blocking AUTOSDE rule is groundable on the changed lines. Nothing survives to Step 2. No findings. [OPUS-REVIEWED] 58cb985 |
|
🤖 Kiro Crew [operator: chenmingwei23]: This PR has been inactive for 7+ days with failing CI. I've assessed the blockers and they appear resolvable — I'll push fixes directly to this branch as a co-author. Assessment: Frontend-only diff (treeExpansionMemory / safeStorage). Backend Tests + Coverage Gate reds are inherited from main. Fix: rebase onto current main; verify the treeExpansionMemory tests pass. If you'd prefer I don't touch this PR, add the |
|
Thank you for this fix, @leonlaiyc! 🙏 This PR had drifted into conflict with Your authorship is kept in git: the commit is still authored by you ( Closing this one in favour of #16596 (tracked by issue #16595). Thanks again for the contribution! |
Problem / Motivation
The Files tree mirrors its expansion state to
localStorageso that a pagereload does not start fully collapsed. On an origin whose quota is full, that
mirror silently stops working and never recovers.
website/src/pierre/treeExpansionMemory.tswrote it raw:That
catchtreats a full quota as unrecoverable. It is not.website/src/utils/safeStorage.ts— used by 91 files — exists precisely forthis write: on a
QuotaExceededErrorit drops one tier of disposable cacheand retries, escalating a tier at a time. Its own header names the condition:
So the bare
catchfired in ordinary use, and threw the write away whilemegabytes of re-derivable cache sat next to it, reclaimable.
A second dead end, on the read side.
readStore()returnednullwhenstorage was unusable, so a doomed write could be skipped — but a value that
merely failed
JSON.parsetook the same branch:rememberExpandedPathsthen returned early without writing, so the corruptstring stayed put and blocked every later write. One bad value disabled the
mirror permanently, for the life of that browser profile.
This is the residual the First-Principles review of #10366 named when the module
landed: "
treeExpansionMemory.tsre-hand-rolls guarded localStorage access thatsafeStorage.tscentralizes — and loses its quota reclaim+retry, so on a fullquota the mirror silently dies." Its stated clearing condition was that the
module read and write through
safeGetItem/safeSetItem.Why it matters
Neither failure is visible at the moment it happens. The module-scope session map
keeps covering the remount case, so the tree behaves correctly for the whole
session; the loss only shows up on the next reload, as a fully collapsed tree and
every file open costing a re-expand from the root. That is the exact cost #10366
set out to remove.
The quota half is not hypothetical: it fires for users with many chat sessions —
the growth
safeStoragewas written to absorb — and it is self-inflicted,because the space needed was already there and reclaimable.
The corrupt-value half is worse in one respect: nothing clears it. There is no
expiry, no version check, and no path that rewrites the key, so the feature stays
dead until the user clears site data.
What changed (motivation → approach → change)
Symptom → the expansion mirror stops persisting across reloads and does not
recover.
Root cause → a hand-rolled storage guard that discards the one error class
the shared helper knows how to recover from, plus a read that conflates "storage
is broken" with "this stored value is garbage".
Change → route both ends through the shared helper:
rememberExpandedPathswrites withsafeSetItem, which reclaims and retries.readStorereads withsafeGetItemand returns{}for anything unusable.Removing the
nullchannel is not a separate decision bolted on — it is what thefirst change makes possible. That channel existed only to avoid a write that
could not succeed, and
safeSetItemalready makes such a write harmless(it returns
falseand warns in dev). With its one purpose gone, keeping it wouldonly preserve the corrupt-value dead end, so it goes, and the next expansion
overwrites the bad value.
Two things deliberately not changed:
full — private mode, storage disabled — still degrades to session-only memory
and still never throws.
safeSetItemonly reclaims for genuine quota errors;a
SecurityErrorreturnsfalseuntouched. The third test pins this, becauseit is the behaviour most at risk from a careless "just use safeSetItem" edit.
MAX_SESSION_QUERY_DIRSinFileBrowserRail.tsxoversized (an LRU cap on asession-only
Mapof typed filter strings). That is a different file, adifferent mechanism, and a sizing opinion rather than a defect — nothing is
lost or stuck. It does not belong in a fix PR.
The module docstring said "private mode or a full quota degrades to session-only
memory". That is now false for the quota half, so it is corrected in the same
commit rather than left describing behaviour the diff removed.
Tests
New
website/src/pierre/treeExpansionMemory.test.ts, 3 cases:reclaims disposable cache and retries when the origin quota is full—seeds a
vc_heights_*key, then makessetItemthrow for the mirror key foras long as that key exists. Asserts the mirror value actually lands, and that
only the disposable tier was sacrificed.
recovers from a corrupt stored value instead of being stuck on it—plants
'{not json', then asserts the next expansion overwrites it and that afresh session recalls the value.
still degrades to session-only memory when storage is unusable— theno-regression control. Makes both
getItemandsetItemthrow aSecurityError; asserts no throw and that recall still answers from thesession map.
One thing worth flagging about the first test, because it nearly shipped wrong:
my initial fixture threw a plain
Errorsubclass namedQuotaExceededError.safeStorage.isQuotaExceededErrorstarts withif (!(err instanceof DOMException)) return false, so that object never reaches the reclaim path at all — the testfailed against the correct fix and would have passed against a fix that did no
reclaiming. It now throws a real
DOMException, and the reason is a comment inthe test so the next person does not re-introduce it.
Run:
main(new tests, production file reverted), with thecorrected fixture:
AssertionError: expected null not to be null— the write was discardedSyntaxError: Expected property name or '}' in JSON at position 1— thecorrupt value was still in storage, unchanged
main, as it must3 passed (3)/85 passed (85), including the existingPierreWorkspaceTreeImplandsafeStoragesuites.npx tsc --noEmit -p tsconfig.jsonandnpx eslinton both files: clean.Manual verification
N/A — unit coverage sufficient: both failures are storage-layer error handling
with no rendered surface, and the tests drive the real exported functions against
a real
localStoragewith the realsafeStoragehelper, stubbing only thebrowser error the quota condition raises.
Related Issues
Follow-up to #10366 (which fixed #9653), closing the storage-layer residual its
First-Principles review recorded. No issue filed for it — the review is the
provenance, quoted above.
Contention was checked against all 300 open PRs on the exact path
website/src/pierre/treeExpansionMemory.ts: zero, verified with aknown-positive control path in the same scan so an empty result could not be a
silently broken query. The two open PRs touching
safeStorage.ts(#9724, #8403)each only add a
safeRemoveItemexport; neither changessafeGetItemorsafeSetItem, which is all this PR consumes.Pattern harvest
Rule candidate:
lintPattern: a bare
try { localStorage.setItem(...) } catch {}outsideutils/safeStorage.ts— a guard that looks defensive while discarding the oneerror the shared helper can recover from.
What generalizes is narrower and more useful than "use the helper". The
hand-rolled version was not careless: it had a comment, it degraded to a sensible
fallback, and it was written by someone who had clearly thought about private
mode. It was wrong only because quota and unusable are different conditions
with different correct responses, and one
catchcannot tell them apart. Alint rule keyed on a raw
setItemin a module that is notsafeStoragewouldhave caught it; a reviewer reading the comment would not, because the comment is
accurate about the case it names.
The read side generalizes the same way: a sentinel that folds "the medium is
broken" together with "this particular value is garbage" will eventually make a
recoverable state permanent, because the caller can only take one branch for both.
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
🤖 Generated with Claude Code