Repository navigation
Description
Summary
Split from #704 ("Same change" paragraph). Every WebSocket replica subscribes to doc:*:saved and doc:*:access in Redis. Each replica that holds the room then calls document.broadcastStateless. The Redis extension also publishes that call to the room's channel, so every other replica sends the frame again. At R replicas, a client gets R copies of each frame. Production runs 2 WebSocket replicas.
This issue sends those frames to local connections only. It adds a subscriber-reconnect counter, because after the change a replica with a dead subscriber has no second path for its clients.
Status, 2026-11-16. Steps 1-7 are in 51773d6b9, deployed 2026-11-16 13:31Z. Left: the step 8 production scratch-pad checks and the 7-day store read, on or after 2026-11-23.
Why
Read from code at HEAD 0b302b222:
apps/hocuspocus.server/src/extensions/redis-subscriber.extension.ts:22subscribes withpsubscribe('doc:*:saved', 'doc:*:access'). Its handler callsdocument.broadcastStateless(...)fordocument:saved(:38). It callshandleDocumentAccessEventfor access events (:51).apps/hocuspocus.server/src/lib/accessRealtime.ts:61,:76,:90and:101calldocument.broadcastStatelessfor thedeleted,readOnlyandprivateframes.@hocuspocus/extension-redisbeforeBroadcastStatelesspublishes every stateless broadcast to the room's channel (dist/hocuspocus-redis.esm.js:276-279). Each other replica then sends it to its own connections.- So at R = 2, each client gets 2 copies of each
document:savedand access frame. This comes from code. The local count is not measured yet. - The webapp sets
providerStatustosavedon eachdocument:savedframe (apps/webapp/src/hooks/useYdocAndProvider.ts:232-235). So each copy is one more workspace store write. - After the change, a replica whose subscriber is down sends no
savedframe to its clients. Their status stays on its last value until the subscriber reconnects. The subscriber is an ioredis client (apps/hocuspocus.server/src/lib/redis.ts:205-230). It logsreadyanderror. Nothing counts its reconnects. apps/hocuspocus.server/src/extensions/statelessRelay.tsrelaysdocTitlefleet-wide on purpose. It stays as it is.
What to change
All code steps are for an agent in the repo. Paths are under apps/hocuspocus.server/src.
- Local before, no code change. Add a
--mode savedtoapps/hocuspocus.server/scripts/redis-sync-probe.ts. It starts two production-mode WebSocket processes on one Redis and puts one client on each. The probe starts no worker today (redis-sync-probe.ts:291), and only the store worker publishesdoc:<id>:saved. So either start a worker withspawnWorkerfromscripts/lib/prodModeStack.ts, or publishdoc:<id>:savedstraight to the probe's Redis 20 times. Record which one ran. It runs 20 saves, then countsdocument:savedframes per client per save. Add one access event (readOnlytrue, then false) and count those frames too. Run it at HEAD and post the counts asMeasured, <date>. - In
extensions/redis-subscriber.extension.ts, replacedocument.broadcastStateless(payload)with a loop:for (const connection of document.getConnections()) connection.sendStateless(payload). - In
lib/accessRealtime.ts, make the same change at all four call sites. Keep the order: send the frame, then close or mark the connections. - In
lib/metrics.ts, add a counterws_redis_subscriber_reconnects_total, seeded at 0 inseedWsAlertSeries. Inlib/redis.ts, increment it on each subscriberreadyevent after the first one. Review the name with Measure stored head size, save and load phases by pad size, and loaded room bytes #750 and Show event-loop stalls on a panel and a non-paging rule, and measure cold-room reloads #729. This issue owns the name. - Check that the
Redis reconnecting...warn line inlib/redis.ts:71also fires for the subscriber. If it does not, add onewarnline on subscriberend, so Loki shows the gap. - Rerun step 1. Then run the drop check. ioredis reconnects about 0.2 s after a single
CLIENT KILL(lib/redis.ts:69-70), so one kill makes no real gap. Hold the subscriber down for 30 s instead. Put it behind a TCP proxy that the probe stops and restarts, or repeatCLIENT KILLin a loop. Make 3 saves during the gap, then let it reconnect. Record saved frames during the gap (expected 0) and after it (expected 1 per save), and the reconnect count. - Gates:
bun run --filter @docs.plus/hocuspocus typecheckandbun run --filter @docs.plus/hocuspocus test. Runscripts/e2e-versions.ts, which readsdocument:saved. Then stop at a review checkpoint. - Maintainer. Commit through the
commit-reviewskill and deploy with a(build): backtip. Keep the replica-restart check local. On production, run only the scratch-pad checks (reload, two browsers, offline, fast tab close) at a quiet hour, plus the 7-day store read. A production replica restart disconnects every user on it.
Content safety
This changes the sync path. The frames carry no document content, but the save status depends on them. Run every check on a scratch pad you create, in desktop Chrome and phone Safari. Delete the pad after. Never type into /demo.
- Reload: every typed word is there.
- Two browsers on the same pad, on different replicas if you can: each sees the other's edits, and each shows
savedafter a save. - Offline, type, then online: the text syncs.
- Close a tab 50 ms after typing: the text is there after reopen.
- Restart one WebSocket replica while typing: no text is lost. Local only.
- Failed store jobs,
document_persist_fallback_totaland the store dead-letter queue stay at 0 for 7 days after the deploy. The lost-lock lineCaught error during storeDocumentHooksstays at 0 in Loki.
Benchmark
| Field | Value |
|---|---|
| Metric | (a) document:saved frames per client per save at R = 2 WebSocket replicas (exact). (b) Access frames per client per access event at R = 2 (exact). (c) ws_redis_subscriber_reconnects_total change after a 30 s subscriber drop. (d) saved frames per client during the drop and after it |
| Before | (a) 2, (b) 2, from code at HEAD 0b302b222. Local count not measured yet: agent in the repo, step 1, before any code change. (c) no counter |
| After | not measured yet |
| Condition | Named laptop, Bun 1.4.4, two production-mode WebSocket processes on one Redis, Redis extension on (redis-sync-probe.ts). A worker from spawnWorker, or direct doc:<id>:saved publishes; record which. Both SHAs recorded |
| How to run | bun --env-file=../../.env.local scripts/redis-sync-probe.ts --mode saved from apps/hocuspocus.server, 20 saves, one client per replica |
| Pass rule | (a) 1 for every client on every save. (b) 1. (c) moves by exactly 1 after a proxy drop, or by the number of kills in a CLIENT KILL loop. Clients on that replica get saved and access frames for every save after it reconnects. (d) 0 during the 30 s gap, 1 per save after it. A run that counts 0 frames with the subscriber up is a broken probe, not a result. Stop rule: if any client gets 0 saved frames for a save while its subscriber is up, revert the commit |
| Guard | The content-safety list above. stateless_relay_dropped_total{reason="broadcast-frame"} does not move |
| Owner | Steps 1-7: agent in the repo. Step 8 and production reads: maintainer |
| Claim | Internal: "Each editor now gets 1 save confirmation per save, down from 2 at 2 replicas." |
Related
#704 (split from; the empty-save skip stays there). #736 (the status chip reads saved). #705 (directed Redis sync replies, same Redis extension). #363 (parent of #704).
Activity
HMarzban commentedon Nov 12, 2026
Moved to v2.3.7, 2026-11-12 (maintainer ruling). v2.3.6 ships on 2026-11-14 with only finished, measured work, and it waits on an earlier result or a gate read. The before values and the plan in this issue stay as they are.
test(hocuspocus): add saved and N-replica modes to the sync probe
fix(hocuspocus): send save and access frames to local connections only
HMarzban commentedon Nov 16, 2026
Measured, 2026-11-16
Steps 1 to 7 are committed: the probe mode in
bd9c845c5, the code in51773d6b9. Step 8 is the maintainer's.The 2026-11-12 move note exists. It names no result that gates steps 1 to 7, so all of them ran.
What changed
scripts/redis-sync-probe.tshas a new--mode saved. It publishesdoc:<id>:savedstraight to the probe's Redis 20 times. No worker ran. Then it sends one access event (readOnlytrue, then false). It counts the frames each client gets.psubscribenamesdoc:*:saved.src/lib/accessRealtime.tsexportssendToLocalConnections. It loopsdocument.getConnections()and callsconnection.sendStateless. The four access call sites and thedocument:savedsend insrc/extensions/redis-subscriber.extension.tsuse it. The order is kept: send, then close or mark.ws_redis_subscriber_reconnects_total(unlabelled) is insrc/lib/metrics.ts. It is seeded at 0 inseedWsAlertSeries.src/lib/redis.tsadds 1 on each subscriberreadyafter the first one. The name follows thews_prefix of Show event-loop stalls on a panel and a non-paging rule, and measure cold-room reloads #729'sws_disconnects_total.Redis reconnecting...warn already fires for the subscriber, through the sharedretryStrategy. A logged it 17 times in the 30 s gap, beside 16Redis subscriber errorlines. So noendwarn was added. Note: the warn carriesredis: "sync", the same label as the main client.Before and after
Condition: Apple M5 Max, Bun 1.4.4, HEAD
3bd5ca1c0. Two production-mode WebSocket processes ran on one local Redis (OrbStack, DB 13), with the Redis extension on. One client was on each replica. The saves were directdoc:<id>:savedpublishes, with no worker. Before: 1 recorded run and 1 pilot, with nosrcchange. After: 2 runs. Every run in each set gave the same frame counts. The pilot's room-channel count used the wrong frame type (Stateless, type 5), so only the recorded run's 44 is used. Before = HEAD3bd5ca1c0with nosrcchange; after = the working tree on3bd5ca1c0. The probe file differed between runs (sha2561aef93bf…before,2cf21774…after, from #703 edits); the saved mode is the same in both.document:savedframes per client per savereadOnlyframes per client per access eventhocuspocus:<id>ws_redis_subscriber_reconnects_totalafter a 30 s drop of Astateless_relay_dropped_total{reason="broadcast-frame"}A resubscribed 648 to 650 ms after the proxy let it back in. Before the change, B's republish covered A during the gap. After the change, nothing covers A's clients until A's subscriber reconnects. The pass rule expects that.
How to run, from
apps/hocuspocus.server:Gates
bun run --filter @docs.plus/hocuspocus typecheck: pass.bun run test: pass. 1251 pass, 7 skip, 0 fail.bun --env-file=../../.env.local scripts/e2e-versions.ts: pass.Left
(build): backtip, run the scratch-pad checks and the 7-day store read. Owner: maintainer.apps/hocuspocus.server/CLAUDE.mdline 60 still says these frames leave throughdocument.broadcastStateless. Onlyownerstill does. Owner: maintainer, as a doc ruling.ws_redis_subscriber_reconnects_totalyet. The subscriber's reconnect warn shares thesynclabel. Owner: maintainer, together with Measure stored head size, save and load phases by pad size, and loaded room bytes #750 and Show event-loop stalls on a panel and a non-paging rule, and measure cold-room reloads #729.After the deploy
Deployed with
(build): front back(06f61ee44, run 43876524495, 2026-11-16 13:31Z, Build Images and Deploy Production success). Read-only, production, 2026-11-16 13:48Z:ws_redis_subscriber_reconnects_totalexists on all six processes and reads 0. Step 8's scratch-pad checks and the 7-day store read remain.docs(changelog): record the v2.3.7 work of 2026-11-16
docs(hocuspocus): name the store outcome and reconnect counters
HMarzban commentedon Nov 16, 2026
Review, 2026-11-16 (maintainer approved).
51773d6b9, deployed 2026-11-16 13:31Z. Left: the step 8 production scratch-pad checks and the 7-day store read, on or after 2026-11-23.CLAUDE.mdLeft item in the 2026-11-16 Measured comment is already done.apps/hocuspocus.server/CLAUDE.md:60now namessendToLocalConnections(Send save confirmations and access frames to local connections only #758).ws_redis_subscriber_reconnects_total" note is dropped. No step asks for that alert.HMarzban commentedon Nov 17, 2026
Content-safety checklist. The shared checklist lives in release-product §Content-safety checklist. Run it for this issue, plus the extra checks in this body. Record each item as pass or fail in the Measured comment, as §Measured comment format says. The list in this body stays as it is (#762, ruling A).
HMarzban commentedon Nov 24, 2026
Measured, 2026-11-24: 8-day production guard
Question: Did production pass the 7-day subscriber-reconnect and store-safety guards since the
2026-11-16 13:31Zdeploy?Setup. Production Prometheus and live collab container logs, read-only, window ending
2026-11-24 07:00Z([604800s]Prometheusincrease()/max_over_time(), plus current container counters one4d36ae0f).Result:
2026-11-24)ws_redis_subscriber_reconnects_total([604800s]+ live across 6 processes)0jobs_total{queue="store-documents",status="failed"}([604800s])0document_persist_fallback_total([604800s])0max_over_time(queue_jobs{queue=~".*-dlq"}[604800s])(all 3 DLQs)0Caught error during storeDocumentHooks(6containers)0Not measured. Dedicated local browser checks 1–5 were not re-run separately for
#758after#704verified the local save path on2026-11-22. Local probe rows(a)–(d)passed in the2026-11-16Measuredcomment (50 %fewer saved/access frames per client atR = 2).Verdict: All production and probe guards pass; closing
#758.