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

feat(sync): add a reliable inbound sync controller#138
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

Add createInboundSync, a small app-facing controller for reconciling and subscribing the same filters across registered peer transports.

  • Register, replace, remove, or clear peers by stable id.
  • Run one-shot reconciliation across selected peers and filters.
  • Keep declarative live subscriptions aligned with the current peer/filter set.
  • Expose busy, peer, desired-filter, and active-subscription status.
  • Report target context to optional status/error observers.

This is the controller-only layer of the former #138. Protocol cancellation lives in #204; playground adoption is a separate follow-up.

Failure contract

syncOnce resolves only when every requested peer/filter target succeeds. It lets all requested targets finish, then throws InboundSyncAggregateError when any failed. Each entry retains the exact peerId, filter, and original error, including unknown requested peers.

A timeout aborts the underlying protocol session rather than merely stopping the caller's wait.

Observer callbacks are notifications: exceptions from onError or onStatus cannot replace the aggregate result or corrupt controller state. Repeating the same declarative filter set restarts subscriptions that previously failed.

Fast paths left

  • With no peers or filters changing, subscribe reuses the existing filter objects and only starts missing peer subscriptions.
  • Duplicate filters and requested peer ids are deduplicated.
  • Existing subscriptions are retained when a transport is unchanged.
  • One-shot sync delegates directly to SyncPeer.syncOnce; the controller adds only target iteration, status, timeout, and aggregation.
  • No transport discovery or background scheduler is introduced.

Verification

  • Combined @treecrdt/sync stack: 31/31 tests.
  • Focused inbound-controller suite: 12/12.
  • Regressions cover partial failure, missing peers, real cancellation, retrying identical failed subscriptions, transport replacement, synchronous startup failure, observer exceptions, close/cleanup, and busy-state restoration.

Dependency

Stacked on #204. Review only this five-file controller diff.

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