oficina / docs Public

Safari: "Trouble saving" with no requests sent, and a 10 s shutdown that exits 1 open

On branch fix/safari-save-stall

What Paul saw

"Trouble saving. Retrying…" in Docs in Safari on docs.oficina.works (29b6dea), cleared by a reload. The edge logged no POSTs from 12:44 to 12:49:41, so the saves never left the browser.

Root cause: WebKit sends no ordinary request while a link the page opened is still loading

While a page's main frame is waiting for a navigation's answer, WebKit rejects every ordinary fetch() and XMLHttpRequest the page starts. The rejection is immediate (TypeError: Load failed) and no request is sent. The page stays on screen and editable the whole time. A navigation answered with a download, or never answered at all, never takes the page away. A reload ends the navigation.

The save queue reads that rejection as a network failure. So it shows "Trouble saving. Retrying…" and retries four times a second, and every retry is refused the same way. That matches all three facts: the message, no POSTs at the edge, and a reload clearing it.

Measured, not inferred:

  • WKWebView, scripted. A link to a URL that never answers: 22 to 30 saves were refused in about 7 s, none reached the server, and the status stayed retrying until stopLoading/reload. Probing during the pending navigation: fetch and XHR are refused; fetch(..., {keepalive: true}) and sendBeacon are sent. The same refusal happens while a navigation's response waits on a policy decision (Safari's "allow downloads on this site?" sheet), and while a navigation to a dead connection is retried and then fails.
  • Playwright, the same page. WebKit: 0 POSTs reached the server, status retrying. Chromium: 6 POSTs reached it and were answered 204. This is WebKit-only.
  • Hypotheses that did not reproduce. A download through the download attribute (Export PDF), a 204, a cancelled or slow navigation policy, mailto:, saves failing while hidden, a server restart with the stream open, and a back/forward-cache round trip all recovered on main.

Which link Paul's tab was waiting on is not provable from the edge's per-minute counts. What is proven is that the outage made such a wait possible. At 12:49:18 the platform stopped Docs, Sheets and Slides together (generations g546→g1, g554→g11, g555→g10). That was not hibernation. Sheets and Slides did not answer again until 12:50:03–04, and Docs not until 12:49:41.

A second stall, found while fixing it

A keepalive save that is answered while its page is in the back/forward cache never settles in WebKit. The queue has one save on the wire, so it then waited forever. In WKWebView: leave with a save in flight, come back, and nothing typed afterwards was ever sent, the fetch's own timeout included. On main, a plain fetch is cancelled as the next page commits, so this did not happen there.

Fix (client)

  • Saves go keepalive, which WebKit still sends then and which also survives leaving the page. Batches are at most 32 KiB, half the browser's 64 KiB keepalive cap, leaving the rest for the unload beacon (saveRequest, maxBatchBytes).
  • The fetch is aborted after 30 s plus 1 s per 8 KB, so a large paste on a slow link is not cut off. The queue gives up on any save left unanswered 5 s after that, and sends again. A late answer is ignored.
  • pageshow with persisted calls queue.resume(), which sends again at once whatever was on the wire as the page left, without saying anything failed.
  • Residual: a single edit larger than 32 KiB (a big paste) still goes as an ordinary request. A pending WebKit navigation can still hold it up, and "Retrying…" then shows without a request having failed.

Fix (server shutdown)

net/http's graceful shutdown cancels no request contexts, so stream.go's "or the server is draining" branch could never fire. An open editor held the shutdown for rastrillo's whole 10 s, and the process then exited 1. That is exactly 12:49:18 → 12:49:28 context deadline exceeded. Sheets and Slides exited 0 in 2 s.

cmd/docs now listens for SIGTERM/SIGINT itself. rastrillo.Serve owns the signal and has no hook, but every signal.Notify channel receives the signal. On the signal it calls app.Drain(), which closes the hub: open streams return and new ones get a 503. The client reopens on its next activity.

