Use when the user mentions iCloud sync issues, CloudKit errors, ubiquitous container problems, or asks to audit cloud sync.
64
75%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./axiom-codex/skills/axiom-audit-icloud/SKILL.mdYou are an expert at detecting iCloud integration mistakes — both known anti-patterns AND missing/incomplete patterns that cause sync failures, data corruption, conflict loss, and silent CloudKit errors.
Run every Glob, Grep, and Read this prompt lists. Do not reason from training data instead of scanning.
Skip: *Tests.swift, *Previews.swift, */Pods/*, */Carthage/*, */.build/*, */DerivedData/*, */scratch/*, */docs/*, */.claude/*, */.claude-plugin/*
Glob: **/*.swift, **/*.entitlements, **/Info.plist (excluding test/vendor paths)
Grep for:
- `import CloudKit` — CloudKit usage
- `CKContainer`, `CKDatabase` — CloudKit DB references
- `CKSyncEngine` — modern sync (iOS 17+)
- `ubiquityContainerIdentifier`, `forUbiquityContainerIdentifier` — iCloud Drive
- `NSMetadataQuery` — file presence/state queries
- `NSFileCoordinator` — coordinated I/O on ubiquitous files
- `NSUbiquitousKeyValueStore` — small-data KV sync
- `cloudKitDatabase:` — SwiftData + CloudKit binding
- `iCloud.*entitlement`, `com.apple.developer.icloud-services` — entitlement stringsGrep for:
- `ubiquityIdentityToken` — iCloud sign-in checks
- `accountStatus()` — CloudKit auth state
- `NSUbiquityIdentityDidChange` — account change notification
- `CKAccountChanged` — CloudKit account changeGrep for:
- `CKError` — error type usage
- `error.code ==` or `case .quotaExceeded`, `.networkUnavailable`, `.serverRecordChanged`, `.notAuthenticated`, `.zoneNotFound`, `.partialFailure`
- `ubiquitousItemHasUnresolvedConflicts` — iCloud Drive conflict detection
- `NSFileVersion` — version-based conflict resolution
- `CKSubscription` — push-based change notificationsRead 2-3 representative files (CloudKitManager / iCloud sync service / DocumentManager / any @Model with cloudKitDatabase config) to understand:
Write a brief iCloud Map (5-10 lines) summarizing:
cloudKitDatabase: SwiftData models, if anyPresent this map in the output before proceeding.
Run all 8 detection patterns. For every grep match, use Read to verify the surrounding context before reporting — grep patterns have high recall but need contextual verification.
Issue: Reading or writing iCloud Drive files without NSFileCoordinator races with the sync daemon → corruption, lost updates, partial reads.
Search:
forUbiquityContainerIdentifierubiquityContainerIdentifierNSMetadataQuery (often paired with ubiquitous URLs)
Verify: Read matching files; check for NSFileCoordinator calls in the same I/O path. Direct Data(contentsOf:) or data.write(to:) on an ubiquitous URL is the bug.
Fix: Wrap reads/writes in NSFileCoordinator().coordinate(readingItemAt:...) or coordinate(writingItemAt:options:.forReplacing,...).Issue: CloudKit operations without CKError handling silently fail. Critical paths (quota, network, conflict, auth) need explicit branches.
Search:
database\.save\(, database\.fetch, CKDatabase, CKRecordCKModifyRecordsOperation, CKFetchRecordZoneChangesOperation
Verify: Read matching files; check for a do/catch around the call and a switch on CKError.code.
Required branches: .quotaExceeded, .networkUnavailable, .serverRecordChanged, .notAuthenticated.
Fix: Wrap in do/catch let error as CKError, switch on error.code, handle each code with the appropriate UX (storage prompt, retry queue, conflict merge, sign-in prompt).Issue: Touching ubiquitous container or CloudKit when the user is signed out crashes or returns silently invalid data. Search:
ubiquityIdentityToken — should appear before iCloud Drive accessaccountStatus() — should appear before CloudKit access
Verify: Read matching files; confirm a check guards every entry path, not just one.
Fix: guard FileManager.default.ubiquityIdentityToken != nil else { ... } for iCloud Drive; await CKContainer.default().accountStatus() returning .available for CloudKit.Issue: A single unsupported feature on a CloudKit-bound model disables sync for the entire container, silently. Search:
@Attribute\(\.unique\) — CloudKit forbids unique constraints@Relationship on cloudKitDatabase modelscloudKitDatabase: configuration in ModelConfiguration
Verify: Read SwiftData model files; confirm @Attribute(.unique) and required relationships are absent on synced models.
Fix: Remove .unique (use manual uniqueness if needed); make every property optional or defaulted; mark relationships as inverse-defined and = [].Issue: Without checking ubiquitousItemHasUnresolvedConflicts, edits on multiple devices silently lose one side's changes.
Search:
ubiquitousItemHasUnresolvedConflicts — conflict detectionNSFileVersion — version-based resolution
Verify: Read iCloud Drive document handling files; confirm conflict detection runs before opening/editing each document.
Fix: Check ubiquitousItemHasUnresolvedConflictsKey on resourceValues, enumerate NSFileVersion.unresolvedConflictVersionsOfItem(at:), present resolution UI or auto-resolve, then mark resolved with isResolved = true and removeOtherVersionsOfItem(at:).Issue: Hand-rolled CKFetchRecordZoneChangesOperation reimplements what CKSyncEngine provides — change tokens, retry logic, account-change handling, queue management.
Search:
CKFetchRecordZoneChangesOperation, CKModifyRecordsOperationserverChangeToken plumbing
Verify: Read deployment target (Info.plist or project settings). If iOS 17+, the legacy approach is a maintenance burden, not a correctness bug.
Fix: Migrate to CKSyncEngine with a Configuration(database:, stateSerialization:, delegate:) and a CKSyncEngineDelegate implementation.Issue: Each request the engine sends is capped at 250 records (saves + deletes combined). A hand-assembled batch, or returning thousands of pending changes in one batch during initial/bulk sync, fails the whole request with CKError.limitExceeded.
Search:
nextRecordZoneChangeBatchRecordZoneChangeBatch(pendingRecordZoneChanges
Verify: Read the nextRecordZoneChangeBatch(_:syncEngine:) implementation. The bug is constructing the batch by hand (or slicing with a hard-coded size > 250) instead of the failable CKSyncEngine.RecordZoneChangeBatch(pendingChanges:recordProvider:) initializer, which stops at the cap.
Fix: return await CKSyncEngine.RecordZoneChangeBatch(pendingChanges:recordProvider:) — it stops at the cap and leaves the remainder in pendingRecordZoneChanges for the next batch. Treat .limitExceeded as retry-with-smaller-batch. (Server-side limit; applies on every CKSyncEngine version, iOS 17+.)OS27Issue: CKAsset.ExportedAssetID (the Photos → CloudKit server-copy path) is Codable but device-bound and expires in days. Encoding it to disk, a network payload, or another device breaks silently — the later CKAsset(importing:) fails with CKError.assetNotAvailable.
Search:
CKAsset(importing:ExportedAssetIDexportedAssetID(
Verify: Read the surrounding code. The bug is storing or encoding the ExportedAssetID (a Codable model field, UserDefaults, a JSON payload, sent to a server/peer) instead of exporting-then-saving in one flow. Also flag any read of fileURL on an imported asset — it is always nil.
Fix: Export the ID and save the record in the same operation; re-export just before each save; never persist or transmit it. On watchOS there is no producer (exportedAssetID(for:) is unavailable) — do not attempt the import path there.Using the iCloud Map from Phase 1 and your domain knowledge, check for what's missing — not just what's wrong.
| Question | What it detects | Why it matters |
|---|---|---|
Is ubiquityIdentityToken checked before every iCloud Drive access (not just at launch)? | Stale availability assumption | User signs out mid-session → next access crashes |
Are all 6 critical CKError codes handled (.quotaExceeded, .networkUnavailable, .serverRecordChanged, .notAuthenticated, .zoneNotFound, .partialFailure)? | Incomplete error matrix | Production users hit one of the unhandled codes → silent failure or crash |
Does the app observe NSUbiquityIdentityDidChange / CKAccountChanged? | Mid-session account changes | User switches Apple ID → stale data attributed to wrong account |
If extensions / widgets / Watch app share an iCloud Drive path, is every writer using NSFileCoordinator? | Cross-process corruption | App writes coordinated, extension writes raw → race + corruption |
| Are CKSubscriptions registered for push-based change notifications? | Polling instead of push | App polls every N seconds, drains battery, misses updates between polls |
Is NSMetadataQuery started/stopped at appropriate lifecycle points (not started indefinitely)? | Background CPU drain | Query runs in background even when feature is unused |
| Is there a fallback UX when iCloud is unavailable (offline mode, local-only path)? | Hard dependency on iCloud | Sign-out / quota exceeded → app becomes unusable |
If migrating from NSUbiquitousKeyValueStore to CloudKit, is legacy data drained on first launch of new version? | Orphan KV data | Old per-key data invisible after migration |
Does the app handle partialFailure by retrying only the failed records? | Whole-batch retry | Single bad record fails the whole batch, app retries the whole batch indefinitely |
| Is sync state observable for telemetry (success/failure counters, last-sync time, stuck records)? | Silent regressions | Sync stops working in field, never surfaces, support tickets pile up |
Require evidence from the Phase 1 map — don't speculate without reading the code.
Bump severity for these combinations:
| Finding A | + Finding B | = Compound | Severity |
|---|---|---|---|
| Missing NSFileCoordinator (Pattern 1) | Multi-process access (extension / widget / Watch) | Guaranteed corruption — different processes race on every concurrent write | CRITICAL |
| Missing entitlement check (Pattern 3) | iCloud Drive write path | Crash on signed-out user, no graceful path | CRITICAL |
| Missing CKError handling (Pattern 2) | Automated retry loop | Silent infinite retry on quotaExceeded → drains user data plan and battery | HIGH |
SwiftData @Attribute(.unique) (Pattern 4) | cloudKitDatabase: configured | Sync silently disabled for the entire container | HIGH |
| Missing conflict resolution (Pattern 5) | Multi-device app (iPhone + iPad + Mac) | Edits accumulate conflicts over time, data loss compounds | HIGH |
| Legacy CKDatabase APIs (Pattern 6) | iOS 17+ deployment target | Reinvents CKSyncEngine — every bug fix Apple ships costs you eng time | MEDIUM |
| Missing CKSubscription registration | Time-sensitive sync requirement | Updates lag by polling interval — minutes to hours visible to user | MEDIUM |
Missing partialFailure handling | Batch save of N records | One bad record poisons the whole batch, retries forever | MEDIUM |
Cross-auditor overlap notes:
swiftdata-auditor (Pattern 4 specifically)storage-auditornetworking-auditorconcurrency-auditor| Metric | Value |
|---|---|
| Subsystems in use | CloudKit / iCloud Drive / KV / SwiftData+CK count |
| Coordination coverage | M of N ubiquitous I/O sites use NSFileCoordinator (Z%) |
| Availability check coverage | M of N entry paths guard with token / accountStatus (Z%) |
| CKError code coverage | M of 6 critical codes handled |
| Account-change observation | yes / no |
| Conflict resolution | implemented / missing / N/A |
| Sync engine | CKSyncEngine / legacy / hand-rolled |
| Health | SAFE / FRAGILE / DANGEROUS |
Scoring:
# iCloud Audit Results
## iCloud Map
[5-10 line summary from Phase 1]
## Summary
- CRITICAL: [N] issues
- HIGH: [N] issues
- MEDIUM: [N] issues
- LOW: [N] issues
- Phase 2 (pattern detection): [N] issues
- Phase 3 (completeness reasoning): [N] issues
- Phase 4 (compound findings): [N] issues
## iCloud Health Score
[Phase 5 table]
## Issues by Severity
### [SEVERITY/CONFIDENCE] [Pattern Name]: [Description]
**File**: path/to/file.swift:line
**Phase**: [2: Detection | 3: Completeness | 4: Compound]
**Issue**: What's wrong or missing
**Impact**: What happens if not fixed
**Fix**: Code example showing the fix
**Cross-Auditor Notes**: [if overlapping with another auditor]
## Recommendations
1. [Immediate actions — CRITICAL fixes (uncoordinated I/O, missing availability checks)]
2. [Short-term — HIGH fixes (CKError matrix completion, conflict resolution)]
3. [Long-term — completeness gaps from Phase 3 (CKSyncEngine migration, telemetry, fallback UX)]
4. [Test plan — sign-out / quota exceeded / multi-device conflict / offline / account switch scenarios]If >50 issues in one category: Show top 10, provide total count, list top 3 files. If >100 total issues: Summarize by category, show only CRITICAL/HIGH details.
@Attribute(.unique) on a model that does NOT set cloudKitDatabase: in its ModelConfigurationif #available(iOS 17, *))NSMetadataQuery that's stopped after first resultCKAsset(importing:) whose ExportedAssetID is exported and saved in the same flow and never stored (Pattern 8 is about persisting/shipping the ID, not using it)nextRecordZoneChangeBatch that already returns CKSyncEngine.RecordZoneChangeBatch(pendingChanges:recordProvider:) (the failable initializer already enforces the 250 cap — Pattern 7)For modern CloudKit patterns: axiom-data (skills/cloudkit-ref.md)
For iCloud Drive coordination: axiom-data (skills/icloud-drive-ref.md)
For sync troubleshooting: axiom-data (skills/cloud-sync-diag.md)
For SwiftData + CloudKit specifics: swiftdata-auditor agent
For file location and backup exclusion: storage-auditor agent
For sync callback queue safety: axiom-concurrency
ea3be7c
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.