Skip to content

Design a fix for concurrent TOC section moves that duplicate sections #510

Closed

Description

@HMarzban

Part of #499. Read the parent first. Not on the release path. Owner of the Decision: the maintainer.

This issue measures and designs. It writes no product code. Code waits for a ruling on Decision CM1.

Summary

Two peers who move TOC sets at the same time can duplicate sets that nobody dragged. The duplicate toc-ids then stay in the document (measured on a scratch copy, 2026-10-15). A peer's concurrent typing can be lost, also in a set that nobody moved (measured on a scratch copy).

Names in this issue:

  • A set (R6) is one heading plus its whole subtree. This issue says "set" for the thing a user moves.
  • A section is the flat-document range that holds a set. It runs from the heading to the next heading at its level or higher. This issue says "section" only for that range, as in moveSection.

The cause is not new. Today's moveSection moves a section as one delete plus one insert (move-section.ts:8-26; read from code). The new planner in #500 keeps that path for real moves. So this defect does not gate the TOC move release.

This issue reproduces the defect on a real local pad, confirms or refutes the lost-edit case, and posts one recommended design for a maintainer ruling.

Maintainer rulings that bind this issue

The full text is on #499. One line each:

  • R1. A level change of d on the dragged heading shifts every sub-heading in its set by the same d. So a moved set can carry several markup steps.
  • R2. Think like a flat document. A level change is a level change, and the section logic derives the tree. So an in-place re-level needs no delete and no insert.
  • R3. The Title never moves and is never a drop target above. Step 0 checks that every merged and reloaded outline still starts with one H1 Title with its original toc-id.
  • R4. A shift that passes H6 stays at H6. No case here needs a depth refusal.
  • R5. A drop on a heading puts the set inside it. That is one more move path with the same delete plus insert (case 8b-5 below).
  • R6. A set is one heading plus its whole subtree. The set is the unit that a move deletes and re-inserts.

Depends on / Blocks

Current behaviour

Why a move rewrites content

  • moveSection copies the section slice, then deletes the old range and inserts the copy in one transaction (move-section.ts:8-26; read from code).
  • The TOC calls it from moveHeadingSection (moveHeading.ts:94-115; read from code).
  • Today a pure re-level also takes this path. isSamePosition is true only when the level does not change, so a same-slot level change still runs moveSection (moveHeading.ts:75-112; read from code). Move a TOC section with its sub-headings and keep the Title fixed #500 changes that to markup steps only.
  • The pad syncs through the Tiptap Collaboration extension on the provider's Y.Doc (TipTap.tsx:296-299; read from code).
  • The ProseMirror-to-Yjs sync does not replay a move. updateYFragment matches child nodes from the left and from the right. It then rewrites the middle, or deletes and re-inserts it. Source (read from code, no repo permalink): installed @tiptap/[email protected], dist/y-tiptap.js lines 1542-1690, "find number of matching elements from left" / "from right".
  • So the blocks that get new Yjs items are the ones the diff picks. That can be the moved set, or the blocks it jumped over (secondary / inferred from that code and from the lost-edit rows below).
  • Two peers who both delete the same old items and both insert new copies get two copies after the merge (secondary / inferred).

Why duplicate toc-ids stay

  • UniqueID skips every transaction from a collab change origin (TipTap.tsx:147-152, filterTransaction: (transaction) => !isChangeOrigin(transaction); read from code).
  • On a local transaction, UniqueID re-keys a duplicate only when the step deleted its old position. Source (read from code, no repo permalink): installed @tiptap/[email protected], dist/index.js lines 193-195, if (deleted && duplicatedNewIds.includes(id)).
  • So nothing re-keys a duplicate that arrived by sync, and a later local edit does not either (measured: rows 8b-1, 8b-2 and 8b-5 below).

What a duplicate toc-id breaks (secondary / inferred, not run in the UI)

  • findHeadingById returns the first top-level heading with the id (moveHeading.ts:16-39; read from code). A later move of the second copy moves the first one.
  • A heading chat room is keyed by (workspace_id, heading_id) (apps/hocuspocus.server/CLAUDE.md:131; read from code). Two headings would share one room and one unread count.
  • Fold state is a set of toc-ids (heading-fold-plugin.ts:13-19; read from code). Two copies would fold together.
  • The change digest pairs sections by toc-id. pairSections pairs them (apps/hocuspocus.server/CLAUDE.md:102). A reorder that keeps its toc-id is moved (:104). zippable refuses to zip two sections that both carry a toc-id (:107). All three read from code. A duplicate may report the wrong section.

How wide the window is

  • Two edits conflict only when each is made before its peer sees the other. With both peers online, that is about one network round trip (secondary / inferred, not measured).
  • The pad keeps an IndexedDB mirror of every Y update (useYdocAndProvider.ts:86-92; apps/webapp/CLAUDE.md:185; read from code). An offline peer's edits merge on reconnect. So the window can be the whole offline time (secondary / inferred).
  • A peer can keep editing only while the browser itself reports offline. A dropped socket with navigator.onLine true ends in providerStatus: 'error', and 'error' turns on the editing lock (useYdocAndProvider.ts:185-195; isDocumentEditingLocked.ts:8-14; read from code).

Evidence from a scratch copy (measured, 2026-10-15)

Harness: a headless Tiptap Editor in jsdom with the real Collaboration extension (ySync and yUndo), the repo's UniqueID config and the repo's TitleDocument. Two Y.Docs relay updates through an in-memory link. The link is paused for each case, both peers move, then the link resumes. The moves use a scratch planner that copies moveSection line for line and adds the R1 shift. Versions: tiptap 3.31.3, y-tiptap 3.0.9, yjs 13.6.32, jsdom 26.1.0, Bun 1.4.3.

How to read the rows:

  • 8b-1 to 8b-5 are the scratch case ids.
  • Name#id is a heading and its toc-id.
  • After the merge, the harness edited one heading's text in one peer. !X marks that edit in the first (or only) copy. ?A marks it in the second copy.

Start outline for every 8b case: Title#T A#A B#B X#X X1#X1 X1a#X1a Z#Z. That is H1 Title, H2 A, H2 B, H2 X (with H3 X1 and H4 X1a) and H2 Z, with one paragraph each.

Case Peer A Peer B Merged on both peers Result
8b-1 X before A X before A Title X X1 X1a A B A B Z duplicates=Ax2,Bx2. A and B were never dragged.
8b-2 A after Z A after Z Title B X X1 X1a Z A A duplicates=Ax2
8b-3 X before A X after Z Title Z X X1 X1a A B duplicates=none, but Z jumped to the top. Nobody moved Z.
8b-4 X before A re-level X in place, d=+1, markup steps only Title X X1 X1a A B Z, X H3, X1 H4, X1a H5 duplicates=none. Both edits kept, and the R1 shift held.
8b-5 X inside A, last child the same Title A XX X1 X1a B B Z duplicates=Bx2, and heading text X doubled to "XX".
  • In every case both peers converged to the same document (Y fragments equal=true PM JSON equal=true). The document is wrong, not split.

  • After a local edit in either copy, the duplicates stayed. 8b-2 and 8b-5 gave the same result. The 8b-1 harness output was:

    after a local edit in the 2nd copy of A: Title#T !X#X X1#X1 X1a#X1a A#A B#B ?A#A B#B Z#Z duplicates=Ax2,Bx2
    

Lost-edit rows. This harness calls updateYFragment directly on a minimal schema, not through ySync and the real Editor. Peer B types PEER- into one paragraph while peer A moves. The labels in the first column are the scratch labels.

Move by peer A Peer B edits Edit kept
small A section after D a1, inside the moved set false
small A section after D b1, outside true
D section before A (up) d1, inside the moved set false
A after C with cascade +1 a2, inside the moved set false
re-level A only, markup steps a1, inside the set true
LARGE A section after small B a1, inside the moved set true
LARGE A section after small B b1, the set that stayed false
  • The last two rows show the rule. The edit is lost in whichever blocks the diff rewrites, and that can be a set nobody moved.
  • The LARGE rows used the start outline Title, A (a1-a5), B (b1), with no other sets (measured: scratch measure/move-yjs.mjs:85).
  • The scratch scripts are not in the repo. The maintainer can attach editor-real.ts, planner.ts, measure/move-yjs.mjs and their output files if wanted.

