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: consolidate withCursors calls from 4 to 2 in syncWithPeer

Adam Eivy95ba7b484ddc
diff --git a/server/services/syncOrchestrator.js b/server/services/syncOrchestrator.js
index 4238f48da0..2291e97eae 100644
--- a/server/services/syncOrchestrator.js
+++ b/server/services/syncOrchestrator.js
@@ -115,28 +115,18 @@ export async function syncWithPeer(peer) {
const peerId = peer.instanceId;
// Read cursor snapshot outside lock so network I/O doesn't block other peers
- const brainCursor = await withCursors(async (cursors) => {
+ const cursor = await withCursors(async (cursors) => {
if (!cursors[peerId]) cursors[peerId] = {};
return { ...cursors[peerId] };
});
- const brainResult = await syncBrainFromPeer(peer, brainCursor);
+ const brainResult = await syncBrainFromPeer(peer, cursor);
+ const memoryResult = await syncMemoryFromPeer(peer, cursor);
+ // Persist both cursors in a single lock acquisition
await withCursors(async (cursors) => {
if (!cursors[peerId]) cursors[peerId] = {};
cursors[peerId].brainSeq = brainResult.brainSeq;
- cursors[peerId].lastSyncAt = new Date().toISOString();
- });
-
- const memoryCursor = await withCursors(async (cursors) => {
- if (!cursors[peerId]) cursors[peerId] = {};
- return { ...cursors[peerId] };
- });
-
- const memoryResult = await syncMemoryFromPeer(peer, memoryCursor);
-
- await withCursors(async (cursors) => {
- if (!cursors[peerId]) cursors[peerId] = {};
cursors[peerId].memorySeq = memoryResult.memorySeq;
cursors[peerId].lastSyncAt = new Date().toISOString();
});