Skip to content

fix(start-os): keep the browser's PatchDB snapshot in IndexedDB - #4752

Merged
MattDHill merged 3 commits into
masterfrom
fix/patchdb-cache-quota
Nov 16, 2026
Merged

MattDHill merged 3 commits into
masterfrom
fix/patchdb-cache-quota

Conversation

@MattDHill

@MattDHill MattDHill commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Since #4583, every page load in the StartOS UI logs ERROR DOMException: The quota has been exceeded.

  • Cause: PatchDataService serialized the whole public database into localStorage (_startos/patchDB) on every revision. registryCache now holds each registry's package list plus the release notes of its other versions, about 2.5 MB per registry. The two default registries alone fill the roughly 5 MB localStorage quota. setItem threw inside the stream and took down PatchDataService, including the osRegistry watcher that drives loadOS.

  • Change: the snapshot moves to IndexedDB (startos-patchdb), so registry caches stay in it:

    • PatchDbCache (replacing LocalStorageBootstrap) stores one record per top-level key, plus the revision id. It writes keys and id in one transaction.
    • The PatchDB client applies patches copy-on-write, so a revision rewrites only the top-level values it replaced. Install progress no longer re-serializes the registry catalogs.
    • Tabs share the records, so a write first checks the stored revision in the same transaction. Only when that revision is the tab's own last write does it skip unchanged keys; otherwise it rewrites the whole snapshot. A tab writing behind another, or after another cleared on logout, can't store a mixed snapshot.
    • Write errors are caught and logged instead of tearing down the stream.
    • If a write fails, the stored revision is deleted, so a partially written snapshot is never read back.
    • The snapshot now carries the real revision id instead of a hard-coded 1. The follow-up resume-from-revision PR builds on this.
    • PatchDbSource reads the snapshot asynchronously, emits it first, then subscribes to the server.
    • Logout clears the snapshot. Startup removes the old localStorage key, and StorageService.migrate036 becomes migrate, which no longer copies the 0.3.x cache into it.
  • Also: removes ClientStorageService, the dev-tools toggle. Its SHOW_DEV_TOOLS value was read into a subject nothing subscribed to, and nothing called its toggle.

No changelog fragment: #4583 hasn't been in a stable release, so this defect never shipped.

Verification

  • npm run check:ui passes: type check plus 275 tests. The new patch cache tests cover the round trip, selective rewrites, key removal, invalidation after a failed write, clear, and another tab advancing or clearing the snapshot. The two cross-tab tests fail against the previous write.
  • npm run check:rpc-clients: the PatchDB source lifecycle cases pass with the async snapshot. One unrelated test fails locally, Brochure reports malformed registry URLs and can load the next selection, and it fails identically on master; CI's master run is green.

🤖 Generated with Claude Code

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved at 2f322fc9880d2abc01d1ef43c1e84bba3366f7c4; the head merges cleanly with current master. No correctness findings.

The browser's _startos/patchDB snapshot now omits registryCache, the package catalogs responsible for the reported localStorage quota failure. All other snapshot fields, including OS-update metadata, remain unchanged. The existing bootstrap reader restores the omitted catalog as an empty object, and each database subscription supplies a full server dump. Existing snapshots remain readable; no API change or migration is required.

The tradeoff is that marketplace listings are unavailable from the browser snapshot before reconnecting to StartOS. The server's registry caches are unchanged, including their availability when an upstream registry is offline. This reuses the existing bootstrap and synchronization paths without adding storage or recovery machinery.

Implementation diff: +1 / −1 lines in 1 file (excludes lockfiles, tests, docs, release notes, and changelog).

The author reports npm run check:ui passing, including typechecking and 273 tests, with the new snapshot-omission regression failing against the previous implementation. I inspected that regression and the existing missing-field bootstrap coverage; I did not run builds or tests. Browser quota exhaustion was not exercised end to end in this review. Prettier, Conflict Markers, and Dependency Licenses have passed. Run Automated Tests, Formatting & Lockfiles, Generated Artifacts, Changelog fragments & versions, and all three Compile Base Binaries jobs remain pending.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

The whole public database, registry caches included, outgrew the
roughly 5 MB localStorage quota: setItem threw inside PatchDataService's
stream on every page load and tore down the osRegistry watcher with it.

