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): scope outbound consent to the categories in THIS request
[._.]/ Adam Eivy8ec686a2d629
diff --git a/server/services/instances.js b/server/services/instances.jsindex 4e355ed9ee..4a1b318305 100644--- a/server/services/instances.js+++ b/server/services/instances.js@@ -873,12 +873,15 @@ export async function applyReciprocalSync(instanceId, categories, { fullSync } =const fullSyncFlips = wantsFullSync && entry.fullSync !== true;const fullSyncOffFlips = wantsFullSyncOff && entry.fullSync === true;const categoriesFlip = !Object.keys(next).every(k => next[k] === prev[k]);- // The full-sync state once this request is applied.- const resultingFullSync = wantsFullSync ? true : (wantsFullSyncOff ? false : entry.fullSync === true);- // Does the resulting state mean we will push per-record data to this peer —- // full mirror, or at least one per-record category on? That is the signal that- // the peer's reciprocal request is consent for us to push back to it.- const enablesPushable = resultingFullSync || PER_RECORD_CATEGORY_KINDS.some(([cat]) => next[cat] === true);+ // Does THIS reciprocal request itself ask us to push per-record data back —+ // full mirror, or at least one per-record category carried IN the request?+ // Scope the consent decision to what the peer asked for this time (wantsFullSync+ // / sanitized), NOT the preserved `next` map: a request that only reciprocates a+ // snapshot category (or a per-record kind we merely happen to already have on+ // locally) must not silently widen us to push every locally-enabled kind back.+ // The request is the consent signal, so it also scopes what that consent covers.+ const requestEnablesPushable = wantsFullSync+ || (sanitized ? PER_RECORD_CATEGORY_KINDS.some(([cat]) => sanitized[cat] === true) : false);const directions = Array.isArray(entry.directions) ? entry.directions : [];// An `/announce`-created peer record is inbound-only (it announced to us; the// user here never added it back), and `peerAllowsOutbound` then refuses our@@ -890,7 +893,7 @@ export async function applyReciprocalSync(instanceId, categories, { fullSync } =// that adopted fullSync/categories BEFORE this fix (#1636) but stayed inbound-// only never back-fills, and the echo guard below would return first — so the// missing direction has to participate in change detection to heal it.- const needsOutboundAdopt = enablesPushable && directions.length > 0 && !directions.includes('outbound');+ const needsOutboundAdopt = requestEnablesPushable && directions.length > 0 && !directions.includes('outbound');// No-op only when nothing flips AND there's no outbound to adopt — the echo guard.if (!fullSyncFlips && !fullSyncOffFlips && !categoriesFlip && !needsOutboundAdopt) return entry;if (fullSyncFlips || fullSyncOffFlips) {@@ -921,7 +924,11 @@ export async function applyReciprocalSync(instanceId, categories, { fullSync } =for (const [cat, kind] of PER_RECORD_CATEGORY_KINDS) {const enabledNow = entry.fullSync === true || !!(entry.syncCategories && entry.syncCategories[cat] === true);const flippedOn = prev[cat] !== true && next[cat] === true;- if ((fullSyncFlips && enabledNow) || flippedOn || (needsOutboundAdopt && enabledNow)) {+ // On a heal (outbound just adopted, no flip) only back-fill kinds THIS request+ // enabled — full mirror, or the specific per-record category it carried — so a+ // heal never pushes a kind the current request didn't authorize.+ const requestEnablesKind = wantsFullSync || !!(sanitized && sanitized[cat] === true);+ if ((fullSyncFlips && enabledNow) || flippedOn || (needsOutboundAdopt && enabledNow && requestEnablesKind)) {turnedOnKinds.push(kind);}}diff --git a/server/services/instances.test.js b/server/services/instances.test.jsindex 6f07f92075..ef77102eb0 100644--- a/server/services/instances.test.js+++ b/server/services/instances.test.js@@ -932,6 +932,19 @@ describe('instances.js', () => {expect(peer.directions).toEqual(['inbound']);});+ it('a snapshot-only reciprocal request does NOT widen outbound just because a per-record category is already enabled locally (#1636)', async () => {+ // Consent is scoped to THIS request: reciprocating `goals` (a snapshot+ // category) must not opportunistically start pushing the locally-enabled+ // `universe` records back — the peer never asked us to mirror universe here.+ const peers = [{ id: 'p1', instanceId: 'inst-A', name: 'A', directions: ['inbound'], syncCategories: { universe: true }, syncEnabled: true }];+ readJSONFile.mockResolvedValue({ self: { instanceId: 'me' }, peers });+ const { changed, peer } = await applyReciprocalSync('inst-A', { goals: true });+ expect(changed).toBe(true); // goals (snapshot) was enabled+ expect(peer.syncCategories.goals).toBe(true);+ expect(peer.syncCategories.universe).toBe(true); // preserved+ expect(peer.directions).toEqual(['inbound']); // NOT widened to outbound+ });+it('disabling fullSync reciprocates fullSync:false even with an empty category map', async () => {// The empty-map case is the one the no-categories send guard used to drop:// a just-disabled mirror peer whose underlying syncCategories is empty must