Whole-branch review: Claude Fable (model id claude-fable-5-2), 7a4972d on bde01ef
Verdict: CHANGES NEEDED
One finding breaks the slice's central invariant (the snapshot can persist state that was never committed). The fix is a few lines. Everything else is small. Don't canary with DOCS_WARM_HANDLE=on until finding 1 is fixed; with the switch off the branch is safe to carry.
Read with git diff bde01ef 7a4972d in a review-only worktree (removed). Findings 1–3 were each reproduced with a throwaway test there, not only read.
Findings
1. A rejected update can be half-applied to the kept handle, and the next snapshot persists it. HIGH. warm.go:278-282 (rule 2).
- The rule "a clean
RejectedErrorleaves the handle as it was" is not true forERR_APPLY(-3). yrs integrates an update's structs one at a time (native/vendor/yrs-0.23.5/src/update.rs,item.repair(store)?inside the loop); a later struct failing withInvalidParentreturns the error after the earlier structs are in the store, andcore/src/lib.rs:132drops the transaction, which commits them. - The cold path never noticed because it threw the handle away. The warm path keeps it.
- Reproduced: a 27-byte update (struct 1 a string under a named root, struct 2 with that string item as its parent) answers 400 with
apply rejected the update: code -3. The warm handle then holds struct 1's text. After 256 more ordinary POSTs thedoc_snapshotsrow at seq 256 contains it, and so does every later replay. Nodoc_updatesrow holds it. - Effect: any writer can put content into the document that no client ever receives over
?since=, and that appears for whoever loads the page after the next snapshot. Server state and open editors disagree permanently. - Fix: drop the handle on any error from
Apply(a rejection then costs one replay on the next POST), or keep it only forERR_DECODE. Add the crafted update toTestWarmHandleSurvivesARejectedUpdateand to the property test, whose "garbage" case is decode-only today. The spec's rule 2 wording andcore.go's "leaves the instance untouched" comment need the same correction.
2. A panic between Apply and commit keeps an uncommitted handle. MEDIUM. warm.go:245 (defer release), warm.go:289.
releaseruns on a panic too, and nothing marks the handle as applied-but-uncommitted.net/httprecovers the panic, the process lives, and the next POST findsMAX(seq) == e.seqand keeps using it.- Reproduced with a panic in the commit seam: entry kept at seq 1, warm state
word1 word2, logword1. - Fix: set a flag on the entry before
warmApplyand clear it only after a successful commit;releasecloses a flagged handle. That also covers every future early return.
3. An entry evicted while a POST is between acquire's two locks becomes an orphan that is never closed. MEDIUM/LOW. warm.go:105-120, warm.go:124-142.
acquirereads the entry underc.mu, unlocks, then takese.mu. In that gapdrop(grant, revoke, visibility, delete) or a cap eviction can remove the entry andTryLocksucceeds, sodeadis not set. The POST then replays into the removed entry, andreleaseonly handlesdead,closedand the byte cap, so it marks it kept without it being in the map.- Reproduced by stepping the interleaving by hand: cache reports 0 handles, the entry is not in the map, and the wasm instance is still open. Nothing sweeps, caps or drops it again; the runtime holds the instance until the process ends.
- This is rule 6's own case (decrypted state outliving a revoke), and it is outside the 128 MB cap. The window is microseconds, so it is rare, not impossible. It never serves a later POST, so it is a leak, not a divergence.
- Fix: in
release, close whenc.entries[e.docID] != e.
4. Tests: no concurrency, no team mode, no sealed rows. MEDIUM. warm_test.go.
- Every warm test is single-goroutine. Rule 1 (the per-document lock),
dead, andTryLockeviction are not exercised. I ran 8 goroutines × 400 POSTs with interleaved drops and sweeps under-race: clean, and log, cold replay and warm handle agreed. That test should be in the branch. - The fixture is a local actor with sealing off (
content sealing not activatedin every run), so the team-mode snapshot branch (warm.go:263-269) and sealed rows are covered only by the hand-run probe. - The hub gate builds with
CGO_ENABLED=0, so nothing in CI runs-raceon this code.
5. Rule 6 is narrower than the spec. LOW. warm.go header, team_access.go:219.
- Spec §3.5 rule 6 lists restore and team state. Restore does not exist yet; team roster changes arrive from outside and drop nothing. Permission is still checked on every POST and in the transaction, so this is retention only (until 60 s idle), not access. The same holds for a grant changed by a second process during a deploy overlap.
- Say so in the header, and leave a note at the place version restore will be written: it must drop the handle, since a restore that rewrites rows could leave
MAX(seq)equal.
6. Entries without a handle count toward the 64 cap. LOW. warm.go:176-193.
- After a re-seed, a failed replay or a rule 3 drop, the entry stays in the map with no handle until it idles out, and
capLockedcounts it. Under many active documents it can evict a real handle early. Delete the entry inreleasewhene.h == nil.
7. A client that disconnects mid-Apply logs the rule 2 warning. LOW. warm.go:284.
- A cancelled request context makes
Applyreturn aRecoveredError, sodocs: warm handle dropped, replayingfires and the cold retry then fails on the same context. Correct, but the canary instruction says that line should be rare; skip the log and the retry whenctx.Err() != nil.
Checked and found sound
- Log writers: only
commitUpdate, import (import.go:234, seq 1 of a new document) and the offline content migration writedoc_updates. No path deletes rows, and deletion is soft, so ids are not reused.boundTois the only Store copy left. - Staleness check:
MAX(seq)is read in the same single-writer transaction as the insert. A second store, the agent paths and a failed or cancelled commit all end in a drop. The seq advances only after commit. - Snapshot placement: written at the handle's seq before the new update is applied, as the cold path does. Apart from findings 1 and 2 the handle holds exactly rows ≤
e.seq. - Uncommitted state to clients: nothing in 1a sends from the handle; readers and
?since=still replay from the database. - Locking:
c.muonly everTryLocks an entry, so there is no lock-order deadlock. Drain and Close setclosed; an in-flight POST closes its own handle on release. - Off path:
applyColdis the old body with the transaction moved intocommitUpdate; the added calls are nil-safe no-ops. Unset means off; a bad value refuses to start. - Retention: an unauthorised POST is refused before
acquire, so it cannot keep a handle fresh. With no stream and no POST a handle lives until hibernation, as rule 7 says.
Gate
go vet ./...andgo vet -tags browser ./...: clean.go test -count=1oninternal/docs,internal/core,cmd/...: pass. Warm tests under-race: pass.internal/shippedfails on Homebrew's Go 1.27.3 (noLICENSEin its tree) and passes withGOTOOLCHAIN=go1.26.5. Not this branch.- Timing gate: relative, about 7× margin, fine.