The snapshot now lives in IndexedDB, one record per top-level key, so a
revision rewrites only the keys whose references it replaced. A failed
write drops the stored revision, so a partially written snapshot is never
read back. Logout clears it, and the old localStorage key is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MattDHill
MattDHill force-pushed the fix/patchdb-cache-quota branch from 2f322fc to 994fcf9 Compare November 16, 2026 18:49
@MattDHill MattDHill changed the title fix(start-os): leave registry caches out of the browser's PatchDB snapshot fix(start-os): keep the browser's PatchDB snapshot in IndexedDB Nov 16, 2026

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Request changes at 994fcf97f5e97eb55784a5f3240bf9623c06ceef for one correctness issue.

P2 — Validate the stored snapshot before skipping unchanged fields. In projects/start-os/web/ui/src/app/services/patch-db/patch-db-cache.ts, write() compares against saved, which is private to one tab, while the IndexedDB records are shared across tabs. For example, both tabs start at revision 3; the faster tab writes revision 5 with changed UI and package data; the slower tab writes revision 4 with changed UI but its original package-data reference. The slower tab skips package data and publishes revision 4 alongside revision 5's package data. After another tab clears the database on logout, the same optimization instead skips records that no longer exist. A subsequent bootstrap therefore receives mixed or missing state under a nonzero revision, until the server dump repairs it. These cases do not require overlapping transactions.

The proposal retains the revision alongside the local reference baseline and checks the stored revision inside the same read-write transaction. It preserves selective writes when that baseline matches; otherwise it replaces the complete snapshot. It also records the cross-tab completeness invariant at the cache owner and adds regression cases for another tab advancing or clearing the snapshot.

Proposed changes: 994fcf9...proposal/4752

The reviewed head merges cleanly with current master. CI remains in progress. The proposal and regression cases are unexecuted; I did not build, test, typecheck, or lint during review.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

Tabs share the IndexedDB records but each compared against its own last
write, so a tab writing behind another, or after another cleared the
snapshot on logout, skipped keys it believed unchanged and stored a mixed
snapshot under its revision. A write now checks the stored revision in the
same transaction and rewrites every key unless it matches the tab's last.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved at bd287660bbfd2ecba2192ccb6b7bca771cb6c516. The cross-tab issue is addressed, and the head merges cleanly with current master. No remaining correctness findings.

The complete browser PatchDB snapshot moves from localStorage to IndexedDB, retaining registry catalogs without consuming localStorage's small quota. This addresses the reported exception that terminated snapshot persistence and OS-update observation. It reuses PatchDB's existing copy-on-write references to avoid rewriting unchanged top-level values.

The new startos-patchdb database stores top-level values and their real revision in one transaction. Following my review proposal, selective writes check the stored revision against the tab's baseline inside that transaction; a mismatch replaces the whole snapshot. This preserves completeness after another tab advances or clears the cache, without adding a lock. The snapshot may reflect a slower tab's older revision, but its fields belong together.

Startup reads the snapshot asynchronously before observing the server. The old _startos/patchDB localStorage entry is removed rather than migrated, so the first load after upgrade needs a server dump before cached content becomes available. Logout clears the new cache. Read failures fall back to an empty snapshot; write failures are logged and trigger revision invalidation instead of ending observation. RPC contracts are unchanged, and connections still receive full dumps; revision-based stream resumption is not implemented here. One obsolete storage comment is also removed.

Implementation diff: +130 / −45 lines in 7 files (excludes lockfiles, tests, docs, release notes, and changelog).

The author reports npm run check:ui passing with typechecking and 275 tests, including both cross-tab regressions failing against the previous write implementation. The author also reports the async source lifecycle cases passing, but check:rpc-clients remains locally failing in the brochure malformed-URL case, reproduced on master. I inspected the changes and evidence without running builds or tests. Cache coverage uses an IndexedDB test double; no native-browser quota or multi-tab run is recorded.

Prettier, Conflict Markers, and Dependency Licenses have passed. Run Automated Tests, Formatting & Lockfiles, Generated Artifacts, Changelog fragments & versions, the StartOS binary matrix, StartTunnel package matrix, and StartWRT riscv64 binary build remain pending.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

ClientStorageService read SHOW_DEV_TOOLS from localStorage into a
subject nothing subscribed to, and nothing called its toggle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved at ab136f6ec97c9be18b87153fc3871fdc77d690f5; the head merges cleanly with current master. No correctness findings.

Since my previous approval, the only code change removes the unused ClientStorageService dev-tools toggle and its startup initialization. Repository-wide inspection confirms no remaining references, subscribers, or toggle callers. Authentication still completes before initial navigation. The snapshot implementation and cross-tab fix are unchanged.

