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
fix: invalidate brain projections after restore (#5440)
[._.]/ Adam Eivyde17d702d9c9
diff --git a/server/services/backup.js b/server/services/backup.jsindex ecf916936a..49ab854fc3 100644--- a/server/services/backup.js+++ b/server/services/backup.js@@ -22,6 +22,7 @@ import { emitErrorEvent, ServerError } from '../lib/errorHandler.js';import { isSafeSubdirFilter } from '../lib/sharedSchemas.js';import { getIo } from './socket.js';import { reloadSettings } from './settings.js';+import { invalidateAllCaches as invalidateBrainCaches } from './brainStorage.js';// Module-level statelet isRunning = false;@@ -669,10 +670,14 @@ export async function restoreSnapshot(destPath, snapshotId, { dryRun = true, sub}const changedFiles = await runRsync(srcDir, PATHS.data, flags);- // A live restore rsyncs settings.json into place outside the save() path, so- // getSettings()'s read-cache (and other settings:updated-driven caches) would- // keep serving pre-restore values until the next save/restart. Re-sync them.- if (!dryRun) await reloadSettings();+ if (!dryRun) {+ // A live restore writes outside normal service mutation paths. Re-sync the+ // caches whose backing files may have changed instead of serving the+ // pre-restore projection until each record is next mutated or the process+ // restarts. A selective restore can target only one top-level directory.+ if (!subdirFilter || subdirFilter === 'brain') invalidateBrainCaches();+ await reloadSettings();+ }return { dryRun, snapshotId, subdirFilter, changedFiles };}diff --git a/server/services/backup.test.js b/server/services/backup.test.jsindex 3cde210077..58c0f24b6e 100644--- a/server/services/backup.test.js+++ b/server/services/backup.test.js@@ -90,7 +90,12 @@ vi.mock('./settings.js', async (importOriginal) => ({...(await importOriginal()),reloadSettings: vi.fn(async () => {}),}));+vi.mock('./brainStorage.js', async (importOriginal) => ({+ ...(await importOriginal()),+ invalidateAllCaches: vi.fn(),+}));import { reloadSettings } from './settings.js';+import { invalidateAllCaches as invalidateBrainCaches } from './brainStorage.js';import { DEFAULT_EXCLUDES, computeEffectiveExcludes, listSnapshots, openSnapshotStream, restoreSnapshot } from './backup.js';// fs.access is mocked file-wide because backup.js probes the .in-progress marker@@ -1218,6 +1223,7 @@ describe('restoreSnapshot snapshotId, filter flags, and settings re-sync', () =>beforeEach(() => {spawn.mockReset();reloadSettings.mockClear();+ invalidateBrainCaches.mockClear();});// Drive a mocked rsync to a clean exit so restoreSnapshot resolves.@@ -1297,14 +1303,28 @@ describe('restoreSnapshot snapshotId, filter flags, and settings re-sync', () =>await runRestore('/dest', 'snap-1', { dryRun: false });expect(reloadSettings).toHaveBeenCalledTimes(1);+ expect(invalidateBrainCaches).toHaveBeenCalledTimes(1);// A live restore must not pass --dry-run to rsync.expect(spawn.mock.calls[0][1]).not.toContain('--dry-run');});+ it('invalidates Brain projections after a selective live Brain restore', async () => {+ await runRestore('/dest', 'snap-1', { dryRun: false, subdirFilter: 'brain' });++ expect(invalidateBrainCaches).toHaveBeenCalledTimes(1);+ });++ it('keeps Brain projections after a selective live restore outside Brain', async () => {+ await runRestore('/dest', 'snap-1', { dryRun: false, subdirFilter: 'images' });++ expect(invalidateBrainCaches).not.toHaveBeenCalled();+ });+it('does not reload settings for a dry run', async () => {await runRestore('/dest', 'snap-1', { dryRun: true });expect(reloadSettings).not.toHaveBeenCalled();+ expect(invalidateBrainCaches).not.toHaveBeenCalled();expect(spawn.mock.calls[0][1]).toContain('--dry-run');});