Skip to content

Feat(sync): a ZenNotes app can keep an offline copy of this vault - #88

Merged
adibhanna merged 2 commits into
mainfrom
feat/sync-protocol
Nov 24, 2026
Merged

adibhanna merged 2 commits into
mainfrom
feat/sync-protocol

Conversation

@adibhanna

Copy link
Copy Markdown
Contributor

A remote vault was a pass-through: with the server away, nothing opened
and nothing saved (ZenNotes#1108). The offline copy is a real folder on the
device, kept in step by ZenNotes Cloud's own sync engine, and this is the
half that lives on the server.

The server now keeps a revision for every text file in the vault and a
change log, in .zennotes/sync/ inside the vault, so it follows a vault
switch or a move to another server. Every write path records its change
under the vault lock it already takes: the web client, the phones, both zn
builds and /mcp. A rename, trash or folder rename is one move per file, so
each keeps its identity, and Empty Trash is one delete per file. Edits made
outside the server (a shell, git pull, Syncthing) are found by a reconcile
that stats first and hashes only what changed. Until one has run, a sync
write compares the disk, so such an edit is never written over.

/api/sync/manifest, /api/sync/changes and /api/sync/mutations speak Cloud's
wire shapes without encryption. A change lands only if its file is still at
the revision it was built on, each change is answered on its own, and a
repeated operation id gets its first answer. A copy older than the 90-day
log rebuilds from the manifest. /api/capabilities says supportsSync: 1.
Attachments are not part of a copy yet and are set aside as Cloud sets
aside a path it refuses.

integration/cloud-engine drives Cloud's CloudSyncCoordinator and the
desktop's sync repository, taken from a pinned ZenNotes commit, against a
real server: bootstrap, offline edits replayed, a conflict held for review,
renames and deletes both ways, an edit made on the server's disk, and a
cursor older than the log. CI runs it on Linux, macOS and Windows.

Phase 2 of docs/ideas/remote-offline-copy.md in ZenNotes/zennotes. No release, no version bump: which server release carries it is still open.

Verified locally: go vet ./..., go test ./..., -race on vault, httpserver and watcher, and the engine integration test (11 scenarios) on macOS and Linux (arm64, in Docker). Windows runs for the first time in the new sync-engine job.

A remote vault was a pass-through: with the server away, nothing opened
and nothing saved (ZenNotes#1108). The offline copy is a real folder on the
device, kept in step by ZenNotes Cloud's own sync engine, and this is the
half that lives on the server.

The server now keeps a revision for every text file in the vault and a
change log, in .zennotes/sync/ inside the vault, so it follows a vault
switch or a move to another server. Every write path records its change
under the vault lock it already takes: the web client, the phones, both zn
builds and /mcp. A rename, trash or folder rename is one move per file, so
each keeps its identity, and Empty Trash is one delete per file. Edits made
outside the server (a shell, git pull, Syncthing) are found by a reconcile
that stats first and hashes only what changed. Until one has run, a sync
write compares the disk, so such an edit is never written over.

/api/sync/manifest, /api/sync/changes and /api/sync/mutations speak Cloud's
wire shapes without encryption. A change lands only if its file is still at
the revision it was built on, each change is answered on its own, and a
repeated operation id gets its first answer. A copy older than the 90-day
log rebuilds from the manifest. /api/capabilities says supportsSync: 1.
Attachments are not part of a copy yet and are set aside as Cloud sets
aside a path it refuses.

integration/cloud-engine drives Cloud's CloudSyncCoordinator and the
desktop's sync repository, taken from a pinned ZenNotes commit, against a
real server: bootstrap, offline edits replayed, a conflict held for review,
renames and deletes both ways, an edit made on the server's disk, and a
cursor older than the log. CI runs it on Linux, macOS and Windows.
Git Bash on Windows rewrites an argument that starts with / into a Windows
path, so the sparse-checkout patterns (/packages/shared-domain/src/ and the
rest) matched nothing and the ZenNotes checkout came out empty. The step now
names the folders in cone mode, with no leading slash.
@adibhanna
adibhanna merged commit 1040fad into main Nov 24, 2026
41 of 44 checks passed
@adibhanna
adibhanna deleted the feat/sync-protocol branch November 24, 2026 15:45
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