Repository navigation
fix(web): cache keyed PatchDB maps one IndexedDB entry per child - #4888
Conversation
The browser's PatchDB cache stored one IndexedDB entry per top-level key, so any revision under registryCache rewrote every registry's cached catalog (30 MB on a server following six registries), and any change to one package rewrote all of packageData. Entries are now keyed by JSON pointer, with packageData and registryCache stored one entry per child, so a revision rewrites only the rows it replaced. The store version moves to 2 and drops the old layout, which costs one dump on the first load after the update. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
helix-white
left a comment
There was a problem hiding this comment.
[P1] The version-2 upgrade can prevent the web interface from synchronizing while another tab remains open. The version-1 implementation keeps its IndexedDB connection open without an onversionchange handler. Opening version 2 in a new/reloaded tab therefore fires blocked rather than success or error; open() never settles. PatchDbSource.stream$ awaits cache.read() before subscribing to live$, so the new tab never starts its live database subscription, even though the server is reachable. This is newly reachable with this schema-version bump.
The proposal rejects blocked opens into the existing empty-baseline fallback, closes a connection that opens after that rejection, and releases successful connections on future version changes. A blocked tab runs without persistent caching until reload rather than waiting for another tab to close. It records the cache-failure contract at read() and adds regression cases for blocked-open fallback, late-open cleanup, and version-change closure.
Two accompanying corrections: reuse pathFromArray / arrayFromPath, already exported by patch-db-client, instead of introducing a second JSON-pointer codec; and add the browser-write improvement to the pending database-resume changelog fragment.
The per-child diffing, pointer round-trip, map/non-map transitions, deletion, cursor transaction, and stale-baseline rewrite otherwise look consistent. The reviewed head merges cleanly with origin/master. I did not build, run tests, typecheck, or lint; the proposal's tests are unexecuted and belong to the author's verification if adopted.
Proposed changes: 0f8a48f...proposal/4888
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
Another tab holding the version-1 connection blocked the version-2 open, so read() never settled and the tab never subscribed live. A blocked open now rejects into the empty-baseline fallback and closes a connection that opens later; every connection closes on a version change. The JSON-pointer codec reuses patch-db-client's pathFromArray/arrayFromPath. Adopted from helix-white's proposal/4888. Co-Authored-By: helix-white <267227783+helix-a@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
helix-white
left a comment
There was a problem hiding this comment.
Approved at ddd8bf8c80b76b2d30a3cc45d5e5971fe632e484. The earlier findings are addressed, and the head merges cleanly into integration/registry-cache-sync.
The cache now rewrites only changed services or registries instead of their entire top-level collections. Reference-based diffing, cursor/value atomicity, removed-entry deletion, and complete rewrites after a stale baseline remain intact. The change reuses PatchDB's exported JSON-pointer helpers.
The browser storage format moves from version 1 to 2: packageData and registryCache each have a root marker and one row per child; other top-level values remain whole. Upgrading discards the previous snapshot and requires a fresh dump, without changing server data or RPC schemas. The adopted review proposal prevents an older open tab from blocking live synchronization: a blocked upgrade falls back to an empty baseline, with persistence unavailable until reload, and late-opened connections are closed. Successful connections release themselves for subsequent upgrades. The cache-failure contract and pending changelog are updated.
Implementation diff: +67 / −18 lines in 1 file (excludes lockfiles, tests, docs, release notes, and changelog).
Verification evidence: the author reports 303 UI tests and 108 RPC-client tests passing for the original implementation. Those results predate the upgrade-lifecycle fix; the added blocked-open, late-close, and version-change cases are present, but their execution is not recorded in the PR. Current-head Prettier, formatting/lockfiles, changelog, and script CI checks passed; product builds and several Rust/generated checks were still running when inspected. I reviewed the code and regression cases without running builds or tests. Real browser multi-tab upgrade behavior has no recorded end-to-end verification.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
The browser's PatchDB cache (
patch-db-cache.ts) stored one IndexedDB entry per top-levelDataModelkey and compared at that level only. Any revision underregistryCache, even one new version of one package on one registry, therefore re-saved every registry's cached catalog: about 30 MB on demo.local, which follows six registries. Likewise any change to one package re-saved all ofpackageData.Entries are now keyed by JSON pointer. The maps declared in
KEYED(packageData,registryCache) are stored as a root entry plus one entry per child (/registryCache/<escaped url>,/packageData/<id>); every other top-level key is stored whole under/<key>. A write diffs the previous snapshot's entries against the new one's by reference, so a revision re-saves only the rows it replaced and deletes the rows it removed. A keyed root that isn't a map (e.g.null) is stored whole. Extending the rule to another map-shaped root is one entry inKEYED.The existing contract is unchanged: the cursor (
id/epoch) is written in the same transaction as the values, a write from a stale or cleared baseline rewrites the whole store, a failed write drops the cursor so the next load dumps, and #4755's resume cursor still reads back. The IndexedDB version moves to 2; upgrading from 1 drops and recreates both stores, which costs a single dump on the first load after the update.This is one of three changes splitting up the RC3 registry-cache regression (initial dump of 31 MB, 30.5 MB of it
registryCache). The other two slim the public registry cache and resume the server's registry subscriptions; this one stands on its own.Verification:
npm run check:ui: 303 tests pass, including new cases for per-child keying with pointer escaping, removal of a child, a keyed root that becomes non-map and back, and dropping a version-1 store.npm run check:rpc-clients: 108 tests pass.review effort: 'high'
🤖 Generated with Claude Code