Repository navigation
Conversation
… not forever When the server held an older version of a record than the Mac's journal (sync set up again over an old sync.sqlite), every push of the record came back as a conflict. Journal.receive saved the merge at the higher of the two versions, so the Mac kept its own, the record stayed dirty, and the next push went on the same base and met the same conflict, about twice a second. A merged conflict now takes the version the server gave, with the dirty flag the merge left, so the next push lands on top of it and is accepted.
naman0r
marked this pull request as ready for review
November 24, 2026 06:09
[Medium impact] The PR appears safe to merge; the new check addresses the previous risk of erasing server-only fields. SummaryPrevents repeated conflicts when the server's record version is behind the journal.
Code review found no new actionable issues. Tests were not run during this review; the PR reports passing targeted suites.
|
…'s fields The version the server gave was taken even when the merge of its record didn't happen: a failed write in Journal.receive, or the app's deliver turning the record away, both swallow the error. The unmerged record then went on the server's version and replaced the fields only the server had. The version is now taken only when the server's record is already in the local one, checked and saved in one step; otherwise the next push meets the conflict again and merges then.
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.
What changes
When the sync server holds an older version of a record than the Mac's journal, the Mac sends the record once more on the server's version and goes quiet. Before, it sent the same change about twice a second for as long as Yab was open, using a core and uploading tens of KB a second.
Fixes #1088
Why it happened
A push whose
baseis not the server's version comes back as a conflict.SyncClient.heardhands conflicts totake(conflicts)(Sources/SyncKit/SyncClient.swift:323-333), which merges them throughJournal.receive. That saves the merge atmax(version, had?.version ?? 0)(Sources/SyncKit/Journal.swift:799), so when the Mac's version is the higher one, it keeps it. The record stays dirty,push()runs again at once (SyncClient.swift:340) on the same base, and the server answers with the same conflict, forever.The fix: after a conflict is merged, the record takes the version the server gave, keeping the dirty flag the merge left (
Journal.conflicted, called right aftertake(conflicts)). The next push lands on the server's real version and is accepted. The version is taken only when the server's record is already in the local one (merging it again changes nothing), checked and saved in one step:takeand the app'sdeliverboth swallow a failed merge, and an unmerged record sent on the server's version would replace the fields only the server has.Journal.receivekeeps itsmax, since catch-up deliveries rely on it never lowering a version.Why no change can be lost
deliverturning the record away) keeps the old version, so the next push meets the conflict again and merges then, as onmain.maxalready gave the server's version there, and this sets the same value.SyncCenter.deliverinstead ofJournal.receive, but that returns beforetakedoes, so the version is checked after the merge on both paths.Proof
mainand passes here:swift test --filter 'SyncClientTests/aConflictWithAServerBehindIsSentOnTheVersionGiven'The test uses
MemoryServer: the iPhone fills the account first (version 1), then the Mac starts with a dirty record at version 5 that changes another field.MemoryServernow counts pushes by device.On
main(fix reverted, test kept):9,049 pushes in the two seconds the test waits, and nothing settles. With the fix it passes: the Mac pushes exactly 2 times (one conflict, then accepted), keeps the iPhone's
url, and the iPhone gets the Mac's title.swift test --filter 'SyncClientTests/aConflictLeftUnmergedKeepsTheServersFields'The Mac's
deliverdrops what it is given, so the conflict is never merged. On the first commit of this branch (292808d), the unmerged record went on the server's version and the server lost the iPhone'surl:With the fix it passes: the record keeps its old version, and the server keeps
url.Checked on
MemoryServer, on macOS 27.0. No app build, and no real sync server or account.Checklist
swift testpasses (or the suites this touches: list them):SyncClientTests,SyncKitTests,SyncFlushTests,SyncStaleReturnTests,SyncWireTests, 68 tests, all pass./design-check --headis clean, or each exception says why with// design:NativeActions.swift(none added)Not verified
swift test.rebasepath, which already uses the server's version, so this change leaves it as it was.