Whole-branch review of feat/live-push-1b at 2a97f52 (on main 2370192): Claude Fable, model claude-fable-5-2.
Verdict: APPROVE AFTER FIXES
Findings 1 and 2 should be fixed before merge. Findings 3 and 4 should be closed before DOCS_LIVE_PUSH=on on any instance that matters. The rest are notes.
Read from a review-only worktree (now removed). I ran two throwaway probes there for findings 1 and 2 and nothing else; hub CI is the record for the suite.
What holds
- Authorisation on the stream. - Every byte leaves through
write(stream.go:180), which re-runs the full admission chain plusGetFor(single mode) orguard.checkwithcheckPermission(read)(team mode) after the rows are read and immediately before they are written. - Revoke, visibility change, sign-out and delete (deleted_at IS NULLinGetFor) all end the stream at the next write with no frame sent. - A reader gets frames and its POST is refused inApplyUpdate, as before. - Frame cache. Keyed by document id inside one process, read only by a stream already opened on that document, and its output still passes
write's check. I found no path that serves a row across documents or to a session that fails the check. Sealed rows are opened by the sameopenContentUpdatethe fetch uses. - Ordering. Seqs are gapless from the single-writer transaction.
rowsAfterbounds by aMAX(seq)read first, so a missed or coalesced hub notification only delays rows. The cache path is used only when every seq in the range is present. own. It needs the server-issued 128-bit stream id, the same session binding, the same document, and a hash match on the row's bytes, and it is only ever written to that one stream. A client cannot make a peer skip a row. A rolled-back transaction's stale entry can only match byte-identical content.- Switch off.
pushis false,recordOriginis nil, and the header and limiter are gated: the stream and POST paths are today's. The one thing that runs regardless isloadLogEpochat startup (migration 0013 and the sidecar file), so startup now needs the database's directory to be writable. - Old clients, switch on. No
hello, integerupdatedata, noid:. They do get the late-answer limit and theDocs-Log-Epochheader. - Epoch write order (database first, then file) fails towards rotation on a crash between the two, which is the safe direction.
Findings
- Medium: the late-answer limiter is keyed on raw request cookies, so one appended cookie bypasses it.
push.go:50-69, used athandlers.go:1056. -sessionBindinghashes every cookie namedrastrillo_sessionor__Host-rastrillo_session. Authentication reads only the first. - Probe: 45 POSTs from one real session in 100 ms, each with an extrarastrillo_session=junkNappended, all returned 204 under 45 distinct limiter keys. None waited. - Each junk value also adds arecententry. That is bounded only by the 4096 sweep, which scans the whole map under the mutex on every admit once it is over. - Fix: key the limiter and the stream binding on the authenticated session's id (or the actor) from the request context, not on header bytes. -ownis not weakened by this: the stream id is still required.
- Medium: a far-behind stream loads and unseals every row before deciding to send one
update, and the cache keeps rows that can never be pushed.push.go:262-284,push.go:279-281,push.go:302. -rowsAfterreads up to 257 full rows (each up tomaxUpdateBytes, 1 MiB), opens them, and caches them. Only then doespushFramesmeasure the total. - Probe: 20 rows of 33 KiB, then?push=1&since=0. The reply wasupdate 20, after 20 rows (676,800 bytes) were read and opened and all 20 left in the frame cache. None of them is pushable. - Worst case per connect on a paste-heavy document is about 257 MiB transient per stream, and any reader can repeat it. The cache can hold 64 rows of 1 MiB per document, more while a lagging stream is filling it. - Fix: first queryCOUNTandSUM(LENGTH(update_bin))(or selectseq, LENGTH) and take the far-behind exit before loading bytes. Do notcache.putrows overpushMaxRowBytes.
- Medium, before switch-on: the epoch misses the most likely restore.
logepoch.go:23-27. - A Litestream replica is continuous, so a point-in-time restore is nearly always from after the last start. Restored in place, or from a volume snapshot that carries the sidecar along, boot matches and the epoch is kept. - A client at cursor 100 that reconnects after a log restored to 98 has grown past 100 gets rows 101 onwards and silently never sees the new 99 and 100. Thehelloseq check only helps while the log is still behind the cursor. - A code comment saying a runbook can delete the file is not a control. Either the CARLOS restore path removes<db>.log-epoch(tracked on carlos/platform, alongside #1449), or the server rotates on evidence it can check. - Acceptable for merge with the switch off. Not acceptable as the standing answer.
- Confirmed, pre-existing:
roster.Lease.Remaining()returns 0 on lock contention.home/rostercache.go:117-131. - It usesc.mu.TryLock()and returns 0 when it fails.Cache.Checktakes the same mutex withLockon every request's admission, so concurrent editing contends. - It is worse than transient:teammode.Access.Remaining(access.go:73-76) latchesuncertainon a 0. One lostTryLockpermanently ends that stream's lease, andteamStreamGuard.check(team_stream.go:36,:58) fails from then on. - There is a fail-open twin at open.stream.go:109: ifa.Remaining()loses theTryLockthere,guard.deadlinestays zero, and the guard treats the stream as resting on no lease. No lease timer and nobye lease; only the per-write checks remain. - This branch does not change it. It needs a fix in roster (anRLockor an atomic snapshot) before push is switched on for a team.
- Low: a cursor ahead of the log is accepted silently.
stream.go:146-160. WithsinceorLast-Event-IDabovecurrent,sentstays high and rows at or below it are never framed. The server relies entirely on the client comparinghello's seq. Consider ending such a stream afterhellowith abye, or at least add a test that pins the behaviour.
- Low: two near-simultaneous starts can rotate the epoch.
logepoch.go:63-99. Process B reads the database after A'sSavebut before A's rename, sees boot n+1 against a file saying n, and rotates. The result is one spurious resync. Wrapping the read, compare and bump in one write transaction closes it.
- Low: the revocation test is weaker than its name.
push_test.go:512-520. Any non-pushframe satisfies the select, so it does not prove the stream closed. There is no test for delete, sign-out, visibility change or a team roster change mid-stream, and none where the revoked stream would be served from the cache (a second stream warming it). The code is right on these paths; the tests would not catch a regression.
- Note: timing gate.
TestPushIsFasterThanTheFetchPathis relative and best of three, with about 10 ms of margin on a 20 ms round trip. It also matches the race step'sPushpattern. That is fine while it stays green; if it flakes under-race, exclude it there rather than loosen it.
- Note: frame cache. Keeping it is reasonable once finding 2 is fixed. With CPU flat, the per-flush admission chain in
writeis the likely fan-out cost, and it should stay per-write.