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: fix compaction scope, LWW consistency, and sync schema

Adam Eivycfc9abc81978
diff --git a/server/lib/memoryValidation.js b/server/lib/memoryValidation.js
index 3c11aad2af..f2deca56b9 100644
--- a/server/lib/memoryValidation.js
+++ b/server/lib/memoryValidation.js
@@ -132,6 +132,7 @@ const syncMemoryItemSchema = z.object({
expiresAt: z.string().datetime().nullable().optional(),
createdAt: z.string().datetime(),
updatedAt: z.string().datetime(),
+ originInstanceId: z.string().max(36).nullable().optional(),
syncSequence: z.string().regex(/^\d+$/).optional()
});
diff --git a/server/services/brainStorage.js b/server/services/brainStorage.js
index b4f87b9037..389614006c 100644
--- a/server/services/brainStorage.js
+++ b/server/services/brainStorage.js
@@ -590,8 +590,8 @@ export async function applyRemoteRecord(type, id, record, op) {
if (op === 'delete') {
if (!data.records[id]) return { applied: false, reason: 'not_found' };
- // LWW: only delete if local record isn't newer than the remote delete
- if (record?.updatedAt && data.records[id].updatedAt > record.updatedAt) {
+ // LWW: only delete if local record isn't newer than the remote delete (>= for consistency with update path)
+ if (record?.updatedAt && data.records[id].updatedAt >= record.updatedAt) {
return { applied: false, reason: 'local_newer' };
}
delete data.records[id];
diff --git a/server/services/syncOrchestrator.js b/server/services/syncOrchestrator.js
index eee29992e6..1a4db6585d 100644
--- a/server/services/syncOrchestrator.js
+++ b/server/services/syncOrchestrator.js
@@ -164,11 +164,11 @@ export async function syncAllPeers() {
await Promise.allSettled(online.map(p => syncWithPeer(p)));
// Compact sync log below the minimum peer cursor to bound log growth
- // Only consider cursors for peers that still exist to avoid stale entries blocking compaction
+ // Include all enabled peers (not just online) so offline peers don't lose unsynced entries
const cursors = await loadCursors();
- const peerIds = new Set(online.map(p => p.instanceId));
+ const allEnabledIds = new Set(peers.filter(p => p.enabled && p.instanceId).map(p => p.instanceId));
const seqs = Object.entries(cursors)
- .filter(([id]) => peerIds.has(id))
+ .filter(([id]) => allEnabledIds.has(id))
.map(([, c]) => c.brainSeq ?? 0);
if (seqs.length > 0) {
const minSeq = Math.min(...seqs);