Repository navigation
Description
Problem
If the collaboration server dies before a new pad's first save lands, the pad keeps no server copy while its author keeps typing. Saves resume only after the editor loses focus and gets it back.
Found 2026-11-16 in the #701 browser checks, on both y-tiptap 3.0.10 and 3.3.0: 4 of 4 runs on the new build, 1 of 1 on the old one (SIGKILL of the WS process within the pad's first 10 s store window). A SIGTERM restart and a SIGKILL after the first save both pass.
Cause (read from code; the flip was read in the browser)
- After the restart the server finds no stored row and serves
generateDefaultState()(apps/hocuspocus.server/src/config/hocuspocus.config.ts:62-66, :178). That state setsmetadata.isDraft = trueandmetadata.needsInitialization = true. - The client merges it. On a Y.Map key, the winner is decided by client ID, not by time, so the server's
truecan win over the client'sfalse. The browser then readsisDraft: trueandneedsInitialization: trueagain. store()returns without saving whileisDraftis set (hocuspocus.config.ts:250).- The client clears
isDrafton a local edit only whenneedsInitializationis false (apps/webapp/src/hooks/useHandleDraftOnFocus.ts,handleUpdate). That flag came back true, so typing never clears the draft flag. OnlyhandleFocusdoes.
So every keystroke after the restart is held only in the browser and its offline copy. A tab close before a refocus leaves the server with nothing; the offline copy restores it only in the same browser profile.
Benchmark
| Field | Value |
|---|---|
| Metric | Runs where the pad has a stored row 15 s after typing resumes, after a WS SIGKILL inside the first store window |
| Before | 0 of 4 (y-tiptap 3.3.0 build), 0 of 1 (3.0.10 build), 2026-11-16, local make dev-local, Playwright Chromium 156 |
| After | not measured yet |
| Pass rule | 5 of 5, with the text equal to the editor and no doubled text. The SIGTERM and after-first-save cases still pass |
| Guard | The content-safety checks (#762), including a fresh pad that is opened and never edited: it must still store nothing (the anti-empty-doc rule) |
Options (not ruled)
- A. Client: in
handleUpdate, clearisDrafton a local edit whenever the editor already holds the user's text, not only whenneedsInitializationis false. Smallest change; keeps the server rule. - B. Client: watch the metadata map; when
isDraftflips back to true after the editor has saved-intent edits, set it false again. - C. Server: on a missing row, do not seed
isDraft/needsInitializationinto a document the client already holds (needs a way to tell a new room from a lost first save).
Recommended: A, with a Cypress or Playwright spec that kills the WS process inside the first window.
Evidence
Local evidence folder of the #701 run: check5-kill-new-*, check5-kill-old-*, check5-kill-new-recover-* (session scratchpad). Comment on #701: #701 (comment)
Activity
fix(webapp): keep a new pad saving after an early server restart
HMarzban commentedon Nov 21, 2026
Deployed, 2026-11-21
The fix (
e1e48ea2c) is live in production since 2026-11-21 12:48Z, in the6da3a609eimages. CI/CD Production run 44901986374 endedsuccesson attempt 2.6da3a609eand report healthy.afd06574b(2026-11-17). Between the two, this fix is the only product change.Why the deploy came late: no self-hosted deploy job ran from 2026-11-18 until today, because the host upgrade's cleanup had removed a library the Actions runner needs. It is fixed on the host, and the script fix is tracked separately.
HMarzban commentedon Nov 24, 2026
Measured, 2026-11-20 and deployed, 2026-11-21: fix A
Fix A shipped in
apps/webapp/src/hooks/useHandleDraftOnFocus.ts(commite1e48ea2c). It deployed in6da3a609e(run44901986374,2026-11-21 12:48Z) and stays live ine4d36ae0f(run45132328837,2026-11-23 07:49Z). It passes the pass rule and every local guard.The change
isDraftwas when it mounted. Before, it attached no listener whenisDraftwas already false at mount.isDraft, even whenneedsInitializationreturned true.isDraft, because it runs on an empty pad. A pad opened and never edited saves nothing.Results
The services of
make dev-localran without--watch, with the WS process in a restart loop. Playwright Chromium opened a new pad per run. Each run typed, sent SIGKILL to the WS process 2 s later (inside the 10 s store debounce), waited for restart, typed again with no refocus, then decoded the latestDocumentsrow 15 s later.e1e48ea2c)n = 10per side for the main case, because the bug is a merge coin flip (3 of 10saved before).useHandleDraftOnFocus.tsin the same session (2026-11-20 13:27Zto13:47Z). Type check and lint pass.Left
#762local/phone checks 1 to 5 on desktop Chrome and phone Safari.2026-11-28 12:48Z(7 days after6da3a609e): run#762items 6 and 7 across6da3a609eande4d36ae0f, then close#799.