Live push: the slice plan
Slices 0, 1a, 1b, 2 and 3 of spec 2026-11-26-live-push-design.md (revision 3, main bde01ef; #172), with each slice's work, tests and done list from spec §9 and §10.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+194
−0
docs/superpowers/plans/2026-11-26-live-push.md+194 −0
diff --git a/docs/superpowers/plans/2026-11-26-live-push.md b/docs/superpowers/plans/2026-11-26-live-push.md| new file mode 100644 |
| index 0000000..4e7e141 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-11-26-live-push.md |
| @@ -0,0 +1,194 @@ |
| +# Live push: slice plan |
| + |
| +Spec: `../specs/2026-11-26-live-push-design.md` (revision 3, on main bde01ef; |
| +reviewed by Claude Fable 5.2 on oficina/docs #172, APPROVE AFTER FIXES, |
| +fixes applied, no further round). |
| + |
| +**Status:** revision 1, 2026-11-26. Paul: "Let's go". |
| + |
| +**Ground rules for every slice:** |
| +- One worktree and branch per slice, a branch discussion, and a whole-branch |
| + review by the highest available model before the squash merge. |
| +- Hub CI exits 0 before the merge. The Swift and browser checks the hub does |
| + not run are run locally and recorded in the slice's discussion. |
| +- Server slices deploy server-first through the coordinator's canary. Each is |
| + behind its switch (spec §8), so switching it off returns every client to |
| + today's path without a release. |
| +- Each new test was seen to fail for the intended reason (AGENTS.md: break |
| + the rule it holds, watch it go red, read why). |
| +- Measurements are labelled measured or projected. Each slice's numbers go in |
| + its discussion, with the raw summaries under |
| + `native/benchmarks/live-push/results-<date>/`. |
| + |
| +**Order:** 0 → 1a → 1b → 2 → 3. Slices 0 and 1a can share a branch (they |
| +touch different code, and 0 is a test fix). 1b waits for 1a to be proven on |
| +production. 2 waits for 1b's done list (§1b below, the edge check first). |
| +3 waits for 1b to be live. |
| + |
| +## Slice 0: restore the native end-to-end probe |
| + |
| +Branch `feat/live-push-1a` (with 1a). Spec §10 slice 0. |
| + |
| +**Work:** `RealtimeAuditE2ETests` observes `projectionGeneration`, not |
| +`projection`. Since S1a, `projection` is `@ObservationIgnored`, so |
| +`testEndToEndRemoteUpdates` saw no publication and reported n=0. |
| + |
| +**Done when:** `run-e2e.py <p1|p20> testEndToEndRemoteUpdates` reports a |
| +"peer POST start -> visible" median with n equal to the updates posted, at |
| +1 and 20 pages. |
| + |
| +## Slice 1a: the warm handle (server) |
| + |
| +Branch `feat/live-push-1a`. Spec §3.5 rules 1–8, §8 `DOCS_WARM_HANDLE`. |
| + |
| +**Work:** |
| +1. `internal/core`: `Handle.RetainedUpdates()` and `Handle.ResidentBytes()` |
| + (linear memory plus retained updates). |
| +2. `internal/docs/warm.go`: the cache and `applyWarm`. |
| + - **Cache:** a per-document lock; LRU by count (64) and bytes (128 MB); |
| + one handle over the byte cap is not kept; idle 60 s. |
| + - **Sweep:** by every POST and every stream heartbeat; no timers of its |
| + own. |
| + - **Drop:** on `close` (drain and app close). |
| + - **Rules:** rule 2 (clean rejection keeps the handle; anything else |
| + replays cold in the same POST), rule 3 (drop on any failure after |
| + Apply; seq advances after commit; a `MAX(seq)` mismatch drops), rule 4 |
| + (snapshot at the handle's seq, Apply, commit, drop). |
| +3. `Store.ApplyUpdate`: split into `applyCold` (unchanged behaviour) and |
| + `commitUpdate` (the one transaction, returning `MAX(seq)` before the |
| + insert), with `applyWarm` in front when the switch is on. |
| +4. Rule 6 drops: `ownerMutation` (grants, revoke, visibility), |
| + `ownerDeletion`, `deleteDocument`. Sealing is activated offline, with the |
| + app stopped. |
| +5. The agent paths' transaction-bound Store copies (`boundTo`) never use warm |
| + handles. Their commit is a savepoint the caller can still roll back. |
| +6. `$DOCS_WARM_HANDLE` (on/off; unset is off; anything else refuses to |
| + start) in `cmd/docs`, as `Config.WarmHandle`. **Default off** until 1a is |
| + proven on production (spec §8). A follow-up commit makes it on by default |
| + after the canary. |
| + |
| +**Tests (CI):** |
| +- More than 4,096 POSTs to one warm document, none refused, retained updates |
| + ≤ cadence + 2. |
| +- Re-seed order and the next POST's replay from the new snapshot. |
| +- A writer revoked between Apply and commit: the POST fails, the handle is |
| + dropped, and the next snapshot equals a raw replay of the rows it covers. |
| +- Cold fallback on `ErrUpdateLogFull` and on a trap; a clean rejection keeps |
| + the handle. |
| +- Property test (8 seeds × 60 steps): POSTs, failed commits, cancelled |
| + contexts, injected traps, rejections, drops, and commits by another Store |
| + on the same database. The log always holds exactly the committed updates, |
| + and a warm handle after its own POST equals a raw replay. |
| +- Count and byte caps, LRU order, one over-cap handle not kept. |
| +- Drops on grant, revoke, visibility, delete and drain. |
| +- Heartbeat sweep (fake clock, a real stream). |
| +- `boundTo` has no cache. The switch parses as specified and defaults off. |
| +- **Relative timing gate:** a warm POST is faster than a replayed one on a |
| + ~20-page document, same process, best of three medians. |
| + |
| +**Measurements (local, this branch):** `run-probe.py` with `WARM=0`/`1`, |
| +sealed rows, 1 and 20 pages: |
| +- 1 typist; 5 typists in their own documents; 5 typists + 5 watchers in one |
| + document; 20 typists; |
| +- today's pacing (`native250`, `web250`) and sending at once (`idle50`, for |
| + headroom); |
| +- three repetitions at 20 pages; |
| +- latency at 50 ms RTT; |
| +- warm-handle memory (`TestLivePushProbeWarmMemory`). |
| + |
| +**Done when:** hub CI green; Fable branch review; canary with |
| +`DOCS_WARM_HANDLE=on`. Then re-run `load-p1`/`load-p20` and the 5 + 5 shared |
| +document against production-like settings, and flip the default on. |
| + |
| +## Slice 1b: push (server) |
| + |
| +Branch `feat/live-push-1b`. Spec §3.1, §3.2 (server side), §3.4, §3.6 |
| +(`bye`), §5, §8 `DOCS_LIVE_PUSH`. |
| + |
| +**Work:** |
| +1. **Stream frames.** On `push=1`, `stream.go` sends: |
| + - `hello <stream id> <current seq> <log epoch>`, then rows after |
| + `Last-Event-ID` or `since` as `push`, `own` or `update`; |
| + - without either, today's connect-time `update`. |
| + |
| + Rows are read with `updatesGet`'s query and `openContentUpdate`. Over |
| + 32 KiB, unreadable, or more than 256 rows / 512 KiB behind becomes |
| + `update`, and `sent` moves. There is no `id:` on `update`. |
| +2. **`Docs-Stream: <id>.<counter>`** on POST. |
| + - The stream id is bound to the session that opened it; a header from |
| + another session is ignored. |
| + - `commitUpdate` records `(doc, seq) → (stream, counter, SHA-256)` inside |
| + the transaction, in the hub's per-document registry (last 64). |
| + - The stream writes `own` only on a matching id and hash. |
| +3. **Log epoch:** a random value in the database. It is rotated by log |
| + rewinds and at a start without the clean-shutdown marker (written at the |
| + end of a clean drain). It is sent as `Docs-Log-Epoch` on fetch responses. |
| +4. **`bye ttl | lease | drain`** before those closes. |
| +5. **Late answers** (spec §5): |
| + - more than 30 updates/s per session per document is delayed, before the |
| + lock or the writer; |
| + - delay at most 1 s, ended by cancel or drain; |
| + - at most 2 waiting per session, beyond that `503` with `Retry-After: 1`. |
| +6. **Frame cache measurement:** each seq read and unsealed once for all |
| + streams, measured on and off. |
| +7. `$DOCS_LIVE_PUSH`: off ignores `push=1`. |
| + |
| +**Tests (CI):** spec §9.1's Go list; the §9.2 timing gate (push's |
| +server-added p50 ≤ the fetch path's, best of three). |
| + |
| +**Done when** (spec §10): |
| +- hub CI green, Fable review, canary; |
| +- **Paul's edge check** (`edge-timing.js`) run on production; |
| +- the 5 + 5 shared-document fan-out re-run **in team mode too**, deciding |
| + the frame cache and any authorisation-check throttle; |
| +- **replica bytes per minute of typing** measured on CARLOS' Litestream |
| + version (today's pacing against the 50 ms floor), withdrawing or reopening |
| + question 2. |
| + |
| +## Slice 2: web |
| + |
| +Branch `feat/live-push-web`. Spec §3.2, §3.3, §3.6, §3.7 (web). |
| + |
| +**Work:** |
| +1. **`live-updates.mjs`:** |
| + - `push=1&since=<cursor>`; |
| + - frame handling with §3.2's queue rules; |
| + - `own` adoption by counter; |
| + - the epoch check; |
| + - §3.6's visible-tab rule: 8 h since local activity or frames; reopen |
| + after any end (`bye` choosing the delay); fetch first; stop on |
| + 401/403/404; backoff capped at 60 s; the same on non-push streams. |
| +2. **`save-queue.mjs`:** the leading-edge send with the 50 ms floor, |
| + switched on by `hello` per connection; 250 ms on `saveData` or cellular. |
| +3. **`editor-entry.js`:** wire it; `Docs-Stream` on saves. |
| +4. Rebuild the bundle (AGENTS.md: the bundle is never merged by hand). |
| + |
| +**Tests:** spec §9.1's JS list with fake clocks; `scripts/browser-drive.sh`; |
| +the release step (§9.3) with real browsers at 0 and 50 ms. |
| + |
| +**Done when:** 1b's done list is complete (edge check first); review; |
| +deployed with a server deploy. |
| + |
| +## Slice 3: native |
| + |
| +Branch `feat/live-push-native`. Spec §3.2–§3.4, §3.7, §3.8 (native). |
| +Independent of S1b. |
| + |
| +**Work:** |
| +1. **`DocsModel.listen`:** `push=1&since=`, the frame handling and queue |
| + rules, `own` adoption, the epoch check. |
| +2. **Apply frames as `refresh` does,** without its GET. Coalesce queued |
| + frames into one `apply`. |
| +3. **`DocsOfflineAccount`:** |
| + - stream-id registration per lane; |
| + - `Docs-Stream` only when the open model holds the whole batch; |
| + - `sendInterval` 50 ms after `hello` (250 ms on `isExpensive` or |
| + `isConstrained`); |
| + - `pace` stops holding the drainer when the lane is non-empty. |
| + |
| +**Tests:** spec §9.1's Swift list (fake clock); `RealtimeSyncTests`; |
| +`run-e2e.py` (slice 0); `run-clients.sh`. |
| + |
| +**Done when:** review; a native release (Mac and TestFlight) after 1b is |
| +live, with Paul's go-ahead; the release step (§9.3), with today's path and |
| +push interleaved and recorded. |