Skip to content

Sync: ink survives file changes, saves wait for a rest, read per-page notebooks (#273, #274) - #286

Merged
Joost-8 merged 11 commits into
mainfrom
sync-273-274
Nov 21, 2026
Merged

Joost-8 merged 11 commits into
mainfrom
sync-273-274

Conversation

@Joost-8

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

Copy link
Copy Markdown
Owner

Brings together three sync fixes, tested together in the real-Obsidian rig. Supersedes #279, #278 and #282.

Refs #273 #274

Ink survives the file changing on disk (#273, from #279)

  • Since 2.10.0, a change to an open notebook's file on disk replaced the notebook, and unsaved ink was lost with no undo. A re-read of a text this view wrote itself is now skipped. A real change from elsewhere is merged with this device's notebook by id.
  • Anything this device has that the incoming file lacks is kept, saved or not, so an older copy arriving late from another device no longer drops saved ink. The price: something erased on another device while this one has the notebook open comes back. Recording each save's origin (the sync design note's "provenance") would fix that later.
  • Two devices that gave different new strokes the same id now keep both; the other one is renumbered.
  • New: an empty read while the file is being written whole (a copy empties it, then fills it) no longer blanks the notebook. Found in the rig, where it made the merge lose a saved stroke.

Saves wait for a 5 s rest (#274, from #278)

  • Fewer whole-notebook writes into Obsidian Sync's version history. Sync already uploads a large file at most every 30 s, so this is about 2× less history (about 190 → 90 MB per hour of writing), not a fix for the 1 GB limit.

Read notebooks kept as one file per page per device, read-only (#274, the reader for the next release's writer)

  • Replaces Read notebooks kept as one file per page, read-only (#274) #282's layout with Pages/<notebookId>/<pageId>.<deviceId>.md plus per-device meta files, version vectors and per-element change stamps. Nothing writes this layout yet; this release only reads it, so devices a release behind can open what the writer will make.
  • Page embeds and Home read it too.

Also

Tested

  • Gates: typecheck, lint, lint:review, lint:css, format:check, test (9869 passed, 7 skipped), build.
  • Real-Obsidian rig (Obsidian 1.15.1, desktop):
    • A save is made about 5 s after the pen lifts.
    • Unsaved ink survives text appended from outside, and the file then holds both.
    • An older copy of the file brings nothing back over saved ink, alone or with another device's change in it.
    • A per-page-per-device notebook shows each device's ink on its page, is read-only, and nothing in its folder changes when written on.
  • Not tested on an iPad or with a real Obsidian Sync or iCloud account.

🤖 Generated with Claude Code

OskarRabenda and others added 11 commits November 20, 2026 14:38
Every save rewrites the whole notebook, and Obsidian Sync keeps each write
as a version for a month. A save now waits until the pen has rested 5 s
(was 1 s) and at most 60 s (was 20 s): about 56 saves an hour of writing
instead of about 246. PDF rasterising and the background save worker keep
the 1 s quiet; a pen held down 20 s still counts as a lost lift. Leaving the
app, closing the notebook and unloading still save at once.

A save Obsidian asks for after the pen's quiet timer has run now gets a
timer of its own, so it is not left waiting for the next stroke.

Refs #274

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since 2.10.0 the notebook view is not plain text to Obsidian (#246), so a
modify event while the view had unsaved ink replaced the notebook with the
file: the newest strokes vanished and, with the history cleared, undo could
not bring them back. Obsidian's loadFileInternal also reads lastSavedData
only after its awaited read, so a save starting meanwhile made the view's
own previous save look like a change from elsewhere.

A reread of a text this view loaded or wrote is now skipped (history kept),
and a real change from elsewhere is merged three ways, by id, with the
unsaved ink (src/model/reload-merge.ts). The diagnostics export and the
debug HUD count what happened (diskReloads).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A copy of the notebook arriving late from another device made ink this
device had already saved look erased over there, and the merge dropped
it. It also did so with nothing unsaved here, and for a page with no
unsaved changes, which was taken whole from the file.

- Anything this device has that the file lacks is kept, saved or not, and
  saved back. Price: an erase made on another device while this one holds
  the notebook open comes back.
- Pages are looked inside even when unchanged here, and a list the file
  stores as absent (no pictures) counts as empty, not as removed.
- Two devices that counted on from the same highest id gave different new
  strokes one id; the merge kept only this device's. Both are kept now, the
  other renumbered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Layout (c3) of the sync research: Pages/<notebookId>/<pageId>.<deviceId>.md
plus _meta.<deviceId>.md, the notebook id in frontmatter (finenotes-id), the
old payload kept in the notebook file as the legacy source (v2+device-pages).

- provenance.ts: device-dotted ids, version vectors, which version wins.
- device-pages-union.ts: union by id, tombstones that saw the version they
  erase, last-writer-wins registers (Lamport clock, device id tie) for
  settings and page entries, fractional order keys, stale/missing pages
  from rev + hash. Absence is never deletion.
- device-pages.ts: names, safe paths, blocks, FNV-1a 64 hash, readers.
- The plain decoder refuses a device-pages payload, so nothing saves it.

Reuses PR #282's decoder refusal, block files and Home stat; names, meta and
union are new. Read-only: nothing here writes the layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The view shows such a notebook joined from its page folder, holds it
read-only (the load guard echoes the file), and reads it again when one of
its files syncs in. One notice: read-only, or some pages still syncing.
Home counts the page files in a notebook's stamp and reads its pages and
text from them. Nothing writes the layout yet: that is the next release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An embed of such a notebook shows its pages joined from its page folder,
and reads it again when one of the folder's files changes, even when the
newest change stays the same (a page file gone). The vault helpers Home
used move to view/device-pages-files.ts, shared by both. Read-only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	src/view/ink-view.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found in the real-Obsidian rig: a copy over the file empties it, then
fills it. Obsidian read the empty file in between, and the view took it
for a blank notebook (the load guard only holds an empty read when the
file's size is above zero, and here it was already 0). The read of the
filled file then had no base to merge against, so ink this device had
saved was replaced. An empty read is now skipped, and nothing is saved
on it, so the incoming copy is not written over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants