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: report unreadable backup restore dumps and retention inventories
atomantic490b3b037b1f
diff --git a/server/services/backup.js b/server/services/backup.jsindex c0de1accda..2995b75b91 100644--- a/server/services/backup.js+++ b/server/services/backup.js@@ -1902,7 +1902,13 @@ async function restoreHeldDatabase({ snapshotDir, currentSource }, snapshotId, {if (pendingRecovery) return pendingRecovery;const sqlPath = join(snapshotDir, 'portos-db.sql');- const info = await stat(sqlPath).catch(() => null);+ const info = await stat(sqlPath).catch(cause => {+ if (cause?.code === 'ENOENT') return null;+ const { filesystemCode } = inventoryReadError(cause, 'stat-database-dump').context;+ console.error(`❌ restore: dump metadata unreadable for snapshot ${snapshotId} (${filesystemCode})`);+ return false;+ });+ if (info === false) return DUMP_UNREADABLE;// An empty/0-byte dump is as good as absent — restoring it is a silent no-op.// Mirror dumpPostgres's empty-dump guard so a truncated snapshot can't read// as a successful "0 tables" restore.diff --git a/server/services/backup.test.js b/server/services/backup.test.jsindex 5a57fdad59..5e38175b5c 100644--- a/server/services/backup.test.js+++ b/server/services/backup.test.js@@ -1325,11 +1325,27 @@ describe('restorePostgres', () => {});it('returns skipped/no_dump when the sql file is absent', async () => {- vi.spyOn(fs, 'stat').mockRejectedValue(new Error('ENOENT'));+ vi.spyOn(fs, 'stat').mockRejectedValue(Object.assign(new Error('missing'), { code: 'ENOENT' }));const result = await restorePostgres('/dest', '2026-06-05T00-00-00', { dryRun: true });expect(result).toEqual({ status: 'skipped', reason: 'no_dump' });});+ it('reports unreadable dump metadata as a restore failure in preview and execution', async () => {+ const errorLog = vi.spyOn(console, 'error').mockImplementation(() => {});+ vi.spyOn(fs, 'stat').mockRejectedValue(Object.assign(new Error('private storage detail'), { code: 'EIO' }));++ for (const dryRun of [true, false]) {+ expect(await restorePostgres('/dest', 'snap-1', { dryRun }))+ .toMatchObject({ status: 'failed', reason: 'dump_unreadable' });+ }++ expect(errorLog).toHaveBeenCalledWith('❌ restore: dump metadata unreadable for snapshot snap-1 (EIO)');+ expect(errorLog.mock.calls.flat().join(' ')).not.toContain('private storage detail');+ expect(spawn).not.toHaveBeenCalled();+ expect(query).not.toHaveBeenCalled();+ expect(executionRestore.prepare).not.toHaveBeenCalled();+ });+// portos-db.sql is still being written while a backup runs. Replaying a half// dump into the live database is the most destructive thing this module can// do, so the guard has to cover it — not just download and file restore.@@ -4745,6 +4761,29 @@ describe('runBackup lifecycle', () => {return dir;}+ it('logs a failed retention inventory without failing the completed backup or deleting snapshots', async () => {+ const fsp = await actualFs();+ const old = await seedSnapshot(machineHost, '2020-01-01T00-00-00', { generatedAt: '2020-01-01T00:00:00.000Z' });+ const sourceRoot = joinPath(destRoot, 'snapshots', machineHost);+ vi.spyOn(fs, 'readdir').mockImplementation((path, ...args) => String(path) === sourceRoot+ ? Promise.reject(Object.assign(new Error('private storage detail'), { code: 'EACCES' }))+ : fsp.readdir(path, ...args));+ const errorLog = vi.spyOn(console, 'error').mockImplementation(() => {});+ const io = { emit: vi.fn() };+ const proc = fakeProc();+ spawn.mockReturnValue(proc);+ const pending = runBackup(destRoot, io, { retentionCount: 1 });+ await waitFor(() => spawn.mock.calls.length === 1, 'rsync spawn');+ proc.emit('close', 0);++ await expect(pending).resolves.toMatchObject({ status: 'ok', prunedSnapshots: 0 });+ await expect(fsp.stat(old)).resolves.toBeDefined();+ expect(io.emit).toHaveBeenCalledWith('backup:completed', expect.objectContaining({ status: 'ok' }));+ expect(errorLog).toHaveBeenCalledWith('❌ Backup retention prune failed: Backup inventory unavailable: read-retention-namespace (EACCES)');+ expect(errorLog.mock.calls.flat().join(' ')).not.toContain('private storage detail');+ expect(isBackupInProgress()).toBe(false);+ });+it('prunes only the oldest completed snapshots in the current machine namespace, keeping failed/in-progress/other-source snapshots', async () => {const fsp = await actualFs();const old1 = await seedSnapshot(machineHost, '2020-01-01T00-00-00', { generatedAt: '2020-01-01T00:00:00.000Z' });