Harness limits (why Step 0 exists)

  • The 8b provider stub sits on Collaboration. The app puts the real provider on CollaborationCaret (TipTap.tsx:296-299; read from code).
  • The lost-edit rows never ran through the real Editor, Hocuspocus or the IndexedDB mirror.
  • 8b-4 used one set size: a 3-heading X jumped over the 2-heading A+B. A peer move over a larger block may rewrite the re-levelled items and drop the markup (secondary / inferred). Cases R-4b and L-3b check that.
  • 8b-5 used a last-child drop. D4 is ruled on Move a TOC section with its sub-headings and keep the Title fixed #500: the first child. So Step 0 re-runs it that way when possible.
  • No case ran with one peer online and one peer offline, which is the common real shape (secondary / inferred).

Target behaviour

  • This issue holds a real-pad reproduction with outlines and toc-ids for each case.
  • The lost-edit case is confirmed or refuted on a real pad. It covers an edit in the moved set and an edit in a set that stayed.
  • One comment holds the coverage table below, filled with real-pad results, and one recommended design for Decision CM1.
  • No product code changes until the maintainer rules.

Micro-interactions

Not a UI issue. This issue builds no visual and no motion. A ruled option may need a visible state, such as a refused move. Then the follow-up code issue owns that state and its design-system Decision.

Implementation steps

Work on main. Read AGENTS.md, apps/webapp/CLAUDE.md, apps/webapp/src/components/TipTap/CLAUDE.md and apps/hocuspocus.server/CLAUDE.md first. Do the steps in this order. Change no repo file.

Step 0. Reproduce on a real local pad (gates every later step)

  1. Start the local stack with make dev-local. Read the WEBAPP line for the port (usually 3000). The WS server is on 4001 (README.md:45-59; read from code).

  2. Record git rev-parse HEAD. Note which of Move a TOC section with its sub-headings and keep the Title fixed #500 and Drop a section onto a TOC heading to put it inside #508 are in that commit. For each issue:

    • run gh issue view <n> --json state,closedAt and git log --oneline --grep '#<n>';
    • then check that the fix commit is an ancestor of HEAD with git merge-base --is-ancestor <sha> HEAD. Exit code 0 means it is in the commit.
  3. Use two signed-in browsers with two different users. Two Chrome profiles work. Sign in with an email link from the local inbox at http://127.0.0.1:54324.

  4. Use a real pad, not /editor. The playground passes provider: null, so it has no peers (EditorPlayground.tsx:49; read from code). window._editor and window._moveHeading do not exist on pad routes. So every move is a real pointer drag in the TOC, or a Section options row once Add Move rows to Section options and open the menu from the grip #501 ships.

  5. Open /new in browser A. Open the same pad URL in browser B. Type the start outline with the Block style select: H1 Title, H2 A, H2 B, H2 X, H3 X1, H4 X1a, H2 Z. Give each heading one paragraph: t0, a0, b0, x0, x1, x1a, z0. Every case uses this start outline, except L-2.

  6. Read the outline and ids in each browser with this DevTools line. It is scoped to .ProseMirror, because rail ticks also carry data-toc-id:

    [...document.querySelectorAll('.ProseMirror :is(h1,h2,h3,h4,h5,h6)[data-toc-id]')].map((h) => `${h.tagName} ${h.textContent}#${h.dataset.tocId}`).join(' | ')
  7. Cut the offline browser off. In most cases that is browser B. In L-1b it is browser A. Use DevTools → Network → Offline in that browser. The status chip is not proof, because the browser offline event alone sets it (useYdocAndProvider.ts:359-366; read from code).

    • Proof: a word typed in the offline browser does not appear in the other browser within 5 seconds. Delete that word before the case starts.
    • DevTools offline may not close an open WebSocket (secondary / inferred). If the word crosses, use the fallback below.
    • Fallback: run the four processes in separate terminals instead of make dev-local (Makefile:212-219; read from code).
      • First run bun scripts/dev-local-preflight.ts once (Makefile:213; read from code).
      • Then run one of these in each of four terminals: bun --filter @docs.plus/hocuspocus dev:rest, bun --filter @docs.plus/hocuspocus dev:ws, bun --filter @docs.plus/hocuspocus dev:worker, bun --filter @docs.plus/webapp dev (Makefile:215-219; read from code).
      • The scripts exist in apps/hocuspocus.server/package.json:8-10 and apps/webapp/package.json:7 (read from code).
      • Set DevTools Offline in both browsers, then stop only the WS process: press Ctrl+C in the dev:ws terminal. Both peers now queue edits, which is the scratch shape.
      • Both browsers need DevTools Offline first. Otherwise the dropped socket ends in the editing lock (see Current behaviour).
      • Prove the fallback cut with the same typed-word test. To merge, restart dev:ws in its terminal, then clear DevTools Offline in both browsers.
    • Post which cut you used for each case.
  8. Run each case below on a fresh pad. Post five entries for each case. For the merged entry and the reload entry, post one line per browser.

    • the start outline;
    • the online browser's local outline, before the offline browser goes back online;
    • the offline browser's local outline, at the same time;
    • the merged outline;
    • the outline after a reload.

    Read the merged outline only after two checks. First, the status chip in both browsers leaves offline. Second, a word typed in t0 in browser A shows in browser B. Delete that word before the reload.

    Check that every merged and reload outline starts with one H1 Title with its start toc-id (R3).

    In every row except L-1b, browser A stays online and browser B is cut off. In the fallback, both are cut off.

    Some cases need setup before the cut-off. Do the setup, confirm in both browsers that it shows, then cut off.

Id Setup before the cut-off Browser A Browser B Needs
R-1 none Online (offline in the fallback). Drag X before A. Cut off. Drag X before A. today's main
R-2 none Drag A after Z Drag A after Z today's main
R-3 none Drag X before A Drag X after Z today's main
R-4 none Drag X before A Re-level X in place, one level deeper. Use Demote from #501, or a same-slot drag with the sideways offset while it still exists. #500
R-4b Give X five more paragraphs, xp1-xp5. Drag A after Z Re-level X in place, one level deeper, as in R-4 #500
R-5 none Drop X inside A Drop X inside A #500; #508 preferred
L-1 none Drag A after Z Type PEER- at the start of paragraph a0 today's main
L-1b none. Browser A is cut off here. Use the same cut-off proof. Cut off. Drag A after Z. Online. Type PEER- at the start of paragraph a0. today's main
L-2 Own start outline: H1 Title (t0), H2 A (a0-a5), H2 B (b0). It matches the scratch LARGE fixture. Drag A after B Type PEER- at the start of b0 today's main
L-3 none Re-level A in place, one level deeper, as in R-4 Type PEER- at the start of a0 #500
L-3b Give A five more paragraphs, a1-a5. Drag B before A Re-level A in place, one level deeper, as in R-4 #500

R-5 needs #500 for the R1 shift. Before #508 ships, drop X in the gap before B with the sideways offset at H3, on a commit that has #500. Otherwise mark R-5 "skipped: needs #500". Say which drop you ran.

Expected levels after the R1 shift: X H3, X1 H4, X1a H5 in R-4, R-4b and R-5. A H3 in L-3 and L-3b.

  1. Post one comment headed ## Real-pad reproduction, <date> with the commit, the cut-off proof and every case. Mark a case "skipped: needs " when that issue is not in the commit. For R-4, R-4b, R-5, L-3 and L-3b, that issue is Move a TOC section with its sub-headings and keep the Title fixed #500. A missing Drop a section onto a TOC heading to put it inside #508 does not skip R-5. Run the fallback drop above instead.

Step 1. Confirm or refute the lost-edit case

Read the L-1, L-1b, L-2 and L-3 results from Step 0. State for each one whether PEER- survived after both reloads. For L-3b, state whether A kept its new level after both reloads. Then state the rule in one sentence: which blocks lose concurrent edits. If L-2 keeps the edit, say that the scratch "section that stayed" result did not reproduce.

Step 2. Fill the coverage table

Copy this table into the comment and replace each cell with the real-pad result or a one-line reason. The cells now are predictions (secondary / inferred), except the R-4 / 8b-4 and L-3 cells marked measured.

Case (a) Stateless or awareness lock (b) Post-merge toc-id dedupe (c) Markup-only re-level (shipped in #500) (d) Refuse a TOC move while this client is offline
R-1 / 8b-1 duplicates Helps only if both peers are online and the lock arrives first. Cannot reach an offline peer. Deletes the later equal copy of A and B. Outline becomes correct. No effect. Prevents it when the mover is the offline peer.
R-2 / 8b-2 duplicates As above. Deletes the later equal copy. No effect. As above.
R-3 / 8b-3 reorder As above. No effect: there is no duplicate. No effect. As above.
R-4 / 8b-4, R-4b Not needed. Not needed. Merges cleanly (measured on one set size; R-4b checks the other). Not needed.
R-5 / 8b-5 duplicates and "XX" As above. Deletes the later B. "XX" stays. No effect. As above.
L-1 / L-1b / L-2 lost edit No effect: typing is not a move. No effect. No effect on a real move. Helps only in L-1b, where the mover is offline. An offline typist (L-1, L-2) still loses edits.
L-3 lost edit on re-level; L-3b re-level under a peer move Not needed. Not needed. L-3 keeps the edit (measured on scratch). L-3b checks that the new level survives; a prediction. Not needed in L-3. In L-3b, helps only when the mover is offline.

Step 3. Write down the cost of each option

Put one short paragraph per option in the comment. Use these facts.

  • (a) Lock. The stateless relay is an allowlist that holds only docTitle (statelessRelay.ts:13, :26-39; hocuspocus.server.ts:346-366; read from code).
    • The relay has no authorization and reaches the whole fleet. Any public room is joinable with no credentials (apps/hocuspocus.server/CLAUDE.md:50-55; read from code).
    • So a new relayed type is a security change. An anonymous viewer could send a fake lock and block every move in the room (secondary / inferred).
    • Sub-question: carry the lock in awareness instead. Awareness needs no relay change.
      • A remote awareness state is dropped after 30 seconds with no update. Source (read from code, no repo permalink): installed [email protected], awareness.js line 13, outdatedTimeout = 30000, and line 70.
      • A state is also removed when its client disconnects (secondary / inferred, not read in the Hocuspocus source).
      • It has a 64 KiB frame budget (apps/hocuspocus.server/CLAUDE.md:57; read from code). Any client can still write a fake field (secondary / inferred).
    • Either way, the lock never reaches an offline peer. It narrows only the online window.
  • (b) Dedupe. It needs its own pass, because UniqueID ignores synced transactions (see Current behaviour).
    • Say where it runs. On every client, all clients may repair at once. Deleting the same Yjs items twice is safe, but two clients must pick the same copy (secondary / inferred).
    • Rule to evaluate: keep the first copy in document order. Delete a later copy only when its content equals the first copy.
    • When the copies differ (a peer edited one, as in ?A#A), deleting loses that edit. Re-keying keeps both copies, but the second one loses its chat room, folds and unread count. Name which trade you recommend.
    • It does not fix the 8b-3 reorder, the "XX" text or a lost edit.
  • (c) Markup-only re-level. Already shipped by Move a TOC section with its sub-headings and keep the Title fixed #500. No extra cost. It covers only re-levels.
  • (d) Offline refusal. Reuse the 'locked' refusal that Move a TOC section with its sub-headings and keep the Title fixed #500 adds (not on main at 85295b8; read from code: moveHeading.ts returns only booleans). Key it on the provider status.
    • The app sets providerStatus to 'offline' on the browser offline event (useYdocAndProvider.ts:359-366; read from code).
    • On a disconnect it sets 'offline' only while navigator.onLine is false, and otherwise takes an error path (:170-190; read from code). So the gate must name every status that means "not connected".
    • It needs a visible state (no grip, or a disabled Move group), which is a design-system Decision in the code issue.
    • Notion allows offline editing: "All Notion users can view, edit, and create pages offline on the desktop or mobile app." (Notion guide; primary source).
    • Its offline exclusions name embeds, forms, buttons, sharing and permissions, and no move limit (secondary / inferred: the guide does not mention moves).
    • Google Docs and Word were not checked.
    • So no checked peer refuses a move offline. Flag this under AGENTS.md:151 before you recommend it.
  • (e) Count before repair. One Sentry message per pad session when a synced transaction leaves two top-level headings with one toc-id. Reuse captureCollabIssueOnce (observability.ts:75-91; read from code). It repairs nothing. It tells the maintainer how often this happens.
  • Rejected: a server-side move op. It would serialize two moves. But a server write loses authorship: "applyContentToDoc clones every node under the server document's own clientID" (apps/webapp/CLAUDE.md:260; read from code). It still deletes and re-inserts, so it keeps the lost-edit case, and it cannot reach an offline peer (secondary / inferred).

Step 4. Post the Decision

Post one comment headed ## Design proposal, <date>. It holds the Step 1 rule, the filled table, the Step 3 costs and Decisions CM1 and CM2 below, each with the recommended answer first. Update the recommended answer if Step 0 hits a flip rule. Then stop. Code waits for a Maintainer ruling, <date> comment.

Out of scope

  • Any product code before a ruling. That includes a lock, a dedupe pass, a refusal and a detector.
  • Changes to the collab storage design are settled (root CLAUDE.md:44; apps/hocuspocus.server/CLAUDE.md:5). A change to Yjs itself is out of scope for this issue.
  • A patch to @tiptap/y-tiptap so that a move keeps its Yjs items. If Step 1 shows that is the only real fix, say so in the proposal as an upstream follow-up.
  • Concurrent typing with no move. Yjs already merges it.
  • The phone TOC. It has no move path today (tracker D27).

Decisions

The recommended answer comes first. Owner: the maintainer. The ruling is posted as a comment headed Maintainer ruling, <date>. These ids are local to this issue and do not collide with the tracker's D numbers.

  1. CM1. Which design handles concurrent TOC moves? Recommended (before Step 0): accept the loss as a recorded hazard, and ship only the log-only detector (e). Build no lock and no repair yet.
    • The loss you accept, stated plainly: a peer's typing in any block the diff rewrites can be lost when the peers merge. With an offline peer, that is every edit made in those blocks while offline.
    • Also accepted: duplicate sets and toc-ids stay until someone deletes them by hand.
    • Reason: no option fixes the lost-edit case, and the lock cannot reach an offline peer. A repair that deletes content needs evidence that the risk is worth it.
    • Why not (d): it prevents a duplicate only when the mover is the offline peer. It helps a lost edit only when the mover is offline (L-1b).
      • Notion allows offline editing (Notion guide; primary source: "All Notion users can view, edit, and create pages offline on the desktop or mobile app."). Its guide names no move limit (secondary / inferred).
      • Google Docs and Word were not checked. So no checked peer refuses a move offline (AGENTS.md:151).
      • It also adds a visible state that needs a design-system ruling.
    • Flip rule 1: if L-1 or L-2 loses PEER- on a real pad, say which peer was offline. Re-weigh (d) only when the lost edit happened with the mover offline, as in L-1b.
    • Flip rule 2: the production count from (e) is the only real frequency gate. A local stack cannot show how often moves race. If the count is not zero, bring it and re-open this Decision. The house treats a repair like the Report route: the count first.
    • Alternatives: (a) a stateless or awareness lock. (b) Dedupe now. (d) Refuse moves while offline; no checked peer supports it. The server-side move op is rejected in Step 3.
  2. CM2. Where is the accepted hazard recorded? Recommended: one bullet in apps/webapp/src/components/TipTap/CLAUDE.md §Heading Schema, next to "Section reorder is TOC-only".

Acceptance criteria

  • A ## Real-pad reproduction, <date> comment names the commit and the cut-off method. It proves that the offline browser was cut off for each run.
  • Each case in the Step 0 table shows the five entries with toc-ids from Step 0 item 8. That is R-1 to R-5, R-4b, L-1 to L-3, L-1b and L-3b. A skipped case names the issue it waits for.
  • For R-4, R-4b and R-5, check the merged outline and the reload outline in both browsers. X, X1 and X1a each shift by the same d (expected H3, H4, H5 from H2, H3, H4). Read the levels from the tag names in the Step 0 item 6 DevTools line. A case that loses the shift on any sub-heading is reported as a defect.
  • Every merged and reload outline starts with one H1 Title with its start toc-id. A case that breaks this is reported as a defect.
  • The lost-edit case is confirmed or refuted on a real pad. It covers an edit in the moved set and an edit in a set that stayed.
  • A ## Design proposal, <date> comment holds the filled coverage table and the cost of each option.
  • The same comment states CM1 and CM2, each with the recommended answer first.
  • No repo file changed and no product code was written. Dropped by maintainer ruling, 2026-11-09: 745f4c04e shipped the repair.

Verification

  • No test is added. This issue changes no code, so there is no failure mode to pin (AGENTS.md §Test Policy, AGENTS.md:102-110).
  • Local stack: make dev-local, or the four-terminal fallback in Step 0 item 7. Bun only. Do not run next build against the live dev server.
  • Check the working tree after the run: git status --short must show no change caused by this issue.
  • Browser runs use a visible tab. A hidden tab pauses requestAnimationFrame and can stall the TOC.
  • When the follow-up code issue exists, a test is allowed only for a dense branch. For example, the dedupe rule "delete a later copy only when it equals the first" may get one unit test, proved by sabotage.

Docs to update

Read first

  • AGENTS.md §Workflow And Review Expectations (filing is read-only work; majority rule at line 151) and §Test Policy.
  • Root CLAUDE.md §Settled: Collab storage design.
  • apps/hocuspocus.server/CLAUDE.md: the opening paragraph, §Runtime limits (the stateless relay and the awareness budget) and §Documented hazards we accept.
  • apps/webapp/CLAUDE.md §Slug Page Entry And Skeletons (Offline mirror) and §TOC And Heading Actions.
  • apps/webapp/src/components/TipTap/CLAUDE.md §Heading Schema.
  • The tracker [Tracking] Move TOC sections like folders: cascade, drop inside, and a menu path #499: the rulings R1-R6 and the Shared rules (The level rule: every move keeps every toc-id).

Generated by Claude Code

Activity

  1. added
    bug
    Editor
    Toc
    on Oct 16, 2026
  2. added this to the v2.3.0 milestone on Oct 19, 2026
  3. HMarzban commented on Nov 3, 2026

    @HMarzban
    CollaboratorAuthor

    Status, 2026-11-03. No reproduction or design comment exists yet. The 2026-11-03 push (a9b0c69e8..8e25e83df) does not touch moveSection, so the measured duplicate case is still live.

    Left:

  4. HMarzban commented on Nov 6, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-06

    Short answer: yes. The duplicate still reproduces after the planner rewrite. Delete-first moves did not remove it.

    What ran, and what did not

    • This is a harness run, not the real-pad Step 0. Step 0 needs two signed-in users and DevTools Offline. That run is still owed.
    • Harness: two EditorViews in jsdom, the real ySyncPlugin and yUndoPlugin, two Y.Docs and a paused relay.
    • Move code: the shipped planTreeMove and treeMoveTransaction (delete first, then insert), imported from main at 44be025. Each peer plans on its own state.
    • Versions: @tiptap/y-tiptap 3.0.10 with the repo patch, yjs 13.6.33, prosemirror-view 1.42.6, @tiptap/pm 3.32.2, jsdom 26.1.0, Bun 1.4.4.
    • Both peers converged in every row. R3 held in every row: one H1 Title#T, first.
    • Two runs gave byte-identical output.

    Results

    Start outline: Title#T A#A B#B X#X X1#X1 X1a#X1a Z#Z, one paragraph each.

    Case Peer A Peer B Merged Result
    R-1 X before A X before A Title X X1 X1a A B A B Z A and B twice. Nobody dragged them.
    R-2 A after Z A after Z Title B X X1 X1a Z A A A twice.
    R-3 X before A X after Z Title Z X X1 X1a A B No duplicate. Z jumped to the top, and nobody moved Z.
    R-4 X before A drop X onto B Title X(H3) X1(H4) X1a(H5) A B Z No duplicate. Wrong levels: X is H3 straight under the H1 Title.
    R-4b A after Z drop X onto B (X has 5 more paragraphs) Title B X(H3) X1 X1a Z A No duplicate.
    R-5 drop X onto A drop X onto A X, X1, X1a and B each twice Duplicates. The extra X, X1 and X1a are bare headings; each paragraph appears once.
    L-1 A after Z types PEER- in a0 Title B X X1 X1a Z A PEER- lost on both peers.
    L-1b (roles swapped) same as L-1 PEER- lost. A paused relay is symmetric, so L-1b equals L-1 here.
    L-2 A after B (A has a0-a5) types PEER- in b0 Title B A PEER- lost, in the set that did not move.
    L-3, L-3b not run Not reachable in today's UI.

    Notes

    • R-4 and R-4b used a real drop. In-place re-level is gone: the home slot does nothing, and the level picker was removed. "Drop X onto B" nests X under the row above it, which gives the same document as a +1 re-level. So these rows are move-against-move, not the markup-only rows in the 2026-11-04 research.
    • L-3 and L-3b cannot be reached. An in-place re-level of A would need a drop onto an earlier sibling, and A has none.
    • R-5 got wider than the 2026-11-04 delete-first row. That row had X and B twice. Today X1 and X1a double too. Cause, measured: shiftLevels rebuilds every shifted heading before the insert. With setNodeMarkup after the insert, only X and B double.
    • Every remaining difference from the old insert-first order is an upward move. Insert-first made R-1 worse (X, X1, X1a, A and B twice) and lost PEER- inside a moved set. Delete-first keeps that edit.

    Limits

    • Minimal schema: headings with toc-id, and paragraphs. No UniqueID, fold plugin, HeadingScale, Hocuspocus or IndexedDB.
    • The raw ySyncPlugin, not the Tiptap Collaboration extension.
    • locked: false in the planner. On a real pad, isTocMoveLocked does not lock while offline, so an offline peer can still move.
    • No server ordering, because the relay is paused.

    Scripts: run510-planner.mjs and probe-r5-cause.mjs, in the local 11-04 harness folder. No code changed for #510, and nothing was committed.

  5. HMarzban commented on Nov 6, 2026

    @HMarzban
    CollaboratorAuthor

    Design proposal, 2026-11-06 (harness only)

    This is a harness result, not the real-pad Step 0. Step 0 and the real-pad half of Step 1 are still owed. Every cell below comes from the harness.

    Commit: c8ce4adeb. The move code (planTreeMove.ts, tocMove.ts) has not changed since 44be02585.

    Harness: the same setup as the "Measured, 2026-11-06" comment. Two EditorViews in jsdom, the real ySyncPlugin and yUndoPlugin, and a paused relay. Option 4 adds a third Y.Doc as the server. Peer A is online and peer B is offline; B's requests queue and replay after the merge. Two runs gave byte-identical output.

    Step 1. Lost edits (harness)

    Case PEER- after the merge
    L-1: A after Z; peer types in a0 (moved set) lost
    L-1b: the same with roles swapped lost. The paused relay is symmetric.
    L-2: LARGE, A after B; peer types in b0 (the set that stayed) lost
    L-1u (extra): X before A; peer types in x1 (moved set) kept
    L-1uj (extra): the same; peer types in a0 (jumped over) lost
    L-2m (extra): LARGE; peer types in a3 (moved set) kept
    L-3, L-3b Not reachable in today's UI

    The rule. With delete-first, y-tiptap keeps the Yjs items of the longer run of top-level blocks. It creates new items for the shorter run. A concurrent edit in the shorter run is lost, and that run can be a set nobody moved (L-2). No option below fixes this. Only a native Yjs move or an upstream move rebase could.

    Step 2. Coverage table (harness)

    Options:

    • (1) Y-level repair, run by every client after a collab transaction.
    • (2) setNodeMarkup after the insert, instead of rebuilding headings with shiftLevels.
    • (3) An LWW intent map that every peer applies.
    • (4) The server applies move requests.
    • (5) An awareness lease.
    • (d) Refuse a move while offline.

    In-place re-level is no longer reachable in the UI, so the old markup-only column is gone.

    Case Today (1) repair (2) markup after (1)+(2) (3) intent, every peer (4) server (5) lease (d) refuse offline
    R-1 A, B twice fixed A, B twice fixed A, B twice fixed (2nd request is noop) as today no dup; B's move refused
    R-2 A twice fixed A twice fixed A twice fixed as today no dup; B refused
    R-3 Z jumps to the top as today as today as today as today A B Z X: the later request wins as today X A B Z; B refused
    R-4 (drop) X is H3 straight under Title as today as today as today worse: A, B twice X H3 under B as today X H2 first; B refused
    R-4b (drop) clean clean clean clean clean clean as today clean; B refused
    R-5 X, X1, X1a, B twice fixed with the twin rule X, B twice fixed worse: X three times fixed as today no dup; B refused
    L-1 (typist offline) lost lost lost lost lost lost as today lost
    L-1b (mover offline) lost lost lost lost lost kept as today kept (the move is refused)
    L-2 (typist offline) lost lost lost lost lost lost as today lost
    • "As today" for (5) holds by design. A paused relay is an offline peer, and a lease never reaches one.
    • Every row converged. Every row kept one H1 Title#T first.

    Extra findings:

    • A repair must write to the Y.XmlFragment directly. When both peers ran a repair through a ProseMirror dispatch, the re-keyed copy of B appeared twice (R-1t). The Y-level version converged when both peers repaired and when one did.
    • A plain "equal copy" rule leaves three bare headings in R-5. A narrow twin rule fixes it: delete a bare copy only when the next block is an equal heading. It never deleted a copy that held PEER-.
    • Option 2 fixes a caret bug that needs no race. When a drop shifts levels, an online peer's caret in a shifted sub-heading jumps to the last section, and their next key lands there. With setNodeMarkup after the insert, the caret stays. Undo of a solo move stays clean.
    • Undo after an R-5 race leaves H1 headings with toc-id null, with or without a repair. A repair cannot fix that.
    • An intent map that every peer applies is worse than today (R-5 gives X three times). It only helps with one applier, which is option 4.

    Step 3. Cost of each option

    • (1) Repair. One extension under TipTap/extensions/, about 80 lines plus a unit test. It runs on collab-origin transactions that change the list of top-level heading ids, inside one ydoc.transact with its own origin, so it never lands on an undo stack. Pass 1 deletes a bare copy only when the next block is an equal heading. Pass 2: the first copy owns the id; a later equal set is deleted, and a different set is re-keyed. A new id must be a deterministic hash that fits heading_id varchar(36). It must be gated like isTocMoveLocked, because the server drops writes from read-only connections. Risk: it deletes content, guarded by equality, and it was measured with two peers only.
    • (2) Markup after. About 10 lines in treeMoveTransaction: insert the slice unshifted, then setNodeMarkup. It keeps the caret carry and the NEW_HEADING_CREATED meta.
    • (3) Intent map. A new shared Y.Map. Worse than today when every peer applies it.
    • (4) Server applier. The moved copy loses its author, the mover's Undo no longer reverts the move, an offline typist still loses edits, and two WS replicas can apply one request twice. High cost. Not chosen.
    • (5) Lease. Covers only an online race, can be faked, and needs a new visible state. Not chosen.
    • (d) Refuse offline. Small, but it needs a visible state and helps only an offline mover. Not chosen.
    • (e) Count. Small: reuse captureCollabIssueOnce, fired before the repair and before the read-only gate.

    Step 4. Decision

    CM1 (maintainer, 2026-11-06): build (2), (e) and (1) now.

    • (2) fixes the caret jump that needs no race, and it narrows R-5.
    • (e) counts duplicate ids in production, so we learn how often races happen.
    • (1) removes duplicate sections and ids now, because a duplicate id shares a chat room, a fold and a digest pairing. It writes to Yjs directly and uses the twin rule.
    • Not chosen: (3), (4), (5), (d). Re-weigh (d) only if a real pad loses PEER- with the mover offline.

    CM2. One bullet in apps/webapp/src/components/TipTap/CLAUDE.md records the hazards that stay: typing in the shorter run of a concurrent move can be lost; R-3 can reorder a set nobody moved; R-4 can leave a level that does not fit its parent; undo after an R-5 race leaves H1 headings with toc-id null.

    Limits

    • Minimal schema: no UniqueID, fold plugin or HeadingScale.
    • The raw ySyncPlugin, not the Tiptap Collaboration extension.
    • No Hocuspocus, no IndexedDB and no replicas.
    • Two peers only, and no timing for an online race.
  6. HMarzban commented on Nov 9, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-11-09

    The acceptance box "No repo file changed and no product code was written" is dropped. 745f4c04e shipped the repair under the 2026-11-06 ruling. The real-pad Step 0 and the design comment below still stand.

    Real-pad reproduction, 2026-11-09

    Short answer: every Step 0 case ran on a real local pad. The shipped repair (745f4c04e) removes the duplicates of R-1, R-2 and R-5 within milliseconds. R-3, R-4 and three lost-edit cases (L-1, L-1b, L-2) still happen. L-1b lost PEER- with the mover offline, so flip rule 1 fires.

    Commit and setup

    • Commit: d31ed9033f81a01e3e150e1c388a3834e06478f2 (git rev-parse HEAD).
    • Move a TOC section with its sub-headings and keep the Title fixed #500 is in it: the planner dd287cbfb. Drop a section onto a TOC heading to put it inside #508 drop inside is in it: 8d4ef6057. The repair 745f4c04e is in it. git merge-base --is-ancestor exited 0 for all three.
    • Stack: make dev-local (webapp :3000, WS :4001). Real pads made with /new, one fresh pad per case.
    • Two headless Chromium contexts (Playwright 1.64.1), viewport 1440x1000, so the wide TOC renders. Two different signed-in users: Swarm Actor 1 (browser A) and Swarm Actor 2 (browser B), signed in with applyActorSession.
    • Seed: the Title node stays, with its own toc-id. The rest of the pad is replaced through the editor once, in browser A. UniqueID gives the ids. Browser B must show the same blocks and ids before the cut.
    • Moves are real pointer drags in the TOC. Hover the row, press its .toc-drag-handle, move in steps, release. Each drag was checked to change the local outline. No move went through a script.
      • "Before W": the top tenth of W's row. "After Z": the bottom tenth of Z's row. "Onto W": the middle of W's row (drop inside, Drop a section onto a TOC heading to put it inside #508).
      • R-4 and R-4b re-level X in place by dropping X onto B. X then nests as the last child of B, which is its own slot. In-place re-level has no other TOC path today.
      • L-3 and L-3b re-level A with Mod-Alt-3, with the caret in A. The TOC cannot re-level A in place, because A has no earlier sibling. A has no sub-headings, so this gives the same document as an R1 re-level by +1.
    • Typing: real keys. The caret goes to the start of the paragraph, then Playwright types PEER-.

    Cut-off method

    DevTools Offline was not used. The cut is a WebSocket gate in the test browser, plus the browser offline flag.

    • Each context routes ws://localhost:4001 through context.routeWebSocket. The gate forwards frames by hand in both directions.
    • To cut: set the gate closed, call context.setOffline(true), then close the open socket. While cut, every new socket is closed at once, before it reaches the server.
    • setOffline(true) makes navigator.onLine false. So the app sets providerStatus: 'offline', not 'error', and the cut peer can still edit and move.
    • Proof, every run: 0 WS frames left the cut page, 0 reached the server and 0 came back. The provider tried 2 or 3 reconnects, and the gate refused each one. The chip read Offline, and navigator.onLine was false.
    • To merge: open the gate, then setOffline(false). The online event calls provider.connect(), and a fresh socket runs a full sync. Both peers converged within about 0.3 s.
    • Merge gate (Step 0 item 8): both chips left Offline. Then QQ typed in t0 in A showed in B within about 1.5 s, and was deleted before the reload.
    • Before the merge, both pages logged every distinct outline on each editor transaction. That catches the duplicate state before the repair removes it.

    Results

    Start outline: Title A B X X1 X1a Z, H1, H2, H2, H2, H3, H4, H2, one paragraph each (t0 a0 b0 x0 x1 x1a z0). L-2 and L-2m use Title A(a0-a5) B(b0).

    Case Browser A Browser B Merged and reload, both browsers Before the repair Result
    R-1 X before A cut; X before A Title X X1 X1a A B Z A and B twice Fixed by the repair
    R-2 A after Z cut; A after Z Title B X X1 X1a Z A A twice Fixed by the repair
    R-3 X before A cut; X after Z Title Z X X1 X1a A B no duplicate Z jumped to the top. Nobody moved Z.
    R-4 X before A cut; X onto B Title X(H3) X1(H4) X1a(H5) A B Z no duplicate Shift held. X is H3 straight under the H1 Title.
    R-4b A after Z cut; X onto B (X has xp1-xp5) Title B X(H3) X1(H4) X1a(H5) Z A no duplicate Clean. Shift held.
    R-5 X onto A cut; X onto A Title A X(H3) X1(H4) X1a(H5) B Z X twice, side by side; B twice Fixed by the repair. Shift held.
    L-1 A after Z cut; PEER- in a0 Title B X X1 X1a Z A, a0 — PEER- lost (moved set)
    L-1b cut; A after Z PEER- in a0 Title B X X1 X1a Z A, a0 — PEER- lost. The mover was offline.
    L-2 A after B cut; PEER- in b0 Title B A, b0 — PEER- lost (set that stayed)
    L-2m (extra) A after B cut; PEER- in a3 Title B A, PEER-a3 — PEER- kept (moved set, longer run)
    L-3 Mod-Alt-3 on A cut; PEER- in a0 Title A(H3) B X X1 X1a Z, PEER-a0 — PEER- kept. A kept H3.
    L-3b B before A cut; Mod-Alt-3 on A (A has a1-a5) Title B A(H3) X X1 X1a Z — A kept H3 after both reloads. A is now a child of B.
    • The duplicate lived for 2 to 15 ms. In R-1, R-2 and R-5, both browsers showed the extra copies on the first merged transaction. They were gone on the next transaction, which only the repair writes.
    • The TOC list matched the editor after the merge and after the reload: same row count, same toc-id order, in both browsers. Checked in a third run of R-1, R-2 and R-5 (out/run-2026-11-09T05-29-35-742Z.log).
    • Every copy was equal, so the repair deleted copies and re-keyed none. No heading changed its toc-id in any entry.
    • R1 shift (R-4, R-4b, R-5): X, X1 and X1a moved from H2, H3, H4 to H3, H4, H5 (d = +1). That holds in the merged and reload outlines in both browsers. The DOM tag names match.
    • R3: every merged and reload outline, in both browsers, starts with one H1 Title with its start toc-id. No case broke it.
    • Both browsers held the same blocks after the merge and after the reload, in every case.
    • A second full run on fresh pads gave the same outline shapes in all 12 cases.

    Lost edits (Step 1)

    • L-1: PEER- in a0 lost after both reloads. Typist offline; edit in the moved set.
    • L-1b: PEER- in a0 lost after both reloads. Mover offline. The typist was online, and their edit had reached the server.
    • L-2: PEER- in b0 lost after both reloads. Typist offline; edit in the set that stayed. The scratch result reproduced.
    • L-2m (extra): PEER- in a3 kept. The moved set was the longer run.
    • L-3: PEER- kept. A markup-only re-level rewrites no blocks.
    • L-3b: A kept its new level, H3, after both reloads.
    • The rule: y-tiptap gives new Yjs items to the shorter run of a move. Typing in that run while the peers are apart is lost, whether the run moved (L-1, L-1b) or stayed (L-2).
    • Not re-run: typing in a removed copy right after the merge. The 2026-11-06 ruling accepts that loss.

    Per-case entries

    Each entry lists the headings in order, as Name(level). Each name stands for the toc-id in the case's Ids line. The script maps every id back to a start id, and found no unknown id.

    R-1

    • Pad /7sowq7sjz6x. Ids: Title#Kx6af15822aENlt2 A#gLX6af15824BOar3 B#ks6af15824K9oKK2 X#56af15824jGw8HE1 X1#Ot6af15824FigxF2 X1a#OQuoQ76af15824G6 Z#VYeMXzR6af158247
    • Cut-off B: 0 WS frames left the page, 0 reached the server, 0 came back; 3 reconnects refused.
    • 1 Start (A = B): Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 2 Online A, local: Title(H1) X(H2) X1(H3) X1a(H4) A(H2) B(H2) Z(H2)
    • 3 Offline B, local: Title(H1) X(H2) X1(H3) X1a(H4) A(H2) B(H2) Z(H2)
    • First merged state, before the repair: A: Title(H1) X(H2) X1(H3) X1a(H4) A(H2) B(H2) A(H2) B(H2) Z(H2); B: Title(H1) X(H2) X1(H3) X1a(H4) A(H2) B(H2) A(H2) B(H2) Z(H2)
    • 4 Merged A: Title(H1) X(H2) X1(H3) X1a(H4) A(H2) B(H2) Z(H2)
    • 4 Merged B: Title(H1) X(H2) X1(H3) X1a(H4) A(H2) B(H2) Z(H2)
    • 5 Reload A: Title(H1) X(H2) X1(H3) X1a(H4) A(H2) B(H2) Z(H2)
    • 5 Reload B: Title(H1) X(H2) X1(H3) X1a(H4) A(H2) B(H2) Z(H2)
    • Checks: R3 holds in all four outlines. No duplicate id after the merge or the reload. PEER- present: merged false, reload A false, reload B false. Sentinel QQ in t0 crossed A to B in 1513 ms, then was removed.

    R-2

    • Pad /b8nc00lv5dy. Ids: Title#FZD6af1583bgvcH3 A#l7jau6af1583ed55 B#6af1583esyQOcrY0 X#oPs6af1583ex33n3 X1#yTybUo6af1583eQ6 X1a#ZRtoT6af1583ei65 Z#EE6af1583e1tuHi2
    • Cut-off B: 0 WS frames left the page, 0 reached the server, 0 came back; 3 reconnects refused.
    • 1 Start (A = B): Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 2 Online A, local: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 3 Offline B, local: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • First merged state, before the repair: A: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2) A(H2); B: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2) A(H2)
    • 4 Merged A: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 4 Merged B: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 5 Reload A: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 5 Reload B: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • Checks: R3 holds in all four outlines. No duplicate id after the merge or the reload. PEER- present: merged false, reload A false, reload B false. Sentinel QQ in t0 crossed A to B in 1513 ms, then was removed.

    R-3

    • Pad /nd9h37qera3. Ids: Title#nD4Yi6af15855Kg5 A#eK8wc86af15858t6 B#5wwPXPd6af158587 X#92aL6af15858R994 X1#BsnyxG6af15858G6 X1a#39U6af15858aOwh3 Z#u6af15858HNpUXy1
    • Cut-off B: 0 WS frames left the page, 0 reached the server, 0 came back; 3 reconnects refused.
    • 1 Start (A = B): Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 2 Online A, local: Title(H1) X(H2) X1(H3) X1a(H4) A(H2) B(H2) Z(H2)
    • 3 Offline B, local: Title(H1) A(H2) B(H2) Z(H2) X(H2) X1(H3) X1a(H4)
    • 4 Merged A: Title(H1) Z(H2) X(H2) X1(H3) X1a(H4) A(H2) B(H2)
    • 4 Merged B: Title(H1) Z(H2) X(H2) X1(H3) X1a(H4) A(H2) B(H2)
    • 5 Reload A: Title(H1) Z(H2) X(H2) X1(H3) X1a(H4) A(H2) B(H2)
    • 5 Reload B: Title(H1) Z(H2) X(H2) X1(H3) X1a(H4) A(H2) B(H2)
    • Checks: R3 holds in all four outlines. No duplicate id after the merge or the reload. PEER- present: merged false, reload A false, reload B false. Sentinel QQ in t0 crossed A to B in 1512 ms, then was removed.

    R-4

    • Pad /abbeaacqq00. Ids: Title#jEY6af1586fDq6f3 A#6af15872LLoB4jo0 B#b6af15872thkvxz1 X#Yabpgi6af1587236 X1#5A6af158725s32V2 X1a#tK9a6af15872FCs4 Z#6H6af158722eDRu2
    • Cut-off B: 0 WS frames left the page, 0 reached the server, 0 came back; 3 reconnects refused.
    • 1 Start (A = B): Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 2 Online A, local: Title(H1) X(H2) X1(H3) X1a(H4) A(H2) B(H2) Z(H2)
    • 3 Offline B, local: Title(H1) A(H2) B(H2) X(H3) X1(H4) X1a(H5) Z(H2)
    • 4 Merged A: Title(H1) X(H3) X1(H4) X1a(H5) A(H2) B(H2) Z(H2)
    • 4 Merged B: Title(H1) X(H3) X1(H4) X1a(H5) A(H2) B(H2) Z(H2)
    • 5 Reload A: Title(H1) X(H3) X1(H4) X1a(H5) A(H2) B(H2) Z(H2)
    • 5 Reload B: Title(H1) X(H3) X1(H4) X1a(H5) A(H2) B(H2) Z(H2)
    • Checks: R3 holds in all four outlines. No duplicate id after the merge or the reload. PEER- present: merged false, reload A false, reload B false. Sentinel QQ in t0 crossed A to B in 1512 ms, then was removed.

    R-4b

    • Pad /bvja4xea1mi. Ids: Title#Wep2F6af1588blz5 A#hIL6af1588d0m2e3 B#Ok6af1588dXks6S2 X#3U86af1588dpBq73 X1#MOlh6af1588dFNN4 X1a#LSxfppr6af1588d7 Z#LBFf6af1588dLTz4
    • Cut-off B: 0 WS frames left the page, 0 reached the server, 0 came back; 3 reconnects refused.
    • 1 Start (A = B): Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 2 Online A, local: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 3 Offline B, local: Title(H1) A(H2) B(H2) X(H3) X1(H4) X1a(H5) Z(H2)
    • 4 Merged A: Title(H1) B(H2) X(H3) X1(H4) X1a(H5) Z(H2) A(H2)
    • 4 Merged B: Title(H1) B(H2) X(H3) X1(H4) X1a(H5) Z(H2) A(H2)
    • 5 Reload A: Title(H1) B(H2) X(H3) X1(H4) X1a(H5) Z(H2) A(H2)
    • 5 Reload B: Title(H1) B(H2) X(H3) X1(H4) X1a(H5) Z(H2) A(H2)
    • Checks: R3 holds in all four outlines. No duplicate id after the merge or the reload. PEER- present: merged false, reload A false, reload B false. Sentinel QQ in t0 crossed A to B in 1510 ms, then was removed.

    R-5

    • Pad /bnh2j8jxe6u. Ids: Title#MI6af158a5fzLBi2 A#4iYKPak6af158a87 B#u6af158a8R9YnLQ1 X#wdim6af158a8PQH4 X1#PWQXF6af158a8oK5 X1a#W6af158a8yrkYeo1 Z#7LpeSA6af158a8f6
    • Cut-off B: 0 WS frames left the page, 0 reached the server, 0 came back; 3 reconnects refused.
    • 1 Start (A = B): Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 2 Online A, local: Title(H1) A(H2) X(H3) X1(H4) X1a(H5) B(H2) Z(H2)
    • 3 Offline B, local: Title(H1) A(H2) X(H3) X1(H4) X1a(H5) B(H2) Z(H2)
    • First merged state, before the repair: A: Title(H1) A(H2) X(H3) X(H3) X1(H4) X1a(H5) B(H2) B(H2) Z(H2); B: Title(H1) A(H2) X(H3) X(H3) X1(H4) X1a(H5) B(H2) B(H2) Z(H2)
    • 4 Merged A: Title(H1) A(H2) X(H3) X1(H4) X1a(H5) B(H2) Z(H2)
    • 4 Merged B: Title(H1) A(H2) X(H3) X1(H4) X1a(H5) B(H2) Z(H2)
    • 5 Reload A: Title(H1) A(H2) X(H3) X1(H4) X1a(H5) B(H2) Z(H2)
    • 5 Reload B: Title(H1) A(H2) X(H3) X1(H4) X1a(H5) B(H2) Z(H2)
    • Checks: R3 holds in all four outlines. No duplicate id after the merge or the reload. PEER- present: merged false, reload A false, reload B false. Sentinel QQ in t0 crossed A to B in 1513 ms, then was removed.

    L-1

    • Pad /hbr01079j5z. Ids: Title#QNG3BK6af158c0s6 A#eb6af158c3Wqev02 B#wXRco6af158c3X15 X#AhdWMz6af158c3c6 X1#6af158c3fOAKlKP0 X1a#LGZ6af158c3QdAa3 Z#bwUM6af158c3wMH4
    • Cut-off B: 0 WS frames left the page, 0 reached the server, 0 came back; 3 reconnects refused.
    • 1 Start (A = B): Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 2 Online A, local: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 3 Offline B, local: Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 4 Merged A: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 4 Merged B: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 5 Reload A: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 5 Reload B: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • Checks: R3 holds in all four outlines. No duplicate id after the merge or the reload. PEER- present: merged false, reload A false, reload B false. Sentinel QQ in t0 crossed A to B in 1509 ms, then was removed.

    L-1b

    • Pad /q76woushuh8. Ids: Title#aq7ox6af158d9ng5 A#e0jyps6af158dce6 B#0Pjd6af158dch1P4 X#rArwV6af158dcUy5 X1#11e6af158dcG7Ut3 X1a#kBCT6af158dcg2C4 Z#h6af158dclhHdFq1
    • Cut-off A: 0 WS frames left the page, 0 reached the server, 0 came back; 3 reconnects refused.
    • 1 Start (A = B): Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 2 Online B, local: Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 3 Offline A, local: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 4 Merged A: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 4 Merged B: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 5 Reload A: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • 5 Reload B: Title(H1) B(H2) X(H2) X1(H3) X1a(H4) Z(H2) A(H2)
    • Checks: R3 holds in all four outlines. No duplicate id after the merge or the reload. PEER- present: merged false, reload A false, reload B false. Sentinel QQ in t0 crossed A to B in 1512 ms, then was removed.

    L-2

    • Pad /oohyn67dfee. Ids: Title#6GVdx6af158f1Zl5 A#Gj5zWun6af158f47 B#J6af158f4tSGO581
    • Cut-off B: 0 WS frames left the page, 0 reached the server, 0 came back; 2 reconnects refused.
    • 1 Start (A = B): Title(H1) A(H2) B(H2)
    • 2 Online A, local: Title(H1) B(H2) A(H2)
    • 3 Offline B, local: Title(H1) A(H2) B(H2)
    • 4 Merged A: Title(H1) B(H2) A(H2)
    • 4 Merged B: Title(H1) B(H2) A(H2)
    • 5 Reload A: Title(H1) B(H2) A(H2)
    • 5 Reload B: Title(H1) B(H2) A(H2)
    • Checks: R3 holds in all four outlines. No duplicate id after the merge or the reload. PEER- present: merged false, reload A false, reload B false. Sentinel QQ in t0 crossed A to B in 1509 ms, then was removed.

    L-2m

    • Pad /tr88lebttyb. Ids: Title#GGlN6af1590aji84 A#aGM6af1590cTdsc3 B#Sw6af1590cyX3C62
    • Cut-off B: 0 WS frames left the page, 0 reached the server, 0 came back; 2 reconnects refused.
    • 1 Start (A = B): Title(H1) A(H2) B(H2)
    • 2 Online A, local: Title(H1) B(H2) A(H2)
    • 3 Offline B, local: Title(H1) A(H2) B(H2)
    • 4 Merged A: Title(H1) B(H2) A(H2)
    • 4 Merged B: Title(H1) B(H2) A(H2)
    • 5 Reload A: Title(H1) B(H2) A(H2)
    • 5 Reload B: Title(H1) B(H2) A(H2)
    • Checks: R3 holds in all four outlines. No duplicate id after the merge or the reload. PEER- present: merged true, reload A true, reload B true. Sentinel QQ in t0 crossed A to B in 1511 ms, then was removed.

    L-3

    • Pad /5dg0oij4ft4. Ids: Title#gDYj7pc6af159227 A#4t4Tv6af15924iN5 B#ay1WpG6af15924d6 X#Fodsk6af15924UW5 X1#Zt6af15924RPinu2 X1a#5hU1O7D6af159247 Z#l36af15924ZH3Lf2
    • Cut-off B: 0 WS frames left the page, 0 reached the server, 0 came back; 3 reconnects refused.
    • 1 Start (A = B): Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 2 Online A, local: Title(H1) A(H3) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 3 Offline B, local: Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 4 Merged A: Title(H1) A(H3) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 4 Merged B: Title(H1) A(H3) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 5 Reload A: Title(H1) A(H3) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 5 Reload B: Title(H1) A(H3) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • Checks: R3 holds in all four outlines. No duplicate id after the merge or the reload. PEER- present: merged true, reload A true, reload B true. Sentinel QQ in t0 crossed A to B in 1512 ms, then was removed.

    L-3b

    • Pad /x8pliqujp6z. Ids: Title#xRCwXF06af159397 A#YH36af1593b6KUy3 B#ndKuTr6af1593bb6 X#t4oap06af1593bl6 X1#EUtq9Q6af1593bU6 X1a#6af1593bBoVnPFg0 Z#a6af1593buC19rz1
    • Cut-off B: 0 WS frames left the page, 0 reached the server, 0 came back; 2 reconnects refused.
    • 1 Start (A = B): Title(H1) A(H2) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 2 Online A, local: Title(H1) B(H2) A(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 3 Offline B, local: Title(H1) A(H3) B(H2) X(H2) X1(H3) X1a(H4) Z(H2)
    • 4 Merged A: Title(H1) B(H2) A(H3) X(H2) X1(H3) X1a(H4) Z(H2)
    • 4 Merged B: Title(H1) B(H2) A(H3) X(H2) X1(H3) X1a(H4) Z(H2)
    • 5 Reload A: Title(H1) B(H2) A(H3) X(H2) X1(H3) X1a(H4) Z(H2)
    • 5 Reload B: Title(H1) B(H2) A(H3) X(H2) X1(H3) X1a(H4) Z(H2)
    • Checks: R3 holds in all four outlines. No duplicate id after the merge or the reload. PEER- present: merged false, reload A false, reload B false. Sentinel QQ in t0 crossed A to B in 1510 ms, then was removed.

    Limits

    • Headless Chromium, not two Chrome profiles by hand. The cut is a test-browser WebSocket gate, not DevTools Offline. The app sees the same signals: a closed socket and navigator.onLine false.
    • One offline peer at a time. No timing for an online race, and no replicas.
    • Once, in an earlier run, a reload in L-1 showed the "Something went wrong" page. A second reload loaded the pad. It did not happen in the 36 later reloads. Screenshot: out/L-1-A-error.png (local folder).
    • Scripts and logs: run510.ts, lib.ts and out/run-2026-11-09T05-20-33-274Z.log, in the local folder Notes/local-docs/2026-11-09-v230-team/sse-510/. No repo file changed.
  7. HMarzban commented on Nov 9, 2026

    @HMarzban
    CollaboratorAuthor

    Design proposal, 2026-11-09

    This replaces the harness-only proposal of 2026-11-06 for every case that ran on a real pad. Real-pad data: the "Real-pad reproduction, 2026-11-09" comment. Commit d31ed9033.

    What the shipped repair changes

    CM1 and CM2 were ruled on 2026-11-06, and 745f4c04e shipped (1) the Y-level repair, (2) markup after the insert and (e) the count. So "today" now means (1)+(2)+(e).

    • Duplicates no longer stay. On 2026-10-15 they stayed after every later edit. Now they last 2 to 15 ms (R-1, R-2, R-5), and both browsers repair to the same document. A reload shows no duplicate.
    • R-5 doubles only X (two X headings side by side) and B, as the harness predicted for (2). The twin rule removes the extra X.
    • Every copy in these runs was equal, so the repair deleted and re-keyed nothing. No heading lost its chat room, folds or unread count.
    • The repair does not touch R-3 (Z jumps), R-4 (X H3 straight under the Title) or any lost edit. That matches the 2026-11-06 hazard list.
    • (e) counts duplicates only. R-1, R-2 and R-5 would report collab:duplicate-heading-id. R-3, R-4 and every lost edit leave no duplicate, so (e) never counts them. Flip rule 2 cannot measure a lost edit.

    Step 1. The lost-edit rule (real pad)

    y-tiptap gives new Yjs items to the shorter run of a move. Typing in that run while the peers are apart is lost.

    • Lost: L-1 (moved set, typist offline), L-1b (moved set, mover offline, typist online and saved), L-2 (set that stayed).
    • Kept: L-2m (moved set, longer run), L-3 (markup-only re-level). L-3b kept its new level.
    • Flip rule 1 fires. It said: re-weigh (d) only if a real pad loses PEER- with the mover offline. L-1b did, in both full runs.

    Step 2. Coverage table

    The "Today" column is the real pad. The (d) column is a prediction from the planner and the real-pad rows. The (3), (4) and (5) columns are the 2026-11-06 harness results; they were not re-run.

    Case Today, real pad: (1)+(2)+(e) Add (d): refuse a TOC move while offline (prediction) (3) intent map, every peer (harness) (4) server applies moves (harness) (5) awareness lease
    R-1 fixed by the repair; A, B twice for ms no duplicate; B's move refused A, B twice fixed as today: a lease never reaches an offline peer
    R-2 fixed by the repair; A twice for ms no duplicate; B refused A twice fixed as today
    R-3 Z jumps to the top Title X X1 X1a A B Z; B refused as today A B Z X: later request wins as today
    R-4 X H3 straight under Title X H2 first; B refused worse: A, B twice X H3 under B as today
    R-4b clean, shift held clean; B refused clean clean as today
    R-5 fixed by the repair; X, B twice for ms no duplicate; B refused worse: X three times fixed as today
    L-1 (typist offline) lost lost lost lost as today
    L-1b (mover offline) lost kept: the move is refused lost kept as today
    L-2 (typist offline) lost lost lost lost as today
    L-3 (re-level, typist offline) kept kept not run not run as today
    L-3b (re-level offline under a move) level kept level kept: Mod-Alt-3 is not a TOC move, so (d) does not refuse it not run not run as today

    Every real-pad row converged, and kept one H1 Title with its start id.

    Step 3. Cost of each option

    • (1) Repair, (2) markup after, (e) count. Shipped. Real-pad cost: one extra Yjs transaction per merged duplicate, a few ms after the merge. Side effect: React logs "two children with the same key" in dev while the duplicate lasts, because the TOC keys rows by toc-id. After the repair, the TOC rows matched the editor headings in count and order, in both browsers. So the warning left no wrong row.
    • (d) Refuse a TOC move while offline. Small code: one check on the move path only, in planTocMove and at drag start. It refuses while providerStatus is 'offline'. Read providerStatus, never navigator.onLine (webapp §Collab Provider Status). 'error' already locks moves.
      • Do not put it in isTocMoveLocked. HeadingIdRepair calls that predicate and returns with no retry. On the reconnecting peer, the status stays 'offline' until onSynced: shouldRestoreSavedOnReconnect needs isSynced, which is false after a disconnect (read from code). If the merge lands first, that peer would skip its own repair.
      • It keeps a co-editor's saved typing when the mover is offline (L-1b). That loss can span the whole offline time, and the victim saw the edit saved.
      • It also stops an offline peer from making R-1, R-2, R-3, R-4 and R-5 at all.
      • It does nothing for an offline typist (L-1, L-2), or for an online race.
      • Visible state: a refused drag can look like a locked pad, which starts no drag. So no new species is needed. A hint that says why ("Moves need a connection") is new copy, and needs a design-system and copy Decision in the code issue.
      • Peer check: Notion allows offline editing ("All Notion users can view, edit, and create pages offline"; primary source). Its guide names no move limit (secondary / inferred). Google Docs and Word were not checked. So (d) has no checked peer, and needs a recorded maintainer exception under AGENTS.md:154.
    • (3) Intent map. Worse than today when every peer applies it (harness). Not recommended.
    • (4) Server applier. The moved copy loses its author, and Undo no longer reverts the move. An offline typist still loses edits, and replicas can apply a request twice. High cost. Not recommended.
    • (5) Lease. Covers only an online race, can be faked, and needs a new visible state. Not recommended.
    • Upstream. Only a native Yjs move, or a y-tiptap move rebase, fixes L-1 and L-2. That is an upstream follow-up, out of scope here.

    Step 4. Decisions

    1. CM1. What changes now? Recommended: keep (1)+(2)+(e), and add (d): refuse a TOC move while providerStatus is 'offline'.
      • Reason: flip rule 1 fired on a real pad. An offline mover silently deletes a co-editor's saved typing, and (e) cannot count it.
      • (d) is small. It also removes every offline-peer source of duplicates, and of the R-3 and R-4 shapes. It must stay out of isTocMoveLocked, so the repair still runs.
      • The cost: a deviation from the one checked peer (Notion), and one hint string with a design-system Decision.
      • Alternative: keep today's code, and record L-1b in the CM2 hazard bullet. Choose this if offline moves must stay allowed for peer parity.
    2. CM2. Where is the remaining hazard recorded? Recommended: the existing bullet in apps/webapp/src/components/TipTap/CLAUDE.md §Heading Schema, with one added clause.
      • The clause: "When the mover is offline, a co-editor's saved typing in the shorter run is lost, for the whole offline time. The duplicate count does not see it."
      • If (d) ships, the clause instead says that a TOC move is refused while offline, and why. The code issue also updates apps/webapp/CLAUDE.md §TOC And Heading Actions.
      • Alternative: apps/hocuspocus.server/CLAUDE.md §Documented hazards we accept. The defect lives in the client move path, so the editor file stays the better home.

    Code waits for a Maintainer ruling, <date> comment.

  8. HMarzban commented on Nov 9, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-11-09

    • CM1: add (d). Keep (1)+(2)+(e), which shipped in 745f4c04e. Also refuse a TOC move while providerStatus is 'offline'.
      • Reason: case L-1b, reproduced on a real pad today. An offline mover silently deletes a co-editor's saved typing, and the duplicate count cannot see it.
      • This is a recorded exception to AGENTS.md:154 (follow Google Docs, Word and Notion). Notion allows offline editing and names no move limit. So no checked peer refuses offline moves. Do not "fix" this back to peer parity.
    • CM2: the hazard bullet in apps/webapp/src/components/TipTap/CLAUDE.md §Heading Schema gets the recommended clause. Once (d) ships, it says that a TOC move is refused while offline, and why.
    • The build is a new code issue on v2.4.0, linked below. This issue measured and designed, as it set out to. Every acceptance box now has its evidence, so it closes.

    Build issue: #714

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

    EditorOffline-ModeTocbug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions