wip: write checkpoints and checkpoint requests#198
Draft
stevensJourney wants to merge 4 commits into
Draft
Conversation
This was referenced Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This implements core changes relevant to the Checkpoint requests proposals:
The linked proposals refactor Write checkpoint requests to a new Checkpoint Requests methodology. This shifts the focus, allowing clients to track and generate checkpoint request ids (previously generated by the PowerSync service).
For some context on the current system: read the temporary doc in
docs/historic-write-checkpoints.md. For a more detailed overview of the proposed new system, read thedocs/write-checkpoint-requests.mddoc.Migrations
We currently track write checkpoint targets and applications in a
$localbucket in theps_bucketstable. There have been mentions of moving this state to dedicated values. This PR moves those values to the key-valueps_kvtable. The mapping currently maps to individual key-values. It could also be possible to migrate to some single - perhaps JSON - value: it seems like having these values as separate keys would make querying simpler.For more details, see the "Migration from
$local" section indocs/write-checkpoint-requests.md.Migrations have been added to forwardly extract values from the
$localbucket and reverse the process for SDK downgrades.Additions
SQLite functions
On a high level, SDK clients need the ability to request checkpoints (for checkpoint request APIs) and write checkpoints (which serve as a barrier for applying incoming sync state after writes have been processed).
These two requirements relate to getting a checkpoint request ID from the core and potentially associating a checkpoint request ID with a target op (in the case of write checkpoints).
Note: The split here is very intentional. We only want to block applying incoming OPs for write checkpoints - not for Checkpoints requests made through
requestCheckpoint.For getting a client-side auto incremented checkpoint request ID, a new
powersync_next_checkpoint_request_idSQLite function has been added. This will increment and return the next checkpoint request ID. Clients should call this from awriteTransaction.In the case of write checkpoints, clients should get a request ID and then set it as the target when appropriate. A new SQLite function
powersync_probe_local_target_opis added which can be used to both get the current target or update the current target.Sync Status
A general flow for a SDK
requestCheckpointcall would be to:sync/request-checkpointendpoint.In order to achieve the
waitstep above. We need some form of stream to indicate when the last applied checkpoint has been updated. The work here takes advantage of the currently existingSyncStatusstream to convey this information. The core sync implementation now emits alast_applied_checkpoint_request_idfield. SDKs can use existing sync status watchers to wait for the corresponding update.Open Items
There are a few open items at the moment. I'll generally make comments at the relevant code to ease with discussions.
I'll link PRs for the PowerSync Service and initial Swift SDK implementation soon. These will also add more context.
AI Disclosure: I initially implemented the work by hand without AI. Codex 5.5 then assisted with creating tests and writing docs. All AI changes have been manually guided and verified.