Skip to content

Apply records fetched outside the sync engine - #560

Open
streamxapp wants to merge 1 commit into
pointfreeco:mainfrom
streamx-labs:apply-fetched-record-zone-changes
Open

streamxapp wants to merge 1 commit into
pointfreeco:mainfrom
streamx-labs:apply-fetched-record-zone-changes

Conversation

@streamxapp

Copy link
Copy Markdown

Problem

CKSyncEngine.fetchChanges() does not always go to the server. When no push, scheduled sync or app activation has flagged changes, the engine logs no zone IDs needing to be fetched, not fetching changes / no need to fetch changes for scope all and returns without a request. On an Apple TV left on one screen (never re-activated) with pushes not arriving, records saved on another device sat on the server for many minutes while every manual SyncEngine.fetchChanges() was skipped. A direct CKDatabase.recordZoneChanges(inZoneWith:since:) saw them immediately.

Apps can read a zone's changes themselves, but there is no public way to hand those records to SyncEngine, so they can't be applied without bypassing the sync metadata (writing rows directly queues them as local edits and re-uploads them).

Change

  • SyncEngine.applyFetchedRecordZoneChanges(modifications:deletions:scope:): runs records fetched outside the engine through the existing handleFetchedRecordZoneChanges path, against the private or shared engine. Records the engine later delivers again merge as no-ops.
  • Engines released by stop() are cancelled, and their late stateUpdate and will/did fetch/send events are ignored, so they can't overwrite the running engine's saved state or leave isFetchingChanges stuck. Activity counts reset on stop().
  • Test: applyRecordsFetchedOutsideTheEngine.

Happy to adjust the API shape or split the stop() hardening into its own PR.

🤖 Generated with Claude Code

Adds applyFetchedRecordZoneChanges so an app can read a zone itself when CKSyncEngine skips
the server, and still keep the sync metadata consistent. Engines released by stop() are
cancelled and can no longer overwrite saved state or the activity counts.
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