Skip to content

Conversation

@nrainhart
Copy link
Contributor

@nrainhart nrainhart commented Dec 30, 2025

Description

Currently, if CoValue sync is interrupted and the app is restarted, the sync process won't resume until the unsynced CoValue is loaded again.

This PR implements sync state tracking for CoValues in persistent storage, so that the sync process can be automatically resumed when the app restarts. Sync resumption is performed in batches, to avoid slowing down the performance of the app on startup.

Manual testing

Ran some performance testing in the browser to analyze the additional cost of tracking CoValue sync state. After applying some performance optimizations (persist pending sync updates in batches, minimize the number of times the sync state tracking callbacks are executed), managed to reduce it to what I consider a reasonable cost:

Screenshot_2025-12-30_at_2 56 34_PM

This measures the time it takes to create 10k tasks in the stress test app (which means creating 30k CoValues, including the tasks themselves, their group owners & their text content).

Tests

  • Tests have been added and/or updated

Checklist

  • I've updated the part of the docs that are affected the PR changes => don't think it's necessary. If you do, let me know
  • I've generated a changeset, if a version bump is required
  • I've updated the jsDoc comments to the public APIs I've modified, or added them when missing

Note

Introduces persisted tracking of unsynced CoValues and automatic sync resumption after restart, focused on persistent server peers and batched writes for performance.

  • New UnsyncedCoValuesTracker with batched storage persistence, per-CoValue/global subscriptions, and flush on gracefulShutdown
  • Extend StorageAPI with trackCoValuesSyncState, getUnsyncedCoValueIDs, stopTrackingSyncState
  • IndexedDB: new unsyncedCoValues store, schema v5, CRUD in idbClient; SQLite: new unsynced_covalues table + migrations and client methods
  • SyncManager integration: trackSyncState, resumeUnsyncedCoValues() (batched), only track persistent server peers, resume during startPeerReconciliation
  • SyncStateManager.subscribeToPeerUpdates now keyed by (peerId, coValueId); related call sites updated
  • LocalNode/contexts accept syncWhen and propagate; logout/shutdown now awaits tracker flush
  • Tests added for tracking, persistence, resumption; IDB transaction supports custom store sets; minor test/config updates

Written by Cursor Bugbot for commit 633321e. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Dec 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
clerk-demo Ready Ready Preview, Comment Jan 7, 2026 5:59pm
design-system Ready Ready Preview, Comment Jan 7, 2026 5:59pm
file-upload-demo Ready Ready Preview, Comment Jan 7, 2026 5:59pm
form-demo Ready Ready Preview, Comment Jan 7, 2026 5:59pm
gcmp-homepage Ready Ready Preview, Comment Jan 7, 2026 5:59pm
image-upload-demo Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-chat Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-chat-1 Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-chat-2 Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-filestream Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-image-upload Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-inspector Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-multi-cursors Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-nextjs Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-organization Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-paper-scissors Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-richtext Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-todo Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-vector-search Ready Ready Preview, Comment Jan 7, 2026 5:59pm
jazz-version-history Ready Ready Preview, Comment Jan 7, 2026 5:59pm
music-demo Ready Ready Preview, Comment Jan 7, 2026 5:59pm
passkey-demo Ready Ready Preview, Comment Jan 7, 2026 5:59pm
passphrase-auth-demo Ready Ready Preview, Comment Jan 7, 2026 5:59pm
quint-ui Ready Ready Preview, Comment Jan 7, 2026 5:59pm
1 Skipped Deployment
Project Deployment Review Updated (UTC)
jazz-homepage Ignored Ignored Preview Jan 7, 2026 5:59pm

Comment on lines 181 to +184
peers?: Peer[];
syncWhen?: SyncWhen;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer both params to be part of a single SyncConfig object, but didn't want to introduce a breaking change in the local node API

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Copy link
Collaborator

@gdorsi gdorsi left a comment

Choose a reason for hiding this comment

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

Let's go!!!

}),
);
},
["unsyncedCoValues"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like this API!

Co-authored-by: Guido D'Orsi <[email protected]>
@gdorsi gdorsi merged commit 1e44cab into main Jan 8, 2026
40 checks passed
@gdorsi gdorsi deleted the feat/resume-sync-on-restart branch January 8, 2026 14:17
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.

3 participants