feat(sync): add a race-safe outbound controller#137
Open
marcus-pousette wants to merge 1 commit into
Open
Conversation
This was referenced May 5, 2026
d7c5bb6 to
edcaec2
Compare
7821011 to
b1b50a2
Compare
This was referenced Jul 12, 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.
What this does
Adds
createOutboundSync, an application-facing controller for publishing exact committed local operations through oneSyncPeerand one or more outbound transports.Applications report a local edit once with
queueOps(...). The controller wakes low-level live subscriptions, deduplicates pending TreeCRDT operations by operation ID, and keeps exact outbound upload queued until a target is available and online.Transport discovery, websocket UI, inbound subscription filters, and playground adoption are intentionally outside this PR.
Correctness guarantees
SyncPeer.pushOpsoperation; it cannot continue signing or sending later chunks after the controller retries.flush()is a shared drain barrier: concurrent callers receive the same promise and wait for work queued during the active run.attachTarget(id, sameTransport)calls share one peer attachment and use reference-counted, idempotent cleanup. Stale cleanup cannot detach a replacement transport.onStatus,onError, and rejected local-update notifications cannot corrupt queue state or create unhandled rejections.close()aborts active work, clears queued operations, and detaches targets without restoring the cleared snapshot later.Fast paths and limits
meta.id; custom op shapes may provideopKey.send()has already begun. It prevents later frames and session continuation; a late valid frame remains safe because operation IDs are idempotent.Debloated from the original PR
Validation
@treecrdt/syncTypeScript build and tests: 19/19