Skip to content

Apply rows for implicit partial sync with prio 0 - #228

Open
simolus3 wants to merge 3 commits into
mainfrom
prio-zero-workaround
Open

simolus3 wants to merge 3 commits into
mainfrom
prio-zero-workaround

Conversation

@simolus3

@simolus3 simolus3 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Changes from buckets with priority zero are supposed to be applied even if there's local data (in ps_crud, or a target_checkpoint_request_id that has not yet been reached). Usually, this works with the PowerSync service sending priority 0 data followed by a partial_checkpoint_complete.

When all buckets in a checkpoint have priority zero, there's no partial_checkpoint_complete message. The service sends all bucket data followed by checkpoint_complete. We should still be able to run an implicit partial checkpoint at this point.

Note

We can't simply ignore the can_apply_sync_changes check for full checkpoints consisting exclusively of priority zero buckets. The reason is that a full sync also considers ps_updated_rows, so a concurrent checkpoint before these have been uploaded would lead to flicker even for insert-only tables. Running a partial checkpoint before a full checkpoint (which would then fail due to local data) is necessary.

To fix this, we check if all buckets are of priority zero when a full checkpoint failed due to local data. If that's the case, we retry as a partial checkpoint. The sync client needs to react to this "downgrade", because we shouldn't set the global lastSyncedAt field here.

AI use: Reviewed with Claude Code, which found some issues where a full checkpoint downgraded to a partial checkpoint would not be retried after a crud upload notification. Fixed that with Claude as well.

@simolus3
simolus3 marked this pull request as ready for review October 12, 2026 10:00
@simolus3
simolus3 requested a review from rkistner October 12, 2026 10:18

@rkistner rkistner 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.

There's another case here: If we receive a checkpoint_complete with both priority 0 and priority 1 buckets, and the apply is blocked by local changes - can we still apply the priority 0 changes?

@simolus3

simolus3 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

There's another case here: If we receive a checkpoint_complete with both priority 0 and priority 1 buckets, and the apply is blocked by local changes - can we still apply the priority 0 changes?

Wouldn't we receive a partial_checkpoint_complete for the priority 0 subset first then? That should apply regardless, and I think we should get that message even if there's no new data on the priority 0 buckets.

@rkistner

Copy link
Copy Markdown
Contributor

Ok, confirmed that the service always sends a partial_checkpoint_complete between buckets of different priorities. We should probably formalize the spec for that, to ensure we don't change that in the future without considering this use case

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.

2 participants