Skip to content

Break the peerSync <-> peerSyncReceive import cycle by extracting the subscription store to a leaf - #6091

Merged
atomantic merged 1 commit into
mainfrom
claim/issue-5919
Sep 3, 2026
Merged

Break the peerSync <-> peerSyncReceive import cycle by extracting the subscription store to a leaf#6091
atomantic merged 1 commit into
mainfrom
claim/issue-5919

Conversation

@atomantic

Copy link
Copy Markdown
Owner

Summary

  • sharing/peerSync.js and sharing/peerSyncReceive.js statically imported each other, forming a two-module ESM cycle on the federation path. In a static cycle whichever module evaluates first sees undefined for the other's bindings, so a module-ordering change could turn peer sync into a boot-time crash — a cross-machine outage, not a local one.
  • Extracts the peer-subscription store into a new leaf, sharing/peerSubscriptions.js: listPeerSubscriptions, findPeerSubscription, getOutboundCoverageForPeer, subscribePeer, unsubscribePeer, plus the background-operation registry and the debounce timer map unsubscribePeer must cancel against. It imports only peerSyncShared, peerTombstoneCursors, and peerSyncPush — none of which reach back into peerSync.
  • Both peerSync.js and peerSyncReceive.js now import the declaring module. peerSync.js keeps re-exporting the surface, so every existing deep importer (routes, sharing/index.js, dataSync, tools, tests) is unchanged. No await import() — the cycle is removed, not dodged.
  • Drops the peerSyncShared imports peerSync.js no longer uses (including two that were already dead: peerSyncEvents, ERR_SCHEMA_VERSION_AHEAD — both still re-exported via export … from).
  • Deletes the component's entry from KNOWN_CYCLIC_COMPONENTS in server/services/serviceImportCycles.test.js, so the baseline shrinks.

Closes #5919

Test plan

  • cd server && npx vitest run services/serviceImportCycles.test.js — 5 passed; the cycle guard now holds with the baseline entry removed.
  • cd server && npx vitest run services/sharing/ — 22 files, 607 tests passed.
  • cd server && npx vitest run routes/peerSync.test.js routes/peerSyncAuthIntegration.test.js routes/instances.test.js services/syncOrchestrator.test.js services/dataSync — 216 passed.
  • cd server && npm test — 1909 files passed, 38,515 tests passed, 24 skipped.

…nd peerSyncReceive stop importing each other (#5919)

peerSync.js and peerSyncReceive.js formed a two-module ESM cycle on the
federation path: peerSync statically imported applyIncomingPush while the
receiver imported findPeerSubscription/subscribePeer back out of peerSync.
In a static cycle whichever module evaluates first sees undefined bindings,
so a module-ordering change could turn peer sync into a boot-time crash.

The subscription CRUD now lives in sharing/peerSubscriptions.js (a leaf over
peerSyncShared/peerTombstoneCursors/peerSyncPush), along with the
background-operation registry and the debounce timer map unsubscribePeer has
to cancel against. Both peerSync and peerSyncReceive import the declaring
module; peerSync keeps re-exporting the surface so outside callers are
unchanged. Drops the now-dead peerSyncShared imports peerSync no longer uses.
@atomantic
atomantic merged commit 82839d4 into main Sep 3, 2026
7 checks passed
@atomantic
atomantic deleted the claim/issue-5919 branch September 3, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Break the sharing peerSync <-> peerSyncReceive static import cycle

1 participant