Repository navigation
Add failing test to demonstrate delete-then-reinsert issue #418 - #575
Merged
stephencelis merged 13 commits intoNov 9, 2026
Merged
Conversation
…` and `add(pendingDatabaseChanges:)`
jsutula
commented
Nov 5, 2026
Member
|
Hey @jsutula, thanks for the PR! I rebased this on all the work we merged today, and things are looking good. Will either merge this soon, or may spend some time investigating a fix. |
Member
|
I just pushed 3aec4e3 that now fixes the delete+reinsert bug. Could you give it a test and let me know if it works for you? |
Contributor
Author
|
Great, looks like a clean fix. To test, I rebased the original live repro setup on top of these changes - jsutula@5271521. Result: data loss no longer occurs on every other update.
|
Member
|
Hi @jsutula, thanks for testing! I ended up uncovering a few new semi-related issues while exploring things and glommed them onto this PR (GitHub doesn't yet support stacked PRs across forks). We hope to get things merged and released soon! |
stephencelis
approved these changes
Nov 9, 2026
4 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.
Refs #418.
Two small stacked commits extracted from #421:
1. Dedupe by ID in
MockSyncEngineStateadd(pendingRecordZoneChanges:)andadd(pendingDatabaseChanges:)According to Apple docs for
CKSyncEngine.State.add(pendingRecordZoneChanges:), for a givenCKRecord.ID, adding a delete after a save discards the save, and adding a save after a delete discards the delete.In other words, pending save and delete changes are deduplicated by
CKRecord.ID, retaining the last change added. The same is true forCKSyncEngine.State.add(pendingDatabaseChanges:), but deduped onCKRecordZone.IDinstead ofCKRecord.ID.Currently
MockSyncEngineStateonly deduplicates fully identical changes (ID + type(save/delete)) in itsaddmethods. This commit changes its implementation to matchCKSyncEngine.Statebehavior and dedupe on ID alone. This is accomplished by switching its internal pending changes storage:OrderedSet<CKSyncEngine.PendingRecordZoneChange>->OrderedDictionary<CKRecord.ID, CKSyncEngine.PendingRecordZoneChange>OrderedSet<CKSyncEngine.PendingDatabaseChange>->OrderedDictionary<CKRecordZone.ID, CKSyncEngine.PendingDatabaseChange>.2. Add failing test to demonstrate delete-then-reinsert issue #418
(failing assertions wrapped in
withKnownIssue)In order to be meaningful, this new test depends on the
MockSyncEngineStatechanges in the first commit. Without the mock changes, a fix for #418 that queues a save after the delete would result inMockSyncEngineStateholding both the pending save and the pending delete (since there's no deduping on ID). With both present, only the delete is handled, and the result would be an unexpectedly empty CloudKit and still-failing assertions, even though the realCKSyncEnginewould discard the delete and send only the save.