Repository navigation
Notebooks sync page by page: one file per page per device (#274) - #289
Merged
Merged
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:<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.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.Tested
diff_main(base, mine, true, 0)→patch_apply);Not tested on a real iPad with real Obsidian Sync yet.
🤖 Generated with Claude Code