Repository navigation
Description
Goal
In a room held on both replicas, every edit triggers a full sync handshake across Redis. Cut that cost without losing the self-healing it gives today.
Facts
Measured locally on 2026-10-23, unless marked "read from code".
@hocuspocus/[email protected]onChangecallspublishFirstSyncStepfor every local change (src/Redis.ts:387-390, read from code). Each peer replica answers with a full SyncStep2, which includes the whole delete set.- With 2 replicas, one keystroke costs 4 publishes. On a 5.36 MB edited fixture, that was 281,224 bytes published for a 22-byte edit.
- With 3 replicas, it rises to 9 publishes.
- The cost grows with deleted history, not with visible text. Only rooms held on both replicas pay it. Production runs 2 replicas.
- Hocuspocus v4 coalesces SyncStep1 (Feat/redis pending flushes ueberdosis/hocuspocus#1135) and answers only the requester (fix(extension-redis): publish sync replies to the requester only ueberdosis/hocuspocus#1152). This repo stays on v3, because Bun cannot run v4.
- So the fix is a Bun patch on extension-redis 3.4.4, through
patchedDependencies. The repo has no patch yet. A subclass would need casts, becausepubKey,encodeMessageandpublishFirstSyncStepare TSprivate. - The catalog pins
^3.4.4(package.json:134). Pin it to exactly3.4.4in the same commit as the patch.
Decision
Design: the lossless SyncStep1 throttle (ruling 4 on #575, 2026-10-24). Still post the two measurements below, before and after.
- Recommended: a lossless SyncStep1 throttle. A trailing window of about 100–250 ms per document. It saves less, but it keeps the per-edit self-healing that the accepted cross-replica hazard in
apps/hocuspocus.server/CLAUDE.mdrelies on. Upstream #1135 uses the same lossless idea, but it collapses only within one event-loop turn (setImmediate). - Update relay. Publish the update as a SyncStep2 frame, plus a trailing debounced SyncStep1. It saves the most. But Redis pub/sub delivers at most once, so a lost message leaves replicas apart until the next SyncStep1. That widens the hazard accepted on 2026-07-29, so its text must change in the same commit.
With either design, the SyncStep1 must fire on the trailing edge, after edits stop. Otherwise the accepted case "the last edit before a quiet period is lost" gets worse.
What to build
- The chosen design, as a Bun patch on extension-redis 3.4.4. All three
docker/Dockerfile.bunfiles (webapp, hocuspocus.server, admin-dashboard) copy only listed files beforebun install --frozen-lockfile. Bun fails that install when apatchedDependenciesfile is missing. So copy the patch file into every stage that runs that install. Prove it with one localdocker buildofapps/hocuspocus.server/docker/Dockerfile.bun. - A small script under
apps/hocuspocus.server/scripts/, usingscripts/lib/e2eHarness.ts. It starts two Hocuspocus instances on one Redis, with one writer on each.RedisExtensionloads only whenNODE_ENVisproductionandREDISis true (src/config/hocuspocus.config.ts:126).spawnServerssetsdevelopmentand starts one instance, so it cannot do this as it is. Production mode also turns on Postgres SSL (src/lib/prisma.ts:43) and refuses invalid tokens. Check at startup thatRedisExtensionloaded, or the publish counts read zero. - With that script, count Redis publishes per edit, by subscribing to the document's channels. Run it before and after.
- With the same script, run a convergence check before and after. Kill one instance 30 times mid-edit, restart it, and count the edits that reach the other side. The 2026-10-23 baseline was 21 delivered and 9 lost.
Acceptance criteria
- Publishes per edit, before and after, are posted here.
- The convergence check, before and after, is posted here. The after number is not worse.
- The hazard text in
apps/hocuspocus.server/CLAUDE.mdstays as it is (ruling 4).
Effort and order
Effort M. Ruling 4 chose the lossless SyncStep1 throttle, so this issue can start now. The production delete-set density on large edited heads is still unknown; #576 reads it.
Parent: #575. Source: the 2026-10-23 backend perf plan, refined on 2026-10-24.
Activity
HMarzban commentedon Oct 24, 2026
Maintainer ruling, 2026-10-24
Use the lossless SyncStep1 throttle, not the update relay. The accepted cross-replica hazard text in
apps/hocuspocus.server/CLAUDE.mdstays as it is.The acceptance criteria still hold: post the publishes per edit and the convergence check, before and after. The SyncStep1 must fire on the trailing edge, after edits stop.
This issue is unblocked.
HMarzban commentedon Oct 26, 2026
Built and committed on local main as
6301b369b. Awaits the maintainer's final push.Design: the lossless SyncStep1 throttle from ruling 4, as a bun patch on
@hocuspocus/extension-redis3.4.4. It publishes at once, then at most once per 250 ms per document, and always once more after the last change. The catalog pins exactly3.4.4.Measured with the new
apps/hocuspocus.server/scripts/redis-sync-probe.ts: two replicas, one Redis, one writer on each, on the 5.36 MB edited fixture. Unpatched and patched ran back to back.Publishes per edit
Convergence (30 server kills, 0 to 29 ms after an edit; delivered / lost)
A trace showed that every marker edit in these rounds opens a new window. So it publishes at once, on the same path as before the patch. The spread is run-to-run noise: the handshake closes about 8 to 10 ms after an edit on this laptop, and after-run 3 shared the machine with a Cypress run. With 10 ms steps, both sides lost only the 0 ms and 10 ms rounds.
The hazard text in
apps/hocuspocus.server/CLAUDE.mdis unchanged. A clean frozen install applies the patch, and the hocuspocus production image builds with it inside.fix(hocuspocus): add a per-connection byte budget to history.watch
perf(hocuspocus): throttle the Redis SyncStep1 to once per 250 ms per…
HMarzban commentedon Nov 3, 2026
Status, 2026-11-03.
6301b369bis pushed and deployed with8e25e83df. Production now runs the SyncStep1 throttle patch on extension-redis3.4.4. Left:HMarzban commentedon Nov 3, 2026
Result, 2026-11-03. This is the #576 read for this issue. It ran on production on 2026-10-25, read-only. The head bytes were streamed out and decoded locally.
Can close now: no. The convergence check is still open.
HMarzban commentedon Nov 4, 2026
Measured, 2026-11-04.
I ran the convergence check again, with the two sides alternating: unpatched, patched, unpatched, and so on. That gives 6 runs per side. Each run used
scripts/redis-sync-probe.ts --mode convergence --rounds 30 --step-ms 1 --redis-db 7, on the 5.36 MB fixture, with two replicas and one Redis.A run is "quiet" when no Cypress, headless browser or build process was seen, and the 1-minute load stayed under 7 on 18 cores. For U1 to P2, only the load before each run was checked.
Verdict: the patched side is not worse than the unpatched side. The ranges overlap, and the patched sum is a little higher. The busy run does not change this. The earlier before figure of 62/90 does not come back on this machine today: no three unpatched runs in a row went above 55/90. So compare the pair above, not the old pair of 62 and 55.
The open item meets its acceptance, "the after number is not worse". This can close when the maintainer agrees.
HMarzban commentedon Nov 6, 2026
Maintainer ruling, 2026-11-06
Accepted: the after number is not worse. The alternating runs in the 2026-11-04 comment meet the acceptance item. The hazard text in
apps/hocuspocus.server/CLAUDE.mdstays as it is (ruling 4).Closing as completed. The local
@hocuspocus/extension-redispatch stays while we run Hocuspocus 3.4.4.feat(hocuspocus): drop the 1 s Redis wait after a direct store