Skip to content

fix(syncer): a conflict version reaches the hub when a pulled delete comes first - #121

Merged
bketelsen merged 3 commits into
mainfrom
fix/conflict-version-survives-pulled-delete
Oct 30, 2026
Merged

bketelsen merged 3 commits into
mainfrom
fix/conflict-version-survives-pulled-delete

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

This fixes a real lost write. It makes main's scheduled CI green again (run 41049111551, TestScenarioContentionProfile/concurrent).

The cause

A stale write on a device conflicts in every hunk. Only a local conflict version keeps it. The device pushes that version as a conflict item, from the file's agreed row (sync-protocol.md, Pending changes).

  1. The device's push() reads PendingConflicts before the stale write happens.
  2. The pull() that comes next applies the hub's delete of the file and drops the file's agreed row (DeleteAgreed).
  3. PendingConflicts joins on that row, so it never finds the version again.

The hub would have taken the item: rule 10 accepts it whether the file is live or deleted. Instead the text stayed only in the device's local history. This is what lost tok2-10 in the CI run.

The fix

  • store.Tx.DropAgreed drops the agreed row for a delete that applies: a pulled head, an answer, or dropOther. Before it drops the row, in the same transaction, it records each conflict version of the file that no push carried as an unanswered conflict push. Each push holds the row's hub file, revision, revision hash and path. The hash goes in the new column sync_pushes.base_hash, added by migration 0005. The file's other unanswered conflict pushes take the row as their base too.
  • The device sends these pushes like every unanswered push, also after a restart. items() uses the stored base while the file has no agreed row, and the agreed row's base after a later pull makes one. No delete is pushed back.
  • sync.status counts unanswered conflict pushes as pending.
  • The checker (internal/synctest/check.go, neverAgreed) stops counting one kind of token as lost: a token that only a local conflict version holds, of a file its device deleted before it ever agreed the file with the hub. The protocol cannot carry that version: the device has no hub file for it. Please check this part: internal/synctest is planner-owned (ADR-0020).
  • Docs: docs/specs/sync-protocol.md (Pending changes, Pulling and applying) and docs/design/sync.md.

The first fix (commit db84059) kept the agreed row and pushed the delete back. The cross-review found that this synthetic delete could delete a file that another device had restored in the meantime. Commit ae3d266 replaces that design with the one above.

Commit c316315: the parking flake

The flake was TestAnAnswerLeavesAParkedFileForTheFollowingPull (run 40799665394). push() read the quiet-period marks again for each change, so an event that arrived between 2 reads split a swap. Now 1 copy (l.marks()) judges all of a push's changes.

Not in this PR

  • TestShutdownWithNoDataDirectory (run 40664351233) is already fixed on main by bba6721 (lodge kit v0.3.1, lodge#40).
  • A crash window that is older than this PR: internal/vault/apply.go removes the file before it commits the index and agreed-row changes. A crash in that window can, after the restart, push a delete with the old base. The reviewer agreed that this gap is out of scope.

Evidence

  • TestAConflictVersionReachesTheHubWhenAPulledDeleteComesFirst: with the old DeleteAgreed calls it failed 3 of 3 runs. With the fix it passed.
  • TestAConflictVersionCarriedPastADeleteLeavesARestoredFile reproduces the reviewer's sequence. It failed 3 of 3 runs at c316315 (the hub deleted the restored file) and passed 50 of 50 with -race at ae3d266.
  • Other new tests: TestDropAgreedCarriesConflictVersions (store) and TestScenarioAConflictOfAFileTheHubNeverHadStaysOnItsDevice (synctest).
  • Contention sweep: 4 failures in 600 seeds before. After the redesign: 0 failures in 2,100 concurrent seeds.
  • make check passes.

Coder: github-copilot/claude-opus-5.5. Cross-review: openai/gpt-6.1-sol. Ready at ae3d266 (re-review 1 of 3), Blocking: none.

…lete

A writer's content that lost a merge on a device is pushed as a conflict
item from the file's agreed row. When a delete of the file applied first
(a pulled head, or an answer), the row was dropped, so PendingConflicts
never found the version again and the edit never reached the hub: a lost
write, seen in TestScenarioContentionProfile/concurrent (CI run
41049111551, tok2-10).

DropAgreed now keeps the row while the file has a conflict version that
no answered push carried; the device pushes the version, then the delete
back (accepted, appending nothing), whose answer drops the row.

The checker no longer counts as lost a token that only a local conflict
version holds, of a file its device deleted before it ever agreed the
file with the hub: no conflict item can carry it (sync-protocol.md,
Pending changes).
push() read the quiet-period marks again for each change, so an event
between two reads could split a swap: one file went alone and the hub
numbered it onto the path the other still held. Seen as a flake of
TestAnAnswerLeavesAParkedFileForTheFollowingPull (CI run 40799665394).
…synthetic delete

DropAgreed kept the agreed row of a file with an unpushed conflict
version after a pulled or answered delete. Pending then read the row and
the missing file as a local delete, and the device pushed that delete
with the old base: if another device had restored the hub's file
meanwhile (a rename with unchanged content, which the hub applies as a
restore), the hub deleted the restored file.

DropAgreed now drops the row at once. In the same transaction it first
records each of the file's conflict versions that no push carried as an
unanswered conflict push from the row (hub file, revision, the
revision's hash in the new sync_pushes.base_hash column, migration 0005,
and path), and rebases the file's unanswered conflict pushes on the row.
items() sends a conflict push without an agreed row with that stored
base; the hub keeps a conflict item of a deleted or restored file.
dropOther uses DropAgreed too, and sync.status counts unanswered
conflict pushes as pending.

TestAConflictVersionCarriedPastADeleteLeavesARestoredFile replays the
review's sequence and fails on the previous head.
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Oct 30, 2026
@bketelsen
bketelsen merged commit 189ae2f into main Oct 30, 2026
9 checks passed
@bketelsen
bketelsen deleted the fix/conflict-version-survives-pulled-delete branch October 30, 2026 23:11
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