Skip to content

feat: Checkpoint Requests - #153

Merged
stevensJourney merged 59 commits into
mainfrom
request_checkpoint
Aug 3, 2026
Merged

stevensJourney merged 59 commits into
mainfrom
request_checkpoint

Conversation

@stevensJourney

@stevensJourney stevensJourney commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Overview

This is the Swift SDK implementation of the Request Checkpoint proposal: https://github.com/orgs/powersync-ja/discussions/324

Related to:

This adds a new requestCheckpoint method which returns a CheckpointRequest. The CheckpointRequest instance exposes a waitForSync method which resolves once the requested checkpoint has been synced and applied locally.

func refreshFromRemote(timeout: TimeInterval = 30) async throws {
    let checkpoint = try await powerSync.requestCheckpoint()
    try await checkpoint.waitForSync(timeout: timeout)
}

The SDK is updated to cater for the Rust core and PowerSync service changes. ConnectOptions now has a checkpointMode, and checkpoint requests are enabled by connecting with checkpointMode: .requests(). The retry delay for unapplied requests is configurable via .requests(checkpointRequestRetryDelay:). In request mode the sync client posts checkpoint requests to the service, tracks the latest applied checkpoint request ID from core sync status, retries unapplied requests with a delay, and cancels pending waits when the sync client disconnects or closes.

For backends that process uploads asynchronously, this also adds CustomCheckpointRequestConnector. A connector can implement this to handle checkpoint requests itself and return the effective checkpoint request ID accepted by the backend.

Errors thrown while creating a request (CheckpointRequestError) and while waiting for one (CheckpointWaitError) both conform to a shared CheckpointError protocol, so a caller driving both steps in a single do block can catch them together as catch let error as any CheckpointError while still switching on the concrete type when needed.

These APIs are documented as alpha and may change in future releases.

Demo

The PowerSyncExample has been updated to include a pull-to-refresh action which shows a loading spinner until a checkpoint request has been resolved.

In order to showcase the functionality a bit better, a new Admin page has been added to the demo which conveys the SyncStatus. In the demo below, we go offline, create 50k todos which will be synced, then connect and await a checkpoint request. We can see the download progress reach 100%, but the data is only available after the checkpoint has been applied locally. The checkpoint request correctly keeps the operation in a loading state until the data is actually available.

request-checkpoint.mp4

There is also a small SwiftPM command-line demo under Demos/CustomCheckpointDemo which shows a custom checkpoint request connector against the Node.js todo backend.

Testing

I added coverage for creating and waiting on checkpoint requests, timeout/error behavior, unsupported service responses, reconnects, seeded/reseeded checkpoint request state, retry timing, disconnect cancellation, custom checkpoint request connectors, upload integration, and the mock HTTP client hook used by these tests.


AI disclosure: This work was assisted by Codex and Claude Code. I manually guided and reviewed the changes.

@stevensJourney stevensJourney changed the title wip feat: Request checkpoint wip feat: Checkpoint Requests Jul 6, 2026
@stevensJourney
stevensJourney requested a review from simolus3 July 29, 2026 14:30

@simolus3 simolus3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good to me. I didn't check the tests in detail, the suite being serialized is a minor red flag but I don't think that should necessarily delay landing this.

Comment thread Tests/PowerSyncTests/SyncTests.swift Resolved

@simolus3 simolus3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@stevensJourney
stevensJourney merged commit 3949ad5 into main Aug 3, 2026
8 of 10 checks passed
@stevensJourney
stevensJourney deleted the request_checkpoint branch August 3, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants