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 (codex): keep hard-delete intent sticky on resync coalesce (#1318)

[._.]/ Adam Eivy40d057df27e3
diff --git a/server/services/brainMemoryBridge.js b/server/services/brainMemoryBridge.js
index 2d9dda4caf..ea59878aa0 100644
--- a/server/services/brainMemoryBridge.js
+++ b/server/services/brainMemoryBridge.js
@@ -488,10 +488,15 @@ export function queueResync(records) {
if (!Array.isArray(records)) return;
for (const { type, id, hardDelete } of records) {
if (!id || !TYPE_MAP[type]) continue;
- // Last touch wins on coalesce. A real local `{type}:deleted` carries
- // hardDelete:true; upserts and synced applies leave it false so a tombstone
- // they reach stays soft-archived (resurrectable).
- pendingResync.set(bridgeKey(type, id), { type, id, hardDelete: !!hardDelete });
+ const key = bridgeKey(type, id);
+ // Sticky hard-delete on coalesce: once a real local `{type}:deleted` marks a
+ // key for a hard prune, a later touch for the same key before the flush — a
+ // concurrent `sync:applied` carrying no flag, say — must NOT downgrade it to
+ // a soft archive, or the dead embedding lingers. Safe to keep sticky because
+ // resyncBrainRecord's record-present branch upserts a resurrected record
+ // regardless of the flag, so a true intent can never hard-delete a live row.
+ const prevHardDelete = pendingResync.get(key)?.hardDelete;
+ pendingResync.set(key, { type, id, hardDelete: !!hardDelete || !!prevHardDelete });
}
if (pendingResync.size === 0 || resyncTimer || resyncFlushing) return;
resyncTimer = setTimeout(() => {
diff --git a/server/services/brainMemoryBridge.test.js b/server/services/brainMemoryBridge.test.js
index 4d08ec7b25..36d0ff0795 100644
--- a/server/services/brainMemoryBridge.test.js
+++ b/server/services/brainMemoryBridge.test.js
@@ -188,6 +188,21 @@ describe('brainMemoryBridge — queueResync debounce + dedup', () => {
expect(getById).toHaveBeenCalledWith('people', 'p1');
});
+ it('keeps a hard-delete sticky when a later soft touch coalesces onto the same key (#1318)', async () => {
+ const bridge = await loadBridge();
+ bridgeFileContents = JSON.stringify({ [bridge.bridgeKey('people', 'p1')]: 'mem-del' });
+ getById.mockResolvedValue(null); // still tombstoned at flush time
+
+ // Local delete marks p1 for a hard prune; a concurrent sync:applied (no flag)
+ // coalesces onto the same key before the flush. The hard intent must survive.
+ bridge.queueResync([{ type: 'people', id: 'p1', hardDelete: true }]);
+ bridge.queueResync([{ type: 'people', id: 'p1' }]);
+ await bridge.flushPendingResync();
+
+ expect(deleteMemory).toHaveBeenCalledWith('mem-del', true);
+ expect(updateMemory).not.toHaveBeenCalledWith('mem-del', { status: 'archived' });
+ });
+
it('processes the queue sequentially across multiple records', async () => {
const bridge = await loadBridge();
getById.mockImplementation(async (_type, id) => ({ id, name: id }));