Skip to content

fix(storage): bound chrome.storage.local growth and stop quota errors losing drafts - #332

Merged
nownabe merged 1 commit into
mainfrom
fix/289-storage-eviction
Sep 20, 2026
Merged

nownabe merged 1 commit into
mainfrom
fix/289-storage-eviction

Conversation

@nownabe

@nownabe nownabe commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Why

chrome.storage.local was write-only: every PR ever opened kept its full synced mirror (a whole anchor.quote per comment) plus whole-file edits, under keys nothing ever removed, against the 10 MB quota the storage permission grants. When the quota was hit, persist() rejected, upsertComment threw, and the draft the reviewer had just typed was lost behind a generic error.

unlimitedStorage is deliberately not requested: it removes the ceiling instead of the growth, and the mirror of every PR ever opened would still accumulate. The project's core principle is to start restrictive and loosen only when something actually breaks — with eviction, steady-state storage is bounded by the PRs that still carry unsubmitted work.

What

  • Eviction at bootstrap — new evictStalePrStorage() in lib/pr/chrome-storage.ts, called fire-and-forget at the end of bootstrapPullRequest (it must never delay or fail the load). It drops every other PR's :state when that state holds no draft/syncing comment, thread or fileEdit: the synced part is a first-paint cache of GitHub (ADR 0001 §1: GitHub is the source of truth), and only the PR being opened can still paint from it. Drafts, :suggestion-edits and :dismissed-suggestions are user work and are kept. A value that cannot be hydrated at all is dropped too. For the current PR, all three keys go once it is merged — nothing stored against a merged branch can still be submitted ([Low] No PR lifecycle gating: commits and reviews go to merged or closed PRs #288 gates commits on merged/closed); closed PRs can be reopened, so they are treated like any other PR.
  • prStorageKeys(owner, repo, number) lists the three keys off the same prefix prStorageKey uses, so eviction and lib/drafts.ts cannot drift. (lib/drafts.ts still builds its keys via storageKeys.pr; collapsing the two prefixes belongs to [Refactor] Sweep tombstone comments, dead CSS and no-consumer leftovers #301.)
  • BrowserStorageAPI widens to get(key: string | null) and remove(keys: string | string[]) — both already what chrome.storage.local offers.
  • Persist never throws — PullRequestRepository.persist() catches the storage rejection and reports it through a new optional RepositoryOptions.onPersistError. Memory stays authoritative, and because every mutation writes the whole state again, the next successful write catches up; no retry timer.
  • useSuggestionEdits.flushPendingWrites gets the same treatment: on failure it puts the un-flushed writes back into the pending buffer (never over a newer edit to the same path) so the next flush retries, and calls a new optional deps.onSaveError.
  • App.tsx passes reportError into both, so a quota error reaches the global Snackbar (ADR 0005 §4) instead of killing the mutation.
  • SuggestionEdit.base is kept, with a comment saying why a patch was rejected: base is read on every render for files that are not open, so a patch would need a FileContent fetch per edited file before a local list could render. The duplication is bounded by the files edited in one PR and is dropped by eviction once the PR merges.
  • ADR 0001 §2 gains the Retention and Persist-failures paragraphs.

Red-test evidence

Each test was written and run red first.

tests/pr/chrome-storage.test.ts — evictStalePrStorage (7 cases)

  • Initial run: SyntaxError: Export named 'prStorageKeys' not found in module '.../lib/pr/chrome-storage.ts'.
  • With only the "other PR" rule implemented, the two remaining predicted reds appeared, and the guards passed:
    • removes all three keys of the current PR once it is merged → Expected ["pr:o/r#2:dismissed-suggestions", "pr:o/r#2:state", "pr:o/r#2:suggestion-edits"] / Received [].
    • removes an unparseable pr state value → TypeError: undefined is not an object (evaluating 'entities.some') from the naive some(...) over a string value.

tests/pr/repository.test.ts — persist failure (2 cases) — both a rejected save keeps the draft in memory and reports the error and the next successful save catches up on what the failed one dropped failed with the rejection escaping the mutation: error: QUOTA_BYTES quota exceeded ... at persist (lib/pr/repository.ts:178) at upsertComment (lib/pr/repository.ts:97).

tests/pr/bootstrap.test.ts — wiring (3 cases)

  • evicts another PR's stale mirror and keeps another PR's drafts → expect({...}).toEqual({}), PR 6's :state still fully present.
  • removes everything stored for the current PR once it is merged → same, PR 7's three keys still present.
  • forwards onPersistError to the Repository instead of failing the load → Expected number of calls: >= 1 / Received number of calls: 0. (The design predicted this one would fail by bootstrap rejecting; because the Repository step had already landed, bootstrap resolved and the failure was simply the unreported error — the same missing wiring.)

tests/useSuggestionEdits.test.tsx — a failed flush reports through onSaveError and retries on the next flush (#289) → error: QUOTA_BYTES quota exceeded ... at useSuggestionEdits.ts:96, i.e. flushPendingWrites() rejected instead of reporting.

All green after the change.

Checks

bun run test (708 pass, 0 fail, 62 files) · check:lint · check:format · typecheck · build — all clean. Typecheck is what proves the App wiring (Step 5 had no separate test; reportError's Snackbar path is already covered by tests/AppSubmitFailure.test.tsx).

Manual verification

Reload the unpacked extension from .output/chrome-mv3, then:

  1. Open PR A, draft a comment; open PR B and reload it; in DevTools inspect chrome.storage.local — A's :state is still there (it holds a draft), while any previously visited PR with no drafts has no :state.
  2. Open a merged PR → its three keys disappear after the load (its stored work still renders for that session, since hydrate ran first).
  3. Fill storage (set a ~10 MB dummy key in DevTools) and type a draft → the Snackbar shows the quota error and the draft stays on screen; remove the dummy key, add another draft, reload → both drafts persisted.

Note for reviewers

A merged PR reopened in Bark shows its stored drafts for that session (hydrate happens before eviction) but they are gone on the next load, with no notice beyond the ADR. If that surprises users, the follow-up is a one-line notice when merged is true — deliberately out of scope here.

Closes #289

… losing drafts

Nothing was ever removed from chrome.storage.local, so every PR ever opened kept its full synced mirror against a 10 MB quota; when the quota hit, persist() rejected out of the mutation and the draft just typed was lost. Eviction keeps steady-state storage bounded by the PRs that still carry unsubmitted work, so unlimitedStorage stays unrequested.

Persist failures now report through the Snackbar while memory stays authoritative and the next whole-state write retries.
@nownabe nownabe self-assigned this Sep 20, 2026
@nownabe
nownabe merged commit 1f96120 into main Sep 20, 2026
10 checks passed
@nownabe
nownabe deleted the fix/289-storage-eviction branch September 20, 2026 07:20
nownabe added a commit that referenced this pull request Sep 20, 2026
#353)

## Why

Comments that say where code *used to* live, or that name a
refactor-plan phase
(`Pack B / R8b`, `L7e-1`, `Phase 4`), send the reader looking for
something that
either moved or was never in this repo. CSS rules with no markup and
exports with
no importer cost the same kind of lookup. Two of them were worse than
noise: the
`pr:{owner}/{repo}#{n}` key prefix and the UTF-8 base64 decoder each had
two
independent definitions that could silently drift.

Net **-130 lines** (135 insertions / 265 deletions) across 29 files,
plus one
deleted file. No behaviour change.

## What

**1. Tombstone / phase-tag comments.** Re-located by content (the
issue's line
numbers are from before #303–#350). Rewritten to say what the code is,
or deleted
where the comment only described history: `App.tsx` (a garbled
half-sentence, six
"now lives in …" markers, and the `L5` / `L6c` / `L6d-1` / `L7e-1` /
`R3` / `R6`
tags), the five `hooks/` headers, both `adapters/` headers plus
`displayPositionToAnchorStatus.ts`, `highlight.ts`, `suggestionView.ts`,
`lib/drafts.ts`, `lib/comments.ts`, `lib/pr/repository.ts`.
`lib/storage.ts`'s
header advertised an IndexedDB layer that does not exist — it now says
chrome.storage.local and points at ADR 0001 §2. Real "why not" sentences
(the
reviewer note on thread visibility, the `canAccept` rationale, every
`simplify:`
and issue-numbered note) are untouched.

**2. Dead CSS.** Deleted `.field--mono`, `.badge--review`,
`.badge--suggestion`,
`.badge--anchored`, `.composer__routing`, `.radio-row` (+ `.radio-row
label`)
after an exact-token search over `entrypoints/`, `lib/`, `tests/` found
no
producer. `.badge--anchored` is unreachable by construction as well:
`ThreadItem`
builds `badge--${status}` from `AnchorStatus` (`current` | `reanchored`
|
`outdated`), gated on `STATUS_LABEL[status]`, which only defines
`reanchored` and
`outdated`. `docs/design-principle.md` no longer lists `.field--mono`.

**3. No-consumer leftovers.**
- Deleted the empty root `components/` directory (nothing in
`wxt.config.ts`,
`tsconfig.json` or the docs configures a root components dir; the real
one is
  `entrypoints/review/components/`).
- Dropped `useUiPanels.closePrInfo` (only the hook's own test called
it).
- Un-exported `APP_SLUG`, `SubmitCommitGroup`, `SubmitSummary` — all
used only in
their defining module. `SubmitGroup` stays exported:
`SubmitConfirmModal` imports it.
- `prStorageKey` / `prStorageKeys` now build on `storageKeys.pr`, the
same prefix
`lib/drafts.ts` builds, so #332's eviction and the drafts keys cannot
drift.
- `base64Decode` is exported from `lib/pr/metadata.ts` and reused by
`remote-fetcher.ts`; the fetcher keeps its own whitespace strip (GitHub
wraps
its base64 at 60 chars) rather than pushing that into the fence decoder.
- Deleted `fetchThreads` (no production caller — `fetchRemoteState`
inlines
  `listReviewThreads` + `threadsFromRaw`). Its four tests now call
`threadsFromRaw(await listReviewThreads(...))` through a 2-line local
helper, so
the paging coverage is unchanged and the only export is a function
production
  actually uses.

**4. `AppState.currentFiles`.** Verified no consumer anywhere in
`entrypoints/`;
deleted it with `buildCurrentFiles` and its two tests.

## Test evidence

This is a deletion PR, so there is no red step except for the two shared
helpers,
where the rule was to pin current behaviour *before* unifying:

- `tests/pr/chrome-storage.test.ts` — "shares its prefix with the keys
  lib/drafts.ts builds": `prStorageKey("acme","site",42)` ===
`` `${storageKeys.pr("acme","site",42)}:state` ``. Added and run **green
against
the two independent definitions**, then `prStorageKey` was rewritten
onto
  `storageKeys.pr`; still green.
- `tests/pr/remote-fetcher.test.ts` — "decodes UTF-8 from the
line-wrapped base64
GitHub returns": multibyte source, base64 wrapped at 60 chars. Added and
run
green against the fetcher's private decoder, then repointed at the
shared
  `base64Decode`; still green.

Full set on the rebased branch: **816 pass / 0 fail** (`bun run test`),
`check:lint`, `check:format`, `typecheck` and `build` all clean.

## Dropped from the issue (already fixed on main)

- `DebugFab.tsx`'s undefined `var(--green)` — gone with DebugFab's
preview.
- `lib/pr/bootstrap.ts:8-17` — the current header describes the live
composition
  accurately; nothing to remove.
- `lib/pr/repository.ts:159` — that line is live code today; only the
`(Phase 4)`
  tag on line 8 needed a fix.

## Left out, on purpose

Two phase tags remain in `App.tsx`'s submit flow — `// already
double-written by
L4/L6a` and `// (the L6d-1 effect is best-effort…)`. Both sit inside the
`composeDraftBody` call regions that the still-open #351 edits, so they
are left
for a one-line follow-up after that merges rather than handed #351 a
conflict.

Closes #301
nownabe pushed a commit that referenced this pull request Sep 20, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.4.0](bark-v0.3.0...bark-v0.4.0)
(2026-09-20)


### Features

* **pr:** accept .markdown and .mdx as Markdown
([#322](#322))
([e22ee68](e22ee68)),
closes [#293](#293)
* **pr:** commit fork pull requests to the fork's repository
([#342](#342))
([4e2adef](4e2adef)),
closes [#273](#273)
* **pr:** create a top-level draft Comment's Thread with it
([#323](#323))
([6e192f3](6e192f3)),
closes [#272](#272)
* **pr:** resolve out-of-diff threads via the root comment fence
([#310](#310))
([7e0ecb9](7e0ecb9)),
closes [#270](#270)
* **reanchor:** bounded region search for single-line anchors and
line-local suggestion merge
([#309](#309))
([0f735da](0f735da)),
closes [#269](#269)
* **reanchor:** locate multi-line anchors per endpoint in the region
search ([#347](#347))
([f4fd457](f4fd457)),
closes [#311](#311)
* **review:** preview the merge for shifted suggestions in the editor
([#354](#354))
([f822f41](f822f41)),
closes [#312](#312)


### Bug Fixes

* **anchor:** define anchor.quote as the source text at anchor.range
([#327](#327))
([11a935d](11a935d)),
closes [#276](#276)
* **background:** focus an existing review tab instead of opening a
second one ([#325](#325))
([58efa63](58efa63)),
closes [#277](#277)
* **pr:** compose the quote and permalink for every out-of-diff post
([#351](#351))
([f85b99b](f85b99b)),
closes [#282](#282)
* **pr:** count patch lines starting with ++ or -- in parseRightRanges
([#314](#314))
([9dfbd46](9dfbd46)),
closes [#284](#284)
* **pr:** keep the rel=next link in the ETag cache so 304 pages still
paginate ([#318](#318))
([6472de2](6472de2)),
closes [#286](#286)
* **pr:** offer Resolve only when GitHub would accept it
([#335](#335))
([b05fdcc](b05fdcc)),
closes [#274](#274)
* **pr:** park a failed resolve toggle in synced, not draft
([#320](#320))
([56e815b](56e815b)),
closes [#275](#275)
* **pr:** post drafts in the current head's coordinates
([#303](#303))
([28ef345](28ef345))
* **pr:** recover comments stuck in syncing instead of re-posting them
([#305](#305))
([3548086](3548086))
* **pr:** refuse commits to a merged or closed PR
([#330](#330))
([2a239ff](2a239ff)),
closes [#288](#288)
* **pr:** refuse to submit a draft whose quoted text changed upstream
([#346](#346))
([d4118a4](d4118a4)),
closes [#313](#313)
* **pr:** route replies on the parent's GitHub object kind
([#326](#326))
([1df6462](1df6462)),
closes [#285](#285)
* **pr:** serialise refresh and execution under one Repository lock
([#336](#336))
([1864488](1864488)),
closes [#281](#281)
* **pr:** sweep entities left syncing at the end of a submit
([#331](#331))
([108caa9](108caa9)),
closes [#271](#271)
* **release:** pin publish-browser-extension to ^4.0.5
([#263](#263))
([b77104f](b77104f))
* **review:** derive a suggestion draft's cid from the hunk it
materialises ([#337](#337))
([963339d](963339d)),
closes [#308](#308)
* **review:** end a whole-line selection on the line it actually covers
([#319](#319))
([3364d18](3364d18)),
closes [#291](#291)
* **review:** map comment positions between head and edited coordinates
([#348](#348))
([9465718](9465718)),
closes [#283](#283)
* **review:** reject a suggestion by resolving its thread on GitHub
([#340](#340))
([d088a8d](d088a8d)),
closes [#287](#287)
* **review:** resolve accepted-suggestion threads only after the commit
lands ([#341](#341))
([770f901](770f901)),
closes [#278](#278)
* **review:** surface failed comment posts and keep the reviewer's edits
([#307](#307))
([48cb675](48cb675))
* **review:** validate the PR number from the review URL
([#321](#321))
([457a942](457a942)),
closes [#295](#295)
* **storage:** bound chrome.storage.local growth and stop quota errors
losing drafts ([#332](#332))
([1f96120](1f96120)),
closes [#289](#289)
* **suggest:** consume a longer closing fence instead of leaking a
backtick ([#316](#316))
([d2e0683](d2e0683)),
closes [#290](#290)


### Performance Improvements

* **reanchor:** replace the LCS table with a memoised line-level Myers
diff ([#344](#344))
([8caebdd](8caebdd)),
closes [#280](#280)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please-nownabe-bark[bot] <295690643+release-please-nownabe-bark[bot]@users.noreply.github.com>
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.

[Low] chrome.storage.local grows without eviction and quota errors lose drafts

1 participant