Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

docs([issue-1094]): document reciprocal-sync full-mirror semantics + pin with test

Adam Eivy1d78351d63cc
diff --git a/server/services/instances.js b/server/services/instances.js
index 1492f23b5a..73edf235ac 100644
--- a/server/services/instances.js
+++ b/server/services/instances.js
@@ -737,6 +737,22 @@ export async function connectPeer(id) {
// toward peer B only makes US pull B's C. For B to pull OUR C, B must enable C
// toward US. `requestReciprocalSync` asks B to do exactly that; the peer side
// is `applyReciprocalSync`, invoked by the POST /sync-categories route.
+//
+// SEMANTICS — full mirror, NOT enable-only (resolved, issue #1094). A peer's
+// announced map is applied as a full replace (`{ ...prev, ...sanitized }`), so
+// a peer sending `C:false` DISABLES C on our record for that peer even when we
+// had independently enabled C toward them. This is intentional, not a bug:
+// - The 'Make mutual' UI deliberately pushes the sender's *current* set
+// (including its disables) so a previously-offline / one-directional peer
+// converges to the sender's view in one round-trip.
+// - It's the recovery path for clearing a stale enabled category after a peer
+// was offline during a disable (the all-false / offline-disable test below).
+// Treating sync categories as a symmetric mirror (rather than two strictly
+// independent per-direction switches) is the chosen model. If a future change
+// wants per-direction-independent semantics, 'Make mutual' must grow a separate
+// explicit-disable path so reciprocation never clobbers an independent enable —
+// don't quietly switch this to enable-only, which would regress the two paths
+// above. The full-mirror behavior is pinned by tests in instances.test.js.
// Keep only the keys DEFAULT_SYNC_CATEGORIES defines, coerced to booleans, so a
// peer can never inject unknown/garbage category flags onto our peer record.
diff --git a/server/services/instances.test.js b/server/services/instances.test.js
index c83dbfcbe9..0d4a24f34d 100644
--- a/server/services/instances.test.js
+++ b/server/services/instances.test.js
@@ -591,6 +591,25 @@ describe('instances.js', () => {
expect(peer.syncEnabled).toBe(false); // nothing left enabled
});
+ it('full-mirror is intentional: a peer\'s category:false disables a category we independently enabled (issue #1094)', async () => {
+ // Decision (issue #1094): sync categories are a symmetric full mirror, not
+ // two strictly-independent per-direction switches. So when a peer announces
+ // `{ goals: false }` (e.g. via 'Make mutual' pushing its current set), it
+ // DISABLES goals on our record for that peer even though we had enabled it
+ // toward them independently. This pins that behavior so a future refactor to
+ // enable-only reciprocation can't silently regress 'Make mutual' / the
+ // offline-disable recovery path without tripping this test.
+ const peers = [{ id: 'p1', instanceId: 'inst-A', name: 'A', syncCategories: { brain: true, goals: true }, syncEnabled: true }];
+ readJSONFile.mockResolvedValue({ self: { instanceId: 'me' }, peers });
+
+ const { changed, peer } = await applyReciprocalSync('inst-A', { goals: false });
+
+ expect(changed).toBe(true);
+ expect(peer.syncCategories.goals).toBe(false); // full replace clobbers our independent enable
+ expect(peer.syncCategories.brain).toBe(true); // untouched keys preserved
+ expect(peer.syncEnabled).toBe(true); // brain still on
+ });
+
it('returns changed:false for an unknown peer instanceId', async () => {
readJSONFile.mockResolvedValue({ self: { instanceId: 'me' }, peers: [] });
const { changed, peer } = await applyReciprocalSync('nope', { brain: true });