Skip to content

fix: keep a plain write over a version its client never read - #176

Merged
Mearman merged 10 commits into
mainfrom
fix/lost-update-on-plain-write
Dec 4, 2026
Merged

Mearman merged 10 commits into
mainfrom
fix/lost-update-on-plain-write

Conversation

@Mearman

@Mearman Mearman commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Fixes #169
Fixes #170

A WebDAV PUT without If-Match went handle_put → ScopedBackend::update (a writers = any scope with no block_size takes the plain path) → P2pBackend::update → write_content with no check, which reads the row current at that moment and bumps its vector ("a peer row merged in between is extended rather than overwritten"). When the peer's concurrent row had already been merged on the writing node, the new row dominated it, so merge_one on the peer took it as a successor and never logged preserving losing version as conflict copy: the peer's write was gone with no copy. #128 fixed this for writes that name a version (If-Match, commit with ReplaceIfVersion); a plain write named none.

A write with no precondition is now committed against the version the client edited:

  • Backend::commit_edit commits against a stated base and hands a failed precondition to the scope's conflicts policy. Its default is commit; ScopedBackend admits the path as for any write and runs commit_with_policy, so fork keeps a conflict copy and reject refuses with CommitError::Rejected.
  • ServedVersions (engine, commit::served) records per backend and path the version a presenter served or wrote, and ServedVersions::write commits a plain write through commit_edit against it. The base is the version last served or written there; with none, CreateIfAbsent when the client's listing lacked the path (so a file a peer created meanwhile is kept too), else the version current at the write (an unconditional overwrite, as before). A backend without committed versions is written unconditionally. A landed write becomes the base; a forked one leaves the base alone, since the client still has not seen what the path holds.
  • The base is recorded where content is served, never at write time: reading the current version just before the write would only narrow the window. WebDAV records a GET whose version held still across the fetch; the HTTP API, FFI and File Provider record the version read before the download (older than or equal to what was served, so the error direction is a spurious fork, never a lost write).

CommitOutcome moves from commit::policy to commit so the trait can name it.

Write paths:

Presenter Write with no precondition before Now
WebDAV PUT (no If-Match) update/upload: extends the current row ServedVersions::write, one record per path shared by the server's clients (no per-client handle in WebDAV); 409 in a reject scope; DELETE/MOVE forget the paths
WebDAV PUT with If-Match/If-None-Match: * commit, 412 on a mismatch unchanged; a landed commit becomes the path's base
HTTP API PUT (no If-Match) metadata then update/upload ServedVersions::write per bearer; a reject scope answers 409 Conflict; a fork returns the conflict copy's entry
HTTP API PUT with If-Match commit, 412 unchanged; records the base
FFI upload metadata then update/upload ServedVersions::write, base recorded by read_file
File Provider import_document update (existing) or upload (new) ServedVersions::write, base recorded by fetch_contents; a new name is a create-if-absent
NFS WRITE/SETATTR rewrite: read version, patch the byte range into the current content, commit, retry on PreconditionFailed unchanged: per-WRITE positional patches merge at byte level rather than lose the whole write, but a save over a peer edit neither forks nor keeps either version whole; needs close-to-open buffering, tracked in #174
FUSE EROFS (read-only) unchanged
ProjFS, FSKit no write path in the Rust presenters unchanged
Sync runner (upload of dirty files) upload unchanged: it writes a local folder's changes, not a client's edit of a served version
CLI, cross-backend move (vfs::tree) upload unchanged

Also fixed: a PUT or MOVE stamped its item with the backend-relative path, so a GET of the mount-prefixed path on the writing daemon answered 404 until the sync runner re-added the item (#170). Both now stamp the mount-prefixed path, as directory expansion does.

Tests (crates/presenter-webdav/tests/plain_put_conflicts.rs, two P2P nodes from the backend-p2p harness behind real WebDAV servers and ScopedBackend; the interleaving is ordered, never timed: B's client lists and GETs base, A's edit is written and polled until B holds it, then B's client PUTs):

  • a plain PUT over A's edit: both contents survive, one at doc.txt and one conflict copy, identical on both nodes
  • the same under :policy conflicts=reject: 409, A's edit stands, no copy
  • a plain PUT creating new.txt after A created it: both survive
  • sequential PUTs (two in a row with no read between, then one after reading A's later edit): no conflict copy; a read straight after the writer's own PUT returns it

On main (ae5caf9, with only the test commits) the fork and create tests time out waiting for both contents to be held on both nodes, the reject test gets 201 instead of 409, and the sequential test gets the 404 of #170. With the change all four pass.

Two-host rerun of the issue's reproduction with this branch (release builds, one P2P backend per host, WebDAV on loopback, concurrent unconditional PUTs overlapping in time): both writes survived, with identical trees and hashes on both hosts, in 10 of 10 trials, converging within about 2 s. Six trials were kept by the PUT's policy commit (a (name date).conflict copy) and four by the P2P merge (a .conflict-<id>-<time> copy). The overwrite check (v1 reaches the peer, then v2 and v3 written straight after) served v3 on the peer in 20 of 20 trials with no conflict copy. The copy label is the backend name rather than the device's, which is #178.

… served

A write that states no precondition went through Backend::update,
which extends whatever version is current when it lands,
so a peer's edit that arrived after the client's read was superseded with no conflict copy.

Backend::commit_edit commits against a stated base and leaves a failed precondition to the scope's
conflicts policy (ScopedBackend runs commit_with_policy: fork keeps a copy, reject refuses).
ServedVersions records the version a presenter served or wrote per path
and writes a plain write through commit_edit against it,
CreateIfAbsent when the client's listing lacked the path,
and unconditionally only on a backend without committed versions.
CommitOutcome moves beside Commit so the trait can name it.
A PUT with no If-Match now commits against the version the presenter last served for the path
(a GET whose version held still across the fetch, or the presenter's own last write),
so a peer's version that landed in between is forked or rejected by the scope's policy
instead of being superseded. A PUT to a path the listing lacks creates only if absent.
DELETE and MOVE forget the paths they take away.

A PUT or MOVE also stamped the item with its backend-relative path,
so a GET of the mount-prefixed path missed it until the listing was refreshed;
both now stamp the mount-prefixed path as directory expansion does.
… presenter

The HTTP API's PUT without If-Match, the FFI upload and the File Provider import
wrote through Backend::update or upload, superseding a version another node wrote
after the client's read with no conflict copy, as the WebDAV PUT did.
Each now records the version it serves and writes through ServedVersions,
so the scope's conflicts policy keeps or refuses such a write.
The HTTP API keeps a record per bearer, answers a write a reject scope refuses
with 409 Conflict rather than an If-Match failure, and names the conflict copy
a forked write landed as.
Copilot AI balanced review requested due to automatic review settings December 4, 2026 08:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Mearman
Mearman merged commit 44978ca into main Dec 4, 2026
111 of 112 checks passed
@Mearman
Mearman deleted the fix/lost-update-on-plain-write branch December 4, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants