Safari App Extension fails to connect to CloudKit daemon (cloudd) with XPC communication errors -- CKErrorDomain Code=6 / NSCocoaErrorDomain Code=4099 – Unable to connect to CloudKit daemon

I'm working on a macOS app with a Safari web extension. I'm trying to share a SwiftData model between devices using CloudKit synchronization. I am able to get synchronization in the main app on the same device, CloudKit sync works correctly — changes appear in the CloudKit Dashboard under com.apple.coredata.cloudkit.zone. However, in the Safari App Extension, data is saved locally and persists across launches, but never syncs to CloudKit.

I have followed the recommended practices for configuring the App Group and entitlements, but the issue persists.

Questions:

Is there an official limitation preventing Safari App Extensions from connecting to the CloudKit daemon (cloudd)?

If not, what entitlements or configuration changes are required for a Safari App Extension to successfully sync with CloudKit?

Is the xpc_error=159 from bootstrap_look_up() a known sandbox restriction for this extension type?

Any guidance from Apple engineers or others who have successfully used CloudKit from a Safari App Extension would be appreciated.

What I’ve confirmed:

The extension’s .entitlements includes: <key>com.apple.security.app-sandbox</key><true/> <key>com.apple.developer.icloud-services</key> <array><string>CloudKit</string></array> <key>com.apple.developer.icloud-container-identifiers</key> <array><string>iCloud.dev.example.myapp</string></array>

Same iCloud container ID for both app and extension CloudKit container exists and is initialized in CloudKit Console Running in :Sandbox environment during development Database name in SwiftData matches container identifier (without the iCloud. prefix)

The extension’s codesign output shows correct entitlements App Group is configured (although in this case, extension and app use separate stores intentionally)

Observed behavior in Console.app logs:

CloudKit sync engine initializes in the extension XPC activities are registered for import/export: _xpc_activity_register: com.apple.coredata.cloudkit.activity.export.<UUID> xpc_activity_set_criteria: ... import.<UUID>

Then a bootstrap lookup fails: failed to do a bootstrap look-up: xpc_error=[159: Unknown error: 159] CloudKit daemon connection error: CKErrorDomain Code=6 "Error connecting to CloudKit daemon" NSCocoaErrorDomain Code=4099

There is no “Will attempt to upload transactions” or “Upload succeeded” logs are ever seen.

Symptoms

When the extension is run, I see logs like the following in Console.app:

[0x13e215820] failed to do a bootstrap look-up: xpc_error=[159: Unknown error: 159]

CoreData+CloudKit: -[PFCloudKitSetupAssistant _checkAccountStatus:]_block_invoke(342): Fetched account info for store <private>: (null)

Error Domain=CKErrorDomain Code=6 "Error connecting to CloudKit daemon. This could happen for many reasons..."

This topic is discussed in the following technote section:

The technote is about NSPersistentCloudKitContainer. As of today, SwiftData (DefaultStore) + CloudKit uses NSPersistentCloudKitContainer under the hood, and so the content applies.

Basically, the use case of sharing a CloudKit-back store between a main app and its extension and synchronizing with NSPersistentCloudKitContainer isn't quite supported, and so you might consider avoiding do that.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Hi Ziqiao,

That would be fine, I am actually not interested in sharing a container between the main app and extension. The only reason I even started interacting with the data in the main app was because I couldn't understand why the extension wasn't synchronizing.

With the main app I verified that everything about cloudkit was set up correctly. And then when I put them in the same group, they started sharing a container, and I am sure the extension is reading/writing correctly to the container.

However, if I disable all interaction with the container in the main app, the records from the extension are never synchronized with cloudkit.

Is there some reason for the safari extension to be blocked from synchronizing?

Safari App Extension fails to connect to CloudKit daemon (cloudd) with XPC communication errors -- CKErrorDomain Code=6 / NSCocoaErrorDomain Code=4099 – Unable to connect to CloudKit daemon
 
 
Q