Skip to content

feat(sync): add a reliable inbound sync controller - #138

Open
marcus-pousette wants to merge 1 commit into
cybersemics:fix/sync-once-cancellationfrom
marcus-pousette:sync/scoped-live-controller
Open

marcus-pousette wants to merge 1 commit into
cybersemics:fix/sync-once-cancellationfrom
marcus-pousette:sync/scoped-live-controller

Conversation

@marcus-pousette

@marcus-pousette marcus-pousette commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

What this does

Adds createInboundSync, a framework-agnostic controller for reconciling and subscribing the same filters across application-owned peer connections.

const inbound = createInboundSync({ localPeer: peer });

// The application owns attach/detach.
const detach = peer.attach(transport);
const unregister = inbound.addAttachedPeer(peerId, transport);

addAttachedPeer intentionally registers an already-attached transport. The controller does not attach or detach it, which lets inbound and outbound behavior safely share one connection without ambiguous ownership.

Contract

  • The cleanup returned by addAttachedPeer releases only that exact registration; stale cleanup cannot remove a replacement with the same peer id.
  • Re-registering the same peer id and transport creates reference-counted leases without restarting subscriptions.
  • Replacing/removing a registration aborts reconciliation that still uses it.
  • syncOnce is bidirectional reconciliation despite the inbound-oriented controller name.
  • A run resolves only when every selected peer/filter succeeds; failures are reported together as InboundSyncAggregateError with exact peer, filter, and cause.
  • Equivalent filters and peer ids are deduplicated.
  • subscribe(filters) is declarative and latest-call-wins, including reentrant observer calls.
  • Status changes are published atomically; observer exceptions do not corrupt controller state.
  • close() is terminal, idempotent, and drains active reconciliation plus subscription ready/done work before resolving.

Stack

Based on #204, which provides the underlying abortable protocol session. Playground adoption remains isolated in #205.

Size

Area Diff
Controller implementation +694
Tests +796
Docs and changeset +44
Total +1534

Validation

  • Focused inbound controller: 29/29
  • Combined @treecrdt/sync stack: 55/55
  • TypeScript builds and git diff --check pass

@marcus-pousette
marcus-pousette force-pushed the sync/scoped-live-controller branch from 664668c to 7e98f4b Compare May 5, 2026 08:48
@marcus-pousette marcus-pousette changed the title Add scoped live sync controller Add inbound sync API May 5, 2026
@marcus-pousette
marcus-pousette force-pushed the sync/scoped-live-controller branch from 7e98f4b to 7249913 Compare May 5, 2026 09:00
@marcus-pousette
marcus-pousette force-pushed the sync/app-facing-controller branch from d7c5bb6 to edcaec2 Compare May 5, 2026 12:07
@marcus-pousette
marcus-pousette force-pushed the sync/scoped-live-controller branch 2 times, most recently from 7709dfc to 2f4ba43 Compare May 5, 2026 12:18
@marcus-pousette
marcus-pousette force-pushed the sync/scoped-live-controller branch from 2f4ba43 to 3470733 Compare June 1, 2026 20:33
@marcus-pousette marcus-pousette added enhancement New feature or request area:sync Sync protocol, reconciliation, transport, discovery, and sync servers area:api Public interfaces, bindings, events, and cross-backend contracts labels Jul 12, 2026
@marcus-pousette
marcus-pousette force-pushed the sync/scoped-live-controller branch from 854fd22 to 1c4c0ff Compare July 12, 2026 13:52
@marcus-pousette marcus-pousette changed the title Add inbound sync API feat(sync): add a reliable inbound sync controller Jul 12, 2026
@marcus-pousette
marcus-pousette changed the base branch from sync/app-facing-controller to fix/sync-once-cancellation July 12, 2026 13:52
@marcus-pousette
marcus-pousette force-pushed the fix/sync-once-cancellation branch from a6ed58e to 91ca885 Compare July 12, 2026 14:09
@marcus-pousette
marcus-pousette force-pushed the sync/scoped-live-controller branch from 1c4c0ff to a7f1677 Compare July 12, 2026 14:09
@marcus-pousette
marcus-pousette marked this pull request as ready for review July 12, 2026 14:22
@marcus-pousette
marcus-pousette force-pushed the fix/sync-once-cancellation branch from 91ca885 to e3d69f3 Compare July 12, 2026 15:23
@marcus-pousette
marcus-pousette force-pushed the sync/scoped-live-controller branch from a7f1677 to b187784 Compare July 12, 2026 15:23
@marcus-pousette
marcus-pousette force-pushed the fix/sync-once-cancellation branch from e3d69f3 to 7f537fe Compare July 13, 2026 16:05
@marcus-pousette
marcus-pousette force-pushed the sync/scoped-live-controller branch from b187784 to 039505c Compare July 13, 2026 16:05
@marcus-pousette
marcus-pousette force-pushed the fix/sync-once-cancellation branch from 7f537fe to 88d5372 Compare July 24, 2026 15:13
@marcus-pousette
marcus-pousette force-pushed the sync/scoped-live-controller branch from 039505c to 4c769ae Compare July 24, 2026 15:13
@marcus-pousette
marcus-pousette force-pushed the sync/scoped-live-controller branch from 4c769ae to 197d83b Compare August 19, 2026 08:53
Co-Authored-By: Codex GPT-5 (unknown context) <noreply@openai.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:api Public interfaces, bindings, events, and cross-backend contracts area:sync Sync protocol, reconciliation, transport, discovery, and sync servers enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant