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

address review (claude): reciprocate fullSync disable symmetrically

[._.]/ Adam Eivyf0b4b97fe927
diff --git a/client/src/pages/Instances.jsx b/client/src/pages/Instances.jsx
index bf8222e2fe..dde8ce55a0 100644
--- a/client/src/pages/Instances.jsx
+++ b/client/src/pages/Instances.jsx
@@ -531,8 +531,10 @@ const NON_SNAPSHOT_KEYS = new Set(['brain', 'memory', 'catalog', 'authors', 'art
const SNAPSHOT_CATEGORIES = SYNC_CATEGORY_META.filter(m => !NON_SNAPSHOT_KEYS.has(m.key));
// Indicator backed by REAL coverage diffing (record IDs vs confirmed pushes),
-// not the BIGSERIAL cursors — so "fully mirrored" never lies. Polls on mount and
-// whenever the peer comes online / sub set changes via the `refreshKey` prop.
+// not the BIGSERIAL cursors — so "fully mirrored" never lies. Refetches on mount
+// and whenever `refreshKey` changes; the caller passes peer.lastSeen, so it
+// refreshes on each probe tick — cheap for a single-user box and lets the
+// "N pending" count tick down live as the initial back-subscribe converges.
function FullSyncCoverageBadge({ peerId, peerInstanceId, refreshKey }) {
const [coverage, setCoverage] = useState(null);
const [loaded, setLoaded] = useState(false);
diff --git a/server/services/instances.js b/server/services/instances.js
index bd7504490e..bda413e161 100644
--- a/server/services/instances.js
+++ b/server/services/instances.js
@@ -852,9 +852,13 @@ function sanitizeSyncCategories(input) {
export async function applyReciprocalSync(instanceId, categories, { fullSync } = {}) {
const sanitized = sanitizeSyncCategories(categories);
// A fullSync-only signal (peer asking us to mirror everything) is valid even
- // if the category map didn't sanitize to anything actionable.
+ // if the category map didn't sanitize to anything actionable. An explicit
+ // `fullSync === false` is the peer telling us it STOPPED mirroring us, so we
+ // drop our mirror toward it too — keeping enable AND disable symmetric (a peer
+ // too old to send the field leaves it undefined, which touches nothing).
const wantsFullSync = fullSync === true;
- if (!sanitized && !wantsFullSync) return { changed: false, peer: null };
+ const wantsFullSyncOff = fullSync === false;
+ if (!sanitized && !wantsFullSync && !wantsFullSyncOff) return { changed: false, peer: null };
const turnedOnKinds = [];
let backfillInstanceId = null;
let changed = false;
@@ -867,13 +871,17 @@ export async function applyReciprocalSync(instanceId, categories, { fullSync } =
const prev = { ...DEFAULT_SYNC_CATEGORIES, ...(entry.syncCategories || {}) };
const next = sanitized ? { ...prev, ...sanitized } : prev;
const fullSyncFlips = wantsFullSync && entry.fullSync !== true;
+ const fullSyncOffFlips = wantsFullSyncOff && entry.fullSync === true;
// No-op when nothing actually flips — the echo guard.
- if (!fullSyncFlips && Object.keys(next).every(k => next[k] === prev[k])) return entry;
+ 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);
} 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);
}
@@ -922,10 +930,11 @@ export async function requestReciprocalSync(peer, categories, { fullSync = false
const res = await peerFetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- // Include the full-sync flag so a peer new enough to understand it adopts
- // mirror mode too. Older peers ignore the unknown field and still mirror
- // via the all-on syncCategories map we sent.
- body: JSON.stringify({ instanceId: self.instanceId, syncCategories: sanitized, ...(fullSync ? { fullSync: true } : {}) }),
+ // Always carry our current full-sync state (true OR false) so a peer new
+ // enough to understand it adopts mirror mode on enable AND drops it on
+ // disable. Older peers ignore the field; on enable they still mirror via
+ // the all-on syncCategories map we sent.
+ body: JSON.stringify({ instanceId: self.instanceId, syncCategories: sanitized, fullSync: fullSync === true }),
signal: controller.signal
}, peer);
if (res.ok) {
diff --git a/server/services/instances.test.js b/server/services/instances.test.js
index fabb88c956..947f89b125 100644
--- a/server/services/instances.test.js
+++ b/server/services/instances.test.js
@@ -805,6 +805,37 @@ describe('instances.js', () => {
expect(peer.syncEnabled).toBe(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.
+ const peers = [{ id: 'p1', instanceId: 'inst-A', name: 'A', fullSync: true, syncEnabled: true, syncCategories: { brain: true } }];
+ readJSONFile.mockResolvedValue({ self: { instanceId: 'me' }, peers });
+ const { changed, peer } = await applyReciprocalSync('inst-A', { brain: true }, { fullSync: false });
+ expect(changed).toBe(true);
+ expect(peer.fullSync).toBe(false);
+ expect(peer.syncEnabled).toBe(true); // brain still on underneath
+ });
+
+ it('applyReciprocalSync ignores an absent fullSync field (older peer) — mirror untouched', async () => {
+ const peers = [{ id: 'p1', instanceId: 'inst-A', name: 'A', fullSync: true, syncEnabled: true, syncCategories: { brain: true } }];
+ readJSONFile.mockResolvedValue({ self: { instanceId: 'me' }, peers });
+ // No fullSync key in opts → undefined → must not clear the mirror.
+ const { peer } = await applyReciprocalSync('inst-A', { brain: true });
+ expect(peer.fullSync).toBe(true);
+ });
+
+ it('disabling fullSync reciprocates fullSync:false to the peer', async () => {
+ readJSONFile.mockResolvedValue({
+ self: { instanceId: 'me-id' },
+ peers: [{ id: 'p1', instanceId: 'inst-A', name: 'A', enabled: true, fullSync: false, syncCategories: { brain: true } }],
+ });
+ const fetchMock = vi.fn().mockResolvedValue({ ok: true, status: 200 });
+ vi.stubGlobal('fetch', fetchMock);
+ await enqueueReciprocalSync('p1');
+ const body = JSON.parse(fetchMock.mock.calls.at(-1)[1].body);
+ expect(body.fullSync).toBe(false);
+ });
+
it('updateSelf persists the new-peer full-sync default', async () => {
readJSONFile.mockResolvedValue({ self: { instanceId: 'me', name: 'box' }, peers: [] });
const self = await updateSelf(undefined, { defaultPeerFullSync: true });