Core Data CloudKit stops syncing after incomprehensible archive error

Ive been getting this error on an app in the dev environment since iOS16. it continues to happen in the latest iOS release (iOS18).

After this error/warning, CoreData_CloudKit stops syncing and the only way to fix it is to delete the app from all devices, reset the CloudKit dev environment, reload the schema and reload all data. im afriad that if I ever go live and get this error in production there won't be a way to fix it given I cant go and reset the production CloudKit environment.

It doesn't happen straight away after launching my app in a predictable manner, it can take several weeks to happen.

Ive posted about this before here and haven't got a response. I also have a feedback assistant issue submitted in 2022 as part of ios16 beta that is still open: FB10392936 for a similar issue that caused the same error.

would like to submit a code level support query but it doest seem to have anything to do with my code - but rather the Apple core data CloudKit syncing mechanism.

anyone have any similar issues or a way forward?

> error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _requestAbortedNotInitialized:](2200): <NSCloudKitMirroringDelegate: 0x301e884b0> - Never successfully initialized and cannot execute request '<NSCloudKitMirroringImportRequest: 0x3006f5a90> D823EEE6-EFAE-4AF7-AFED-4C9BA708703B' due to error: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x53, 0x6f, 0x6d, 0x65, 0x20, 0x73, 0x61, 0x6d)" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x53, 0x6f, 0x6d, 0x65, 0x20, 0x73, 0x61, 0x6d)}

This error message your post provided indicates that Core Data failed to unarchive the import request (NSCloudKitMirroringImportRequest). Archiving / unarchiving an import / export request is a Core Data internal logic, and so I agree your assessment that it is not about your code.

The feedback report you filed (FB10392936) doesn't mention the error message, and so I'd suggest that you file a new one to specifically report the error – If you do so, please share your report ID here for folks to track.

Regarding FB10392936, you most likely hit CloudKit throttles. For more information of this topic, see the following documentations:

When uploading a big data set and hitting CloudKit throttles, the only thing you can do is to lower the CloudKit operation rate. When using Core Data + CloudKit, however, you don't control how NSPersistentCloudKitContainer synchronizes data. Based on today's API, the only thing you can do is to somehow control the upload pace in the following way:

  • Discover the synchronization state by observing eventChangedNotification and looking into event details. For a sample that demonstrates how to handle the notifications, see Sharing Core Data objects between iCloud users.

  • Upload more data (by saving the data to the Core Data store, which triggers an export) after the previous export is successful.

With this, the time to upload the whole dataset may still be long, but you will much less likely run into the system throttles.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

as requested, I've created another feedback issue: FB15652576

on FB10392936, the error message is in the followup comments. here is the error from that issue - also an incomprehensible archive error.

on that issue yes I had to lower the CloudKit operation rate to complete the upload - it took a month or 2 - it would be great if there was some mechanism for bulk uploads that bypass the throttles. But throttles shouldn't also corrupt the CloudKit database. not only would it throttle, but it would corrupt the database - the only way to recover was to reset the database and reload the schema and start from scratch- not possible in production.

> [error] error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _importFinishedWithResult:importer:](1306): <PFCloudKitImporter: 0x2815fca80>: Import failed with error: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x53, 0x6f, 0x6d, 0x65, 0x20, 0x65, 0x78, 0x61)" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x53, 0x6f, 0x6d, 0x65, 0x20, 0x65, 0x78, 0x61)} 2022-09-08 14:04:43.136554+1000 Tupperty[1354:139717] [error] error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate recoverFromError:](2165): <NSCloudKitMirroringDelegate: 0x28397c8c0> - Attempting recovery from error: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x53, 0x6f, 0x6d, 0x65, 0x20, 0x65, 0x78, 0x61)" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x53, 0x6f, 0x6d, 0x65, 0x20, 0x65, 0x78, 0x61)}

Thanks for filing the feedback report for us.

"on that issue yes I had to lower the CloudKit operation rate to complete the upload - it took a month or 2 - it would be great if there was some mechanism for bulk uploads that bypass the throttles."

"a month or 2" is ... too long. I'd suggest that you mention the above in your feedback report for the CloudKit team to consider.

"But throttles shouldn't also corrupt the CloudKit database."

The error message doesn't indicate that the CloudKit database is corrupted though. It can be that CoreData+CloudKit failed to unarchive the persisted request and then the synchronization process stopped. You might follow up with your feedback report to see what the Core Data team has to say.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Core Data CloudKit stops syncing after incomprehensible archive error
 
 
Q