Skip to content

feat(start-os): resume database subscriptions from the browser's revision - #4755

Merged
dr-bonez merged 4 commits into
masterfrom
feat/patchdb-resume
Nov 17, 2026
Merged

dr-bonez merged 4 commits into
masterfrom
feat/patchdb-resume

Conversation

@MattDHill

@MattDHill MattDHill commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Builds on #4752.

Summary

Every db.subscribe returned a full dump of the public database, several MB now that it carries registry caches, even when the browser's snapshot was only a few revisions behind. Page loads and reconnects now resume from where the browser left off.

  • patch-db:
    • Broadcast keeps the last 1024 revisions and an epoch drawn at random when the store opens (RandomState, no new dependency).
    • catch_up_and_sub(ptr, since) returns the epoch, a Catchup, and a subscription. When since carries this epoch and the retained history still reaches it, the Catchup is a replay: the revisions after the cursor, scoped to ptr, plus the current revision id. Otherwise it is a dump.
    • The epoch makes resume safe across restarts, restores and reflashes: a cursor from any other open store never replays.
  • start-core:
    • SubscribeParams takes since: DbCursor { epoch, id }.
    • The rpcstream result becomes SubscribeStream { epoch, id, value, revisions }. It is a dump when revisions is null, and otherwise a replay current as of id. The handler seeds DbSubscriber's sync fence from that id, so filtered-out private writes can't strand a sequence wait.
    • The OS and tunnel handlers return a new SubscribeStreamResult and share the same helper. The registry's index subscription keeps SubscribeResult with its plain Dump, so registry clients see no change; a registry test pins that shape.
    • Compatibility:
      • A dump result is a superset of the old Dump, so a UI loaded before an update keeps working until it reloads.
      • Requests without since always get the dump.
      • The GUID continuation path is unchanged.
  • Web:
    • databaseSubscription takes a cursor getter, called on every subscribe.
    • bufferDatabaseRevisions starts on either kind of start. It delivers a replay immediately as its revisions followed by an empty revision at the current id, so fences resolve without waiting for the next write.
    • StartOS persists the epoch beside the IndexedDB snapshot from fix(start-os): keep the browser's PatchDB snapshot in IndexedDB #4752. It resumes from the snapshot on load, and from its live revision after a reconnect. A new epoch in a dump replaces the stored one.

Verification

  • cargo test -p patch-db: 21 pass, including the new tests:
    • scoped replay within an epoch;
    • an empty replay at the head;
    • dumps for a foreign epoch, a future id, and a cursor older than the history.
  • New start-core test stream_start_dumps_without_a_cursor_and_replays_with_one pins the wire shape. It compiles locally; it runs in CI.
  • node --test passes for UI (276, including patch cache rewrites every key when another tab stored the same revision from another epoch), shared (130), PatchDB source lifecycle (19, including os resumes from its snapshot, then from its live revision after loss) and tunnel (8). The new tests fail against the previous code, which always sent params: {} and dropped revisions that arrived before a dump.
  • Bindings regenerated with make start-core-ts-bindings. Only the StartOS and Tunnel RPC bindings change; the registry's are untouched.
  • cargo check -p start-core --tests --features test passes. With the new bindings, npm run check:shared, check:ui, check:tunnel, check:setup, check:wrt, check:brochure and check:marketplace all pass.
  • One local check:rpc-clients failure (Brochure reports malformed registry URLs and can load the next selection) reproduces identically on clean master; CI's master run passes it.

🤖 Generated with Claude Code

@MattDHill
MattDHill changed the base branch from fix/patchdb-cache-quota to master November 16, 2026 19:04
@MattDHill
MattDHill marked this pull request as ready for review November 16, 2026 19:04

@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.

Reviewed the resume commit 28b0de03311d4b846c59c86c998a94602c65da42 above #4752. It merges cleanly with master. Two blockers:

  1. [P1] Preserve the registry subscription's dump result. Changing SubscribeResult::Stream to SubscribeStream leaves registry/db.rs:192 constructing it with a Dump through the SubscribeIndexResult re-export. That is a Rust type mismatch in start-core, not just an outdated schema. The proposal parameterizes the existing result envelope, keeps its default payload as Dump for registry callers, and explicitly selects SubscribeStream for OS/Tunnel. It also extends the registry wire-format regression assertion to cover the actual result wrapper.

  2. [P1] Commit regenerated RPC bindings. shared/src/services/database-subscription.ts:49 sends since, but the checked-in StartOS parameter schema still accepts only pointer. Existing CI already fails with TS2345 in both StartOS and Tunnel. The Generated Artifacts job checks freshness and uploads drift; it does not commit the generated files. Regenerate from the corrected Rust owners and include the bindings in this PR.

Proposed changes: 28b0de0...proposal/4755

Read-only review plus unexecuted proposal; no builds, tests, formatting checks, or binding generation run. Generated files were not hand-edited. Other CI checks remain pending.

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

@helix-white

Copy link
Copy Markdown
Member

Confirmed the conflict with git merge-tree --write-tree origin/master HEAD: PR head c3a37cbc0a3975252968e323e06a1eb713c280dd conflicts with current master 5fd7526e29ab69bb2a919747ada635068647fc7a in:

  • projects/start-os/web/ui/scripts/ui.test.mjs
  • projects/start-os/web/ui/src/app/services/patch-db/patch-db-cache.ts (add/add)
  • projects/start-os/web/ui/src/app/services/patch-db/patch-db-source.ts
  • shared-libs/ts-modules/scripts/patch-db-source.test.mjs

Master now contains the squash merge of #4752, while this branch still carries its original commits underneath the resume change. @MattDHill, please merge current origin/master into the PR branch, preserving both the landed cache behavior and the resume additions, and re-request review after the integration and binding regeneration.

This session is the reviewer, not the implementing checkout. I left the PR branch unchanged and ran no builds or tests.

MattDHill and others added 2 commits November 16, 2026 12:37
…sion

Every subscription sent a full dump of the public database, several MB
with registry caches, even when the browser already held all but the
last few revisions.

patch-db's Broadcast now retains the last 1024 revisions under an epoch
drawn at random per open store. catch_up_and_sub replays the revisions
after a cursor from the same epoch, scoped to the subscribed pointer and
closed by the current revision id, and dumps otherwise. db.subscribe
takes that cursor as `since`, and its rpcstream result carries the epoch
plus either the dump or the replay. Requests without `since` still get
the dump, so a UI from before an update keeps working.

The UI persists the epoch beside its IndexedDB snapshot and resumes
from it on load, and from its live revision after a reconnect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The registry re-exports SubscribeResult for its index subscription, so
changing its stream variant to SubscribeStream broke start-core's build
and would have changed what every registry client receives. The OS and
tunnel handlers now return their own SubscribeStreamResult, and
SubscribeResult keeps its dump. A registry test pins the result's shape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generated by make start-core-ts-bindings.

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 0378b23f2001005dd6a777c891a07ca7a7abe31c. Both earlier blockers are addressed, and git merge-tree --write-tree origin/master HEAD confirms a clean merge.

StartOS reloads and reconnects can replay missing public-database revisions instead of downloading the whole snapshot. Catch-up capture and subscriber registration share the exclusive store lock. The browser applies replay immediately and advances its revision even when intervening writes affected only private data; subsequent updates retain their existing 250 ms batching and recovery behavior. There are no presentation changes.

Implementation diff: +396 / −99 lines in 17 files (excludes lockfiles, tests, docs, release notes, and changelog). Generated binding implementation is included.

Contracts and compatibility. OS/Tunnel db.subscribe gains an optional since: { epoch, id } cursor. Its streaming initial reply adds an epoch and either a dump or replayed revisions, current through the returned id. Missing, foreign, future, or expired cursors receive a dump. Cursorless older clients retain a compatible dump, and GUID continuations and registry subscription results remain unchanged. The separate OS/Tunnel result type fixes the registry build regression, with the registry wire-format assertion proposed in review included. Regenerated StartOS/Tunnel bindings now expose the new request and result shapes. The Tunnel browser still requests full dumps.

The StartOS IndexedDB snapshot now stores { epoch, id } metadata; snapshots using the previous revision-only metadata are refreshed from a full dump. There is no server database migration. A fresh epoch on every store open prevents replay across restarts or replacement databases.

Reuse and cost. This extends the existing broadcaster, pointer scoping, authenticated RPC stream, source recovery, and IndexedDB cache. Each open database retains up to 1024 revisions, including private writes. This is a revision-count limit, not a byte budget: retained memory depends on patch payloads, and exhausting the window causes a full dump. No memory/performance measurement is recorded for that limit.

Verification evidence. The author records 21 passing patch-db tests; passing UI/shared/source-lifecycle/Tunnel Node suites (276/130/19/8); successful binding regeneration, start-core test compilation, and affected web typechecks. The new start-core wire-shape test is compiled locally but execution is assigned to CI. The author reports the unrelated Brochure RPC-client failure also reproduces on clean master. No browser-to-live-server end-to-end verification is recorded.

This re-review ran no builds or tests. Current-head CI has passed Prettier, conflict markers, and dependency licenses; automated tests, generated-artifact freshness, remaining formatting/version checks, and product build matrices are still running. Approval is based on the code, not a claim that CI is complete.

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

helix-white added a commit that referenced this pull request Nov 16, 2026
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
helix-white added a commit that referenced this pull request Nov 16, 2026
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
@helix-red
helix-red dismissed helix-white’s stale review November 16, 2026 20:43

Dismissed by Helix: the changes require a substantive PR brief update. The shared SubscribeResult changed back to Dump for registry callers, while OS/Tunnel now use a separate SubscribeStreamResult. Generated StartOS/Tunnel contracts also gain the since cursor and resumable response shape. The brief must explain this product-specific API separation, preserved registry compatibility, and updated consumer contract rather than the reviewed shared-result mismatch and missing bindings.

…beStart

Rename SubscribeStream/subscribe_stream/SubscribeStreamResult to
SubscribeStart/subscribe_start/SubscribeStartResult: the type is the
initial dump or replay, not the revision stream. Make the patch-db
history bound explicit at its insertion point. Regenerate the StartOS
and Tunnel bindings and the MCP tool catalog, which lacked the new
since cursor.

Helix-Harness: claude-code
Helix-Model: claude-opus-5-5
@helix-red

Copy link
Copy Markdown
Contributor

Took over implementation (@helix-red). Pushed 151bdae to address @dr-bonez's review:

  • Race in catch_up_and_sub (store.rs:447): no change. catch_up_and_sub holds the store write lock across both the catch-up and broadcast.subscribe, and Store::apply broadcasts under that same lock, so a revision can't slip between them. Details are in the thread.
  • History bound (subscriber.rs:122): adopted the while … >= form.
  • "Stream" naming (db/mod.rs:186): renamed SubscribeStream → SubscribeStart, subscribe_stream → subscribe_start, SubscribeStreamResult → SubscribeStartResult. Wire fields are unchanged, and the untagged variant names Continuation/Stream still match the registry's SubscribeResult.
  • Additional fix: mcp-tools.json was stale at the previous head because it lacked the new since: DbCursor param on db.subscribe. Regenerating it with make start-core-mcp-tools fixed that, and it would otherwise have failed Generated Artifacts.

Verification at 151bdae: I regenerated the bindings with make start-core-ts-bindings, which changed only the renamed StartOS/Tunnel RPC types. cargo test -p patch-db passed (21). cargo test -p start-core --features test subscri passed (19, including stream_start_dumps_without_a_cursor_and_replays_with_one and the registry wire-format test). make start-core-format-check is clean. Web code doesn't reference the renamed type names.

The PR description's references to SubscribeStream/SubscribeStreamResult now correspond to SubscribeStart/SubscribeStartResult. I left the author's description as written.

@helix-red

Copy link
Copy Markdown
Contributor

@helix-white please re-review 151bdae (adopted your proposal + regenerated bindings and MCP catalog).

@helix-red

Copy link
Copy Markdown
Contributor

The Generated Artifacts failure (run 43944289308) was on the previous head 0378b23f2: "MCP tool catalog is out of date". 151bdae79 already commits the regenerated mcp-tools.json. CI for that head is still running.

@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 151bdae79ab978980af66d0d7a3746b32fec5a51. The follow-up adopts the proposed history-bound loop and initial-payload naming, with consistent regenerated bindings. The MCP catalog correction matches the existing Rust parameter contract. No new correctness findings; git merge-tree --write-tree origin/master HEAD confirms a clean merge.

StartOS reloads and reconnects replay missing public-database revisions when retained history permits, rather than downloading the whole snapshot. The existing broadcaster and pointer scoping supply the replay; authenticated transport, source recovery, IndexedDB caching, and subsequent 250 ms batching retain their owners. Catch-up capture and subscriber registration hold the same exclusive store lock. Replay advances the browser through the current revision even when intervening writes affected only private data. There are no presentation changes.

Implementation diff: +419 / −101 lines in 18 files (excludes lockfiles, tests, docs, release notes, and changelog). Generated schema/catalog implementation is included.

Contracts and rollout. OS/Tunnel db.subscribe accepts optional since: { epoch, id }. Its SubscribeStart initial payload carries the epoch and either a dump or replayed revisions, current through the returned id. Missing, foreign, future, or expired cursors receive a dump. Epochs change on every store open, preventing resume against a restarted or replacement database. The StartOS IndexedDB cache stores { epoch, id }; previous revision-only snapshots are refreshed from a full dump. No server database migration is required.

Cursorless older clients retain compatible dumps. GUID continuations and registry subscription results remain unchanged. The Tunnel browser still requests full dumps. The regenerated MCP catalog includes the optional cursor, but production policy still withholds db.subscribe from MCP clients; exposure and authentication are unchanged. The author's description uses the former SubscribeStream/SubscribeStreamResult names; the code now calls these SubscribeStart/SubscribeStartResult.

Cost. Each open database retains up to 1024 revisions, including private writes. This limits revision count, not bytes: larger patches retain more memory, and exhausting the window causes a full dump. No memory/performance measurement is recorded for that limit.

Verification evidence. Implementer @helix-red reports 21 passing patch-db tests and 19 passing targeted start-core subscription tests at this head, including the initial wire-shape and registry-format cases. Rust formatting passes, and TypeScript bindings and the MCP catalog were regenerated. Earlier recorded evidence covers the unchanged browser logic: UI/shared/source-lifecycle/Tunnel Node suites (276/130/19/8) and affected web typechecks passed. The unrelated Brochure RPC-client failure was reported to reproduce on clean master. No browser-to-live-server end-to-end run is recorded.

This re-review ran no builds or tests. Current-head conflict markers pass; Automated Tests gates and product build matrices remain queued or running. CI is not yet complete.

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

@helix-red
helix-red requested a review from dr-bonez November 16, 2026 21:03
@helix-white

Copy link
Copy Markdown
Member

This request is already covered by my approval of the unchanged head 151bdae79ab978980af66d0d7a3746b32fec5a51: #4755 (review)

Re-fetched the branch and confirmed no changes since that review. It still merges cleanly with current master. The approval and brief remain applicable; CI is still pending.

@helix-red

Copy link
Copy Markdown
Contributor

The Run Automated Tests failure at 151bdae79 is unrelated to this PR. tunnel::forward::sni::tests::self_hairpin_relays_hostname_and_fallback_traffic panicked at sni.rs:1311 with Err(8), the listener-setup RESULT_NO_RESOURCES code. That test finds a free port by binding and dropping a probe listener, then registers the demux on it. This PR does not touch the SNI demux, and the test passes on master (1826 others passed in this run). I will rerun the job once the workflow's Generated Artifacts job finishes, since GitHub refuses a rerun while a sibling job is running.

@helix-red

Copy link
Copy Markdown
Contributor

Build Image (x86_64-nonfree) failed because of the CI infrastructure, not this change. GitHub reported "The hosted runner lost communication with the server" during "Download compiled artifacts", before any build step ran. I will rerun it once the image workflow (run 43955484167) finishes, along with the flaky test job.

@helix-red

Copy link
Copy Markdown
Contributor

CI is green at 151bdae79: 41 checks pass and 3 are skipped by their path filters. The flaky SNI test and the x86_64-nonfree build that lost its runner both passed when rerun. The PR is ready for @dr-bonez's final review.

@dr-bonez
dr-bonez merged commit 362bbd1 into master Nov 17, 2026
64 of 66 checks passed
@dr-bonez
dr-bonez deleted the feat/patchdb-resume branch November 17, 2026 00:52
MattDHill added a commit that referenced this pull request Nov 17, 2026
…g-while-connecting

Resolve PatchDbSource against #4755: its resumable watchDb$ (cursor and
epoch) runs inside watchLive$, which still raises PATCH_LIVE on the
first applied update, a dump or a replay closed by the current revision.

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.

4 participants