Hibernation: its stops today (12:02, 12:14, 12:23, 12:24) exited 0 within 1 s. The 12:49 stop was the platform stopping the box. During a 10 s drain the listener is closed, so saves made then could not reach the instance. The edge recorded no 5xx, and carlos availability shows only the exit. With the fix that window is milliseconds.

Tests (each seen to fail first, for the stated reason)

  • internal/docs/saving_browser_test.go + fixtures/engines/saving.mjs + fixtures/engines/saving-webkit.swift. A link the server holds unanswered, then type: the words must reach the server while the link is held, and the page must never say retrying/failed. Before the fix it failed in Playwright WebKit and WKWebView ("no save reached the server", states [retrying]) and passed in Chromium, the control. The WKWebView back scenario covers the second stall; with the resume removed it fails ("missing \"After\"").
  • cmd/docs/shutdown_test.go builds and runs the real binary, opens a signed-in stream and sends SIGTERM. With the drain disabled it fails: "exited 1 after 10.007s".
  • stream_test.go TestStreamEndsWhenTheAppDrains, and five new save-queue.test.mjs cases (keepalive and timeouts, bounded batches, an oversized update, give-up with a late answer ignored, resume). Each was checked against a mutation.
  • The save queue's four real-timer tests used fixed 40–60 ms sleeps and failed about 1 run in 20 on main too. They now wait for the condition.

Slides has the same bugs (not fixed here)

  • fixtures/editor-entry.js makeSaveQueue posts with a plain fetch, so WebKit refuses it during a pending navigation in the same way. Slides' save-queue.mjs has no keepalive, timeout or resume.
  • internal/slides/live.go:579 and presentation.go:1174 have the same "or the server is draining" comment on r.Context().Done(). share.go:427 has an event stream too. None of them can end on SIGTERM.

Needs the highest-capability review before merge, per AGENTS.md. The editor bundle is rebuilt: whoever merges second re-runs fixtures/build-bundles.mjs.

Verification

Head 617149c. TMPDIR=/tmp GOTOOLCHAIN=go1.26.5 .amadan/ci.d/10-gate passes. The full -tags browser suite passed with RASTRILLO_CHROME set to Chrome for Testing 1234 (on a230f3f; 617149c only changes the timeout scaling). The saving, leaving and resync browser tests, including both WKWebView scenarios, were re-run on 617149c and pass.

LLM

WebKit refuses ordinary fetches while a link the page opened is still loading; saves now go keepalive, resend after the back/forward cache, and give up on unanswered requests. SIGTERM now drains the live streams, so the process exits 0 at once.

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 fetch and XHR rejected in 0–1 ms ("Load failed", "xhr error"), nothing reaches the server; fetch(keepalive) (100 B and 32 KiB) and sendBeacon are 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-gate exit 0 locally; amadan ci status passed 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: false and the bundle rebuilt: Playwright webkit and WKWebView held-link fail with no save reached the server … states [retrying] and the three words missing from the document; chromium passes as the control; the unit test a save is sent keepalive… reddens. With app.Drain() removed: TestStoppingWithAnEditorOpenExitsAtOnce fails with exited 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.rs apply_update is yrs's txn.apply_update, which integrates structs it already holds as nothing and returns Ok, so a re-sent batch is never a 400; Store.ApplyUpdate then 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's noteOwnSeq adopts only cursor+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.timeout fires 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), and resume() usually gets there first. Correct.
  • Drain (5): both signal.Notify channels receive SIGTERM; Drain closes hub.done, streams return, net/http.Shutdown finishes. In-flight POSTs are not touched by the drain and complete under Shutdown (not re-sent). New streams get 503; live-updates.mjs closes the EventSource on error, so no native reconnect loop against a restarting instance. Saves during the restart gap get a real connection failure → retrying is honest there.
  • #90 and dadf9c1 (6): git merge-tree of #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 inside pageshow; 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 delete editor.7ff107f6ce88eea0.js and add their own bundle, so a textual merge leaves two and assets.go panics — 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.

Fable's findings, addressed — head 1b0e00f, hub CI passed

Rebased onto main twice, past #90 (25cd32a) and the Colophon (317e09b). The bundle was rebuilt with fixtures/build-bundles.mjs: one bundle, and a fresh build matches it. Each new test below was seen to fail first, for the stated reason.

P1: the unload beacon and keepalive's shared 64 KiB. Fixed.

  • The queue now tracks whether the batch on the wire went keepalive (post(bytes, onWire); q.onWire).
  • pendingBytes({ wire: 'plain' }) leaves out a keepalive save. The beacon sends that plus unsaved, then falls back to the queue alone (wire: 'none'), then to a keepalive fetch of the smallest payload.
  • New browser case playwright/{chromium,webkit}/closing. A 32.6 KB paste is held 3 s by the server, about 2 KB is typed behind it, and the page leaves. Before the fix the queued text was missing in both engines; the paste landed. Now both pass.
  • New unit case for pendingBytes with a keepalive or plain save on the wire, checked against a mutation.

P2, quick return from the back/forward cache. New WKWebView case back-quick: a 32.6 KB save is held, the page comes back after 300 ms, and the text typed then must save with no failure shown. It passes. It also passed with the probe disabled, so the flash did not reproduce in WKWebView; it stays as a no-loss regression check. The probe below covers the quota-refusal path, and unit tests exercise it.

P2 (a), a probe before "Trouble saving". A save refused with no answer is followed by reachable('/healthz'): a keepalive HEAD first, then an ordinary one. If either answers, the browser refused the save, so it is retried quietly. If neither answers, the line says retrying. A 5xx is the server's answer and is still reported without a probe. A probe that answers after the batch has been saved says nothing.

  • New browser case webkit/large: an 80 KB random paste during a held link. Before: [retrying]. After: calm.
  • Unit cases for the probe and for reachable, mutation-checked.

P2 (b), gzip. Saves of 1 KB or more are gzipped and go keepalive if what is actually sent fits.

  • New finding: while a link is loading, WebKit fails every Blob read too ("NotReadableError: The I/O read operation failed", measured in WKWebView), so new Response(blob.stream().pipeThrough(...)) returned nothing. The compressor writes to the CompressionStream writer directly instead.
  • Server side, updatesPost reads through readPostedUpdate. It gunzips Content-Encoding: gzip under the existing MaxBytesReader and bounds the decompressed update by maxUpdateBytes again: 2 MB of zeros gzipped is a 413. Corrupt or truncated gzip is a 400, and any other encoding a 415. TestAPostedUpdateMayBeGzipped covers this; with the decompressed limit removed it fails ("204, want 413"). TestEveryPlainTextErrorIsClassified is updated for the new error responses.
  • New browser case webkit/prose: a 64 KB paste of prose during a held link reaches the server while the link loads. It failed before gzip and passes now.
  • Deploy check: this relies on the edge passing Content-Encoding on a request body through unchanged. That has not been verified on the platform.

P2, AGENTS.md. Added two settled conventions, keepalive saves and the SIGTERM drain, and corrected build-editor.mjs to build-bundles.mjs.

The test harness now leaves to /healthz. The documents list lays out a thumbnail of every document, and with the new 64–80 KB documents that blew the 30 s waits on this machine at load 40 or more.

Verification. The local gate passed at dbc54c8. On 1b0e00f its only failure is #90's carry.test.mjs "2000 changes … in under 3 s" wall-clock budget, at load 50+; this branch leaves carry.* unchanged from main. Hub CI passed on 1b0e00f. TestSavingContinuesWhileALinkIsLoading passes in all eleven sub-cases (Playwright Chromium and WebKit: held-link, large, prose, closing; WKWebView: held-link, back, back-quick). The full browser suite is re-running.

Slides is ported on oficina/slides fix/safari-save-stall, in its own discussion.

Full browser suite on 1b0e00f, with RASTRILLO_CHROME set to Chrome for Testing 1234: passes (1507 s). Slides port: oficina/slides#30, hub CI passed at 48f161e. Tasks 89 (the Slides port) and 90 (checking the edge passes gzip request bodies through) are on this branch.

