Skip to content

A collaboration server restart in a new pad's first save window stops saves until the editor refocuses #799

Open

Description

@HMarzban

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)

  1. 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 sets metadata.isDraft = true and metadata.needsInitialization = true.
  2. The client merges it. On a Y.Map key, the winner is decided by client ID, not by time, so the server's true can win over the client's false. The browser then reads isDraft: true and needsInitialization: true again.
  3. store() returns without saving while isDraft is set (hocuspocus.config.ts:250).
  4. The client clears isDraft on a local edit only when needsInitialization is false (apps/webapp/src/hooks/useHandleDraftOnFocus.ts, handleUpdate). That flag came back true, so typing never clears the draft flag. Only handleFocus does.

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, clear isDraft on a local edit whenever the editor already holds the user's text, not only when needsInitialization is false. Smallest change; keeps the server rule.
  • B. Client: watch the metadata map; when isDraft flips back to true after the editor has saved-intent edits, set it false again.
  • C. Server: on a missing row, do not seed isDraft/needsInitialization into 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

  1. added this to the v2.3.7 milestone on Nov 16, 2026
  2. added
    bug
    Editor
    on Nov 16, 2026
  3. HMarzban commented on Nov 21, 2026

    @HMarzban
    CollaboratorAuthor

    Deployed, 2026-11-21

    The fix (e1e48ea2c) is live in production since 2026-11-21 12:48Z, in the 6da3a609e images. CI/CD Production run 44901986374 ended success on attempt 2.

    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.

  4. HMarzban commented on Nov 24, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-20 and deployed, 2026-11-21: fix A

    Fix A shipped in apps/webapp/src/hooks/useHandleDraftOnFocus.ts (commit e1e48ea2c). It deployed in 6da3a609e (run 44901986374, 2026-11-21 12:48Z) and stays live in e4d36ae0f (run 45132328837, 2026-11-23 07:49Z). It passes the pass rule and every local guard.

    The change

    • The hook now listens for edits whatever isDraft was when it mounted. Before, it attached no listener when isDraft was already false at mount.
    • A focused local edit on a pad that already holds text clears isDraft, even when needsInitialization returned true.
    • The template seed never clears isDraft, because it runs on an empty pad. A pad opened and never edited saves nothing.

    Results

    The services of make dev-local ran 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 latest Documents row 15 s later.

    Case Before (old hook) After (fix A, e1e48ea2c) Pass rule
    SIGKILL inside first store window: stored nothing 7 of 10 0 of 10 (100% fewer failures) 0: met
    Same runs: stored text matches editor 3 of 10 (30%) 10 of 10 (100%) 10 of 10: met
    Guard: new pad opened, never edited — 3 of 3 stored nothing met
    Guard: SIGTERM restart in first store window — 2 of 2 stored met
    Guard: SIGKILL after first save — 2 of 2 stored met
    • n = 10 per side for the main case, because the bug is a merge coin flip (3 of 10 saved before).
    • Before and after runs swapped only useHandleDraftOnFocus.ts in the same session (2026-11-20 13:27Z to 13:47Z). Type check and lint pass.

    Left

    • Maintainer: run #762 local/phone checks 1 to 5 on desktop Chrome and phone Safari.
    • On or after 2026-11-28 12:48Z (7 days after 6da3a609e): run #762 items 6 and 7 across 6da3a609e and e4d36ae0f, then close #799.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    EditorHigh Prioritybug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions