Implement new protocol for checkpoint requests - #1072
Conversation
🦋 Changeset detectedLatest commit: a9da7c3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@simolus3 I wonder if there's a way to auto-detect the feature, instead of requiring opt-in? Some options:
I haven't worked through the implications of any of those, just wondering if something like that is feasible? |
Chriztiaan
left a comment
There was a problem hiding this comment.
Happy with the changes, Ralf's suggestion could be a blocker if we want to incorporate it.
|
The implementation here mostly follows the Swift implementation, which also doesn't try to auto-detect the feature. Adding that sounds reasonable to me, perhaps as we start maturing the APIs (they're currently marked as
I could see an
Note that We also tell the core extension that we want to use request checkpoints which makes the sync client behave slightly differently, throwing when we try to request a checkpoint without completing the reconciliation first (IIRC). So we'd need a way to tell the core extension about that downgrade as well. Finally, we want explicit sync via cc @stevensJourney for more ideas |
|
Considering the alpha status, I guess it makes sense to keep the old behavior as the default for now. We can revisit changing the default to a kind of "auto" mode at a later stage. |
|
My thoughts align with what Simon mentioned. I think auto detection should be possible in the future. My general thoughts are that I'd like to gradually release this instead of instantly switching everyone over by default. |
This adds an option making the JS SDKs use the new checkpoint request protocol described in https://github.com/orgs/powersync-ja/discussions/317. While that discussion contains all the relevant context, it basically boils down to flaws in the current
/write-checkpoint2.jsonrequest used to request write checkpoints after uploads. Requested write checkpoints are embedded in the sync protocol, allowing clients to recognize when their local writes should have synced back down again, at which point downloaded changes can be applied./write-checkpoint2.jsonhas two flaws fixed by the new protocol:(device_id, user_id)pair. This means the service can't ever delete write checkpoint state.(device_id, user_id)pair which means the next write checkpoint might disrupt the sequence. Nothing in the client is prepared for that, and this can lead to the sync client not applying changes.The new protocol replaces
GET /write-checkpoint2.jsonwithPOST /sync/checkpoint-request. The key change is that the client includes an expected counter in the request, the service uses that value or its own (whichever is higher). This fixes both problems, but requires a few implementation changes:postCheckpointRequestto backend connectors.Note that this does not add checkpoint requests, I will add support for those in a follow-up PR.
AI use disclosure: I used Claude Code to help with simpler tests and to self-review this.