Corruption trap hunt: catalogue every way a note can be duplicated or lose text #3

Open
opened 2026-10-13 14:44:26 +00:00 by kayg · 2 comments
Owner

Find every way a note can get duplicated, lose text, resurrect deleted text, or be written without the user typing, before kayg ever sees it.

Sources: v0 issue history (git.kayg.org/kayg/calternal-v0), v0 audits, y-codemirror / Yjs / yrs known issues, CodeMirror 6 issues, and first-principles reasoning about our design (one Y.Text per file, server rooms, IndexedDB offline, watcher + outside writes, renames, migrations, multiple tabs and devices, agents via MCP/CLI).

Output, posted on this issue:

  1. A catalogue: trap → how it happens → which v0 issue (if any) → the guard in our design → the test that proves it (unit / property / multi-client fuzz / kill -9 / real-browser).
  2. Gaps where our current design has no guard yet, with a proposed fix.

The catalogue becomes a permanent test suite. Already guarded by decision G1c: own-keystroke-only transforms, delete-vs-type, one room per id + /data lock, echo writes by hash, diff against last-written base, duplicate-id copies, all writes through the room, history before flush, no title ping-pong, idempotent migration, lists keyed by id, intentional repeats kept.

Find every way a note can get duplicated, lose text, resurrect deleted text, or be written without the user typing, **before** kayg ever sees it. Sources: v0 issue history (git.kayg.org/kayg/calternal-v0), v0 audits, y-codemirror / Yjs / yrs known issues, CodeMirror 6 issues, and first-principles reasoning about our design (one Y.Text per file, server rooms, IndexedDB offline, watcher + outside writes, renames, migrations, multiple tabs and devices, agents via MCP/CLI). Output, posted on this issue: 1. A catalogue: trap → how it happens → which v0 issue (if any) → the guard in our design → the test that proves it (unit / property / multi-client fuzz / kill -9 / real-browser). 2. Gaps where our current design has **no** guard yet, with a proposed fix. The catalogue becomes a permanent test suite. Already guarded by decision G1c: own-keystroke-only transforms, delete-vs-type, one room per id + /data lock, echo writes by hash, diff against last-written base, duplicate-id copies, all writes through the room, history before flush, no title ping-pong, idempotent migration, lists keyed by id, intentional repeats kept.
Author
Owner

Corruption trap catalogue (round 1)

Format: trap: mechanism · v0 evidence · guard · proving test. "G1c" items are already decided. Test kinds: U unit, P property/fuzz, M multi-client fuzz (2-5 clients + server, random delays), K kill -9 / crash, B real browser, D disk fault injection.

A. Doc identity and seeding

  1. Seeding from text on more than one peer: two peers each insert(0, fileText) into an empty Y.Text, so the merged doc holds the text twice. This is the classic Yjs duplication (yjs forum, init guide). v0 #634, #1279. Guard: G1c server-only doc lineage; clients never insert file text, they only apply server state. Test: M (N fresh clients open a never-opened note at once), B.
  2. Two lineages meet: server state is lost or rebuilt from the file (crash, restore, migration) while a client keeps an old IndexedDB doc, so the reconnect merges two unrelated histories and everything doubles. v0 #1424, #1475 (epochs), #1197. Guard: G1c lineage id on every doc plus offline diff-replay (client diffs its local text against its last-synced base and replays only that diff onto the new lineage). Test: M + K (wipe server state, keep offline edits, reconnect from 3 clients).
  3. clientID reuse: a duplicated browser tab copies sessionStorage, so two docs share a clientID and corrupt permanently (Yjs FAQ). v0: none seen. Guard: never persist clientID; G1c tabs share one stored doc (one leader tab owns IndexedDB, others go through BroadcastChannel). Test: B (duplicate tab, type in both).

