Skip to content

Notebooks sync page by page: one file per page per device (#274) - #289

Merged
Joost-8 merged 12 commits into
mainfrom
claude/issue-274-device-pages-writer
Nov 21, 2026
Merged

Joost-8 merged 12 commits into
mainfrom
claude/issue-274-device-pages-writer

Conversation

@Joost-8

@Joost-8 Joost-8 commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Refs #274

What

Notebooks now keep their pages in small files of their own, one file per page per device, in a Pages/<notebook id>/ folder beside the notebook:

Lecture.notebook.md            the note, and the notebook as it was (label v2+device-pages=<id>)
Pages/<id>/p3.<device>.md      page p3 as this device wrote it
Pages/<id>/_meta.<device>.md   this device's page list, settings, and rev + hash of its files
  • A save writes only this device's files for the pages that changed, plus its meta. Obsidian Sync stores a few hundred KB per hour of writing instead of 90–390 MB, and no file comes near Sync's 5 MB limit.
  • A device writes only files ending in its own id, so Sync never has to merge ink. A page is the union of every device's file for it, joined by element id. Ids are <device>.<counter> dots, and every change carries a version vector. An erase is a tombstone that names the version it erased. Absence is never deletion.
  • PDF tabs, their ink and recordings are joined by id the same way.
  • Moving over: a one-file notebook moves at its first save after updating, and new notebooks start in the layout. The move only relabels the payload it was read with (v2: → v2+device-pages=<id>:), with an id made from its path and payload. Two devices moving one notebook at once therefore make the same file, and the frontmatter is never touched.
  • Older builds: they refuse the unknown label and hold the notebook read-only with "update FineNotes". Nothing is written over.
  • Export notebook as one file (command palette) makes a copy in the old layout, for a device that cannot update yet.
  • While any page file is missing or behind its meta, the notebook is read-only with a "still syncing" notice and writes nothing.

Tested

  • Unit tests:
    • the union and the writer with two simulated devices;
    • Sync's merge of concurrent moves (Obsidian's diff_main(base, mine, true, 0) → patch_apply);
    • crash repair, order keys and dot ids;
    • PDF tabs and recordings on two devices;
    • erase records cleaned up once nothing they hide is held any more.
  • Real-Obsidian rig, two vaults plus one on released 2.10.0, with a Sync stand-in (throttle, merge, delays, reordering, dropped and half-written files):
    • conversion of 10 real notebooks (68 pages and 3.7 MB the largest), read back element by element;
    • 2.10.0 read-only and wrote nothing, then updated and edited;
    • both devices writing at once: 983 strokes kept, none doubled, erases honoured;
    • partial and out-of-order sync;
    • a crash between page files and the meta;
    • pages added, deleted, moved and copied while the other device writes;
    • undo across a save;
    • rename and move;
    • embeds and Home;
    • search;
    • case-insensitive names;
    • ink on one PDF page from both devices at once.
  • Sync storage, one hour of steady writing on a 30-page notebook: 386 MB → 0.4 MB.
  • At 4× slower CPU: the first save of the 3.7 MB notebook takes 0.44 s on the main thread; later saves 148–172 ms in all (2.10.0: 366–1,467 ms); the longest task while the pen is down is 67 ms (2.10.0: 55 ms).

Not tested on a real iPad with real Obsidian Sync yet.

🤖 Generated with Claude Code

Joost-8 and others added 12 commits November 21, 2026 16:33
- dot-ids.ts: a per-notebook DotClock; every id minter (pages, strokes,
  text boxes, images, tables, graphs, equations, comments, connectors,
  links, tasks, sections, regions, page copies) asks it first, so a
  notebook in the layout gets `<device>.<counter>` ids and two devices
  never make the same one. Other notebooks get the ids they always did.
- device-pages-writer.ts: this device's file for each page it changed
  (its elements whose last change was made here, tombstones for what it
  erased that another source still holds) and its meta (page entries as
  Lamport registers, settings, rev + hash per file, version vector). Dots
  live in the writer, not the document. Conversion helpers: notebook id
  in frontmatter, legacy payload.
- order-keys.ts: fractional keys; only pages out of order get new ones.
- Union: tombstones name their list (`l`); a tombstone erases any version
  of unknown origin (legacy); the union reports per-element dots and
  holders for the writer. Legacy order keys end in "i".

Edits of another device's element keep its id and take a newer dot
(provenance rule 4), rather than tombstone + new id (note rule 3): a new
id would break connectors, links, tasks and undo that point at the old one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…274)

- A one-file notebook moves to the layout at its first save: its id goes
  in the frontmatter, the notebook as it is becomes the legacy payload,
  written once. New and imported notebooks are made in the layout.
- A save writes only this device's changed page files and its meta
  (view/device-pages-session.ts), on the main thread; the notebook file is
  written only when the note's text changes.
- Another device's file arriving is read again once the pen is up, after
  this view's own changes are written; this device's own files are never
  reread. While any page is still syncing (or from a newer build) the
  notebook takes no edits and nothing is written, with one notice.
- Pages/ is one of a notebook's own folders (moves and hides with it,
  made at the first page written); a notebook found away from its page
  folder takes it along. Duplicating a notebook forks it: a new id, every
  device's pages joined into the copy.
- Home and embeds read a notebook in the layout before its folder exists;
  an embed of one page reads only that page's files.
- Command "Export notebook as one file": a copy in the old layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng (#274)

- The view passes the pages its changes named to the writer; a change
  that names none, and the save when a note closes, look at every page.
  A page whose stored form is as it was writes nothing. One changed page
  of a 300-page notebook saves in about 13 ms instead of 1.9 s.
- A blank page added writes no empty page file.
- Re-attaching a moved notebook's page folder trashes the empty Pages/
  it left. "Export notebook as one file" goes beside a notebook's own
  folder, not into it.
- CHANGELOG: reader and writer ship together.

Tested in the real-Obsidian rig with two vaults (two device ids): ink
written at once on one page by both is kept on both; an eraser split on
one device reaches the other; a device with another's meta but not its
page file shows "still syncing", refuses edits and writes nothing, then
fills in; pages added at once on both are both kept in one order; a
one-file notebook moves to the layout at its first save; renaming a
notebook's own folder and moving a loose notebook keep its pages; an
embed of one page and Home's cards show page-file ink; release 2.10.0
opens a converted notebook read-only ("update FineNotes") and changes
no file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…page mid-sync (#274)

Found by the two-device rig campaign:
- Two devices moving one notebook at once made different files (random
  ids, payloads encoded from each one's own edits), which Sync then
  merged into a broken payload. A notebook now moves with the payload it
  was read with, relabelled `device-pages` (no re-encoding), and an id
  made from its path and that payload, so both make the same file; what
  each changed since goes to its own page files. A one-file notebook's
  new ids are this device's dots from the moment it is read.
- A crash between a page file and the meta left the meta describing an
  older file; the next save now rewrites the meta to match.
- A page file a sync writes empty first (or cut short) is read as the last
  whole copy meanwhile, so the page never blanks.

Tests: two devices moving at once make the same file; crash repair; a page
file written whole by a sync; the real-notebook corpus round trip
(FINENOTES_CORPUS, skipped in CI); Sync storage for an hour of writing
(386 MB -> 0.4 MB on a 3.3 MB fixture); one page of 300 saved in ~13 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found by the rig campaign: renaming or moving an open notebook kept the
view writing to the old page folder, while other devices, reading the
notebook at its new place, took the folder along: two folders, each
device writing to its own. The view now follows the rename: what it had
not written goes to the old folder, which is then moved to the new place
(or found there, for a notebook in its own folder), and saves go there.

The storage measurement test is opt-in (FINENOTES_BENCH=1): it takes a
minute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ntmatter (#274)

Found by the rig campaign with Obsidian Sync's merge: two devices moving
one notebook at once make the same edit, and Sync's three-way merge
applies an edit both sides made twice. With the id in the frontmatter that
gave `finenotes-id` twice, and Obsidian then read the whole frontmatter as
null (properties, Home and embeds lost it); taking the duplicate out again
is unsafe, since two devices doing that at once lose the id altogether.

Now the label carries it, `v2+device-pages=<id>:` (Joost's decision). The
frontmatter is never touched; a label holding the id twice reads the same
(the first counts), so nothing needs repairing. Older builds still refuse
the label. Home, embeds and Duplicate read the id from the file; Home
remembers it per file version, so it still reads a one-file notebook only
when its worker's cache misses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…search (#274)

Found by the rig campaign: moving a notebook left `Moved/Pages/Pages/…`
nested twenty levels deep, with another notebook's pages inside. The view
looked for a notebook's page folder anywhere a folder named by its id
sat under a `Pages/`, and moved what it found; that can take a folder
into itself, or another notebook's copy. Now a rename (of an open or a
closed notebook, from the plugin's rename handler) moves exactly the old
page folder to the new place, only when it is there and the new place is
free (`pagesFolderMove`); nothing ever searches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…one at a time (#274)

Found in the rig: moving an open notebook nested its pages as
`Moved/Pages/Pages/<id>`. Obsidian calls a view's onRename for other files
renamed too (here the page files, moving along with their folder), and the
view took each for its notebook moving into its own page folder. The view
now follows only its own file. Moves of a page folder also run one at a
time, each looking afresh, so the view and the rename handler asking at
once move it once.

Checked in the rig: moved while open, saved after, moved while closed:
one page folder, in the right place, the old empty `Pages/` gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…not at its first save (#274)

The first save of a one-file notebook decoded its payload again to learn
what had changed since it was read, on the main thread: 2.2 s with the
CPU slowed 4x on a 3.7 MB, 69-page notebook. The view now takes that
starting point when the notebook is read (before a merge, a relink or an
edit can change it), and the first save only relabels the file and
writes the pages that changed: 0.44 s at 4x for the same notebook.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…274)

Joost asked to consider what main already has, such as PDF tabs (#263).
They were part of the notebook's settings, a register the newest copy
wins whole: ink written on one PDF on two devices at once kept one side's,
a PDF tab or recording added on both kept one, and every stroke on a PDF
rewrote the whole settings entry. Now:
- each PDF tab's page of marks is a page of its own in the page files
  (joined by element id, tombstones, provenance, as any page);
- the notebook's PDF tabs (without their ink) and recordings are elements
  of the notebook's own page, joined by id;
- a PDF tab's ink, a new tab and a new recording take this device's dots,
  so they never share an id with another device's.
The settings register keeps only settings.

Tests: ink on one PDF page from two devices at once, an erase there, tabs
and recordings added on both at once; both fail on the earlier design.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…274)

A device's tombstone for another device's element stays only while some
other copy still holds that element: once its own device has seen the
erase and written its file without it, the record hides nothing and is
left out at the page's next write. A record of the legacy notebook's ink
stays, since that copy is written once and never changes. No format
change; older records keep working.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Joost-8
Joost-8 merged commit 353dbd2 into main Nov 21, 2026
1 check passed
@Joost-8
Joost-8 deleted the claude/issue-274-device-pages-writer branch November 21, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant