oficina / slides Public

Safari: saves refused while a link loads, and a stop that waits on open streams (Docs #94, ported) open

On branch fix/safari-save-stall

Why

Docs #94 found two bugs in code Slides shares. This branch ports Docs' fix, including the round that answered Claude Fable's review there.

  1. WebKit sends no ordinary request while a link the page opened is still loading. fetch, XHR and even Blob reads are refused at once, and nothing is sent. The page stays editable the whole time, and a link answered with a download, or never answered, never takes it away. Slides' save queue is the same code as Docs', so every save read as a failure: "Offline, retrying" four times a second, and no request reached the server.
  2. A graceful shutdown cancels no request. deckStream (live.go) and streamPresentation (presentation.go, which the share link's sharedStream also uses) each waited on r.Context().Done() "or the server is draining". It never fired. An open editor, projector or follower would hold the stop for rastrillo's whole 10 s, and the process would exit 1, as Docs did at 12:49 today.

What changed

Client (fixtures/save-queue.mjs and editor-entry.js, ported from Docs with Slides' header and comments kept):

  • Saves go keepalive, which WebKit still sends then, at most 32 KiB a batch, and gzipped from 1 KB by writing to CompressionStream directly, never through a Blob.
  • Timeouts: the fetch aborts after 30 s plus 1 s per 8 KB, and the queue gives up on a save left unanswered 5 s after that.
  • pageshow with persisted resends what was on the wire, because WebKit never settles a keepalive save answered while its page was in the back/forward cache.
  • The unload beacon leaves out a keepalive save already on the wire. It shares the 64 KiB quota, and repeating it lost the edits queued behind it.
  • A save refused with no answer is followed by a probe of /healthz (keepalive, then ordinary). It reads as retrying only if neither probe answers; otherwise it stays "saving" and retries quietly.

Server:

  • updatesPost gunzips Content-Encoding: gzip under the same MaxBytesReader and bounds the decompressed update by maxUpdateBytes. Corrupt gzip gets a 422 and any other encoding a 415.
  • internal/slides/drain.go: app.Drain() ends both stream loops. cmd/slides/main.go calls it on SIGTERM/SIGINT through its own signal.Notify, because rastrillo.Serve has no hook.
  • A stream opened while stopping gets a clean 200 end with retry: 3000. An error status would end a projector's EventSource for good; this way it reconnects to the next instance.

Other: AGENTS.md gains the two rules. The editor bundle is rebuilt and the credit inventory names it.

Tests (each seen to fail first)

  • internal/slidestest/saving_browser_test.go, with fixtures/engines/saving.mjs and saving-webkit.swift (Docs' harness, with Slides' page and ready check): - Playwright, on main's client: WebKit fails held-link ("no save reached the server", states [saving retrying …]), large ([saving retrying]) and prose (the paste never reached the server). Chromium passes, as the control. - WKWebView, on main's client: held-link, back and back-quick all fail (retrying shown, words missing). - With the fix: all eleven sub-cases pass. - closing passes on main too; it guards the regression the keepalive change could have caused.
  • cmd/slides/shutdown_test.go builds and runs the real binary with a signed-in deck stream open, then sends SIGTERM. With the drain disabled it fails: "exited 1 after 10.003s".
  • internal/slidestest/drain_test.go: - TestStreamsEndWhenTheAppDrains covers both stream kinds, and checks that a stream opened while draining gets retry: and no event. - TestAPostedUpdateMayBeGzipped covers the decompressed limit (413), corrupt and truncated gzip (422) and unknown encodings (415). - Both were mutation-checked.
  • save-queue.test.mjs: Docs' nine new cases. Slides' four real-timer tests also lose their fixed sleeps.

Verification

  • Hub CI: passed at 48f161e.
  • Locally: make ci passes, and so do the JS tests except one. The full gate stops at the wasm cmp on this machine; main has the same mismatch here, and hub CI ran the check and passed. The one JS failure is carry.test.mjs "2000 changes … in under 3 s" (from #90's port) at load 100+.
  • Browser tests: TestLeavingAPageLetsGoOfItsStream passes all ten surfaces. The full browser suite is running.
  • Deploy check: gzip relies on the edge passing a request body's Content-Encoding through unchanged. Not verified on the platform.

Needs the highest-capability review before merge. Don't merge.

LLM

Docs' fix for WebKit refusing ordinary saves during a pending navigation (keepalive, gzip, quota-aware beacon, resend on pageshow, give-up, probe), and a SIGTERM drain for the editor and presentation streams.

Full browser suite on 48f161e, with RASTRILLO_CHROME set to Chrome for Testing 1234: everything passes except TestFontEnginesSlidesChangeWithoutAGap, which failed at load 100+ and passes when re-run on its own at load 10. It is a font-reveal timing test, and this branch does not touch font code.

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

Branch fix/safari-save-stall at 48f161e, read as one diff against origin/main (4c23861, the merge base). Scratch worktree under /tmp, removed afterwards. Reviewed alongside Docs #94 at 1b0e00f, whose client this ports.

Verdict: needs changes. The same P1 as Docs (the client is the same code), one P2 on the test; the Slides-specific work (the drain, the retry: answer, the gzip server) is right.

What I verified

  • Port fidelity. fixtures/save-queue.mjs differs from Docs' only in comments; editor-entry.js's post, probe, pageshow and the beacon are the same code with Slides' Slides-Seq and status.drop(); queueStatusState maps the queue's saving and the quiet retry. The unit tests are Docs' nine on a harnessWith(options) beside Slides' own harness.
  • Gate. The wasm cmp fails on this Mac as known (Homebrew's rustc), so I ran what follows it: node --test *.test.mjs and make ci (vet, gofmt, the Go tests including cmd/slides with the real-binary shutdown test, migration check, credits check) pass. The one JS failure was carry.test.mjs's "2000 changes in under 3 s" at 3,053 ms under load; alone it passes 45/45. Not this branch's code. The bundle is reproducible: build-bundles.mjs writes the same editor.6401451793bdc579.js, one file, and assets.json names it.
  • Browser. TestSavingContinuesWhileALinkIsLoading with RASTRILLO_CHROME = Chrome for Testing 1234: all eleven sub-cases pass (72 s), the save line never saying retrying.
  • Drain. drain is lazy so the zero app works; Drain is idempotent; deckStream and streamPresentation (which sharedStream uses, so the share link is covered) both return on draining.done(), and a stream opened while stopping gets 200 + retry: 3000 and no event. That is the right answer for the projector: present.js relies on EventSource's own reconnection, which a 503 would end for good; the editor's live-updates.mjs closes on the end and reopens on activity. There is no other long-lived handler (grep text/event-stream). In-flight POSTs are untouched. TestStreamsEndWhenTheAppDrains and TestStoppingWithAStreamOpenExitsAtOnce ran.
  • Gzip server. Same shape as Docs: wire bounded by MaxBytesReader, expansion bounded by LimitReader(maxUpdateBytes+1), 2 MB of zeros is a 413, other encodings 415. Corrupt is 422 here and 400 in Docs; see the nit.
  • Beacon, probe, quota. The analysis is on Docs #94 and applies unchanged: the accounting is correct in every combination; the probe cannot read an outage as a hold through one edge host; the quota sharing was re-measured through the Docs test server (the repeated beacon and its fallback refused beside a 27.9 KB held keepalive save; with the fix, the 2 KB beacon arrives during the hold).
  • Edge. The coordinator read the carlos edge source: ReverseProxy, body untouched, Content-Encoding untouched. So the gzip header should reach Slides as sent.

Findings

P1 — a 4xx to a gzipped save drops the batch (same as Docs #94). The queue treats any 4xx as permanent and drops the batch. A server that does not gunzip (origin/main, which a rollback of this deploy brings back while a tab holds the new bundle; or any future hop that strips the header) refuses the gzipped bytes as a bad update, 4xx, and every save of 1 KB or more from that tab is lost with "some changes were not saved". Main has no such path. Fix in post: when the request went gzipped and the answer is 400, 415 or 422, send the same bytes once uncompressed (keepalive if they fit) and return that answer, before the queue classifies. Unit case alongside.

P2 — the closing case cannot see the beacon fix, as this discussion already says ("passes on main too"). Measured on Docs' identical test: the 32.6 KB paste gzips to 19.7 KB so the quota is never exceeded, and even when the paste is sized to exceed it the old page outlives the 3 s hold (the navigation queues behind the per-host connection limit the earlier pages' held links and streams occupy), so the queue delivers the queued text after the hold and the beacon is never needed. The discriminating check is a POST for the closing deck answered 2xx while the large save is still held (the fix produces one, the mutant none); count that server-side, as held already does for the held link, and size the paste to compress to 24–31 KB.

Nit: Docs answers corrupt gzip 400, Slides 422; one of the two.

Verdict

Needs changes for the P1, with the P2 test fix alongside. The drain and its retry: answer are ready as they are. Reviewed as session 21a32889's whole-branch review per AGENTS.md.

Round 2 addressed — head a5a6572, hub CI passed

The same changes as Docs #94 round 2, on the same code.

  • P1: createPoster resends a gzipped save refused with 400, 415 or 422 uncompressed, and the page stops gzipping. On main, Slides answers a gzipped body 422 (errUpdateRefused). The new stripped browser case (the test server strips Content-Encoding) showed [saving failed] in Chromium and WebKit before the fallback, and passes now.
  • P2, closing: a 46 KB paste (about 28 KB gzipped), a 2xx save required while the large one is still held, and finished pages closed. With the beacon fix reverted it fails in both engines ("nothing reached the server while the large save was held").
  • Nits: corrupt gzip is a 400 now, as in Docs; an update the core refuses is still a 422. Quiet retries back off to 4 s.
  • Housekeeping: AGENTS.md updated, the bundle rebuilt, and the credit inventory names it.

Verification.

  • All thirteen saving sub-cases pass.
  • make ci passes, and so do the JS tests (269/269).
  • Hub CI passed on a5a6572.

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

Branch fix/safari-save-stall at a5a6572, against origin/main f2b93b1. Scratch worktrees under /tmp, removed afterwards. Reviewed alongside Docs #94 at c384a25, whose client this ports; 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 P2 are addressed and verified. No new finding above P2.

Round 2, verified

  • Port fidelity. fixtures/save-queue.mjs differs from Docs' only in comments and blank lines (diff with comments stripped: nothing). createPoster is the same code; editor-entry.js's wrapper differs only in Slides' own Slides-Seq, noteSeq, strip.flush() and status.drop().
  • P1, the gzip fallback. A gzipped save answered 400, 415 or 422 is re-sent identity, keepalive if it fits, and the page's one poster stops gzipping; a resync keeps the poster. Mutation-checked: with the fallback block removed, save-queue.test.mjs goes 21/23, the two new cases reddening. 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 bounded and nothing is stranded.
  • P2, the closing test counts a 2xx save answered while the large one is held, with a 46 KB paste and each finished page closed.
  • Corrupt gzip is 400, as in Docs. Bundle reproducible, one file, named in credits/assets.json. The branch conflicts with main only in credits/assets.json; a scratch merge builds one bundle and passes the JS suite 280/280.

Engine tests, with fixtures/engines installed

Run one at a time, CGO_ENABLED=0 go test -tags browser -count=1 -timeout 40m, RASTRILLO_CHROME = Chrome for Testing 1234, node 24, with other sessions' browser suites on the same machine for most of it (load 20–45).

| Test | Result | |---|---| | TestEnginesEveryChangeWhileARefusalIsPendingIsKept | PASS (71 s) | | TestFontEnginesFirstRevealIsTheFinalLayout | FAIL once (300 s, heavy load): webkit, viewer, no gate: "the slide was never seen with text on it" (the two controls were caught; this was a plain scenario whose text never appeared inside its capture window). Then alone, alternating: branch PASS 252 s, main PASS 241 s, branch PASS 259 s, main PASS 239 s. (One further main run failed in 2 s because my main worktree lacked fixtures/node_modules for the deck generator; my setup, not the test.) | | TestFontEnginesSlidesChangeWithoutAGap | PASS (73 s) | | TestFontEnginesAWaitKeepsThePage | PASS (14 s) | | TestLeavingAPageLetsGoOfItsStream | PASS (13 s) | | TestFontEnginesAWaitingPasteSurvivesARefusedSave | PASS (134 s) | | TestSavingContinuesWhileALinkIsLoading | PASS 72 s, PASS 73 s, thirteen sub-cases each |

The first-reveal failure is not the branch's. first-reveal.mjs is byte-identical on the branch and on main, both pass twice when run alone, and the failing scenario is a font-reveal timing capture, as this discussion already recorded for SlidesChangeWithoutAGap at load 100+. This branch touches no font or stage code.

Findings

P2 — the saving harness, shared with Docs. In Docs, the same TestSavingContinuesWhileALinkIsLoading failed once in twelve runs on the webkit held-link case (the first word on the server, the next two not, nothing reported) and did not reproduce; the Slides port passed both times here. The harness reads the server after a fixed pause(3000) and closes with page.close(), which in Playwright does not run beforeunload, so it skips the beacon a real close sends, and a slow pass and a stall look alike. Do what Docs' 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. Land it with Docs' copy. Not blocking.

P2 — merge note. After merging main (f2b93b1), the only conflict is the generated credits/assets.json (and the bundle it names): rebuild with fixtures/build-bundles.mjs so there is one bundle and the inventory names it, then make ci for the credits check. The merge also brings main's undo engine test; run it once on the merged tree.

Nits: none new.

Verdict

Ready to merge: APPROVE-WITH-NITS. The drain, the retry: answer, the gzip server and the ported client are all as reviewed. Reviewed as session 21a32889's whole-branch review per AGENTS.md.