Skip to content

Fix conflict-on-fetch scenario - #581

Open
lukaskubanek wants to merge 2 commits into
pointfreeco:mainfrom
structuredpath:fix-conflict-on-fetch
Open

lukaskubanek wants to merge 2 commits into
pointfreeco:mainfrom
structuredpath:fix-conflict-on-fetch

Conversation

@lukaskubanek

Copy link
Copy Markdown
Contributor

This is a small subset of #414, a PR that revamps merge conflict tests to cover all possible conflict scenarios.

This PR isolates a single scenario that the current implementation gets wrong and applies a minimal fix.

The first commit corrects a wrong assertion in one of the existing merge conflict tests, namely serverRecordEditedAfterClientButProcessedBeforeClient. It edits the title on the client at t=30 and on the server at t=60, then processes the fetch before the client’s pending send goes out, a.k.a. conflict on fetch. It currently asserts that the client’s "Get milk" wins and ends up with the server’s timestamp. Under last edit wins the server’s "Buy milk" should win, as its edit is newer. This is the scenario reported in #354 and the remaining part of the divergence in #274.

The second commit adjusts the merge in CKRecord.update(with:row:columnNames:parentForeignKey:). So far a field changed on the client was always kept, regardless of timestamps. It is now kept only if the server did not change the field since the last known server record, or if the client’s change is newer than the server’s. Equal timestamps also favor the client, as elsewhere in the merge.

Fixes #354 and fixes #274.

lukaskubanek added a commit to structuredpath/sqlite-data that referenced this pull request Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Violation of “last edit wins” conflict resolution strategy Data divergence between devices after concurrent offline edits

1 participant