Skip to content

fix(sync): apply changes and deletions to library records a build cannot read by id and standing - #4345

Merged
datlechin merged 5 commits into
mainfrom
fix/sync-unreadable-records
Nov 19, 2026
Merged

datlechin merged 5 commits into
mainfrom
fix/sync-unreadable-records

Conversation

@datlechin

@datlechin datlechin commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

A record the connection library stores but this build cannot decode now meets iCloud sync by its id and its standing, never by its payload. CloudKit hands a deletion over as a record ID and type only, and a save starts from the last known server record (CKSyncEngine sample, CKRecordSaveChangedKeys); the repo already defers what a device cannot apply yet (deferredDeletions, adoptReadableRecordTypes).

  • A record that does not decode is never re-encoded or written over: fix(storage): read the iOS connection library per record and back up both apps' library as last saved #4339 let a saved record with its id replace it, now such a save is refused. Imports on both apps treat its id as taken.
  • A pulled change to it is held (record name in the sync metadata), kept out of the record cache, and not appended as a second record. A build that reads the copy fetches that record by id and takes the change; resetting the change token would drop deletions a delta still carries. Before, macOS and iOS appended the server copy, which then replaced the record, a Local only one included.
  • A deletion from iCloud removes it by id when its standing says it syncs, leaves a Local only one, and waits for a build that reads it when no standing was recorded. Before, macOS left it and iOS kept it forever. On macOS the device-only Keychain items its id owns go with it, found by the id they end with (KeychainStoring.deviceOnlyKeys(endingWith:)), since naming a plugin field needs the type the record no longer gives.
  • Standing is recorded by id whenever the store reads a record (SyncMetadataStorage.recordConnectionStanding): a Local only connection on macOS keeps its iCloud record and cached server copy, so neither tells Local only apart.
  • macOS no longer drops the upload mark of a connection or credential profile it cannot read; it waits for a build that can push it.
  • Saved queries of an owner it cannot read upload only when the owner's standing says it syncs (macOS boundary, iOS uploads and pull merge). A macOS full fetch counts unread connections that sync when it proves deletions.
  • Credential profiles (macOS), groups and tags (iOS) follow the same rules; a profile's deletion waits for a build that reads it, since unlinking its connections needs it.
  • CloudKitSyncEngine.fetch(recordIDs:) sends at most 200 ids per operation and splits a batch CloudKit refuses as too large, as its own refetch does, so a large recovery backlog still goes through.
  • The decision is in .claude/rules/data-sync-storage.md, with rows for the new metadata keys.

Test plan

  • SyncUnreadableCopiesTests (macOS): remote delete of an unread synced connection removes it; a Local only one stays byte-identical; no standing holds the deletion; a remote change is held and not cached; a newer build reading the copy fetches the record by id and takes the change; held deletions apply once readable, yield to a record the zone still lists, and wait while the category is off; the upload mark is held; an import leaves the id alone.
  • AppStateSyncWiringTests (iOS): the same deletion, kept-off, held change and newer-build (fetch by id) cases through the app's sync wiring, plus an unread group.
  • SyncMetadataStorageTests, LibraryFileRecordsTests (swift test): standing, held changes and deletions, a save refused over a kept record.

Refs #4273

@datlechin
datlechin merged commit 7c310ae into main Nov 19, 2026
11 checks passed
@datlechin
datlechin deleted the fix/sync-unreadable-records branch November 19, 2026 15:54
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.

1 participant