B. Writes nobody asked for

  1. Write on open: load normalises bytes (a trailing paragraph, added ids) and saves. v0 #661. Guard: the server writes only after a transaction whose origin is a user or agent, and skips the flush when the bytes hash equals the last write. Test: B (open 50 notes, switch fast, assert bytes, mtime, ETag and journal unchanged), P.
  2. Auto-transforms rerun on unchanged text: linkify, [[ conversion and anchor insertion run in a view-update or focus callback, re-enter a half-built view and duplicate text. v0 #1440 (focus callback during DOM replacement), #1384. Guard: G1c transforms only on the user's own keystroke; a lint rule bans dispatch inside update listeners and focus handlers. Test: P (load arbitrary markdown, idle 5 s, zero transactions), B (Copy link on several blocks, then a byte-exact diff).
  3. Echo of our own write: the watcher sees the server's write as an outside edit and re-applies it. v0 #634 family. Guard: G1c echo detection by hash. Test: U, P (watcher storm).

C. Outside writers

  1. Outside write while a room is open: MCP, CLI, DAV, a backfill or a tag rewrite writes the file underneath a live room, and merging block-wise or reloading on top duplicates or drops text. v0 #634, #1197 (43 failed flushes, edits lost at shutdown). Guard: G1c every writer goes through the live room, and an outside edit is diffed against the last-written base. Test: M matrix (every writer × open room × concurrent typing), zero loss.
  2. Missed watcher event: an inotify overflow or a write during startup is missed, and the next flush overwrites the outside edit. v0: implied by #1197. Guard: see Gap G1. Test: D (drop events), P.

D. Concurrency and retries

  1. Concurrent delete plus edit: one client deletes a block while another types in it, and the edit is lost. v0 #332. Guard: Y.Text keeps concurrent inserts by design (G1c delete-vs-typing). Test: M both delivery orders.
  2. Non-idempotent retry: an append or create succeeds, the response is lost (503, 412 after commit, timeout), and the retry appends again. v0 #1279, #1474, #844. Guard: see Gap G2 (Yjs updates are idempotent; plain HTTP actions are not). Test: P (inject response loss after commit, every mutating action).
  3. Lost update from a stale full replace: a client or agent PUTs a whole body or view read earlier, and the server's "merge into live room" diffs it against current text, deleting everything typed since the read. v0 #731, #777. Guard: see Gap G3. Test: M (agent reads, user types, agent PUTs).
  4. Stale read applied as a write: an old refresh response lands after a newer local write and gets saved back. v0 #936. Guard: one client store fed by the journal; responses carrying a sync token older than the store's are dropped; reads never feed the write path. Test: P with reordered responses.

E. Text encoding

  1. UTF-16 vs UTF-8 offsets: Yjs counts UTF-16 units and yrs defaults to bytes, so server diffs land mid-character. A diff can also split a surrogate pair or ZWJ sequence (yjs forum). Guard: see Gap G4. Test: P with emoji, ZWJ, combining marks, CJK, RTL.
  2. CRLF: CodeMirror counts \r\n as 1 and Yjs as 2, so typing after a CRLF lands in the wrong place (y-codemirror.next#35). Guard: see Gap G5. Test: U, P on CRLF, mixed endings and BOM files.
  3. Unicode normalisation and case in filenames: macOS and DAV send NFD names; Note.md and note.md collide on case-insensitive clients. v0 #618 (case-only rename). Guard: see Gap G6. Test: U, DAV client test.

F. Editor runtime

  1. Detached view drifts: swapping EditorStates in one view leaves the hidden state out of sync with the Y.Text (y-codemirror.next#36); the next local edit is computed against wrong text. Guard: see Gap G7. Test: B (switch notes while a remote client edits).
  2. IME composition plus remote update: a remote change mid-composition (Android Gboard, iOS Japanese) confuses the IME, producing duplicate characters or deleted text (W3C editing thread). Guard: see Gap G8. Test: B on Android Chrome and iOS Safari with a remote typer.
  3. Undo across remote change and across files: undoing a local delete restores text another user meanwhile deleted (acceptable), but → make note touches two files, so per-doc UndoManagers can restore the block in the source while the new note keeps the children: a duplicate. v0 #265 (paste image undo duplicate). Guard: G6 own-actions-only undo; cross-file see Gap G9. Test: B, M (undo → under concurrent edits).
  4. Block id copies: pasting a block that carries ^id creates two blocks with one id, so links become ambiguous. Guard: see Gap G10. Test: P.

G. Durability

  1. Zero-length file after crash: XFS without fsync before rename can leave an empty file (fsync pattern). Guard: see Gap G11. Test: K + D (dm-flakey / power cut on the perf VM).
  2. Crash between history and file: G1c history before flush. Test: K at every step.
  3. Disk full or I/O error mid-flush: a truncated write or a dropped room. Guard: atomic write means the old file stays; the room keeps state, retries, and shows "Not saved yet". Test: D (tiny loop filesystem).
  4. Browser storage eviction: Safari evicts script storage after 7 days for non-installed sites; unsynced offline edits vanish. Guard: see Gap G12. Test: B (clear storage with pending edits).

H. Server-originated edits and lifecycle

  1. Server frontmatter writes race the user: syncing title: and last edited: while the user edits frontmatter in source mode duplicates lines; last edited: updated by a flush triggers another flush (a loop). Guard: G1c no title ping-pong; see Gap G13. Test: M (source-mode typing in frontmatter during a title change).
  2. Version restore forks lineage: "restore version" replaces doc state while others are connected. Guard: see Gap G14. Test: M.
  3. Two servers own rooms: the warm previous version (R1 rollback) or an overlapping deploy runs two room owners on /data. Guard: G1c exclusive /data lock; see Gap G15. Test: K (deploy, rollback, deploy under typing).
  4. Old client after deploy: an old build speaks an older protocol to a new server (v0 #423). Guard: see Gap G16. Test: B (swap build under an open editor with pending edits).
  5. Two devices create today's daily note offline: two files (2026-10-13.md, 2026-10-13 2.md) or two ids for one day. Guard: see Gap G17. Test: M offline/online.
  6. Bulk edits while rooms are open: a tag rename or link rewrite bypasses rooms. v0 #1197, #1486 (a writer reserialised other bytes). Guard: G1c all writes through rooms + V5 bulk-edit job applies minimal text edits only, never reserialises. Test: M + P (byte diff only in the targeted spans).
  7. Migration rerun: G1c idempotent migration. Test: run twice, byte-identical.

Gaps: no guard in the design yet

  • G1 Check before write. Before every flush, compare the on-disk hash with the last-written hash. If they differ, ingest the outside edit first (diff against base), then write. This makes missed watcher events harmless.
  • G2 Idempotency keys. Every mutating Action carries a client-generated operation id. The journal stores id → result for 24 h, and a retry returns the stored result. This applies to API, CLI, MCP and the "+ Log" button.
  • G3 Base-required replace. A full-body PUT or MCP replace must send its base revision (If-Match). The server three-way-merges body vs base vs current through the room. Without a base: 428, never a blind merge. Agents get append and patch tools so they rarely need replace.
  • G4 One offset unit and grapheme-safe diffs. yrs runs with OffsetKind::Utf16 to match Yjs. Every server-side diff snaps to grapheme cluster boundaries. Fuzz with emoji and combining marks.
  • G5 Line-ending policy. The room stores \n only. Each file's original ending and BOM go in room metadata and are restored on write. Mixed-ending files keep their bytes until the first user edit, then use the dominant ending (logged in history).
  • G6 Filename rules. Names NFC-normalised on create; collision checks case-insensitive and normalisation-insensitive; case-only renames via a temporary name.
  • G7 Never detach sync. One EditorView per open note (or a remount check). On attach, if the editor text differs from ytext.toString(), rebuild editor state from the Y.Text; never write editor text into the Y.Text. A debug assert compares the two after every transaction in tests.
  • G8 Composition-safe remote apply. While a composition is active, buffer remote updates to the view (Y.Text still merges) and flush at compositionend or after 500 ms. Run the Android and iOS IME suite on every editor PR.
  • G9 Cross-file actions undo as one operation. → make note, Move to note and Move to daily note run as one journaled bulk edit with a stored inverse. ⌘Z calls that inverse instead of two per-doc UndoManagers.
  • G10 Block ids unique on paste. A pasted ^id that already exists in the Home is replaced with a fresh id. Copy link never inherits an id from a duplicate.
  • G11 Atomic write recipe. Temp file in the same directory, write, fsync file, rename, fsync parent directory. One shared function, the only way to write user files, enforced by a lint.
  • G12 Storage safety in the PWA. Call navigator.storage.persist(). Never show a local-only edit as saved. Show "Not saved yet" with its age when offline edits are older than a few minutes, and nudge to install the PWA (installed apps are exempt from eviction).
  • G13 Server edits are minimal and passive. Server frontmatter changes are key-level text edits through the room with origin server. last edited: is written only inside a flush caused by a user or agent change, so it never triggers a flush itself.
  • G14 Restore is a forward edit. Restoring a version applies the diff current → old as a new user transaction, so every connected client merges it normally and it can be undone.
  • G15 Lock handover. The warm standby never opens rooms or the /data lock. Switching waits for the old process to flush and release the lock, with a bounded wait, and the new process refuses to serve writes until it holds it.
  • G16 Protocol handshake. Client and server exchange a protocol version on connect. A mismatched client keeps its local doc, stops sending, reloads at the next safe boundary (never mid-composition) and replays its pending diff.
  • G17 Deterministic periodic-note ids. A daily note's calternal-id is derived from (user, date), e.g. UUIDv5, so two devices creating the same day offline open the same room and merge instead of making two files.
## Corruption trap catalogue (round 1) Format: **trap**: mechanism · v0 evidence · guard · proving test. "G1c" items are already decided. Test kinds: **U** unit, **P** property/fuzz, **M** multi-client fuzz (2-5 clients + server, random delays), **K** kill -9 / crash, **B** real browser, **D** disk fault injection. ### A. Doc identity and seeding 1. **Seeding from text on more than one peer**: two peers each `insert(0, fileText)` into an empty Y.Text, so the merged doc holds the text twice. This is the classic Yjs duplication ([yjs forum](https://discuss.yjs.dev/t/the-content-is-doubled-when-it-is-synced/2758), [init guide](https://morizbuesing.com/blog/initializing-a-yjs-document-with-a-common-value)). v0 #634, #1279. Guard: G1c server-only doc lineage; clients never insert file text, they only apply server state. Test: M (N fresh clients open a never-opened note at once), B. 2. **Two lineages meet**: server state is lost or rebuilt from the file (crash, restore, migration) while a client keeps an old IndexedDB doc, so the reconnect merges two unrelated histories and everything doubles. v0 #1424, #1475 (epochs), #1197. Guard: G1c lineage id on every doc plus offline diff-replay (client diffs its local text against its last-synced base and replays only that diff onto the new lineage). Test: M + K (wipe server state, keep offline edits, reconnect from 3 clients). 3. **clientID reuse**: a duplicated browser tab copies sessionStorage, so two docs share a clientID and corrupt permanently ([Yjs FAQ](https://beta.yjs.dev/docs/api/faq)). v0: none seen. Guard: never persist clientID; G1c tabs share one stored doc (one leader tab owns IndexedDB, others go through BroadcastChannel). Test: B (duplicate tab, type in both). ### B. Writes nobody asked for 4. **Write on open**: load normalises bytes (a trailing paragraph, added ids) and saves. v0 #661. Guard: the server writes only after a transaction whose origin is a user or agent, and skips the flush when the bytes hash equals the last write. Test: B (open 50 notes, switch fast, assert bytes, mtime, ETag and journal unchanged), P. 5. **Auto-transforms rerun on unchanged text**: linkify, `[[` conversion and anchor insertion run in a view-update or focus callback, re-enter a half-built view and duplicate text. v0 #1440 (focus callback during DOM replacement), #1384. Guard: G1c transforms only on the user's own keystroke; a lint rule bans `dispatch` inside update listeners and focus handlers. Test: P (load arbitrary markdown, idle 5 s, zero transactions), B (Copy link on several blocks, then a byte-exact diff). 6. **Echo of our own write**: the watcher sees the server's write as an outside edit and re-applies it. v0 #634 family. Guard: G1c echo detection by hash. Test: U, P (watcher storm). ### C. Outside writers 7. **Outside write while a room is open**: MCP, CLI, DAV, a backfill or a tag rewrite writes the file underneath a live room, and merging block-wise or reloading on top duplicates or drops text. v0 #634, #1197 (43 failed flushes, edits lost at shutdown). Guard: G1c every writer goes through the live room, and an outside edit is diffed against the last-written base. Test: M matrix (every writer × open room × concurrent typing), zero loss. 8. **Missed watcher event**: an inotify overflow or a write during startup is missed, and the next flush overwrites the outside edit. v0: implied by #1197. Guard: see Gap G1. Test: D (drop events), P. ### D. Concurrency and retries 9. **Concurrent delete plus edit**: one client deletes a block while another types in it, and the edit is lost. v0 #332. Guard: Y.Text keeps concurrent inserts by design (G1c delete-vs-typing). Test: M both delivery orders. 10. **Non-idempotent retry**: an append or create succeeds, the response is lost (503, 412 after commit, timeout), and the retry appends again. v0 #1279, #1474, #844. Guard: see Gap G2 (Yjs updates are idempotent; plain HTTP actions are not). Test: P (inject response loss after commit, every mutating action). 11. **Lost update from a stale full replace**: a client or agent PUTs a whole body or view read earlier, and the server's "merge into live room" diffs it against **current** text, deleting everything typed since the read. v0 #731, #777. Guard: see Gap G3. Test: M (agent reads, user types, agent PUTs). 12. **Stale read applied as a write**: an old refresh response lands after a newer local write and gets saved back. v0 #936. Guard: one client store fed by the journal; responses carrying a sync token older than the store's are dropped; reads never feed the write path. Test: P with reordered responses. ### E. Text encoding 13. **UTF-16 vs UTF-8 offsets**: Yjs counts UTF-16 units and yrs defaults to bytes, so server diffs land mid-character. A diff can also split a surrogate pair or ZWJ sequence ([yjs forum](https://discuss.yjs.dev/t/splitting-emojis-in-ytext-can-lead-to-a-broken-document/243)). Guard: see Gap G4. Test: P with emoji, ZWJ, combining marks, CJK, RTL. 14. **CRLF**: CodeMirror counts `\r\n` as 1 and Yjs as 2, so typing after a CRLF lands in the wrong place ([y-codemirror.next#35](https://github.com/yjs/y-codemirror.next/issues/35)). Guard: see Gap G5. Test: U, P on CRLF, mixed endings and BOM files. 15. **Unicode normalisation and case in filenames**: macOS and DAV send NFD names; `Note.md` and `note.md` collide on case-insensitive clients. v0 #618 (case-only rename). Guard: see Gap G6. Test: U, DAV client test. ### F. Editor runtime 16. **Detached view drifts**: swapping EditorStates in one view leaves the hidden state out of sync with the Y.Text ([y-codemirror.next#36](https://github.com/yjs/y-codemirror.next/issues/36)); the next local edit is computed against wrong text. Guard: see Gap G7. Test: B (switch notes while a remote client edits). 17. **IME composition plus remote update**: a remote change mid-composition (Android Gboard, iOS Japanese) confuses the IME, producing duplicate characters or deleted text ([W3C editing thread](https://lists.w3.org/Archives/Public/public-editing-tf/2018Feb/0007.html)). Guard: see Gap G8. Test: B on Android Chrome and iOS Safari with a remote typer. 18. **Undo across remote change and across files**: undoing a local delete restores text another user meanwhile deleted (acceptable), but **→ make note** touches two files, so per-doc UndoManagers can restore the block in the source while the new note keeps the children: a duplicate. v0 #265 (paste image undo duplicate). Guard: G6 own-actions-only undo; cross-file see Gap G9. Test: B, M (undo → under concurrent edits). 19. **Block id copies**: pasting a block that carries `^id` creates two blocks with one id, so links become ambiguous. Guard: see Gap G10. Test: P. ### G. Durability 20. **Zero-length file after crash**: XFS without fsync before rename can leave an empty file ([fsync pattern](https://pkg.go.dev/github.com/d0ugal/graith/internal/atomicfile)). Guard: see Gap G11. Test: K + D (dm-flakey / power cut on the perf VM). 21. **Crash between history and file**: G1c history before flush. Test: K at every step. 22. **Disk full or I/O error mid-flush**: a truncated write or a dropped room. Guard: atomic write means the old file stays; the room keeps state, retries, and shows "Not saved yet". Test: D (tiny loop filesystem). 23. **Browser storage eviction**: Safari evicts script storage after 7 days for non-installed sites; unsynced offline edits vanish. Guard: see Gap G12. Test: B (clear storage with pending edits). ### H. Server-originated edits and lifecycle 24. **Server frontmatter writes race the user**: syncing `title:` and `last edited:` while the user edits frontmatter in source mode duplicates lines; `last edited:` updated by a flush triggers another flush (a loop). Guard: G1c no title ping-pong; see Gap G13. Test: M (source-mode typing in frontmatter during a title change). 25. **Version restore forks lineage**: "restore version" replaces doc state while others are connected. Guard: see Gap G14. Test: M. 26. **Two servers own rooms**: the warm previous version (R1 rollback) or an overlapping deploy runs two room owners on `/data`. Guard: G1c exclusive `/data` lock; see Gap G15. Test: K (deploy, rollback, deploy under typing). 27. **Old client after deploy**: an old build speaks an older protocol to a new server (v0 #423). Guard: see Gap G16. Test: B (swap build under an open editor with pending edits). 28. **Two devices create today's daily note offline**: two files (`2026-10-13.md`, `2026-10-13 2.md`) or two ids for one day. Guard: see Gap G17. Test: M offline/online. 29. **Bulk edits while rooms are open**: a tag rename or link rewrite bypasses rooms. v0 #1197, #1486 (a writer reserialised other bytes). Guard: G1c all writes through rooms + V5 bulk-edit job applies minimal text edits only, never reserialises. Test: M + P (byte diff only in the targeted spans). 30. **Migration rerun**: G1c idempotent migration. Test: run twice, byte-identical. ## Gaps: no guard in the design yet - **G1 Check before write.** Before every flush, compare the on-disk hash with the last-written hash. If they differ, ingest the outside edit first (diff against base), then write. This makes missed watcher events harmless. - **G2 Idempotency keys.** Every mutating Action carries a client-generated operation id. The journal stores id → result for 24 h, and a retry returns the stored result. This applies to API, CLI, MCP and the "+ Log" button. - **G3 Base-required replace.** A full-body PUT or MCP replace must send its base revision (If-Match). The server three-way-merges body vs base vs current through the room. Without a base: 428, never a blind merge. Agents get `append` and `patch` tools so they rarely need replace. - **G4 One offset unit and grapheme-safe diffs.** yrs runs with `OffsetKind::Utf16` to match Yjs. Every server-side diff snaps to grapheme cluster boundaries. Fuzz with emoji and combining marks. - **G5 Line-ending policy.** The room stores `\n` only. Each file's original ending and BOM go in room metadata and are restored on write. Mixed-ending files keep their bytes until the first user edit, then use the dominant ending (logged in history). - **G6 Filename rules.** Names NFC-normalised on create; collision checks case-insensitive and normalisation-insensitive; case-only renames via a temporary name. - **G7 Never detach sync.** One EditorView per open note (or a remount check). On attach, if the editor text differs from `ytext.toString()`, rebuild editor state **from** the Y.Text; never write editor text into the Y.Text. A debug assert compares the two after every transaction in tests. - **G8 Composition-safe remote apply.** While a composition is active, buffer remote updates to the view (Y.Text still merges) and flush at `compositionend` or after 500 ms. Run the Android and iOS IME suite on every editor PR. - **G9 Cross-file actions undo as one operation.** → make note, Move to note and Move to daily note run as one journaled bulk edit with a stored inverse. ⌘Z calls that inverse instead of two per-doc UndoManagers. - **G10 Block ids unique on paste.** A pasted `^id` that already exists in the Home is replaced with a fresh id. Copy link never inherits an id from a duplicate. - **G11 Atomic write recipe.** Temp file in the same directory, write, fsync file, rename, fsync parent directory. One shared function, the only way to write user files, enforced by a lint. - **G12 Storage safety in the PWA.** Call `navigator.storage.persist()`. Never show a local-only edit as saved. Show "Not saved yet" with its age when offline edits are older than a few minutes, and nudge to install the PWA (installed apps are exempt from eviction). - **G13 Server edits are minimal and passive.** Server frontmatter changes are key-level text edits through the room with origin `server`. `last edited:` is written only inside a flush caused by a user or agent change, so it never triggers a flush itself. - **G14 Restore is a forward edit.** Restoring a version applies the diff current → old as a new user transaction, so every connected client merges it normally and it can be undone. - **G15 Lock handover.** The warm standby never opens rooms or the `/data` lock. Switching waits for the old process to flush and release the lock, with a bounded wait, and the new process refuses to serve writes until it holds it. - **G16 Protocol handshake.** Client and server exchange a protocol version on connect. A mismatched client keeps its local doc, stops sending, reloads at the next safe boundary (never mid-composition) and replays its pending diff. - **G17 Deterministic periodic-note ids.** A daily note's `calternal-id` is derived from (user, date), e.g. UUIDv5, so two devices creating the same day offline open the same room and merge instead of making two files.
Author
Owner

Corruption trap catalogue, round 2: what the code has now

I checked every trap against dev at e6a9b2b. That includes the work merged since round 1: #83 fan-out, #85 anchors and history, #78 rename, links and bulk edit, and #91 PWA. Trash (#98) is not covered.

For each trap I looked for its guard and a test that proves it. Where a test was missing, I wrote it, and I fixed the real bugs those tests found. All of it is in PR #126, and I checked that each fix's test fails without the fix.

Status key:

  • OK: the guard exists and a test proves it.
  • OK (new): the guard exists, and PR #126 adds the test that proves it.
  • FIXED: PR #126 fixes a bug, with a test.
  • PARTIAL: the guard exists, but the test or the guard is incomplete.
  • GAP: there is no guard.

Test kinds: U unit, P property, M multi-client fuzz, K kill -9, D disk fault injection, B real browser.

# Trap Guard (where) Test (where, kind) Status
A1 Seeding on more than one peer Only the server seeds: room/load.rs. Clients only apply server state: sync/client.ts. tests/rooms.rs::fresh_note_opened_by_many_at_once_is_not_doubled (M); sync.test.ts "never seeds" (U) OK
A2 Two lineages meet The room refuses another lineage (room/sync.rs::join, live.ts). Offline changes are replayed as a diff (offline/replay.ts). The browser never knew its lineage: the server sends it with the join, and the fake test room put it in the document. Now learned on join and stored (note.ts). Replay also doubled a collaborator's text received since the last save; the base now follows confirmed state. acks.rs::an_older_lineage_is_refused… (U); traps.test.ts "does not double what a collaborator typed" (M); traps.spec.ts "knows which copy it holds" (B) FIXED
A3 Client id reuse, several tabs Fresh Y.Doc per open. Tabs sync over BroadcastChannel; there is no leader tab, unlike ADR 0020. A tab on the old lineage fed its whole text into a recovering tab. Tabs now share changes only with tabs of the same lineage (sync/client.ts). traps.test.ts "a tab still holding the old lineage…" (M); editor.spec.ts tabs tests; traps.spec.ts "two tabs typing while the network is down" (B) FIXED, gaps T1–T3 below
B4 Write on open Saves happen only after a change by a person or agent (touch), and are skipped when the hash is unchanged (room/save.rs). saving.rs::opening_never_writes; daily/tests.rs::no_file_until_the_first_keystroke (U) OK
B5 Transforms rerun on unchanged text transforms/links.ts runs on input only, never while composing. Lists come from the keymap; tasks from mousedown. editor.test.ts "never transforms text that arrives from elsewhere"; daily.test.ts (U) PARTIAL: there is no lint banning dispatch in update or focus handlers (no eslint or biome config)
B6 Echo of our own write Our own write is recognised by its hash (room/merge.rs::ingest). outside.rs::own_saves_are_not_outside_edits (U, real watcher) OK
C7 Outside write while a room is open Every writer goes through the room. An outside edit is diffed against the last written base. The character diff slid across line breaks, so a line typed at the same moment ended up inside another line. It now compares lines first (diff.rs), and is also 10–30× faster on large notes. outside.rs::outside_edit_while_typing_merges (U); writers.rs (M, 22 seeds, every writer at once, watcher on and off); diff.rs::an_inserted_line_starts_at_a_line_start (U) FIXED
C8 Missed watcher event The file on disk is checked before every save (room/save.rs). outside.rs::missed_watcher_event_is_caught_before_saving; writers.rs (watcher off) (M) OK
D9 Delete while someone types Yjs semantics. rooms.rs::typing_survives_a_concurrent_delete; rooms.rs::random_concurrent_editing… (M) OK
D10 Retry that isn't idempotent The engine stores key → result; edits get a writer id made from the key; jobs get an id made from the key. A create retried after a crash made a second note. The id now comes from the key (lib.rs, watch.rs::id_for_key). engine/tests.rs (U); rooms.rs::retried_change_applies_once, retried_create_makes_one_note (U); notes_crash.rs (K, appends) FIXED; no test retries "+ Log"
D11 Stale full replace A replace needs a base (428 without one) and is merged three ways (room/edit.rs). A version could fail to match its text (see N1), and a replace built from it doubled text. rooms.rs::stale_replace_keeps_newer_typing (U); writers.rs checks version == text on every read (M) FIXED via N1; gap E1
D12 Stale read applied as a write Journal entries are applied in seq order (store.svelte.ts). Block actions carry a hash of the line (block_changed). links.spec.ts "a block that changed on another device" (B) PARTIAL: gap S1
E13 UTF-16 offsets and split characters OffsetKind::Utf16 (ydoc.rs). Diffs work on whole graphemes. Patches that split a character are refused. diff.rs proptests; rooms.rs::patches_use_utf16_positions (U/P) OK
E14 CRLF and BOM The room holds \n only; the style is restored on write (text.rs). text.rs proptest; saving.rs::line_endings_and_bom_are_kept OK. Minor: a stray \r stays in the live text; a mixed file is written in the majority style
E15 NFC names and case collisions fsio/names.rs: NFC, and collisions checked ignoring case and form. Case-only renames go through a temporary name. fsio/tests.rs (U) PARTIAL: gap N2
F16 Editor drifts from the document One view per note; reattach rebuilds the editor from the Y.Text. editor.test.ts (U); inSync() in the Playwright multi-client tests (B) PARTIAL: no runtime debug assert
F17 IME composition with a remote change sync/gate.ts holds remote changes while composing. sync.test.ts (U); editor.spec.ts "remote changes wait… (IME)" (B, Chromium only) PARTIAL: gap T4; no Android or iOS run
F18 Undo across files The UndoManager tracks only y-codemirror. Make note and Move to note are one job; Undo calls notes.undo. editor.test.ts; links.spec.ts Undo tests (B) OK; minor gap T5
F19 Block id copies None. duplicateBlocks copies the ^id; blockLink makes a random id without checking it is unused; there is no paste handler. Note ids are fine (a copied file gets a fresh id). outside.rs::copied_note_gets_a_fresh_id (note ids only) GAP G10
G20 Zero-length file after a crash fsio::write_atomic: temp file, fsync, rename, fsync the folder. A clippy lint bans fs::write, File::create and rename. fsio/tests.rs (U) PARTIAL: the lint does not ban OpenOptions, tokio::fs, fs::copy or remove_file
G21 Crash between history and file Pending save, then write, then promote; a pending save is settled on load. Fan-out comes before fsync (#32). notes_crash.rs (K, HTTP appends); saving.rs::crash_* (simulated); notes_crash_typing.rs (K over the websocket: 3 tabs, 12 kills, about 3,000 words, none lost or doubled, file == note) OK (new); edge case E2
G22 Disk full or I/O error mid-save A failed save keeps the note dirty, backs off and retries, and sends not_saved. An error after the rename doubled the text: the folder fsync failed, and the next check took our own bytes for an outside edit. The file is now read back after a failed write. saving.rs::a_write_error_keeps_the_change (D, injected, so it also runs as root; the old permission test does nothing under CI's root); an_error_after_the_write_does_not_double_text (D) FIXED
G23 Browser storage eviction requestPersistentStorage(); "Not saved yet" with its age. editor.spec.ts, pwa.spec.ts offline tests (B) PARTIAL: gap T6; no test of persist()
H24 Server frontmatter edits race the user Key-level edits that never mark the note changed; last edited has a 60 s slack. saving.rs::saving_does_not_loop, title_and_h1_stay_in_step OK
H25 Version restore forks the lineage None yet: there is no restore action; versions.rs only lists versions. — GAP (not built yet)
H26 Two servers own rooms DataLock (flock) in main.rs. fsio/tests.rs::only_one_process_owns_a_data_folder (U, one process) PARTIAL: no test with two real servers; migrate-v0 and user create/recover don't take the lock
H27 Old client after a deploy None. No protocol version on /live or on join. — GAP G16
H28 Two devices create the same day offline The day's id is day-YYYY-MM-DD; an existing day file is reused. daily/tests.rs::two_offline_devices…, opening_the_same_day_at_once… OK
H29 Bulk edits while rooms are open Each step is a keyed patch through the room; links are retargeted with minimal edits. renames.rs::typing_in_a_linking_note_during_a_rename_is_kept, a_crash_mid_rename…; bulk/undo.rs proptest OK (no tag-rewrite job yet)
H30 Migration rerun Unchanged files are skipped by hash; edited files are refused. migrate-v0 rules.rs::running_twice_gives_the_same_bytes OK
N1 New: changes from one writer arriving out of order (a tab sends its own changes while another tab resends them on reconnect) yrs 0.28 loses a parked change when a second one waits behind the same gap. It can also place a change with a hole, after which its diffs leave text out: history misses text and a version no longer matches its text. The room now refuses a client change that skips ahead, asks that client to resend, and holds its "Saved" until the resend arrives (room/sync.rs, room/acks.rs). Parked changes are re-offered after every update (ydoc.rs). pending.rs (U: the yrs bug itself, and the fix in every order); writers.rs (M) FIXED

Gaps left: design questions or larger changes (not in #126)

Server

  • G10, block ids unique (F19). Strip or renew ^id in duplicateBlocks and on paste. Have blockLink check the id is unused. On the server, refuse to resolve an anchor that appears twice. Small, but it touches the editor UI.
  • G16, protocol version (H27). Add protocol: n to join. The server answers with its own version, and a mismatched client stops sending and reloads at a safe moment. A design choice on the wire format.
  • E1, base after history loss. Version numbers restart at 1 when history.db is lost. A patch or replace whose base was read before the loss then passes the base <= version check and merges against an unrelated state. Proposal: a base names its lineage too (base: {lineage, version}, or reject a base read before the lineage's first seq). This changes the API.
  • E2, crash plus an outside edit before restart. A save was pending (the file was written, the bookkeeping wasn't), and another app edited the file before Calternal restarted. The disk then matches neither copy, and load.rs diffs it against the older base, which doubles the text that was already written. Option: diff against the pending state when the disk shares more with it. Needs a decision on what to trust.
  • N2, NFD names on Linux (E15). The watcher normalises names to NFC, then opens that NFC path. On Linux, a file a Mac or DAV client wrote with an NFD name is never found, and if it is, saving writes a second file. Paths that are not valid UTF-8 have the same problem through to_string_lossy. Fix: keep the on-disk bytes for I/O, and use NFC only as the comparison key. Medium change in watch.rs, scan.rs and index.rs.
  • G20 lint gaps. Also ban OpenOptions::open for writing, tokio::fs::write, fs::copy and remove_file outside fsio. Separately, write_atomic replaces a symlink with a plain file and resets file permissions.
  • H26. Add a two-real-servers test, and make migrate-v0 and user create/recover take the data lock.

Client

  • T1, leader tab (A3). ADR 0020 says one leader tab owns IndexedDB. Today every tab has its own document and shares changes over BroadcastChannel. Without a leader:

    • two tabs that both recover from a lineage change replay the same diff twice;
    • deleteDatabase during recovery waits on other tabs' open connections, and typing in that window is lost.

    A design change: build the leader tab, or let only one tab run recovery (a Web Lock).

  • T2. Changes another tab hands over reach the server only when this tab reconnects. Meanwhile the other tab can show "Saved". All tabs also share one pendingSince record.

  • T3. Of the old fake room's bugs, only the lineage one is fixed. The fake room is still a JS stand-in for the Rust room; the two should be tested against the same cases.

  • T4, IME gate (F17). If compositionend never fires (the editor is torn down mid-composition, or some Android keyboards), remote changes queue forever and the note never syncs. Proposal: release the gate on blur, on destroy, and after a long timeout.

  • T5, undo. "Block deleted → Undo" undoes whatever is on top of the stack. reattach never destroys the old UndoManager.

  • T6, "Saved" after an offline reload (G23). pendingSince is written to IndexedDB asynchronously and isn't in the localStorage write-ahead list. So: type offline, close the tab at once, reopen offline, and the status says "Saved" for a change that exists only on this device. Fix: keep pendingSince in localStorage synchronously as well (it changes rarely).

  • S1, the notes list is a second store (D12). loadNotes and refreshRecent overwrite entries without comparing seq or updated_ms. A slow response can bring back a deleted note or old fields. togglePin writes !n.pinned from that possibly stale map. This affects list fields only, not note text.

Performance

Measured on the shared host, which was busy.

Typing path (fanout_bench, release, no disk load; same with load):

before after
Collaborator sees typing, p50 0.27–0.39 ms 0.33–0.43 ms
Typed until Saved, p50 0.39–0.57 ms 0.43–0.55 ms

Outside edits and replaces (diff::edits):

Note Change before after
2000 lines one-word edit 25.8 ms 0.12 ms
2000 lines half the lines changed 215 ms (hit the deadline) 6.5 ms
## Corruption trap catalogue, round 2: what the code has now I checked every trap against `dev` at e6a9b2b. That includes the work merged since round 1: #83 fan-out, #85 anchors and history, #78 rename, links and bulk edit, and #91 PWA. Trash (#98) is not covered. For each trap I looked for its guard and a test that proves it. Where a test was missing, I wrote it, and I fixed the real bugs those tests found. All of it is in **PR #126**, and I checked that each fix's test fails without the fix. Status key: - **OK**: the guard exists and a test proves it. - **OK (new)**: the guard exists, and PR #126 adds the test that proves it. - **FIXED**: PR #126 fixes a bug, with a test. - **PARTIAL**: the guard exists, but the test or the guard is incomplete. - **GAP**: there is no guard. Test kinds: U unit, P property, M multi-client fuzz, K kill -9, D disk fault injection, B real browser. | # | Trap | Guard (where) | Test (where, kind) | Status | |---|---|---|---|---| | A1 | Seeding on more than one peer | Only the server seeds: `room/load.rs`. Clients only apply server state: `sync/client.ts`. | `tests/rooms.rs::fresh_note_opened_by_many_at_once_is_not_doubled` (M); `sync.test.ts` "never seeds" (U) | OK | | A2 | Two lineages meet | The room refuses another lineage (`room/sync.rs::join`, `live.ts`). Offline changes are replayed as a diff (`offline/replay.ts`). **The browser never knew its lineage**: the server sends it with the join, and the fake test room put it in the document. Now learned on join and stored (`note.ts`). Replay also doubled a collaborator's text received since the last save; the base now follows confirmed state. | `acks.rs::an_older_lineage_is_refused…` (U); `traps.test.ts` "does not double what a collaborator typed" (M); `traps.spec.ts` "knows which copy it holds" (B) | **FIXED** | | A3 | Client id reuse, several tabs | Fresh `Y.Doc` per open. Tabs sync over BroadcastChannel; there is **no leader tab**, unlike ADR 0020. **A tab on the old lineage fed its whole text into a recovering tab.** Tabs now share changes only with tabs of the same lineage (`sync/client.ts`). | `traps.test.ts` "a tab still holding the old lineage…" (M); `editor.spec.ts` tabs tests; `traps.spec.ts` "two tabs typing while the network is down" (B) | **FIXED**, gaps T1–T3 below | | B4 | Write on open | Saves happen only after a change by a person or agent (`touch`), and are skipped when the hash is unchanged (`room/save.rs`). | `saving.rs::opening_never_writes`; `daily/tests.rs::no_file_until_the_first_keystroke` (U) | OK | | B5 | Transforms rerun on unchanged text | `transforms/links.ts` runs on input only, never while composing. Lists come from the keymap; tasks from `mousedown`. | `editor.test.ts` "never transforms text that arrives from elsewhere"; `daily.test.ts` (U) | PARTIAL: there is **no lint** banning `dispatch` in update or focus handlers (no eslint or biome config) | | B6 | Echo of our own write | Our own write is recognised by its hash (`room/merge.rs::ingest`). | `outside.rs::own_saves_are_not_outside_edits` (U, real watcher) | OK | | C7 | Outside write while a room is open | Every writer goes through the room. An outside edit is diffed against the last written base. **The character diff slid across line breaks, so a line typed at the same moment ended up inside another line.** It now compares lines first (`diff.rs`), and is also 10–30× faster on large notes. | `outside.rs::outside_edit_while_typing_merges` (U); **`writers.rs`** (M, 22 seeds, every writer at once, watcher on and off); `diff.rs::an_inserted_line_starts_at_a_line_start` (U) | **FIXED** | | C8 | Missed watcher event | The file on disk is checked before every save (`room/save.rs`). | `outside.rs::missed_watcher_event_is_caught_before_saving`; `writers.rs` (watcher off) (M) | OK | | D9 | Delete while someone types | Yjs semantics. | `rooms.rs::typing_survives_a_concurrent_delete`; `rooms.rs::random_concurrent_editing…` (M) | OK | | D10 | Retry that isn't idempotent | The engine stores key → result; edits get a writer id made from the key; jobs get an id made from the key. **A create retried after a crash made a second note.** The id now comes from the key (`lib.rs`, `watch.rs::id_for_key`). | `engine/tests.rs` (U); `rooms.rs::retried_change_applies_once`, **`retried_create_makes_one_note`** (U); `notes_crash.rs` (K, appends) | **FIXED**; no test retries "+ Log" | | D11 | Stale full replace | A replace needs a base (428 without one) and is merged three ways (`room/edit.rs`). **A version could fail to match its text** (see N1), and a replace built from it doubled text. | `rooms.rs::stale_replace_keeps_newer_typing` (U); `writers.rs` checks version == text on every read (M) | **FIXED** via N1; gap E1 | | D12 | Stale read applied as a write | Journal entries are applied in seq order (`store.svelte.ts`). Block actions carry a hash of the line (`block_changed`). | `links.spec.ts` "a block that changed on another device" (B) | PARTIAL: gap S1 | | E13 | UTF-16 offsets and split characters | `OffsetKind::Utf16` (`ydoc.rs`). Diffs work on whole graphemes. Patches that split a character are refused. | `diff.rs` proptests; `rooms.rs::patches_use_utf16_positions` (U/P) | OK | | E14 | CRLF and BOM | The room holds `\n` only; the style is restored on write (`text.rs`). | `text.rs` proptest; `saving.rs::line_endings_and_bom_are_kept` | OK. Minor: a stray `\r` stays in the live text; a mixed file is written in the majority style | | E15 | NFC names and case collisions | `fsio/names.rs`: NFC, and collisions checked ignoring case and form. Case-only renames go through a temporary name. | `fsio/tests.rs` (U) | PARTIAL: gap N2 | | F16 | Editor drifts from the document | One view per note; `reattach` rebuilds the editor from the Y.Text. | `editor.test.ts` (U); `inSync()` in the Playwright multi-client tests (B) | PARTIAL: no runtime debug assert | | F17 | IME composition with a remote change | `sync/gate.ts` holds remote changes while composing. | `sync.test.ts` (U); `editor.spec.ts` "remote changes wait… (IME)" (B, Chromium only) | PARTIAL: gap T4; no Android or iOS run | | F18 | Undo across files | The UndoManager tracks only y-codemirror. Make note and Move to note are one job; Undo calls `notes.undo`. | `editor.test.ts`; `links.spec.ts` Undo tests (B) | OK; minor gap T5 | | F19 | Block id copies | **None.** `duplicateBlocks` copies the `^id`; `blockLink` makes a random id without checking it is unused; there is no paste handler. Note ids are fine (a copied file gets a fresh id). | `outside.rs::copied_note_gets_a_fresh_id` (note ids only) | **GAP** G10 | | G20 | Zero-length file after a crash | `fsio::write_atomic`: temp file, fsync, rename, fsync the folder. A clippy lint bans `fs::write`, `File::create` and `rename`. | `fsio/tests.rs` (U) | PARTIAL: the lint does **not** ban `OpenOptions`, `tokio::fs`, `fs::copy` or `remove_file` | | G21 | Crash between history and file | Pending save, then write, then promote; a pending save is settled on load. Fan-out comes before fsync (#32). | `notes_crash.rs` (K, HTTP appends); `saving.rs::crash_*` (simulated); **`notes_crash_typing.rs`** (K over the websocket: 3 tabs, 12 kills, about 3,000 words, none lost or doubled, file == note) | OK (new); edge case E2 | | G22 | Disk full or I/O error mid-save | A failed save keeps the note dirty, backs off and retries, and sends `not_saved`. **An error after the rename doubled the text**: the folder fsync failed, and the next check took our own bytes for an outside edit. The file is now read back after a failed write. | **`saving.rs::a_write_error_keeps_the_change`** (D, injected, so it also runs as root; the old permission test does nothing under CI's root); **`an_error_after_the_write_does_not_double_text`** (D) | **FIXED** | | G23 | Browser storage eviction | `requestPersistentStorage()`; "Not saved yet" with its age. | `editor.spec.ts`, `pwa.spec.ts` offline tests (B) | PARTIAL: gap T6; no test of `persist()` | | H24 | Server frontmatter edits race the user | Key-level edits that never mark the note changed; `last edited` has a 60 s slack. | `saving.rs::saving_does_not_loop`, `title_and_h1_stay_in_step` | OK | | H25 | Version restore forks the lineage | **None yet**: there is no restore action; `versions.rs` only lists versions. | — | GAP (not built yet) | | H26 | Two servers own rooms | `DataLock` (flock) in `main.rs`. | `fsio/tests.rs::only_one_process_owns_a_data_folder` (U, one process) | PARTIAL: no test with two real servers; `migrate-v0` and `user create/recover` don't take the lock | | H27 | Old client after a deploy | **None.** No protocol version on `/live` or on join. | — | **GAP** G16 | | H28 | Two devices create the same day offline | The day's id is `day-YYYY-MM-DD`; an existing day file is reused. | `daily/tests.rs::two_offline_devices…`, `opening_the_same_day_at_once…` | OK | | H29 | Bulk edits while rooms are open | Each step is a keyed patch through the room; links are retargeted with minimal edits. | `renames.rs::typing_in_a_linking_note_during_a_rename_is_kept`, `a_crash_mid_rename…`; `bulk/undo.rs` proptest | OK (no tag-rewrite job yet) | | H30 | Migration rerun | Unchanged files are skipped by hash; edited files are refused. | `migrate-v0 rules.rs::running_twice_gives_the_same_bytes` | OK | | **N1** | **New: changes from one writer arriving out of order** (a tab sends its own changes while another tab resends them on reconnect) | yrs 0.28 loses a parked change when a second one waits behind the same gap. It can also place a change with a hole, after which its diffs leave text out: history misses text and a **version no longer matches its text**. The room now refuses a client change that skips ahead, asks that client to resend, and holds its "Saved" until the resend arrives (`room/sync.rs`, `room/acks.rs`). Parked changes are re-offered after every update (`ydoc.rs`). | **`pending.rs`** (U: the yrs bug itself, and the fix in every order); `writers.rs` (M) | **FIXED** | ## Gaps left: design questions or larger changes (not in #126) **Server** - **G10, block ids unique (F19).** Strip or renew `^id` in `duplicateBlocks` and on paste. Have `blockLink` check the id is unused. On the server, refuse to resolve an anchor that appears twice. *Small, but it touches the editor UI.* - **G16, protocol version (H27).** Add `protocol: n` to `join`. The server answers with its own version, and a mismatched client stops sending and reloads at a safe moment. *A design choice on the wire format.* - **E1, `base` after history loss.** Version numbers restart at 1 when `history.db` is lost. A patch or replace whose `base` was read before the loss then passes the `base <= version` check and merges against an unrelated state. Proposal: a base names its lineage too (`base: {lineage, version}`, or reject a `base` read before the lineage's first seq). *This changes the API.* - **E2, crash plus an outside edit before restart.** A save was pending (the file was written, the bookkeeping wasn't), and another app edited the file before Calternal restarted. The disk then matches neither copy, and `load.rs` diffs it against the older base, which doubles the text that was already written. Option: diff against the pending state when the disk shares more with it. *Needs a decision on what to trust.* - **N2, NFD names on Linux (E15).** The watcher normalises names to NFC, then opens that NFC path. On Linux, a file a Mac or DAV client wrote with an NFD name is never found, and if it is, saving writes a second file. Paths that are not valid UTF-8 have the same problem through `to_string_lossy`. Fix: keep the on-disk bytes for I/O, and use NFC only as the comparison key. *Medium change in `watch.rs`, `scan.rs` and `index.rs`.* - **G20 lint gaps.** Also ban `OpenOptions::open` for writing, `tokio::fs::write`, `fs::copy` and `remove_file` outside `fsio`. Separately, `write_atomic` replaces a symlink with a plain file and resets file permissions. - **H26.** Add a two-real-servers test, and make `migrate-v0` and `user create/recover` take the data lock. **Client** - **T1, leader tab (A3).** ADR 0020 says one leader tab owns IndexedDB. Today every tab has its own document and shares changes over BroadcastChannel. Without a leader: - two tabs that both recover from a lineage change replay the same diff twice; - `deleteDatabase` during recovery waits on other tabs' open connections, and typing in that window is lost. *A design change: build the leader tab, or let only one tab run recovery (a Web Lock).* - **T2.** Changes another tab hands over reach the server only when this tab reconnects. Meanwhile the other tab can show "Saved". All tabs also share one `pendingSince` record. - **T3.** Of the old fake room's bugs, only the lineage one is fixed. The fake room is still a JS stand-in for the Rust room; the two should be tested against the same cases. - **T4, IME gate (F17).** If `compositionend` never fires (the editor is torn down mid-composition, or some Android keyboards), remote changes queue forever and the note never syncs. Proposal: release the gate on blur, on destroy, and after a long timeout. - **T5, undo.** "Block deleted → Undo" undoes whatever is on top of the stack. `reattach` never destroys the old UndoManager. - **T6, "Saved" after an offline reload (G23).** `pendingSince` is written to IndexedDB asynchronously and isn't in the localStorage write-ahead list. So: type offline, close the tab at once, reopen offline, and the status says "Saved" for a change that exists only on this device. Fix: keep `pendingSince` in localStorage synchronously as well (it changes rarely). - **S1, the notes list is a second store (D12).** `loadNotes` and `refreshRecent` overwrite entries without comparing seq or `updated_ms`. A slow response can bring back a deleted note or old fields. `togglePin` writes `!n.pinned` from that possibly stale map. *This affects list fields only, not note text.* ## Performance Measured on the shared host, which was busy. **Typing path** (`fanout_bench`, release, no disk load; same with load): | | before | after | |---|---|---| | Collaborator sees typing, p50 | 0.27–0.39 ms | 0.33–0.43 ms | | Typed until Saved, p50 | 0.39–0.57 ms | 0.43–0.55 ms | **Outside edits and replaces** (`diff::edits`): | Note | Change | before | after | |---|---|---|---| | 2000 lines | one-word edit | 25.8 ms | 0.12 ms | | 2000 lines | half the lines changed | 215 ms (hit the deadline) | 6.5 ms |
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal#3
No description provided.