The PR moves the complete browser PatchDB snapshot, including registry catalogs, out of quota-constrained localStorage into IndexedDB. The new startos-patchdb database stores each top-level value and the real revision atomically. Existing copy-on-write references avoid rewriting unchanged catalogs. The adopted review proposal checks the stored revision against the tab's baseline within the write transaction, replacing the whole snapshot when another tab has advanced or cleared it. A slower tab may store an older but complete revision.

Startup asynchronously restores the snapshot before subscribing to the server. The old localStorage snapshot is discarded, not migrated; the first load after upgrade therefore needs a server dump. Logout clears the cache. Persistence errors are logged rather than ending observation, and failed writes trigger revision invalidation. RPC contracts remain unchanged; connections still receive full dumps rather than resuming from the cached revision. An obsolete storage comment is also removed.

Implementation diff: +130 / −72 lines in 8 files (excludes lockfiles, tests, docs, release notes, and changelog).

The PR records a passing check:ui typecheck and 275 tests, including cross-tab regressions demonstrated to fail against the previous write implementation. The author reports async source lifecycle cases passing, with the brochure malformed-URL case in check:rpc-clients failing identically on master. I ran no builds or tests during review. Cache tests use an IndexedDB double; native-browser quota and multi-tab behavior are not covered by recorded end-to-end evidence.

Prettier, Conflict Markers, and Dependency Licenses have passed. Run Automated Tests, Formatting & Lockfiles, Generated Artifacts, Changelog fragments & versions, the StartOS binary matrix, StartTunnel package matrix, and StartWRT riscv64 build remain pending.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@MattDHill
MattDHill merged commit 5fd7526 into master Nov 16, 2026
27 of 28 checks passed
@MattDHill
MattDHill deleted the fix/patchdb-cache-quota branch November 16, 2026 19:33
MattDHill added a commit that referenced this pull request Nov 16, 2026
The restored-snapshot registry errors that started this PR came from the
localStorage snapshot that stopped saving once the database outgrew the
quota, fixed by #4752. With an accurate snapshot, the last known
registry status is the right thing to show, during a refresh and while
the server is unreachable alike, so MarketplaceService no longer masks
it. Tests now assert that the last known status survives restore,
stream loss and disconnection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MattDHill added a commit that referenced this pull request Nov 17, 2026
…stry availability UI (#4756)

* fix(start-os): hide registry warnings until the server is connected

After a page refresh the UI replays the last PatchDB snapshot from
IndexedDB until the websocket connects, so a registry that was in error
when last seen raised warnings on the Updates tab and its registry entry
before the server could confirm anything. While disconnected, every
cached registry status now reads as connecting; the live status takes
over once the connection is up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(start-os): mask restored registry status at the source, live loss at display

Connectivity alone does not prove registry observations are live: the
startup state RPC can report running before db.subscribe delivers its
first dump, which re-exposed the restored snapshot's stale error. Mask
the IndexedDB-restored registryCache in PatchDbSource instead, so the
first live dump supplies the real status (from review proposal/4756).

A mid-session loss of the server connection still reads as connecting,
but only in registries$ and currentRegistry$, downstream of
watchRegistry$. The cache entries feeding package queries and the
marketplace$ catalog behind update refinement no longer change with
connectivity, so a connection change neither refetches an unchanged
package query nor re-runs refinement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(start-os): derive connection state from the live database observation

ConnectionService combined browser online status with StateService's
replayed state, which stays `running` through a server outage: its
startWith sits outside the retriggered pipeline and failed probes emit
nothing. Every consumer therefore treated restored or last-known data as
live, so the header kept saying Connected, service pages kept showing
stale status, registry warnings resurfaced, and metrics/logs retried
without waiting for the server.

PatchDbSource now owns PATCH_LIVE, true once a live dump is applied and
false on stream loss, logout or disposal (from review proposal/4756).
ConnectionService requires it, which also replaces the one-shot rewrite
of the restored registry snapshot. StateService exposes reachable$, false
after a state probe fails, so the header distinguishes No Internet,
Unreachable and Connecting, with Restarting and Shutting down taking
precedence over a dropped connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(start-os): show the last known registry status while disconnected

The restored-snapshot registry errors that started this PR came from the
localStorage snapshot that stopped saving once the database outgrew the
quota, fixed by #4752. With an accurate snapshot, the last known
registry status is the right thing to show, during a refresh and while
the server is unreachable alike, so MarketplaceService no longer masks
it. Tests now assert that the last known status survives restore,
stream loss and disconnection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(start-os): drop the redundant Request failed banner on Updates

The selected registry's table header already shows its Unreachable
status, with the failure details and a retry, under the same condition
the banner used. Remove the banner, the requestErrors$ input that fed
only it, and its now-unused 'Request failed' translation key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(start-os): match registry Unreachable to its warning, rename server state

Registry Unreachable chips were red while the icon flagging the same
registry is yellow, so the icon read as pointing at the yellow
untrusted-signature note in package rows. registryStates.error now uses
the warning appearance and color, which every registry status display
(Updates header, marketplace chip and collapsed dot, Registries column,
brochure) reads.

The header's unreachable-server state becomes "Can't reach server", so
the same word no longer appears in red for the server and in yellow for
a registry. It stays red, alongside No Internet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(start-os): move registry warnings to System and show a stale-data notice

Updates and installs keep working while a registry is unreachable, so
the warning belongs where registries are managed: System and its
Registries item now carry it, while the Updates tab keeps its count with
no warning. The Updates sidebar icon, the Updates table-header status
and the marketplace sidebar status give way to an informational
RegistryNotice above the content of Updates and the Marketplace: its
listings may be out of date, with Retry and Manage Registries, following
Taiga's notification action pattern.

The Marketplace Connect and invalid-URL screens now render inside the
marketplace content, keeping the sidebar's registry selector, and a
remembered registry the server no longer saves falls back to the default
instead of forcing Connect. Start9's registries no longer show their
description banner; custom registries keep theirs, which operators use
for contact and key-verification details, and every beta, alpha and
custom-registry warning stays. On mobile the marketplace content keeps a
20rem minimum and scrolls horizontally, the notice matches the cards'
margins, and the search field regains its spacing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(start-os): scope the registry notice, cancel stale fallback, tidy nav warnings

From review proposal/4756:
- The marketplace notice renders under the shared component's
  URL-matched current() registry, so a previous registry's cached error
  no longer appears above another registry's Connect screen or a newly
  added registry awaiting its first sync.
- The remembered-registry fallback waits for the saved list inside the
  route's switchMap with destruction teardown downstream, so a pending
  fallback yields to an explicit selection or page destruction.
- Desktop navigation shows an item's warning in place of its count.

The mobile System tab shows the System warning in the badge's position,
replacing its count, since Taiga's tab badge accepts only a number.
Clock-sync failure becomes a Metrics warning rather than a count. Updates
picks its default registry from TUI_BREAKPOINT, the signal its layout
uses, instead of the user-agent WA_IS_MOBILE: in a narrow desktop window
it opened on the first registry and Back could not leave it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(marketplace): keep the registry selector honest on Connect and Invalid URL

From review proposal/4756. With the selector now mounted beside the
Connect and Invalid URL screens:
- An unsaved selection is identified by its own URL in both the button
  and the dropdown row, instead of the replayed catalog's name, which
  could still be the previously viewed registry. The redundant
  currentRegistry$ subscription goes.
- Reselecting the active registry reasserts its registry query
  parameter, so choosing the last valid registry leaves an Invalid URL
  view, without reconnecting or refetching the unchanged catalog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(start-os): center the Marketplace Connect and Invalid URL screens

Inside the marketplace's scroll area the block status sat at the top:
tui-scrollbar's internal content wrapper is only as tall as its content,
so the block status's full-height centering had nothing to fill. The
content area is now a size container and the blocked view fills it with
100cqb. Its buttons also inherited the marketplace's flat-grayscale
button defaults; they are explicitly primary again, as they were as
full-page screens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(marketplace): pad the Connect and Invalid URL views

The blocked view gets the same side padding as the catalog header and
cards: 2rem, and 1rem on mobile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
only21mil pushed a commit to only21mil/start-technologies that referenced this pull request Nov 25, 2026
serverInfo.smtp carried the SMTP password, and the public database is
streamed to every authenticated browser and, since Start9Labs#4752, persisted in
each browser's IndexedDB. The full SMTP settings now live in
private.smtp; serverInfo.smtp holds the same settings with a
passwordSet flag instead of the password.

- server.set-smtp takes keepPassword, which retains the saved password
  when none is given. Without it the behavior is unchanged.
- server.test-smtp takes an optional password; omitted, it uses the
  saved password only for the saved host, port and username.
- The get-system-smtp effect reads private.smtp, so services still
  receive the password.
- The 0.4.3 migration (revision 4) moves an existing password into
  private.smtp and is idempotent with revision 3.
- The SMTP page no longer pre-fills the password; it says one is saved
  and offers to remove it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants