Skip to content

prototype(runtime): reactive query loop across two browsers - #343

Closed
allisonmahmood wants to merge 1 commit into
mainfrom
prototype/reactive-loop
Closed

allisonmahmood wants to merge 1 commit into
mainfrom
prototype/reactive-loop

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Prototype, not for merge. Part of #313.

The reactive-query model on the Tier 2 map has only been argued on paper: a subscription is a read the patch already knows, re-run through the runtime's one dispatch point under the subscriber's own binding whenever a table it names is written. This throwaway loop builds exactly that on the dev stack so the hard cases can be measured instead of guessed.

What is here: an in-process after-commit wake in Runtime.dispatch (keys only, table:<patch>/<name>), one SSE stream per open document from the shell broker forwarded to the frame as a subscription event, patchy.tables.<t>.list.subscribe(args, onSnapshot) on the client with refcount, grace window and a per-subscription revision, trailing-debounce coalescing with one re-run in flight and a separate ceiling, must-resync on reconnect, and a loud refusal for postgres.*. Every file is marked PROTOTYPE for #313.

Measured on this machine (Chromium, pnpm test:prototype-reactive, 8 cases in 2.0 minutes):

  • Two browsers, two users: write-start to the other browser's snapshot 40 to 51 ms (mean 43); commit-ack to snapshot mean 31 ms.
  • Write racing subscription setup, 10 rounds: 0 stale snapshots after the write was seen; in one round the first snapshot missed the write and the wake delivered it after up-to-date, which is the model working.
  • Second viewer: each receives only their own filtered result; identity comes from the stream's own admission. Tier 1 table reads carry no per-viewer authority yet.
  • Revocation: deactivation stops the stream with access_denied, 0 snapshots leaked; an expired session stops it with session_expired 121 ms after the next write.
  • Stream drop: resumed in 860 ms with must-resync then a fresh snapshot, 0 duplicates dropped client-side; a 10 s offline window delivered the missed write exactly once on return.
  • Burst: 50 writes became 4 re-runs and 4 deliveries; 200 writes in 1.55 s became 21 re-runs and 17 deliveries, final value correct.
  • Fan-out: 30 documents x 5 subscriptions, one write: 150 re-runs (2 transient retries), 150 deliveries, every document updated within 510 ms, company-database connections peaked at 4.
  • HTTP/1.1: the seventh document in one browser context never loads while six streams hold the pool. The dev server is plain HTTP/1.1; production ingress must terminate HTTP/2.
  • postgres.* subscription: invalid_request with a clear message, never a downgrade.

Try it

Dev stack, by hand:

  1. pnpm dev, sign in, and publish any tier 1 patch whose client calls patchy.tables.<t>.list.subscribe({}, render) (the fixture at test/browser-tier1/reactive-prototype-client.ts is a complete example).
  2. Open the patch in two browser windows or profiles (the dev instance has one seeded user, so both windows are the same user).
  3. Insert a row in one window; the list in the other updates. Kill the network briefly; the status line shows resyncing, then up-to-date.

Every hard case with numbers, one command: pnpm test:prototype-reactive (offline Playwright, isolated server and Postgres, two browser contexts as two users).

Built by Claude Fable 5.1 via Claude Code (subagent)

🤖 Generated with Claude Code

Prototype, not for merge. Part of #313.

A subscription is a tier 1 read op re-run through Runtime.dispatch under the
stream's own admission whenever the table it names is written. The after-commit
hook sits in dispatch after the mutation's record returns success and carries
keys only. One SSE stream per document from the shell broker, forwarded to the
frame as a subscription event; must-resync on reconnect; company Postgres
subscriptions refuse loudly. The Playwright spec runs every hard case and
prints measured numbers: pnpm test:prototype-reactive.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area size:xl Over 1,000 changed lines; review in multiple passes labels Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:server Touches the server area size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant