oficina / docs Public

Live push: collaborator typing in about one round trip (measurements + spec) open

On branch spec/live-push

Paul's report (2026-11-26, Docs native 0.1.12): typing is instant, but the other copy lags, "heading toward 500 ms". This branch measures it end to end and proposes live push. Spec: docs/superpowers/specs/2026-11-26-live-push-design.md. Nothing here changes behaviour: spec, harness and raw results only (every probe skips unless its env var is set). Needs the highest-capability-model spec review before it becomes a plan.

What a person sees today (real clients, 20-page doc, 50 ms injected RTT ≈ Paul to the CARLOS edge)

Keydown on copy A → character on copy B, p50 / p95 ms, 120 keys:

| | web→web | native→native | native→web | web→native | |---|---|---|---|---| | 20 pages, 0 ms | 190 / 319 | 231 / 396 | 218 / 421 | 224 / 334 | | 20 pages, 50 ms | 279 / 439 | 296 / 484 | 274 / 446 | 330 / 497 | | 1 page, 50 ms | 292 / 437 | 289 / 460 | 283 / 463 | 274 / 392 |

Medians at 20 pages, 50 ms, split using the server log: sender waits 120–140 (250 ms upload window) + 25 one-way + server 8–10 + stream event → receiver's GET reaches the server 54–57 (the fetch round trip) + GET 1 + 25 down + apply/draw (web 5–10, native 25–45 at 20 pages / ~10 at 1 page: the fresh-source presentation, audit finding 2).

Prod path from this Mac: TCP to the edge 37–62 ms, warm h2 request 45–56 ms. The edge speaks HTTP/2, flushes text/event-stream and doesn't compress it, so it shouldn't buffer. Not verified end to end, because every stream needs Paul's session.

Protocol matrix (simulated clients with the web's and the native app's exact pacing rules, 20 pages)

Key → arrival, p50/p95 ms. "fetch" is today's path; "push" is when the stream announced the seq (= when pushed bytes would arrive).

| RTT | today native (fetch) | push only | send-when-idle only | both | |---|---|---|---|---| | 20 | 171 | 149 | 57 | 32 / 46 | | 50 | 235 | 177 | 119 | 64 / 82 | | 100 | 344 | 239 | 229 | 122 / 200 |

Cutting the pacing window is the bigger win up to ~100 ms RTT. The fetch is one RTT, so it matters more with distance. You need both.

Proposal (short)

  • Bytes on the existing SSE stream (?push=1&since=N, opt-in, so old clients and old servers keep working): push frames in seq order, read from the committed log (gapless, no ring buffer); update (seq only, fetch) for anything over 32 KiB or a client far behind; own frames for the poster's own update (Docs-Stream header), replacing the web's echo fetches; bye before the 5-min TTL so a hands-free web watcher reopens.
  • Send when nothing is in flight, 50 ms floor, on both platforms (outbox/queue first, as today).
  • Warm replayed handle per active document on the server: today every POST replays the doc. Apply to a warm handle: 15–17 µs, against 1.6 ms (1 page) / 10.8 ms (20 pages).
  • No WebSocket: no latency to gain (one trip each way either way, on the same h2 connection). It would cost a dependency, its own auth/origin/reconnect handling, and a second heartbeat policy. Still the right move when presence arrives.
  • Projected: ~65 ms median (web receiver) / ~75–95 ms (native at 20 pages) at 50 ms RTT, from 274–330 ms.

"Are we DDoSing ourselves?" (20-page doc, per instance)

  • Uploads per typist go from ~3.5/s to ~6/s (one per keystroke at normal typing), self-limited to one in flight and ≤ 20/s. A 50–100 ms floor doesn't reduce that at typing speed; only a ~200 ms+ window would, and that window is the latency we're removing.
  • Requests: today web→web is 68 POSTs + 126 GETs per 120 keys (58 of the GETs are the web sender fetching its own updates back: the broadcast beats the POST answer). native→native is 72 + 72. With push: ~115–120 POSTs and no GETs. Every extra watcher costs a GET per upload today and nothing with push. The shared edge sees no more requests.
  • Server CPU (simulated typists): today native 48 ms/s for 1 typist, 211 for 5, 714 for 20. Sending at once without the warm handle: 87 / 382 / 1,349 ms/s. The profile shows the per-POST replay plus its GC is about a third of CPU, and GETs are 3%. With the warm handle, a typist sending at once costs about today's CPU (~5% of a core at 20 pages).
  • Rails: 32 KiB push cap, slow receivers fall back to fetch (no queues), per-session late answers above 30 uploads/s (not 429: the web save queue drops any 4xx), authz re-checked per flush.

Also found

  • The web sender re-downloads most of its own updates (77–147 per 200 keys at 20–100 ms RTT), because noteOwnSeq arrives after the stream event.
  • A hands-free web watcher stops updating at the server's 5-min stream TTL (accepted in 2026-09-01; open question 2).
  • Two Mac windows of one document in one account can't exist (DocsWindows.reserve), so no in-process fan-out is needed.
  • RealtimeAuditE2ETests.testEndToEndRemoteUpdates now reports n=0: it observes projection, which S1a made @ObservationIgnored.
  • The machine was heavily shared (load average 10–970). CPU figures are ±20%, and the end-to-end runs used the quietest windows.

Open questions for Paul

  1. A 50 ms floor (recommended), or keep a window?
  2. Let a visible web tab reopen across the 5-min TTL (recommended), reversing that part of the 2026-09-01 ruling?
  3. Keep the 250 ms window on cellular / expensive paths (recommended)?
  4. Two minutes with your session to measure a stream and a POST on the real edge?

Slices: server (warm handle, push stream, answer pacing; deployable alone) → web → native release. Harness: native/benchmarks/live-push/, internal/docs/live_push_probe_test.go, native/apple/Tests/DocsKitTests/LivePushLatencyTests.swift. Raw results are in native/benchmarks/live-push/results-2026-11-26/.

Spec review — Claude Fable (model id claude-fable-5-2), read-only against origin/spec/live-push 4ce1a1b

Verdict: APPROVE AFTER FIXES

The direction is right and I would not change it: bytes on the existing SSE stream read from the committed log, send-when-idle with a floor, warm handle, no WebSocket. I checked the load-bearing claims against the code: commit precedes broadcast (ApplyUpdate returns after the transaction, updatesPost broadcasts after), seq is MAX+1 in the single-writer transaction so a reader sees a gapless prefix, the Yjs/yrs wire is untouched, and the raw results match the tables I spot-checked (lat-rtt50, q-p20-rtt50). Findings 1–4 must be fixed in the spec before it becomes a plan; 5–10 should be; the rest are small.

Blocking

1. §3.3 — a warm handle reaches MaxRetainedUpdates and the web then drops the save. (High) core.Handle.Apply appends every accepted update to h.applied and refuses with ErrUpdateLogFull at 4096 (core.go:555). Today that is unreachable because each POST replays into a fresh handle from snapshot + ≤255 rows. A warm handle never resets: at ~6 uploads/s one typist gets there in ~11 minutes of typing, five in ~2. That POST answers 400, which save-queue.mjs treats as a final refusal and drops the batch. "Evict on any error" comes too late for that batch. It also means the handle's memory grows by every update it has seen. The spec must say: re-seed the warm handle (from its own snapshot, as reseedForReplay does) at each snapshot cadence, well under the cap; and a warm-path ErrUpdateLogFull, trap or recovered error falls back to a cold replay inside the same POST instead of failing it. Test: >4096 POSTs to one warm document, none refused.

2. §3.3 — an update applied to the warm handle but not committed poisons it. (High) Apply happens outside the transaction. If the transaction then fails (the in-transaction checkPermission for a writer revoked mid-request, a cancelled request context, a DB error, the team guard), the handle holds bytes that are not in the log, while its seq still equals MAX(seq), so the validity check passes on the next POST. The next cadence snapshot is then written from it, and D5 verifies the candidate against that same handle, so a refused write becomes durable content. "A rejected update leaves the handle usable" is true only for a core rejection. State the rule: any failure after a successful Apply drops the handle; the handle's seq advances only after commit. Test: revoke between apply and commit, then check the next snapshot equals a cold replay.

3. §3.4 / §6 — own is an unverified "you already have this", and adopting it wrongly is silent divergence. (High) A client adopts own N at cursor + 1 without bytes. §6 says a wrong Docs-Stream "starves the forger, the client fetches on the resulting gap", but there is no gap: seq N is exactly next, so the stream that receives own skips the update for good, and later updates that depend on it park invisibly. The risk is ordinary bugs more than forgery (a stale id after a reconnect, the native drainer's "model holds every entry" check being wrong once, two tabs). Make the client able to check it: the header carries <stream id>.<client counter>, own echoes the counter, and the client adopts only for a counter it sent on this stream; anything else is treated as update (fetch). The server should also record the session with the stream id and ignore a header from a different session. Also say which wins on a push stream, own or the POST's Docs-Seq (both are safe under exactly-next, but only one should be specified). Related: the (seq → stream id) entry is recorded after ApplyUpdate commits, so a stream woken by someone else's POST can read row N before the entry exists and send the poster its own bytes. That is harmless for correctness, but on native it costs a fresh-source presentation (25–45 ms at 20 pages) on the typist's main thread during shared editing. Record the entry inside the transaction, before commit.

4. §3.5 / §1.3 cause 7 / question 2 — bye does not fix what Paul will see. (High for the goal, needs Paul) live-updates.mjs closes a visible tab's stream after IDLE_MS = 2 minutes with no local activity and no stream event, and reopens only on activity. So: Paul stops typing for two minutes, types again, and the untouched copy stays stale until he moves the mouse over it. bye across the 5-minute TTL only helps while updates keep arriving. The same holds after any deploy or restart: hub.drain closes every stream and the web reopens only on activity. Question 2 should be put to Paul as the real trade: how long a visible, untouched tab may hold its instance awake (2 minutes today; the Friday-to-Monday hibernation rule is the reason). Options: a longer visible-idle window (say 15–30 minutes), or keep 2 minutes and accept it. Whichever he picks, send bye on drain as well, with a jittered reopen, so a deploy does not strand watchers.

Should fix

5. §3.1 — fetch fallback and frames interleave without a stated rule. (Medium) After update 43 (oversized) the server will send push 44 straight behind it while the client's ?since=42 fetch is in flight. Specify: one fetch in flight; frames that arrive meanwhile queue and are re-checked against the cursor when it lands (drop ≤ cursor, apply cursor + 1, otherwise one more fetch). Specify the server side too: after an update fallback its sent moves to that seq. Without this, both clients will invent their own rule and one will double-fetch or stall.

6. §3.1 — a cursor ahead of the log is undetectable. (Medium) If the log is ever behind the client (database restored from a backup, a team re-provisioned, version restore later), since=N with N > MAX(seq) sends nothing and the client drops new rows as "≤ cursor". Put the server's current seq in hello; a client whose cursor is greater resyncs from 0. Also state that Last-Event-ID beats since when both arrive, and do not put id: on update frames (the bytes were not delivered).

7. §7 — new client, old server is not "only more POSTs". (Medium) It is the "send at once, fetch" row of §4: ~1.8× server CPU, more GETs per watcher, and the web's own-echo fetches. That combination is real, not just a rollback case: one native build talks to every team's instance, including lagged ones. Rule: the client uses the 50 ms floor only on a stream that said hello; otherwise it keeps 250 ms. State also that hello and bye are sent only on push=1 streams.

8. §3.3 / §5 — warm-handle memory is not measured or bounded in bytes. (Medium) "64 handles, LRU" bounds a count. Each handle is a WASM instance whose linear memory grows and does not shrink, plus applied. The quoted 64–127 MB heap is from runs without warm handles. Measure resident size per warm handle at 1 and 20 pages and cap by bytes. Also: drop the handle on delete, restore, team or seal change (a sealed document's plaintext otherwise stays resident for 60 s after access changes); and say how the 60 s eviction works with hibernation (stream.go deliberately has no timer outside a live connection; evict lazily on the next POST plus one sweep, and let shutdown close them).

9. §4 — the two central cost claims are projections, and the worst case was not run. (Medium) No run includes a warm handle or a push frame. "About today's CPU" is arithmetic (and comes out ~15% over today, inside the ±20%). "Key → announced" stands in for push but leaves out what push adds per watcher per notification: the session re-check, a log read, opening sealed rows, base64. Every load run puts each typist in their own document with one watcher; the case that stresses this design is several typists and several watchers in one document (N streams each re-reading and re-opening the same rows). Each cell is one run of 200 keys, so p95 is ten samples, on a machine at load 10–970 (load-p1 rtt0 shows POST p50 at 37–43 ms against 7 ms in the quiet run). The numbers are good enough to choose the design; they are not evidence that the targets are met. Make slice 1 re-run load-p1/load-p20 plus a 5-typists-5-watchers-one-document case with the real implementation, and make question 4 (a stream and a POST through the real edge) a condition of calling slice 2 done, since edge buffering is still unverified.

10. §8 — the latency gate as written will flake or go false green. (Medium) Absolute thresholds (p50 ≤ 50 ms, p95 ≤ 100 ms) on a shared CI runner cannot hold, and a gate that is retried or skipped under load is the false-green pattern we have had before. The gate test does not exist yet (the probes are multi-process, env-gated, and use Node-built updates). Split it:

  • CI, deterministic: fake-clock tests that a key after idle is sent with zero wait and coalesces while in flight (JS and Swift); a Go test that one POST yields exactly one flushed push frame per watcher with no GET, and own for the poster; uploads ≤ 1.2 × keys.
  • CI, timing: server-added time only (measured minus injected RTT), compared with a baseline measured in the same process, best of three; it fails, never skips.
  • Release step: run-clients.sh against the §2 targets with real web and native clients, result file committed beside the release, and it refuses to record a run above a stated load average.

11. §5 — late answers need bounds. (Medium-low) Safe against the clients' timeouts only if stated: delay before taking the document lock or the writer (never while holding either), capped at ~1 s, ended by request cancel and hub.draining(), and with a limit on how many answers one session may have waiting (beyond it, 503 with Retry-After, which the web queue retries; never a 4xx). Without the last, the rail turns a hostile client into held goroutines.

12. §9 — split slice 1 and add switches. (Medium-low) Slice 1 puts a change to the durable write path (warm handle) in the same deploy as the stream. Ship the warm handle first on its own, with the warm-equals-cold property test and findings 1–2, behind an environment switch; then the stream. A server switch that ignores push=1 is free given §7's matrix and turns every client back to today's path without a release. The web's leading-edge send arrives with the server's deploy, so order the commits so it cannot go live before the push stream has been checked on production.

Minor

  1. §3.1: with W watchers each notification does W identical reads and W unseals. Measure under finding 9 before adding a cache.
  2. §5 storage: rows are sealed in production, so a row costs well over 30 bytes; the rate roughly doubles and compaction is still deferred. Give the real per-row figure.
  3. §3.7: treat isConstrained (Low Data Mode) like isExpensive.
  4. §3.3: two processes on one database (a deploy overlap) stay correct because validity is checked in the transaction; say so, and note that a stream on the old process hears nothing until drained.
  5. §8: add tests for a reader's stream (receives frames, cannot post), for access revoked between two frames, and for an old native parser against a push=1-less stream on the new server.
  6. Restore RealtimeAuditE2ETests.testEndToEndRemoteUpdates (n=0 since S1a) before native work starts; it is the existing end-to-end check.

For Paul

Questions 1 and 3 are fine as recommended. Question 2 needs rewording per finding 4. Question 4 should be a yes: two minutes on the real edge is the one measurement nobody else can take.

Revision 2: spec/live-push 9319c64. It answers all 18 of Fable's findings and records Paul's rulings (50 ms floor: yes; visible tabs live: yes; 250 ms on cellular / Low Data: yes; edge check with his session: yes).

To measure finding 9 I built a prototype on branch proto/live-push (12e54ee, never to merge, switches off by default). It has the warm handle and the push stream, and the probe gained push, shared-document and sealed-row modes.

Prototype, measured (20 pages, sealed rows, 3 runs each on fresh servers; median)

| | Today (native 250 ms, fetch) | Push, cold replay | Push + warm handle | |---|---|---|---| | 1 typist: server CPU | 42 ms/s (11.5 ms/upload) | 73 | 20 ms/s (3.3 ms/upload) | | 5 typists, own docs | 173 | 330 | 75 | | 5 typists + 5 watchers, one doc | 436 (25.9 ms/upload) | 678 | 421 (14.7 ms/upload) | | 20 typists (1 run) | 529, p95 1,014 ms (saturating) | 928 | 249, p95 11 ms | | Latency @ 50 ms RTT, 1 typist (to bytes in hand) | 246 / 369 (web 271 / 414) | – | 56 / 67 | | Latency @ 50 ms, 5 + 5 one doc | 264 / 509 | – | 58 / 66 |

  • The warm handle is the prerequisite. It cuts CPU per upload 3.5× and allocation about 40×. With it, push plus sending at once costs less CPU than today for typists in their own documents, and about the same in a shared document. Without it, the same design costs 1.6–1.9× today.
  • Shared-document cost is fan-out (finding 13): about 1.2 ms per stream per frame. Slice 1b measures a per-document frame cache. Throttling the authorisation re-check is left as a decision for the 1b review, with numbers.
  • Warm handle memory (RSS): 1.8 MB at 1 page, 2.7 MB at 20 pages, 16.5 MB at 200 edited pages. The cap is 128 MB and 64 handles.
  • Storage with sealed rows: a keystroke row is about 180 B of database, but each commit writes about 25 KB to the WAL, which Litestream replicates. At one upload per keystroke that is about 150 KB/s per active typist, against about 90 KB/s today. This is open question 2.
  • Every push run measured 0 GETs from watchers and 0 echo fetches. Every own update came back as own.

Findings → revision 2

| # | Finding | Fix (spec section) | |---|---|---| | 1 | Warm handle reaches MaxRetainedUpdates, and the web drops the save | Re-seed at the snapshot cadence (≤ ~257 retained). Full log, trap or recovered error falls back to a cold replay inside the same POST, so the cache never fails a POST. Test: >4,096 POSTs (§3.5 rules 2 and 4, §9.1). | | 2 | Applied but not committed poisons the handle | Any failure after Apply drops the handle; its seq advances only after commit. Test: revoke between apply and commit, then snapshot = cold replay (§3.5 rule 3). | | 3 | own can silently skip; registry race | Docs-Stream: <id>.<counter> with the counter echoed in own. The id is bound to the session (a header from another session is ignored). The origin is recorded inside the transaction with the bytes' SHA-256, and own is sent only on a hash match. The client adopts only its own counter at cursor + 1, otherwise it fetches. On push streams own wins over Docs-Seq. §6 corrected (§3.4, §3.2, §6). | | 4 | bye alone does not fix the 2-minute close | Cause 7 rewritten: the 2-minute IDLE_MS close is the real cause. Per Paul's ruling, visible tabs stay live, up to 8 h without local activity. Hidden tabs keep 30 s. bye on TTL and on drain; reopen at once after TTL, after 1–5 s of jitter after drain (§1.3, §3.6, question 1). | | 5 | Frames during a fallback fetch | One fetch in flight. Frames queue and are re-checked when it lands. Server sent moves after an update frame (§3.2, §3.1). | | 6 | Cursor ahead of the log; Last-Event-ID | hello carries the log's seq; a cursor above it means resync from 0. Last-Event-ID wins over since. No id: on update frames (§3.1). | | 7 | New client on an old server ≈ 1.8× CPU | The 50 ms floor and leading edge only after hello; otherwise 250 ms. hello and bye only on push=1 streams (§3.3, §7). | | 8 | Warm-handle memory and eviction | Measured, as above. Byte cap 128 MB plus 64 handles. Dropped on delete, restore, grant, team or seal change. Lazy sweep on POST (no timers), closed on drain, gone at hibernation (§3.5 rules 5–8). | | 9 | Projections; worst case not run | Prototype measured, 3 runs, including 5 typists + 5 watchers in one document. Measured and projected figures are labelled throughout. Slice 1a re-runs the load cases on the real implementation. The edge check is a condition of 1b being done (§4.2, §2, §10). | | 10 | Absolute-threshold gate would flake | Deterministic CI (Go frames and warm handle; JS and Swift fake clocks). Relative timing check: server-added time against an in-process baseline, best of three, fails and never skips. A release step that commits its result and refuses to record above a load threshold (§9). | | 11 | Late answers need bounds | Delay only before taking the lock or writer; ≤ 1 s; ended by cancel or drain; ≤ 2 waiting per session, beyond that 503 + Retry-After (never 4xx) (§5). | | 12 | Split slice 1, switches | 1a: warm handle alone behind DOCS_WARM_HANDLE. 1b: push behind DOCS_LIVE_PUSH (off means every client is back on today's path). The web's leading edge is switched on by hello, so it cannot go live before push is checked on production (§8, §10). | | 13 | W watchers mean W reads and unseals | Measured: about 1.2 ms per stream per frame. Frame cache in 1b, measured with and without (§4.2). | | 14 | Real per-row storage | About 180 B per sealed row; about 25 KB of WAL per commit (§4.3, question 2). | | 15 | Low Data Mode | isConstrained treated like isExpensive; web saveData (§3.3, §3.8). | | 16 | Two processes on one database | Correct, because validity is checked in the transaction. Old-process streams get bye on drain (§3.5 rule 8, §3.6). | | 17 | More stream tests | Reader's stream, revocation between frames, old parser against the new server (§9.1). | | 18 | Restore the native e2e probe | Slice 0 (§10). |

Paul's edge check (question 4)

native/benchmarks/live-push/edge-timing.js. Paul opens a scratch document, pastes the file into the browser console and sends back the printed DOCS EDGE TIMING {…}. The exact steps are in spec §11. It posts three empty Yjs updates (00 00, no visible change) and times the stream's first event, the fetch round trip, the POST answer, and the stream announcing each POST.

I checked it in headless Chrome against local servers through a 50 ms proxy. Today's server: update events about 0 ms after the answer. Push server: own frames.

Run it now for a baseline. Today's server already announces each upload on the stream, so this answers whether the edge buffers it. Run it again after slice 1b. That second run is a condition of 1b being done.

Open for Paul (revision 2)

  1. 8 h as the bound for an untouched visible tab keeping its instance awake? Or shorter, or unbounded?
  2. WAL/Litestream traffic of about 150 KB/s per active typist, against about 90 today: fine? Or coalesce one session's commits server-side, at the cost of up to that window in latency?

Re-review of revision 2 — Claude Fable (model id claude-fable-5-2), read-only: git diff 4ce1a1b 9319c64, the proto results, edge-timing.js, and the CARLOS activator/Litestream code

Verdict: APPROVE AFTER FIXES — ready to become a plan

All 18 findings are answered in the spec text, and the nine I was asked to look at hardest hold up. The fixes below are spec edits, none is a redesign, and none needs another review round. Slices 0 and 1a can be planned now; findings 1–3 below must be in the spec before 1b and slice 2 are planned.

The numbers in the spec match the raw results (proto/table.md: 56/67 against 246/369; 42→20, 529→249 ms/s, p95 1,014→11; cold push 73/330/678/928 = 1.6–1.9× today). The shared-document warm runs are wide (421 [154–432]) at load 180–850, which the spec says; the 1a/1b re-runs cover it.

The 18, checked

| # | Status | Note | |---|---|---| | 1 | Fixed | §3.5 rules 2 and 4: re-seed at 256 rows, and ErrUpdateLogFull/trap/RecoveredError fall back to a cold replay in the same POST. Test listed. Wording: see finding 5. | | 2 | Fixed | §3.5 rule 3: any failure after Apply drops the handle; seq advances only after commit; a MAX(seq) mismatch drops it. Test listed. | | 3 | Fixed | §3.4: counter echoed, id bound to the session, entry recorded inside the transaction with the bytes' SHA-256. The hash makes a stale entry harmless: a reused seq with different bytes cannot match, and identical bytes are bytes the client holds. own wins over Docs-Seq. | | 4 | Fixed for single-user instances; gap in team mode | Finding 1. | | 5, 6 | Fixed | §3.2 queue rule, sent moves after update, hello carries the seq, Last-Event-ID wins, no id: on update. | | 7 | Fixed | Floor only after hello; §7 matrix is right. Small gap: finding 2. | | 8 | Fixed | Measured, 128 MB / 64 cap, drops listed, lazy sweep. One false sentence: finding 4. | | 9 | Fixed | Measured with warm handle and push, including 5 + 5 in one document. | | 10 | Mostly fixed | Finding 6. | | 11 | Fixed | §5: before the lock, ≤ 1 s, cancel/drain, ≤ 2 waiting then 503 + Retry-After. | | 12 | Fixed | 1a/1b, DOCS_WARM_HANDLE, DOCS_LIVE_PUSH, leading edge gated on hello. | | 13–18 | Fixed | |

Findings

1. §3.6 / §3.1 — a team-mode stream also closes at its lease deadline, with no bye. (Medium-high) stream.go has four server-side ends: TTL, drain, leaseDeadline (team mode: the stream returns when the access lease runs out) and a failed write or authorisation check. The spec gives bye to the first two only. Every team instance (lagged today, all of them after Alta) runs in team mode, so a visible untouched tab there still goes stale at the lease deadline, which is the bug finding 4 was about. Fix: send bye lease before that close, and state the general rule: a visible tab inside its 8 h reopens after any end of the stream, bye or not. bye only chooses the delay (ttl/lease at once, drain 1–5 s). Also say what happens when the reopen fails (instance still starting, 502, access gone): capped exponential backoff, and stop on 401/403/404. Without that, a tab retries a dead instance for 8 hours. Add the lease close to §9.1.

2. §3.6 / §7 — the visible-tab rule on a non-push stream is not specified. (Medium) bye exists only on push=1 streams. New web against an old server, or with DOCS_LIVE_PUSH off, gets a silent TTL close. Say which applies: the 8 h rule with reopen-on-close (my recommendation; it follows from finding 1's general rule and fixes cause 7 everywhere), or today's 2-minute rule when there was no hello. Also state that "has said hello" is per connection and resets on every reopen, so a switch flipped off at a restart takes clients back to 250 ms and Docs-Seq on their next stream. Test: a POST in flight across a reopen (old stream id) arrives as push and is applied as nothing.

3. §4.3 / question 2 — the Litestream figure is WAL bytes, not replicated bytes; do not add group commit. (Medium: it changes a question put to Paul) The 25 KB per commit is real (the probe divides the WAL file's size by 100 commits; six 4 KB frames). But CARLOS pins Litestream 0.5.15, which ships LTX files: each sync writes one copy of each page changed since the last sync, not every WAL frame. One typist rewrites the same ~6 pages on every commit, so at the default 1 s sync the replica gets about 6 pages a second (~25 KB/s before compression) at 3.5 commits/s and at 6. Compaction levels shrink it again, and batched/daily routes send far less. So the extra cost of sending at once is local: ~60 KB/s more WAL writes and more checkpoint work per typist, no extra S3 traffic to speak of. This comes from how LTX sync works, not from a measurement here.

  • Do not require server-side coalescing of commits: it buys back almost nothing on the replica and costs the latency this spec removes.
  • Do require one measurement in 1b's done list: replica bytes per minute of typing (LTX files of a local file replica on 0.5.15, 1 s sync), today's pacing against the 50 ms floor. If they match, withdraw question 2.
  • Optional, for later and with its own review: six pages per keystroke is also SQLite CPU (~25% of the profile). The documents.updated_at and suite-feed bumps are about half of them, but ApplyUpdate owns the invariant that every content write bumps updated_at, and a throttle needs a trailing bump with no timer. Not for this spec.
  • The log growth figure (3.9 MB per hour of typing against 2.3) is right and still fine with compaction deferred.

4. §3.5 rules 6–7 / §6 — "holds plaintext only while the document is being written" is not true as specified. (Medium-low) Eviction is swept only by a POST. One person types, stops, and leaves a visible tab: no further POST, the stream keeps the instance awake for up to 8 h, and the handle (plaintext, up to 128 MB in all) stays resident that long. The process holds the content key anyway, so the exposure is small, but the sentence is wrong and the memory is held. Fix: also sweep from the stream loop's heartbeat (a timer inside a live connection, which the no-timer rule allows). With no stream and no POST the instance hibernates within 15 minutes and the memory goes with it. Also say a single handle above the byte cap is not kept (cold path every time).

5. §3.5 rule 4 — order of the re-seed POST is ambiguous. (Low) "Write the snapshot … before applying the update, then drop the handle" reads as if the POST's own update has no handle to be applied to. State the order: snapshot from the warm state at the handle's seq, Apply, commit, then drop. And state that a failed snapshot write (non-team: logged, not fatal) keeps the handle, with rule 2 as the backstop at 4,096.

6. §9.2 / §9.3 — two gate details. (Low-medium)

  • §9.2 "more than the baseline's own spread" is not a number, and a quiet run has almost no spread. Make it concrete: push's server-added p50 ≤ the fetch path's in the same process (push removes a request, so it must not be slower), best of three.
  • §9.3 refuses to record above load = core count. Every run in this spec was at load 10–970 on this Mac, so as written the release step cannot be run here. Say where it runs or how a quiet window is obtained. "Could not record" must block the release, not pass it.

7. §3.1 — small protocol gaps. (Low)

  • A push stream with neither since nor Last-Event-ID starts at the current seq and sends nothing. The connect-time update it replaces is called load-bearing in stream.go. Say the client fetches when hello's seq is above its cursor and no frame covers it, or make since mandatory with push=1.
  • hello's seq catches a restored log only until new commits pass the client's cursor (restore to 90, twenty commits, a client at 100 sees 110 and skips the new 91–100). Today's protocol has the same hole and Litestream's loss window makes it possible. A log identity in hello (random per database, a mismatch means resync) closes it cheaply. Take it now or record it as known.

8. §10 — the 1b re-run should include team mode. (Low) The prototype ran sealed rows on a single-user instance. Production is moving to team mode, where every flush runs guard.check() instead of nativeStreamAllowed. Add a team-mode run to 1b's fan-out measurement before deciding on the frame cache or on throttling the authorisation re-check.

The 8-hour rule against CARLOS hibernation

Checked in carlos/platform internal/activator: an instance hibernates only when nothing is in flight and 15 minutes (CARLOS_HIBERNATE_IDLE) have passed since the last request finished. An open stream is in flight. So:

  • Today a visible untouched tab releases its instance after 2 minutes + 15. Under §3.6 it holds it for up to 8 h + 15 min after the last touch. A tab left open on Friday evening lets the instance sleep early on Saturday, so the Friday-to-Monday rule holds.
  • A closed lid or dead connection does not hold it: the client never reopens, and the server's 5-minute TTL remains the hard bound. Keep the TTL at 5 minutes for that reason. bye plus reopen is right; a longer TTL would not be.
  • The exposed case is an awake machine with a visible tab (Safari reports a covered window as visible), which holds one resident process per app per team through the working day and 8 hours past it. That is a memory cost on the box, not a correctness problem.
  • The 8 h clock must reset on local activity only (or on real frames, which mean POSTs are keeping the instance awake anyway), never on heartbeats.

8 hours is defensible. 2 hours would fix Paul's complaint as well and halve the awake time. It is his call (question 1); nothing in the design depends on the value.

Edge snippet

edge-timing.js is safe to hand to Paul: same-origin only, a second stream, three empty fetches and three 00 00 POSTs. Today's server sends a connect-time update, so the baseline run resolves without hello. It opens push=1 without since, which is fine for timing.

For Paul

  • Question 1 (8 h): fine as proposed, or 2 h; see above.
  • Question 2 (WAL): my answer is no coalescing. Confirm with one replica-bytes measurement in 1b (finding 3); I expect the question to go away.
  • Run the edge snippet now for the baseline.

Revision 3: spec/live-push d3c00c7. All eight re-review findings applied, as spec edits only. The mapping table is at the end of the spec.

  1. Team streams end at the lease deadline. Added bye lease. General rule: a visible tab inside its bound reopens with since after any end of the stream; bye only picks the delay (ttl/lease at once, drain 1–5 s jittered, none 1 s). Before reopening, the tab fetches ?since= to see the status EventSource hides, and stops on 401/403/404. Other failures back off exponentially with jitter, capped at 60 s. Lease close added to §9.1. (§3.1, §3.6)
  2. Non-push streams. The same rule applies there: the TTL close arrives as an error and the tab reopens after 1 s, so cause 7 is fixed everywhere. Only frames and the 50 ms floor depend on hello. "Has said hello" is per connection and resets on every reopen. Test added: a POST in flight across a reopen arrives as push and is applied as nothing. (§3.3, §3.6, §9.1)
  3. WAL bytes. §4.3 now says the ~25 KB per commit is local WAL (about 60 KB/s more per typist). Replicated bytes should not grow with commit rate. That is the review's LTX reasoning, attributed and not re-verified. Note: carlos/platform main 631f2258 pins Litestream v0.5.14, not 0.5.15. No commit coalescing. Replica bytes per minute of typing is now in 1b's done list, and question 2 is withdrawn pending that measurement. (§4.3, §10, §12)
  4. Warm-handle eviction. Also swept by every open stream's 15 s heartbeat (a timer inside a live connection), so a handle is dropped within about 75 s of its last write. One handle over the byte cap is not kept. §6 now says "decrypted state for up to ~75 s after the last write, dropped at once on access or sealing change". (§3.5 rules 5 and 7, §6)
  5. Re-seed order. Snapshot from the warm state, Apply, commit, drop. A failed snapshot keeps the handle, with the 4,096 cap as the backstop. (§3.5 rule 4)
  6. Gates. §9.2: push's server-added p50 must be ≤ the fetch path's, in the same process, best of three; it fails and never skips. §9.3: today's path and push interleaved three times each, load recorded but no load ceiling. A run that can't complete or be recorded blocks the release. (§9.2, §9.3)
  7. Protocol gaps. - A push stream without since/Last-Event-ID still sends the connect-time update. - hello carries a log epoch (also sent as Docs-Log-Epoch on fetch responses). It is random per instance database and rotated by any operation that rewinds a log, and at any start that didn't find the process's own clean-shutdown marker. So restore, box move and crash rotate it (one resync per open client); a clean deploy does not.

(§3.1, §9.1)

  1. Team mode in 1b. The fan-out re-run includes team mode before the frame-cache and authz-throttle decisions. (§10)

The 8 h untouched-visible-tab bound stays as the default, marked as Paul's call (question 1), with your note that 2 h fixes his complaint equally. I also wrote the 8 h clock rule from your hibernation analysis into §3.6: it resets on activity or frames, never on heartbeats, and the 5 min TTL stays.

Landed on main (squash) at r3 d3c00c7. Next: plan + slices 0 and 1a (warm handle) on their own branch.