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: keep backup state and archive staging on category purge (#11864)
Adam Eivy12baf47f38e4
diff --git a/server/services/dataManager.itemPurge.test.js b/server/services/dataManager.itemPurge.test.jsindex f778856c74..72cd734590 100644--- a/server/services/dataManager.itemPurge.test.js+++ b/server/services/dataManager.itemPurge.test.js@@ -149,3 +149,25 @@ describe('training-run source details', () => {expect(detail.items[0].sourceHref).toBeUndefined();});});++// data/backup/ is shared with the backup service's own state (state.json) and+// the staging directory an in-flight archive writes into. A category-wide purge+// must take the archives and nothing else (#11864).+describe('purgeCategory — backup keeps the service state (#11864)', () => {+ it('removes only archive files and leaves state.json and staging intact', async () => {+ const archiveA = 'images-2026-10-01T10-00-00.tar.gz';+ const archiveB = 'images-2026-10-02T10-00-00-0123abcd-1234-1234-1234-123456789abc.tar.gz';+ mkdirSync(dataPath('backup', '.archive-inflight'), { recursive: true });+ writeFileSync(dataPath('backup', '.archive-inflight', 'partial.tar.gz'), 'partial');+ writeFileSync(dataPath('backup', 'state.json'), '{"lastRun":"2026-10-01"}');+ writeFileSync(dataPath('backup', archiveA), 'a');+ writeFileSync(dataPath('backup', archiveB), 'b');++ const result = await purgeCategory('backup');+ expect(result).toEqual({ category: 'backup', subPath: null });+ expect(existsSync(dataPath('backup', archiveA))).toBe(false);+ expect(existsSync(dataPath('backup', archiveB))).toBe(false);+ expect(existsSync(dataPath('backup', 'state.json'))).toBe(true);+ expect(existsSync(dataPath('backup', '.archive-inflight', 'partial.tar.gz'))).toBe(true);+ });+});diff --git a/server/services/dataManager.js b/server/services/dataManager.jsindex 130cdf1565..608fe814e6 100644--- a/server/services/dataManager.js+++ b/server/services/dataManager.js@@ -48,6 +48,9 @@ const DATA_DIR = PATHS.data;// per-item deletion: naming a directory does not make a live job safe.// Categories with no `busyCheck` are unaffected. Probes live in// `dataManagerBusy.js`.+// purgeFilter — optional `name => boolean`. A category-wide purge removes only+// the entries it accepts. Use it when the directory also holds files the+// category's own service owns (backup's state.json and in-flight staging).export const CATEGORIES = {'agents': { label: 'Agents', description: 'Agent personality data', archivable: false, deletable: false },'ask-conversations': { label: 'Ask Conversations', description: 'Saved Ask chat transcripts', archivable: true, deletable: false },@@ -56,7 +59,8 @@ export const CATEGORIES = {'avatar': { label: 'Avatar', description: 'Uploaded avatar images', archivable: true, deletable: false },// Machine-local ownership authority must survive every generic cleanup action.'backup-admission': { label: 'Backup Admission', description: 'Active publication and snapshot ownership — reconcile through backup recovery', archivable: false, deletable: false },- 'backup': { label: 'Backups', description: 'Data backup archives', archivable: false, deletable: true, purgeScope: 'category' },+ // data/backup/ also holds the backup service's state.json and .archive-* staging; the purge is archives-only.+ 'backup': { label: 'Backups', description: 'Data backup archives', archivable: false, deletable: true, purgeScope: 'category', purgeFilter: name => ARCHIVE_FILENAME.test(name) },'brain': { label: 'Brain', description: 'Brain items and sync log', archivable: true, deletable: false },// The Beeper attachment byte mirror (#37) — the only thing the Beeper feature// writes to `data/`; every other Beeper record is Postgres. Not archivable:@@ -575,11 +579,12 @@ export async function purgeCategory(categoryKey, options = {}) {await rmGuarded(resolvedTarget, { recursive: !itemScoped, force: true });console.log(`🗑️ Purged item from data/${categoryKey}`);} else {- const entries = await readdir(dirPath).catch(() => []);+ const allEntries = await readdir(dirPath).catch(() => []);+ const entries = meta.purgeFilter ? allEntries.filter(meta.purgeFilter) : allEntries;const removals = await Promise.allSettled(entries.map(entry => rmGuarded(join(dirPath, entry), { recursive: true, force: true })));const failed = removals.find(result => result.status === 'rejected');if (failed) throw failed.reason;- console.log(`🗑️ Purged all ${entries.length} entries from data/${categoryKey}`);+ console.log(`🗑️ Purged ${entries.length} of ${allEntries.length} entries from data/${categoryKey}`);}return { category: categoryKey, subPath: wantsItem ? options.subPath : null };