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: guard memory sync behind postgres backend check, add read-only cursor helper
Adam Eivy3d0b52a8bb0a
diff --git a/server/services/syncOrchestrator.js b/server/services/syncOrchestrator.jsindex 72e831ba4a..0a859f7820 100644--- a/server/services/syncOrchestrator.js+++ b/server/services/syncOrchestrator.js@@ -13,6 +13,7 @@ import { getPeers } from './instances.js';import * as brainSync from './brainSync.js';import * as brainSyncLog from './brainSyncLog.js';import * as memorySync from './memorySync.js';+import { getBackendName } from './memoryBackend.js';const CURSORS_FILE = dataPath('instances_sync_cursors.json');const SYNC_INTERVAL_MS = 60000;@@ -36,6 +37,13 @@ async function saveCursors(cursors) {await rename(tmp, CURSORS_FILE);}+async function readCursors(fn) {+ return withLock(async () => {+ const cursors = await loadCursors();+ return fn(cursors);+ });+}+async function withCursors(fn) {return withLock(async () => {const cursors = await loadCursors();@@ -68,9 +76,10 @@ async function fetchPeer(peer, path) {* Get sync status: local sequences + per-peer cursors*/export async function getSyncStatus() {+ const isPostgres = getBackendName() === 'postgres';const [brainSeq, memorySeq, cursors] = await Promise.all([Promise.resolve(brainSyncLog.getCurrentSeq()),- memorySync.getMaxSequence(),+ isPostgres ? memorySync.getMaxSequence() : Promise.resolve(null),loadCursors()]);return {@@ -137,9 +146,8 @@ export async function syncWithPeer(peer) {syncingPeers.add(peerId);// Read cursor snapshot outside lock so network I/O doesn't block other peers- const cursor = await withCursors(async (cursors) => {- if (!cursors[peerId]) cursors[peerId] = {};- return { ...cursors[peerId] };+ const cursor = await readCursors((cursors) => {+ return { ...(cursors[peerId] || {}) };});try {@@ -152,11 +160,14 @@ export async function syncWithPeer(peer) {cursors[peerId].lastSyncAt = new Date().toISOString();});- const memoryResult = await syncMemoryFromPeer(peer, cursor);+ const isPostgres = getBackendName() === 'postgres';+ const memoryResult = isPostgres+ ? await syncMemoryFromPeer(peer, cursor)+ : { memorySeq: cursor.memorySeq ?? '0', totalApplied: 0 };await withCursors(async (cursors) => {if (!cursors[peerId]) cursors[peerId] = {};- cursors[peerId].memorySeq = memoryResult.memorySeq;+ if (isPostgres) cursors[peerId].memorySeq = memoryResult.memorySeq;cursors[peerId].lastSyncAt = new Date().toISOString();});diff --git a/server/services/syncOrchestrator.test.js b/server/services/syncOrchestrator.test.jsindex 1265e63877..4a45b655b7 100644--- a/server/services/syncOrchestrator.test.js+++ b/server/services/syncOrchestrator.test.js@@ -12,7 +12,11 @@ vi.mock('./brainSync.js', () => ({applyRemoteChanges: vi.fn()}));vi.mock('./memorySync.js', () => ({- applyRemoteChanges: vi.fn()+ applyRemoteChanges: vi.fn(),+ getMaxSequence: vi.fn().mockResolvedValue('0')+}));+vi.mock('./memoryBackend.js', () => ({+ getBackendName: vi.fn(() => 'postgres')}));vi.mock('./instanceEvents.js', () => ({instanceEvents: { on: vi.fn(), removeListener: vi.fn() }