Heads-up from #97 (fix/undo-redo-while-diverged): it touches fixtures/carry.mjs, the undo paths of fixtures/editor-entry.js (aroundDispatch, the update handler, beforeTransaction) and fixtures/engines/replay.mjs/undo.mjs, not the save queue. Whichever lands second rebases and rebuilds internal/docs/static/editor.*.js.

Whole-branch review, round 2 — Claude Fable 5.1, for session 21a32889

Branch fix/safari-save-stall at 1b0e00f, read as one diff against origin/main (317e09b, which is also the merge base: the rebase is clean). Scratch worktrees under /tmp, removed afterwards.

Verdict: needs changes. One P1 (a new way to lose a whole batch; a few lines to fix), two P2s. Everything from round 1 is addressed and the beacon fix is right; its regression test is blind, which is one of the P2s.

What I verified

  • Gate: TMPDIR=/tmp GOTOOLCHAIN=go1.26.5 .amadan/ci.d/10-gate passes at 1b0e00f (OrbStack up). The bundle is reproducible: build-bundles.mjs writes the same editor.df7c26273261e92c.js, and there is one.
  • Browser: TestSavingContinuesWhileALinkIsLoading with RASTRILLO_CHROME = Chrome for Testing 1234, node 24: all eleven sub-cases pass (63 s; held-link, large, prose, closing in Chromium and WebKit; held-link, back, back-quick in WKWebView), with the save line never leaving its rest state.
  • Beacon accounting, every combination. Nothing on the wire: queue + unsaved beaconed, keepalive fallback, as main. Plain on the wire (an update still over 32 KiB gzipped, or a batch whose post has not yet called onWire): K + Q + unsaved first, then Q + unsaved, then a keepalive fetch of the smaller. Keepalive on the wire: Q + unsaved only, K lands by itself. A batch given up and resent is the new keepalive batch, and the old one's bytes are omitted too. pendingBytes with batch.keepalive undefined counts as plain, which is right (not sent yet), and the unit case covers it. Correct in all of them. The one residual is the old one: Q itself over about 60 KiB at close is refused (main too), and the beacon cannot gzip because beforeunload is synchronous.
  • The quota, measured again, this time through the branch's own test server. I reverted the beacon to wire: 'all' (rebuilt the bundle), sized the paste so it gzips to 27.9 KB (46 KB of random letters), and logged every POST. Mutant: the held 27,897-byte gzip save, then nothing raw: the repeated beacon (about 76 KB counting the save) and its keepalive fallback were both refused, as in round 1. Fix: a 2,023-byte raw POST arrived during the hold, the beacon carrying the queued text as designed. So the fix does what it says.
  • Probe. A real outage: the POST is refused at the network, both HEADs fail, "Trouble saving" in ms (a hung network: about 10 s later than before, since each HEAD has a 5 s timeout; fine). A browser hold: the keepalive HEAD answers, so nothing is said, and the save is retried every 250 ms. A 5xx is still reported without a probe. The reverse misclassification (outage read as a hold) needs a HEAD answered while a POST fails with no answer; with the edge as one host, a dead instance answers the POST 502, which is an answer. The only false message left: a hold with keepalive's quota wholly spent, so that even the HEAD is refused — a flash, not a loss. rastrillo registers GET /healthz, which Go's mux also matches for HEAD. Fine.
  • Gzip, server. MaxBytesReader bounds the wire, LimitReader(maxUpdateBytes+1) bounds the expansion: 2 MB of zeros is a 413 and never read into memory past 1 MB. Corrupt or truncated is 400, br is 415, identity and empty are read as before. A body cut mid-upload (the fetch's own abort, a dead connection) reaches the gzip reader as unexpected EOF and gets a 400 the client never sees, so it retries. Right.
  • Gzip, client. gzip() writes to the CompressionStream writer and never touches a Blob; the prose case shows a 64 KB paste reaching the server while the link is held in WebKit. saveTimeoutMs is computed on what is sent and answerTimeoutMs on the update, so the fetch's own timeout always fires first. Good.
  • Edge. The coordinator read the carlos edge: httputil.ReverseProxy, body passed through untouched, nothing touches a request's Content-Encoding, and docs.oficina.works CNAMEs straight to it. So a gzipped save should arrive byte for byte. What follows is about the day it does not.
  • Drain. Both signal.Notify channels get SIGTERM; Drain closes hub.done, open streams return, new ones get 503, in-flight POSTs are untouched and finish under Shutdown. stream.go is the only long-lived handler. TestStoppingWithAnEditorOpenExitsAtOnce ran in the gate.
  • #90 and carry. Rebased past #90 and the Colophon. The beacon's extra is unsaved.entries as before; resume() on pageshow acts on currentQueue, which a resync swaps before mounting the new view. No interaction I can find. The carry test's "2000 changes in under 3 s" is a wall-clock budget; not this branch's.

Findings

P1 — a 4xx to a gzipped save drops the batch; a server without gzip support answers one 400. Measured: origin/main's updatesPost reads the gzipped bytes as the update, the core refuses them, 400 badupdate. The queue classifies any 4xx as permanent: the batch is dropped, failed is reported, the session diverges. So the day a save with Content-Encoding: gzip meets a server that does not gunzip it — a rollback of this deploy with a tab still open on the new bundle (the realistic one: this branch is the kind that might be rolled back), or any future hop that strips the header — every save of 1 KB or more from that tab is lost, with "Some changes were not saved" and nothing the person can do but reload and lose them. Below 1 KB saves go through, so it would look like "pastes don't save". Main has no such path. The guard is small and belongs in post in editor-entry.js (or in saveRequest's caller): when the request went gzipped and the answer is 400 or 415, send the same bytes once more uncompressed (keepalive if they fit) and return that answer; only then let the queue classify. A unit case: a gzipped post answered 415 is re-sent identity and the batch is not dropped. Losing an edit is worse than a flash, and this one loses a whole batch for a deploy-shaped reason.

P2 — the closing regression test cannot see the beacon fix. Two reasons, both measured. (1) closingTyping is 32.6 KB of random letters, which gzip to 19.7 KB, so the held save plus the repeated beacon (about 35 KB raw) is 55 KB, under the quota: with the fix reverted and the bundle rebuilt, playwright/{chromium,webkit}/closing pass. The "seen to fail first" predates ad97caf (gzip). (2) Even at a size that does exceed it (46 KB, compressing to 27.9 KB: the mutant's beacon and fallback are refused, no raw POST arrives), the case still passes, because the old page outlives the 3 s hold: the navigation to /healthz queues behind the per-host connection limit that the earlier pages' held links and streams occupy, the held save is answered, and the queue sends the 2 KB itself as an ordinary gzipped keepalive save (POST log: 27,897 gzip held, then 1,281 gzip). The fix run shows the difference the test should assert: a 2,023-byte raw POST reached the server while the large save was still held. Make that the check — count, per document, POSTs answered 2xx while heldLarge is holding (the server already has the hook), and require one for the closing document — and size the paste so it compresses to between 24 and 31 KB. The same test in Slides is blind for the same reasons (its discussion says it passes on main).

P2 — corrupt gzip is 400 in Docs and 422 in Slides (readPostedUpdate and its two switch statements are otherwise identical). Pick one, since the client treats both as permanent; and the catalog key is badupdate either way.

Nits: with the probe, a hold on an over-size save costs three requests every 250 ms (POST, keepalive HEAD, and the next POST) for as long as the link loads — bounded, but worth a longer retry interval once the probe has answered "up" once. reachable() could take the AbortSignal only when the function exists, as saveRequest does; it does. The AGENTS.md entries are right and the build-bundles.mjs correction is welcome.

Verdict

Needs changes for the P1; the P2 on the test should land with it since it is the proof the P1 fix (round 1's) keeps working. With those, ready to merge, bundle rebuilt on top of whatever lands first. Reviewed as session 21a32889's whole-branch review per AGENTS.md.

Round 2 addressed — head c384a25, hub CI passed

Rebased onto 0d00351 (the Colophon follow-ups). The bundle is rebuilt, and there is one.

P1, a 4xx to a gzipped save.

  • createPoster in save-queue.mjs is now the queue's post. When a gzipped save is answered 400, 415 or 422, it sends the same bytes once more uncompressed (keepalive if they fit) and returns that answer, before the queue classifies it.
  • After the first such refusal the poster stops gzipping. There is one poster per page, not per queue, so this survives a resync.
  • Unit cases, which failed with the fallback removed: - main's updatesPost shape (gzip answered 400): sent gzip then identity, the batch saved, never failed, and the next save goes identity only; - a non-gzipped 400 is not resent; - a save refused either way costs one more request and is still refused.
  • Browser case {chromium,webkit}/stripped: the test server strips Content-Encoding on the way in, so updatesPost reads the gzip bytes as the update and answers 400, exactly as main and a rollback would. A 3 KB paste, then a small word. Before the fallback both engines showed [failed] and the paste was missing from the server. Now both pass.

P2, the blind closing test.

  • The paste is 46 KB of random letters, about 28 KB gzipped.
  • The server now records, per document, the 2xx saves answered while the large save is still held, and the test requires at least one for the closing document.
  • Each finished scenario page is now closed. Its held link and stream otherwise occupied the host's connections, which queued the beacon until after the hold. That is why Chromium's closing case first failed with the fix in place.
  • With the beacon reverted to wire: 'all' (bundle rebuilt): fails in Chromium and WebKit ("nothing reached the server while the large save was held"). With the fix: passes.

Nits.

  • Corrupt gzip is a 400 in both apps; Slides changed from 422.
  • Quiet retries (the browser refusing while the probe answers) now wait for the probe, then back off 500 ms → 1 s → 2 s → 4 s (QUIET_MAX_MS). They reset when a save gets an answer. Unit case added.
  • AGENTS.md records both.

Verification.

  • TestSavingContinuesWhileALinkIsLoading: all thirteen sub-cases pass.
  • Local gate: only carry.test.mjs's wall-clock budgets fail, at load 160. That code is unchanged from main.
  • Hub CI passed on c384a25.

Whole-branch review, round 3 — Claude Fable 5.1, for session 21a32889

Branch fix/safari-save-stall at c384a25, against origin/main a6e6c63 (merge base 0d00351). Scratch worktrees under /tmp, removed afterwards. This round finishes the one a usage limit cut off: the engine tests, re-run with fixtures/engines installed.

Verdict: ready to merge (APPROVE-WITH-NITS). Round 2's P1 and both P2s are addressed and verified. No new finding above P2.

Round 2, verified

  • P1, the gzip fallback. createPoster (save-queue.mjs 196–210) re-sends a gzipped save answered 400, 415 or 422 as identity, keepalive if it fits, and sets plainOnly for the rest of the page; editor-entry.js makes one poster per page, so it survives a resync. A fetch that rejects is left to the queue's retry path, which is right. Mutation-checked: with the fallback block removed, save-queue.test.mjs goes 18/20 — "a gzipped save a server refuses is sent again uncompressed, and later saves skip gzip" and "a refused save that was not gzipped is not sent again" redden. Established in the cut-off part of this round: every 400/415/422 in updatesPost happens before anything is persisted, so the re-send cannot double-apply; the quiet backoff is min(250·2^n, 4000) with schedule idempotent, every branch re-arming a timer and a 5 s timeout on each probe HEAD, so nothing is stranded.
  • P2, the closing test now counts a 2xx save answered while the large one is held (duringLarge), with a 46 KB paste (about 28 KB gzipped) and each finished page closed. That is the discriminating check.
  • P2, corrupt gzip is 400 in both apps.
  • Bundle reproducible, one file. The branch conflicts with main only in the generated editor bundle; a scratch merge builds one bundle and passes the JS suite 191/191.

Engine tests, with fixtures/engines installed

Run one at a time, -tags browser -count=1 -timeout 40m, RASTRILLO_CHROME = Chrome for Testing 1234, node 24, on a machine other sessions were also running browser suites on (load 20–45 for most of it).

| Test | Result | |---|---| | TestEnginesEveryChangeWhileARefusalIsPendingIsKept | PASS (67 s) | | TestFontEnginesFirstRevealIsTheFinalLayout | PASS (178 s) | | TestFontEnginesAWaitKeepsThePage | PASS (15 s) | | TestLeavingADocumentEarlyLetsGoOfItsStream | PASS (4 s) | | TestFontEnginesAWaitingPasteSurvivesARefusedSave | FAIL once (212 s, load 40+): chromium (j) and (k), "the pasted words appeared 0 times". Then alone, alternating: branch PASS 141 s, main PASS 81 s, branch PASS 150 s, main PASS 80 s (load 39–45 at each start). | | TestSavingContinuesWhileALinkIsLoading | FAIL once (64 s, load ~25): playwright/webkit held-link only — the server held "Typed" but not "while loading", held > 0, states []; the other twelve sub-cases passed. Then alone: PASS 63 s, PASS 62 s (13/13 each). Then webkit-only, ten more runs with a request trace, load 8 → 35 (CPU burners): 10/10 PASS. |

The paste failure is not the branch's. It is the race main's a6e6c63 removed from fixtures/engines/replay.mjs ("a fixed hold raced the refusal under load"): the branch's base 0d00351 predates that commit, so its replay.mjs still has the fixed pause(1500) and pause(4500), while main waits on conditions. Same script on main passes; the branch inherits the fix at the merge. (That difference is also why the branch's runs take 60 s longer than main's.)

The saving failure did not reproduce in twelve runs, so I cannot name its cause; the one failing log has nothing server-side for that document. In every passing trace the three keepalive POSTs (19, 23, 25 bytes) go at about 1.24, 1.53 and 1.84 s from page start and are answered 204 in ~12 ms each, during the hold (the font prefetch GETs beside them are refused "Load failed", as ordinary fetches should be); at load 35 the last lands at 2.1 s, inside the harness's 3 s window. Two mechanisms fit "first word landed, next two did not, nothing reported": the second POST refused by WebKit and the new quiet backoff (500 ms → 1 s → 2 s) carrying the retry past the window; or the first batch's keepalive promise never settling, as it does not after bfcache, with the next batches waiting for the give-up. In neither case does a real tab lose the words (the beforeunload beacon, the give-up re-send), but the second would be a 35 s stall ending in a false "Trouble saving". Hence the P2.

Findings

P2 — saving.mjs reads the server after a fixed pause(3000) and closes with page.close(). Two things make the one-off undiagnosable and the test harsher than a real tab: Playwright's page.close() does not run beforeunload, so the harness's close skips the beacon a real close would send; and the fixed window cannot tell a slow pass from a stall. Do what a6e6c63 did for replay.mjs: wait until the server holds the text (or held reaches 3) with a ceiling, and on the ceiling print the page's requests (wrap fetch and sendBeacon in an init script, with timings and statuses) in the SAVING RESULT line, so the next failure says which of the two it was. Not blocking: twelve passes, nothing lost in a real browser either way.

P2 — merge note. After merging main (a6e6c63), the only conflict is the generated editor bundle: delete both and rebuild with fixtures/build-bundles.mjs so there is one, per AGENTS.md. The merge also brings main's condition-based replay.mjs and the undo engine test; run TestFontEnginesAWaitingPasteSurvivesARefusedSave and the undo test once on the merged tree.

Nits: none new. The AGENTS.md entries for the fallback and the quiet backoff are right.

Verdict

Ready to merge: APPROVE-WITH-NITS. Reviewed as session 21a32889's whole-branch review per AGENTS.md.