Skip to content

fix(sync): make syncOnce cancellation race-safe - #204

Open
marcus-pousette wants to merge 1 commit into
sync/app-facing-controllerfrom
fix/sync-once-cancellation
Open

marcus-pousette wants to merge 1 commit into
sync/app-facing-controllerfrom
fix/sync-once-cancellation

Conversation

@marcus-pousette

@marcus-pousette marcus-pousette commented Jul 12, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The inbound controller in #138 must stop an in-flight SyncPeer.syncOnce when a timeout fires or an exact peer registration is replaced, removed, or closed. Stopping only the caller's wait would leave auth, backend, responder, or send work running and could recreate state after teardown.

This PR is the protocol-only prerequisite; it contains no controller or playground code.

Fix

  • Add AbortSignal support to syncOnce and reuse it for subscription reconciliation.
  • Make cancellation-aware steps lazy: a pre-aborted signal prevents the auth hook, backend read, RIBLT work, or send from starting.
  • Check cancellation before session creation, upload acknowledgement bookkeeping, and each outgoing batch.
  • Remove initiator state immediately and send best-effort remote cleanup only after Hello was actually transmitted.
  • Register responder cancellation before the first asynchronous Hello step.
  • Cancel superseded work by transport and filter without affecting unrelated filters.
  • Keep Hello-send bookkeeping correct even when transport.send synchronously triggers cancellation.

Cancellation cannot retract a valid frame or operation that was already transmitted or committed; operation IDs make such late valid delivery idempotent. It does prevent later frames, continuation, and state resurrection.

Stack

Based on #137. #138 adds the application-facing inbound controller on top.

Size and validation

  • Incremental diff: 3 files, +405/-78
  • Protocol TypeScript build passes
  • Full protocol suite: 51/51
  • Five focused cancellation regressions cover pre-abort side effects, delayed responder storage, post-cancel batches, session cleanup, and listener cleanup
  • git diff --check passes

@marcus-pousette marcus-pousette added bug Something isn't working area:sync Sync protocol, reconciliation, transport, discovery, and sync servers labels Jul 12, 2026
@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/app-facing-controller branch from 7821011 to b1b50a2 Compare July 12, 2026 15:23
@marcus-pousette
marcus-pousette force-pushed the fix/sync-once-cancellation branch 2 times, most recently from e3d69f3 to 7f537fe Compare July 13, 2026 16:05
@marcus-pousette
marcus-pousette force-pushed the sync/app-facing-controller branch from b1b50a2 to 46cf7ac Compare July 13, 2026 16:05
@marcus-pousette
marcus-pousette force-pushed the sync/app-facing-controller branch from 46cf7ac to c30c662 Compare July 24, 2026 15:13
@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/app-facing-controller branch from c30c662 to d9379ed Compare August 19, 2026 08:52
@marcus-pousette
marcus-pousette force-pushed the fix/sync-once-cancellation branch from 88d5372 to 5cd76f4 Compare August 19, 2026 08:52
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:sync Sync protocol, reconciliation, transport, discovery, and sync servers bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant