Skip to content

fix(syncer): record a head before applying it, so a crash never pushes it back - #122

Merged
bketelsen merged 4 commits into
mainfrom
fix/apply-crash-window
Oct 31, 2026
Merged

bketelsen merged 4 commits into
mainfrom
fix/apply-crash-window

Conversation

@frostyard-machines

Copy link
Copy Markdown
Contributor

Summary

A crash between vault.Apply's change to the disk and its Tx left 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_applying before it applies it (pulled heads, answers, dropOther). The Tx that 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 on 189ae2f):

  • pulled delete: the restored file was deleted again
  • pulled move, and move with edit: a later move was reverted
  • pulled put: a file deleted later came back
  • pulled create: a file deleted later came back
  • answer: a spurious conflict revision flagged the file

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 check passes (with umask 022; this host's umask 0077 fails TestFileRefusesReadableFile on main too).
  • go test -race ./...
  • The new test fails on main and passes here; a 7th case checks that a discarded record does not block a real edit.

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.

…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).
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Oct 31, 2026
@bketelsen
bketelsen merged commit caec361 into main Oct 31, 2026
9 checks passed
@bketelsen
bketelsen deleted the fix/apply-crash-window branch October 31, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants