Repository navigation
fix(syncer): record a head before applying it, so a crash never pushes it back - #122
Merged
Merged
Conversation
…s it back A crash between vault.Apply's change to the disk and its Tx left the agreed row at the old revision. After the restart the device pushed the change back from that base as its own: a pulled delete deleted again a file another device had brought back, and pulled moves, puts, creates and answers undid later changes on the hub. The sync loop now records each head in sync_applying before it applies it; the agreeing Tx deletes the record, and each session settles what a crash left, after the vault's open scan and before any push (ADR-0034).
A scan that fails as a whole (an unreadable folder, an unmounted share) changes nothing, so the index can still hold a file a crash moved away; settling then pushed it as a create. Vault.Scanned now returns ErrNotScanned until a scan has succeeded, and the loop settles before it dials, waiting with its backoff while none has (cross-review of #122).
The delete of a vault's last file, interrupted by a crash, leaves an empty folder over an index that still holds the file: every scan refuses it, so waiting for a scan that succeeded stopped sync for good. A delete record looks at one path, which Apply refreshes, and at its local file's row, so it settles without a scan; a move, put or create record still waits for one (re-review of #122).
… index A delete record proves the intent, not the removal. Over a share that is not mounted, settling it dropped the agreed row of a file that came back with the share, and the file went out as a create. Delete records now skip the wait for a scan that succeeded only when every indexed file is a file one of them removes (re-review of #122).
bketelsen
approved these changes
Oct 31, 2026
This was referenced Nov 2, 2026
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.
Summary
A crash between
vault.Apply's change to the disk and itsTxleft the device's agreed row at the old revision. After the restart, the scan saw the change as an outside edit, and the device pushed it back from the old base as its own change. The worst case (T578): a pulled delete, pushed back, deleted again a file that another device had brought back with the same content (hub rule 4).The sync loop now records each head in
sync_applyingbefore it applies it (pulled heads, answers,dropOther). TheTxthat agrees the head deletes the record. Each session settles what a crash left, after the vault's open scan (Vault.Scanned) and before any push: a file that holds the head is agreed; anything else is discarded and waits for its own push or the next pull. See ADR-0034.Other apply paths (T578 step 3)
The same window was in every apply path, and each one went wrong on main (
TestACrashWhileApplyingAHeadPushesNothingBack, 6 failing cases on189ae2f):All are fixed by the same record. The parking moves (rule 5 and the answers' parking) keep their documented behaviour: a crash leaves the parked name, pushed as a move — a name to fix by hand, nothing lost.
Checks
make checkpasses (withumask 022; this host'sumask 0077failsTestFileRefusesReadableFileon main too).go test -race ./...Docs: ADR-0034 (new),
docs/specs/sync-protocol.md,docs/design/sync.md,docs/design/vault.md,docs/README.md.Coder: github-copilot/claude-opus-5.5.