Skip to content

Change detection

Reconciliation is only as good as its ability to notice what changed. The engine detects local and remote changes differently.

Local files are compared by SHA-1 content hash. Re-hashing an entire tree on every periodic scan would be wasteful, so the scanner uses a quick-check: if a file’s size and whole-second modification time both match its last-synced record, the file is assumed unchanged and its stored hash is reused.

The trade-off: a change that somehow preserves both the byte size and the whole-second mtime of a file isn’t noticed until the next edit that changes size or mtime. This is the same default rsync makes, and it’s rare in practice.

The daemon also watches the folder with the OS filesystem-notification API, so most local edits trigger a reconcile promptly rather than waiting for the periodic scan.

Detecting remote changes is harder, because Proton Drive gives no “this subtree changed” flag — a nested change leaves every ancestor byte-identical. There are two ways to find out what moved.

The straightforward method lists every remote directory with proton-drive filesystem list --json, one call per folder. That’s O(folders) network round trips every scan. It’s correct and simple, but slow on large trees, so it’s used as the bootstrap and as an on-demand fallback (and, if you opt in, a periodic reconvergence) — not the hot path.

Proton’s own clients avoid full walks with a volume-level event stream: fetch a cursor, then poll the deltas since that cursor. That’s O(changes), not O(folders). The engine uses this by default.

Concretely, the engine:

  1. Reads the last stored per-volume event cursor from its index.
  2. Fetches the delta of created / updated / deleted nodes since that cursor.
  3. Overlays that delta onto the last-known remote view to reconstruct a complete remote map — without walking the whole tree — and hands it to the planner.
  4. Advances the cursor only in the final commit of a fully-successful pass, so a failed or withheld pass re-derives from the same cursor next time.

A periodic full-tree scan can be re-enabled as a reconvergence backstop (--events-full-scan-every N), but it is off by default — after the mandatory startup snapshot the daemon stays purely event-driven until it is restarted or the event stream forces a fallback (no cursor, an error the server answered with, a node it cannot place, …). The first reconcile after the daemon starts is always a full scan — a fresh process has no pending-change history, so it can’t safely trust an incremental pass alone.

When Proton’s event stream does not answer

Section titled “When Proton’s event stream does not answer”

A request that times out, is cut off, can’t connect, or gets a “try again later” from the server (HTTP 429 or a 5xx) tells the engine nothing about what changed. Walking a large folder in reply takes about half an hour, so the engine doesn’t: that sync pass is skipped, nothing is planned or changed, and the next poll — thirty seconds later — asks again. A skipped pass leaves nothing behind: no “last synced” time, no error, no history entry. A restart that was waiting to resume from its saved position still resumes from it on the next try.

If the stream stays silent for ten minutes in a row, the engine checks the tree by walking it instead, because the proton-drive CLI may work when the event stream does not. Nothing is synced during those ten minutes, and afterwards changes wait until each walk finishes. It says so: the folder’s last error reads “Proton’s change feed has not answered for …” until the stream answers again. While it stays down, that walk happens at most once every ten minutes.

An answer that is wrong — the server rejects the saved position, or the reply can’t be read — doesn’t wait: asking again would get the same reply, so the engine walks at once, as before.

Event-driven mode is on by default. Opt out with --no-events-driven (or events_driven = false), which restores the byte-identical snapshot-only path.

The event stream is for your whole Proton volume, not for the folder you sync, so most of what it reports may be about other folders — other devices, other synced folders, the web app. A folder ignores an event about another folder, as long as it knows which Drive folder is its own, every folder in its tree has an id, and every file it has recorded sits in a folder it has recorded too. A poll in which every event was about other folders costs nothing: no scan of the remote tree and no scan of your local folder. The folder cannot tell in these cases, and then re-scans once, as it always did. The first is right after it has made a folder itself: that folder has no id until Proton’s event for it arrives (normally within one poll), and a change elsewhere in that gap could be about it. The second is an index that records a file but not the folder it is in (an event elsewhere, a removal included, could be about that folder), or a file recorded under an id from an older version (the re-scan rewrites it). The third is a change to the synced folder itself (renamed, moved, trashed), or a folder moved in from elsewhere, because the stream describes nothing inside them. The fourth is an event that names no folder at all, because then nothing says where the file is. The fifth is a file or folder it has recorded that moves to a folder it does not know: that is either a move out of your synced folder or a move into an empty folder it has no record of, and the event cannot tell which, so it looks rather than guess.

A folder with an include rule (“only sync these”) never ignores a created or changed item from another folder. The folders on the way to an included file are not recorded, so it cannot tell where such an event belongs, and it re-scans for each one, as before. It does still skip one kind of event, as it always did: the removal of an item it has no record of, when every file it has recorded carries its Proton id. A file it has just uploaded has no id until Proton’s event for it arrives, and while that is so this folder re-scans for a removal too. The folders on the way to an included file have no entry of their own, so trashing one leaves the included files recorded beneath it in place until the next re-scan puts them right.

In Proton’s event stream, moving a file to the Trash arrives as an update with a trashed flag — not as a delete event. The engine normalizes that correctly, so a trash is treated as a removal. (This is the kind of detail the engine’s tests pin down.)

Reading the event delta needs a Proton session but no decryption — the events carry node IDs, parent IDs, type, and trashed/shared flags, all in cleartext. The engine gets that session by reusing the logged-in proton-drive CLI’s session from your desktop keyring (read-only), and fetches the deltas over plain HTTPS. It ships no Proton networking or crypto of its own; the HTTP transport and session provider are injected seams.

Two consequences:

  • The daemon is only as fresh as the CLI keeps the session. If the CLI is idle and its token expires, a pass fails auth and is skipped until the CLI refreshes — and the daemon degrades to snapshot scans meanwhile, so sync keeps working, just less cheaply.
  • Created and updated (non-trashed) remote nodes are resolved with a targeted single-directory list rather than a full walk. That targeted list is also where a newly-created node’s name gets decrypted (unlike its ids, the name is encrypted in the event) — the one lookup unique to creations.

An independent (browser-forked) session that doesn’t depend on the CLI is a deferred design decision. The rationale for all of this is recorded in ADR 0001.

Control Effect
--events-driven / --no-events-driven Turn event-driven detection on (default) or off.
events_driven = true/false The config-file equivalent.
--events-full-scan-every N Force a full-tree reconvergence every N incremental passes. Default 0 disables it — event-driven only after the startup snapshot.
--scan-interval-secs How often the periodic reconcile fires.

See the Daemon reference for all flags.