Whole-branch review — Claude Fable 5.1, for session 21a32889
Branch fix/safari-save-stall at 617149c, read as one diff against origin/main (ce485a5; merge base 29b6dea). Scratch worktree under /tmp, removed afterwards.
Verdict: needs changes. One P1 (a regression that loses queued edits on tab close, measured, small fix), the rest P2. Everything the branch claims checked out.
What I verified myself
- Root cause reproduced, independently of the branch's harnesses. My own page (Node server + Playwright + a WKWebView harness) clicks a link the server never answers, then probes. Playwright WebKit and WKWebView: plain
fetchand XHR rejected in 0–1 ms ("Load failed", "xhr error"), nothing reaches the server;fetch(keepalive)(100 B and 32 KiB) andsendBeaconare sent and answered 204; a later plain fetch is still refused. Chromium sends all six. Exactly as described. - Gate:
TMPDIR=/tmp GOTOOLCHAIN=go1.26.5 .amadan/ci.d/10-gateexit 0 locally;amadan ci statuspassed at 617149c. - Browser test
TestSavingContinuesWhileALinkIsLoading(RASTRILLO_CHROME = Playwright's Chrome for Testing 1234, node 24) passes: Playwright chromium + webkit, WKWebView held-link and back. - Seen to fail, for the right reason. With
keepalive: falseand the bundle rebuilt: Playwright webkit and WKWebView held-link fail withno save reached the server … states [retrying]and the three words missing from the document; chromium passes as the control; the unit testa save is sent keepalive…reddens. Withapp.Drain()removed:TestStoppingWithAnEditorOpenExitsAtOncefails withexited 1 after 10.075s. (First mutant Playwright run took 91 s on the loaded machine; the re-run took 46 s with the same result.) - Idempotency (2b):
core/src/lib.rsapply_updateis yrs'stxn.apply_update, which integrates structs it already holds as nothing and returns Ok, so a re-sent batch is never a 400;Store.ApplyUpdatethen persists it as one more row (handlers.go already relies on this for the updated_at case). Ordering is preserved because one batch is on the wire and a given-up batch goes back to the front. The client'snoteOwnSeqadopts onlycursor+1, so the gap a duplicate row creates costs one fetch, not a skipped row. A late answer for a given-up batch is ignored (inFlight !== batch). Fine. - Give-up timing under a slow success (2c): the fetch's own
AbortSignal.timeoutfires 5 s before the give-up timer, so the promise rejects first and the batch is retried as a real failure; if the server had already persisted it the retry is a duplicate row. The give-up timer only does work when the promise never settles (the bfcache case), andresume()usually gets there first. Correct. - Drain (5): both
signal.Notifychannels receive SIGTERM;Draincloseshub.done, streams return,net/http.Shutdownfinishes. In-flight POSTs are not touched by the drain and complete under Shutdown (not re-sent). New streams get 503;live-updates.mjscloses the EventSource onerror, so no native reconnect loop against a restarting instance. Saves during the restart gap get a real connection failure →retryingis honest there. - #90 and dadf9c1 (6):
git merge-treeof #90 onto this branch, and of this branch onto main, are both clean. #90 touches no queue API this branch changes;resume()on a diverged page only re-sends what the retry timer would have. The pageshow resend runs synchronously insidepageshow; the back scenario shows WebKit sends it (unlike a stream opened there, which live-updates defers a task for). Reminder only: #90 and this branch each deleteeditor.7ff107f6ce88eea0.jsand add their own bundle, so a textual merge leaves two andassets.gopanics — whoever lands second rebuilds, per AGENTS.md. - No rebase needed: main's drift since 29b6dea is native/, internal/contract, export/pdf, fonts.go and show.html; nothing this branch touches.
Findings
P1 — the unload beacon now loses queued edits whenever a keepalive save is in flight at close (fixtures/editor-entry.js ~1191–1226 with save-queue.mjs pendingBytes). The 64 KiB keepalive quota is shared between fetch(keepalive) and sendBeacon in all three engines — measured: with a 32 KiB keepalive POST held by the server, sendBeacon(40 KiB) returns false and fetch(33 KiB, keepalive) rejects immediately with the same TypeError a network failure gives, in Chromium, Playwright WebKit and WKWebView. The save-queue comment assumes the batch cap "leaves the rest for the beacon", but beforeunload beacons pendingBytes(), which merges the in-flight batch again plus the queue. So with K bytes in flight the beacon needs K + (K + Q) ≤ 64 KiB; at K = 32 KiB any queued byte is refused, and the fallback fetch(keepalive) is refused by the same quota. On main the in-flight save was a plain fetch, uncounted (and cancelled by the unload), so K + Q ≤ 64 KiB went through. Measured end to end in Playwright Chromium and WebKit: in-flight 32 KiB save held 3 s, then navigate away with a 33 KiB beacon from beforeunload — plain in-flight (main): beacon arrives; keepalive in-flight (branch): neither the beacon nor the keepalive fallback arrives, while a 1 KiB queue-only beacon from the same handler does. The in-flight keepalive itself survives the unload, so K is safe; Q is lost. Window: a batch ≥ ~16 KiB on the wire (a paste, or the first batch after a retry backlog, on a slow link for up to its 30 s timeout) and edits queued behind it at close. Narrow, but Paul's rule puts a lost edit above everything, and the fix is small: when the in-flight batch went keepalive, beacon only the queue and unsaved (it is already on the wire and will land); and when the merged beacon is refused, retry with the queue-only payload before the keepalive fetch fallback. Expose that from the queue (e.g. pendingBytes({ onWire: false }) or an inFlightKeepalive getter) and add a unit case plus a browser case (server holds a 32 KiB save, type, close, queued text must be on the server). Note Chromium refused a lone 64 KiB keepalive in my probe, so even 32 KiB + 32 KiB is over its line; worth keeping the beacon payload well under the half.
P2 — a quick return from bfcache can show "Trouble saving" with no real failure. Same quota: leaving beacons K + Q beside the in-flight K; if the person comes straight back, resume() sends K + Q again while those may still be counted → immediate TypeError → answered(null) → retrying, retried fine 250 ms later. Needs a return within the requests' lifetime, so rare; the P1 fix (queue-only beacon) shrinks it, and a tiny delay or a single silent retry in resume() would close it.
P2 — the >32 KiB residual. As shipped, a single update over 32 KiB during a pending WebKit navigation reproduces the original symptom exactly (refused four times a second, "Retrying…"), though nothing is lost: it is retried, and a reload beacons it if ≤ 64 KiB. Two ways to narrow it without a chunking protocol: (a) stop the false message — when an ordinary post rejects, fire a tiny keepalive probe (HEAD /healthz) before reporting; if the probe answers, the network is up and the browser refused the request, so stay saving and retry quietly until the navigation settles; report retrying only when the probe fails too. That keeps "Trouble saving means a request failed" true everywhere. (b) raise the ceiling — gzip the body with CompressionStream (Safari 16.4+) under Content-Encoding: gzip, with updatesPost gunzipping behind the existing MaxBytesReader (limit the decompressed reader too); pasted text compresses 3–5×, so most pastes fit a keepalive request. Splitting a Yjs update client-side is possible only through yjs internals; I would not. Not blocking; say which, or record it as a known limit in AGENTS.md.
P2 — AGENTS.md. The branch records the keepalive rule and the drain in code comments and here, but not in AGENTS.md, which carries every other ruling of this kind (and still names fixtures/build-editor.mjs where the gate runs build-bundles.mjs). Two lines under "Conventions that are already settled": saves are keepalive and ≤ 32 KiB and why; Docs drains its streams on SIGTERM and why.
P2 — Slides. The same two bugs are named in this discussion; file the tasks so they are a checklist, not a paragraph.
Nits: send() packs by the sum of update sizes, and saveRequest quietly drops keepalive if the merged batch comes out over 32 KiB — fine in practice, worth a word in the comment. The four de-flaked queue tests are a real improvement (until with a 5 s ceiling and a 30 ms grace).
Verdict
Needs changes for the P1 only; it is a few lines plus a test. With that in, and the bundle rebuilt on top of whatever lands first (#90 or this), ready to merge. Reviewed as session 21a32889's whole-branch review per AGENTS.md.