Repository navigation
Upload an edit once the file has gone quiet, not the moment it closes - #53
Merged
Merged
Conversation
Uploading on close is what made the mount race itself. An atomic save closes a temp file it is about to rename away, so the upload went out under a name the file was about to stop having. A scratch file written and deleted seconds later raced its own upload. An editor saving repeatedly started an upload per save, and they collided with each other on the way out — the 409 nameAlreadyExists churn. Waiting for a file to go quiet removes all three at the source rather than recovering from them: by the time the upload starts, the temp file has become the real one, the deleted file is gone, and ten saves have become one. Default 900s, configurable as upload_debounce_secs; 0 keeps the old upload-on-close behaviour. Rewriting a file pushes its deadline out rather than queueing a second upload, and unlink() drops a waiting edit instead of racing it. What the wait costs is exactly its length: an edit lives only on this machine until then. So shutdown flushes the queue and waits up to 60s for it to drain before unmounting — otherwise a restart would take the window's work with it, which would be a worse bug than the ones this removes. Anything still unsent after that is in the cache and the retry queue, and says so in the log rather than disappearing quietly. pending_uploads over D-Bus now counts waiting edits as well as ones queued for retry. With a 15-minute window the waiting kind is the common one, and leaving it out would show "everything synced" over work that has not left the machine. Tests: five for the queue itself on a paused clock (waits out its delay, a rewrite extends it, a delete cancels it, a flush releases everything, the count covers both waiting and in-flight), and a mount round trip proving a file written and deleted inside the quiet period never reaches OneDrive at all. The delete-during-upload round trip now waits for the upload to actually start before deleting — with a debounce that race is one the client is designed to win, so testing it needs the window opened deliberately. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfrYQTqjBaP4gDF77Ux1wZ
franzjeger
force-pushed
the
claude/upload-debounce
branch
from
August 8, 2026 10:23
346df7e to
cd42449
Compare
CI caught what 20 local runs did not: a file created and deleted in one breath left an entry queued for the whole debounce window. release() is asynchronous with respect to close(), so an unlink can land between release()'s check that the row exists and its scheduling of the upload. The unlink cancels an entry that is not in yet; release then adds one that nothing will remove. It never uploads — it re-reads the row first and gives up — but it counts as an unsent edit for the whole window, and shutdown waits for it. The one number the user is meant to trust becomes wrong. release() now re-checks the row after scheduling, and unlink deletes the row before cancelling rather than after. Whichever of the two runs last finds the state the other left, so both orderings clean up. Confirmed with 20 consecutive runs of the test that failed in CI. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfrYQTqjBaP4gDF77Ux1wZ
…tity CI failed twice on this branch, each time on a different test, and both failures were real bugs — two of them in code already released. **A file could vanish moments after being written.** An upload adopts the real OneDrive ID, moving the row off the temporary `_local_*` one. `local_path` is unique so the two rows cannot both exist, which means there is always an instant where the inode names an ID the database no longer has — whichever order the swap is done in. A read landing there found no row, and for a `_local_*` item with no cache file that is read as "no content anywhere", so it dropped the entry. Reading a file you had just created could delete it. Reads now hold the inode lock across the lookup and adoption takes it for writing across the whole swap, so a reader sees either the entire before or the entire after. This one was shipped in v0.13.1. **An upload could overwrite a rename that beat it to the row.** The task re-read the row for the current name, then made a network call, then wrote — and a rename landing in between was overwritten with the name the upload had started with, leaving the saved file apparently missing until the next delta. The re-read now happens inside the lock, immediately before the write. **A cache file being moved read as a cache file that was gone.** Adopting an ID renames the cached copy, so "missing" during an upload means "moving". Reads in that window get EAGAIN rather than having the entry dropped underneath them. The atomic-save test also asserted on the wrong thing. It required the remote rename that corrects a temp-name upload — but with the upload re-reading the row after its wait, it usually addresses the final name directly and no correction is needed. That is the debounce working, not a failure. It now asserts where the file ends up rather than which route it took. Verified with 60 consecutive runs of the full mount suite, from 8 failures in 40 before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfrYQTqjBaP4gDF77Ux1wZ
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.
Stacked on #52.
Uploading on close is what made the mount race itself:
409 nameAlreadyExistschurn#51 and #52 fix those by recovering afterwards: create the file remotely, then delete it; upload under the wrong name, then rename it. Waiting for the file to go quiet removes them at the source. By the time the upload starts, the temp file has become the real one, the deleted file is gone, and ten saves have become one.
Default 900s, configurable as
upload_debounce_secs.0keeps the old upload-on-close behaviour.Rewriting a file pushes its deadline out rather than queueing a second upload.
unlink()drops a waiting edit instead of racing it.The cost, and what pays for it
What the wait costs is exactly its length: an edit lives only on this machine until then. Fifteen minutes of unsent work is a real exposure, and it is the reason this PR is more than a
sleep.Shutdown flushes the queue and waits up to 60s for it to drain before unmounting. Without that, a restart would take the whole window's work with it — a worse bug than the ones being removed. Anything still unsent after the timeout is in the cache and the retry queue, and says so in the log rather than disappearing quietly.
pending_uploadsover D-Bus now counts waiting edits too, not just ones queued for retry. With a 15-minute window the waiting kind is the common one, and leaving it out would show "everything synced" over work that has not left the machine.Testing
Five tests for the queue on a paused clock — so they assert the timing without spending 15 minutes:
Plus a mount round trip proving a file written and deleted inside the quiet period never reaches OneDrive at all — no PUT, nothing queued.
One existing test changed meaning and was rewritten rather than patched: the delete-during-upload round trip now waits for the upload to genuinely start before deleting. With a debounce, that race is one the client is designed to win, so exercising the recovery path needs the window opened deliberately.
cargo fmt,cargo clippy --workspace --all-targets -- -D warnings, andONEDRIVE_REQUIRE_FUSE=1 cargo test --workspacepass.Generated by Claude Code