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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): preserve per-category selection when adopting full mirror
[._.]/ Adam Eivyefd4444e835f
diff --git a/server/services/instances.js b/server/services/instances.jsindex 6780943e84..a1856591f3 100644--- a/server/services/instances.js+++ b/server/services/instances.js@@ -874,20 +874,26 @@ export async function applyReciprocalSync(instanceId, categories, { fullSync } =const fullSyncOffFlips = wantsFullSyncOff && entry.fullSync === true;// No-op when nothing actually flips — the echo guard.if (!fullSyncFlips && !fullSyncOffFlips && Object.keys(next).every(k => next[k] === prev[k])) return entry;- // When the peer asks us to mirror everything, a full sweep covers all kinds.- if (fullSyncFlips) {- entry.fullSync = true;- for (const [, kind] of PER_RECORD_CATEGORY_KINDS) turnedOnKinds.push(kind);+ if (fullSyncFlips || fullSyncOffFlips) {+ // A full-sync state change. fullSync alone drives gating, so the stored+ // per-category map is PRESERVED untouched — we do NOT apply the sender's+ // all-on compat overlay. That keeps the user's own selection intact so a+ // later disable restores it, exactly like the local toggle path. (Legacy+ // receivers that don't understand fullSync fall into the category branch+ // below and mirror via the all-on overlay instead — that's its purpose.)+ entry.fullSync = fullSyncFlips; // true on adopt, false on drop+ if (fullSyncFlips) {+ for (const [, kind] of PER_RECORD_CATEGORY_KINDS) turnedOnKinds.push(kind);+ }} else {- // The peer stopped mirroring us → drop our mirror; the per-category map it- // sent (preserved underneath while mirroring) becomes authoritative again.- if (fullSyncOffFlips) entry.fullSync = false;for (const [cat, kind] of PER_RECORD_CATEGORY_KINDS) {if (prev[cat] !== true && next[cat] === true) turnedOnKinds.push(kind);}+ entry.syncCategories = next;}- entry.syncCategories = next;- entry.syncEnabled = entry.fullSync === true || Object.values(next).some(Boolean);+ // Recompute from the (possibly preserved) stored map — a full-sync peer is+ // always sync-enabled; otherwise it follows the per-category selection.+ entry.syncEnabled = entry.fullSync === true || Object.values(entry.syncCategories || {}).some(Boolean);if (turnedOnKinds.length > 0) backfillInstanceId = entry.instanceId || null;changed = true;instanceEvents.emit('peers:updated', data.peers);diff --git a/server/services/instances.test.js b/server/services/instances.test.jsindex 6ef6423b9e..7e49d1af54 100644--- a/server/services/instances.test.js+++ b/server/services/instances.test.js@@ -64,6 +64,7 @@ import {applyReciprocalSync,requestReciprocalSync,enqueueReciprocalSync,+ DEFAULT_SYNC_CATEGORIES,startPolling,stopPolling} from './instances.js';@@ -805,6 +806,21 @@ describe('instances.js', () => {expect(peer.syncEnabled).toBe(true);});+ it('adopting full mirror via reciprocation preserves the underlying per-category selection', async () => {+ // The sender includes an all-on compat map alongside fullSync:true. A+ // fullSync-aware receiver must NOT overwrite its own selection with it —+ // otherwise a later disable would leave every category on instead of+ // restoring the user's choice (only brain here).+ const peers = [{ id: 'p1', instanceId: 'inst-A', name: 'A', fullSync: false, syncCategories: { brain: true } }];+ readJSONFile.mockResolvedValue({ self: { instanceId: 'me' }, peers });+ const allOn = Object.fromEntries(Object.keys(DEFAULT_SYNC_CATEGORIES).map(k => [k, true]));+ const { changed, peer } = await applyReciprocalSync('inst-A', allOn, { fullSync: true });+ expect(changed).toBe(true);+ expect(peer.fullSync).toBe(true);+ expect(peer.syncCategories.brain).toBe(true);+ expect(peer.syncCategories.universe).toBeFalsy(); // not clobbered to true+ });+it('applyReciprocalSync drops our mirror when the peer reports fullSync:false (disable reciprocation)', async () => {// The peer stopped mirroring us — symmetric with the enable path. The// preserved per-category map (brain on) becomes authoritative again.