fix(ios): stop silent connection loss after TestFlight update#1260
Merged
Conversation
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.
Summary
After updating from TestFlight build 12 to 13, some users saw every connection, group, and tag disappear on iPhone while Mac kept everything. CloudKit was untouched. Root cause was a chain of silent failures in the mobile persistence + sync code; this PR closes every link in that chain plus adds a user-facing recovery action.
Bug chain
ConnectionPersistence.load()swallowed every read/decode error withtry?and returned[]. "File not yet created" and "file unreadable" were indistinguishable..completeFileProtection(NSFileProtectionComplete), which makes them unreadable while the device is locked.BGAppRefreshTaskcan fire in that state.local = []and the CloudKit pull returned no new changes since the last token, the sync coordinator merged into[]and unconditionally calledonConnectionsChanged([]), which overwroteconnections.jsonwith an empty array. The cloud copy stayed intact, but mobile could never recover because pull is incremental.Fixes (defense in depth)
ConnectionPersistence,GroupPersistence,TagPersistence—load() throws. File-not-found returns the empty/preset baseline; any other failure is propagated and logged via OSLog..completeFileProtectionUntilFirstUserAuthentication, the level Apple recommends for app data that needs to survive background access (used by Mail, Notes).AppState.persistenceIntegritytracks load state (.ok/.loadFailed).retryLoadIfFailed()re-attempts the load on each.activescene transition and before background sync runs. Sync is skipped while integrity is uncertain.IOSSyncCoordinatoronly firesonConnectionsChanged/onGroupsChanged/onTagsChangedwhen the pull returned actual changes or deletions. No-op pulls no longer overwrite the on-disk file.resetSyncToken()clears the local server change token and cachedCKRecords, then runs a full pull. Surfaced in Settings > Sync as Refresh from iCloud with a native confirmation dialog. Settings > Sync also gained a Last Sync row and a Sync Now button.Test plan
connections.json(verify via Console log: "Background sync skipped: persistence load failed" instead of a successful empty merge).connections.json(write garbage bytes) — load logs the error, integrity stays.loadFailed, sync is skipped, Refresh from iCloud recovers the data.