Add outbound sync API#137
Open
marcus-pousette wants to merge 24 commits into
Open
Conversation
This was referenced May 5, 2026
d7c5bb6 to
edcaec2
Compare
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.
Summary
Adds a small outbound sync helper for app code that needs to publish committed local ops through one
SyncPeerthat owns one or more outbound transports.Scope of this PR: replace app-owned outbound local-op upload queues. It does not replace transport discovery, websocket status UI, auth setup, manual reconciliation, or inbound/live subscription filtering. Those pieces still live in the app or are handled by #138.
queueOpsowns the committed-local-op path: it wakes live subscriptions on thelocalPeer, queues exact remote upload for outbound targets, dedupes pending TreeCRDT ops bymeta.id, and handles offline/no-peer retry.attachTargetis the app-facing remote setup helper: it attaches the remote transport to the peer and registers it for outbound upload in one call. Custom op shapes may provideopKeyto override the dedupe key. The helper does not expose peer filtering callbacks or fallback reconciliation hooks.EM Integration Before
Source reference: the current
Antonov548/emfork reports committed local TreeCRDT ops frompushQueue.ts, then handles pending local-op upload intreecrdtWebSocketSync.tsandpushTreecrdtLocalOpsToRemote.Shortened, the current shape is: Redux/database code reports local TreeCRDT ops once.
The awkward part is inside the sync module. It has to keep its own pending queue because local writes can happen before the websocket handle is ready, and upload failures need to preserve ops for retry:
That makes the app sync module responsible for pending op storage, retry ordering, empty-batch policy, and the distinction between committed local ops and full reconciliation.
EM Integration After
With #137, an em-style sync module can create the outbound helper as soon as it has the local
SyncPeer, before the websocket transport is connected. Local writes can then be reported immediately; if no outbound target is registered yet, the helper keeps the ops queued untilattachTargetruns.The Redux/database call site stays simple. The sync module no longer needs a separate
pendingLocalOpsqueue, a manualflushPendingLocalOpsretry path, or app-provided op keys/op-ref derivation for standard TreeCRDT operations.