Repository navigation
fix(syncer): a conflict version reaches the hub when a pulled delete comes first - #121
Merged
Merged
Conversation
…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.
bketelsen
approved these changes
Oct 30, 2026
2 tasks done
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.
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
conflictitem, from the file's agreed row (sync-protocol.md, Pending changes).push()readsPendingConflictsbefore the stale write happens.pull()that comes next applies the hub's delete of the file and drops the file's agreed row (DeleteAgreed).PendingConflictsjoins 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-10in the CI run.The fix
store.Tx.DropAgreeddrops the agreed row for a delete that applies: a pulled head, an answer, ordropOther. 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 columnsync_pushes.base_hash, added by migration 0005. The file's other unanswered conflict pushes take the row as their base too.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.statuscounts unanswered conflict pushes as pending.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/synctestis planner-owned (ADR-0020).docs/specs/sync-protocol.md(Pending changes, Pulling and applying) anddocs/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).internal/vault/apply.goremoves 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 oldDeleteAgreedcalls it failed 3 of 3 runs. With the fix it passed.TestAConflictVersionCarriedPastADeleteLeavesARestoredFilereproduces the reviewer's sequence. It failed 3 of 3 runs at c316315 (the hub deleted the restored file) and passed 50 of 50 with-raceat ae3d266.TestDropAgreedCarriesConflictVersions(store) andTestScenarioAConflictOfAFileTheHubNeverHadStaysOnItsDevice(synctest).make checkpasses.Coder: github-copilot/claude-opus-5.5. Cross-review: openai/gpt-6.1-sol. Ready at ae3d266 (re-review 1 of 3), Blocking: none.