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

fix: report unavailable backup inventories and allow retry (#8673)

[._.]/ Adam Eivyecb635113f1a
diff --git a/client/src/components/BackupWidget.jsx b/client/src/components/BackupWidget.jsx
index 7e587beb4e..4d88bbcdc8 100644
--- a/client/src/components/BackupWidget.jsx
+++ b/client/src/components/BackupWidget.jsx
@@ -248,7 +248,7 @@ function SnapshotList({ restoringSnapshotId, onRestoreStateChange }) {
// Let errors throw — `useSocketResource` preserves the last-good data on
// transient failures. A `.catch(() => null)` here would wipe the snapshot
// list on every blip per the hook's documented gotcha.
- const { data: snapshots, loading } = useSocketResource(
+ const { data: snapshots, loading, error, refetch } = useSocketResource(
() => api.getBackupSnapshots({ silent: true }),
{
events: RESOURCE_EVENTS,
@@ -285,7 +285,17 @@ function SnapshotList({ restoringSnapshotId, onRestoreStateChange }) {
);
}
+ const inventoryError = error && (
+ <div role="alert" className="mt-3 text-xs text-port-warning">
+ <p>Snapshot inventory unavailable.{snapshots !== null ? ' Previously loaded inventory is stale.' : ''}</p>
+ <button onClick={() => refetch()} className="mt-1 min-h-[32px] text-port-accent">
+ Retry snapshot inventory
+ </button>
+ </div>
+ );
+
if (!snapshots || snapshots.length === 0) {
+ if (error) return inventoryError;
return (
<p className="mt-3 text-xs text-gray-500">No snapshots found.</p>
);
@@ -293,6 +303,7 @@ function SnapshotList({ restoringSnapshotId, onRestoreStateChange }) {
return (
<div className="mt-3 space-y-1">
+ {inventoryError}
{snapshots.map(snap => (
<div key={snapshotIdentity(snap)}>
<div className="flex items-center justify-between gap-2 py-1.5 px-2 rounded bg-port-bg/50 hover:bg-port-bg/80 transition-colors">
diff --git a/client/src/components/BackupWidget.test.jsx b/client/src/components/BackupWidget.test.jsx
index a888f4990c..26460e0988 100644
--- a/client/src/components/BackupWidget.test.jsx
+++ b/client/src/components/BackupWidget.test.jsx
@@ -56,6 +56,34 @@ beforeEach(() => {
});
describe('BackupWidget snapshots', () => {
+ it('shows first-load failure and recovers through retry to a valid empty inventory', async () => {
+ mockGetBackupSnapshots.mockRejectedValueOnce(new Error('unavailable')).mockResolvedValue([]);
+ renderWidget();
+ fireEvent.click(await screen.findByRole('button', { name: 'Snapshots' }));
+ expect(await screen.findByRole('alert')).toHaveTextContent('Snapshot inventory unavailable.');
+ expect(screen.queryByText('No snapshots found.')).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'Retry snapshot inventory' }));
+ expect(await screen.findByText('No snapshots found.')).toBeInTheDocument();
+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();
+ });
+
+ it('marks retained inventory stale after refresh failure and clears it on retry', async () => {
+ renderWidget();
+ fireEvent.click(await screen.findByRole('button', { name: 'Snapshots' }));
+ await screen.findByRole('button', { name: /Download snapshot/ });
+ mockGetBackupSnapshots.mockRejectedValueOnce(new Error('unavailable'));
+ await act(async () => {
+ Object.defineProperty(document, 'visibilityState', { configurable: true, value: 'hidden' });
+ document.dispatchEvent(new Event('visibilitychange'));
+ Object.defineProperty(document, 'visibilityState', { configurable: true, value: 'visible' });
+ document.dispatchEvent(new Event('visibilitychange'));
+ });
+ expect(await screen.findByRole('alert')).toHaveTextContent('Previously loaded inventory is stale.');
+ expect(screen.getByRole('button', { name: /Download snapshot/ })).toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'Retry snapshot inventory' }));
+ await waitFor(() => expect(screen.queryByRole('alert')).not.toBeInTheDocument());
+ });
+
it('offers neither action for a snapshot that is still being written', async () => {
mockGetBackupSnapshots.mockResolvedValue([
{ id: '2026-08-25T12-00-00', fileCount: 0, incomplete: true },
diff --git a/server/routes/backup.test.js b/server/routes/backup.test.js
index 7ed1a13036..5e981dd2a1 100644
--- a/server/routes/backup.test.js
+++ b/server/routes/backup.test.js
@@ -2,7 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
import express from 'express';
import { PassThrough } from 'stream';
import { request } from '../lib/testHelper.js';
-import { errorMiddleware } from '../lib/errorHandler.js';
+import { errorMiddleware, ServerError } from '../lib/errorHandler.js';
vi.mock('../services/backup.js', () => ({
getState: vi.fn(),
@@ -152,6 +152,21 @@ describe('backup routes', () => {
});
describe('GET /api/backup/snapshots', () => {
+ it('returns classified inventory failures through the centralized boundary', async () => {
+ getSettings.mockResolvedValue({ backup: { destPath: '/backup/target' } });
+ backup.listSnapshots.mockRejectedValueOnce(new ServerError(
+ 'Backup inventory unavailable: read-namespace (EIO)',
+ { code: 'BACKUP_INVENTORY_UNAVAILABLE', context: { operation: 'read-namespace', filesystemCode: 'EIO' } },
+ ));
+ const res = await request(buildApp()).get('/api/backup/snapshots');
+ expect(res.status).toBe(500);
+ expect(res.body).toMatchObject({
+ error: 'Backup inventory unavailable: read-namespace (EIO)',
+ code: 'BACKUP_INVENTORY_UNAVAILABLE',
+ });
+ expect(JSON.stringify(res.body)).not.toContain('/backup/target');
+ });
+
it('returns the list of snapshots from the configured destPath', async () => {
getSettings.mockResolvedValue({ backup: { destPath: '/dest' } });
backup.listSnapshots.mockResolvedValue([{ id: 's1' }, { id: 's2' }]);
diff --git a/server/services/backup.js b/server/services/backup.js
index 8abf886d59..c3f87f1457 100644
--- a/server/services/backup.js
+++ b/server/services/backup.js
@@ -847,6 +847,16 @@ export async function generateManifest(snapshotDataDir, manifestPath, pgDumpPath
return manifest;
}
+// Keep filesystem diagnostics bounded: native errors include private paths.
+function inventoryReadError(cause, operation) {
+ const code = ['ENOENT', 'EACCES', 'EPERM', 'EIO', 'ENOTDIR', 'EMFILE', 'ENFILE', 'ESTALE']
+ .includes(cause?.code) ? cause.code : 'UNKNOWN';
+ return new ServerError(`Backup inventory unavailable: ${operation} (${code})`, {
+ code: 'BACKUP_INVENTORY_UNAVAILABLE',
+ context: { operation, filesystemCode: code },
+ });
+}
+
/**
* List all snapshots in the backup destination.
* @param {string} destPath - Path to external drive backup root
@@ -861,11 +871,19 @@ export async function listSnapshots(destPath) {
// every directory. Treating it as a snapshot id and reading
// `<.DS_Store>/manifest.json` throws ENOTDIR. Also skip dotfile-named dirs so
// nothing hidden can masquerade as a snapshot (real ids are timestamps).
- const rootEntries = await readdir(snapshotsRoot, { withFileTypes: true }).catch(() => []);
+ const rootEntries = await readdir(snapshotsRoot, { withFileTypes: true }).catch(async cause => {
+ if (cause?.code !== 'ENOENT') throw inventoryReadError(cause, 'read-snapshots-root');
+ // Absence is empty only when the configured destination itself is readable.
+ await readdir(destPath).catch(error => { throw inventoryReadError(error, 'read-destination'); });
+ return [];
+ });
const directories = rootEntries.filter(entry => entry.isDirectory() && !entry.name.startsWith('.'));
const descriptors = (await Promise.all(directories.map(async (entry) => {
const rootEntryPath = join(snapshotsRoot, entry.name);
- const contents = await readdir(rootEntryPath, { withFileTypes: true }).catch(() => []);
+ const contents = await readdir(rootEntryPath, { withFileTypes: true }).catch(cause => {
+ if (cause?.code === 'ENOENT') return [];
+ throw inventoryReadError(cause, 'read-namespace');
+ });
const isLegacySnapshot = SNAPSHOT_ID_PATTERN.test(entry.name) && contents.some(child =>
(child.name === 'data' && child.isDirectory())
|| child.name === 'manifest.json'
diff --git a/server/services/backup.test.js b/server/services/backup.test.js
index 21fd464f24..f5622a1eec 100644
--- a/server/services/backup.test.js
+++ b/server/services/backup.test.js
@@ -455,6 +455,48 @@ describe('listSnapshots', () => {
}
});
+ it.each(['EIO', 'EACCES'])('rejects root and namespace %s without exposing paths or returning partial data', async code => {
+ const cause = Object.assign(new Error('private destination and machine'), { code });
+ const spy = vi.spyOn(fs, 'readdir').mockRejectedValue(cause);
+ await expect(listSnapshots('/dest')).rejects.toMatchObject({
+ code: 'BACKUP_INVENTORY_UNAVAILABLE',
+ message: `Backup inventory unavailable: read-snapshots-root (${code})`,
+ context: { operation: 'read-snapshots-root', filesystemCode: code },
+ });
+ spy.mockImplementation(async path => {
+ if (String(path) === joinPath('/dest', 'snapshots')) return [dirent('healthy', true), dirent('unreadable', true)];
+ if (String(path).endsWith('unreadable')) throw cause;
+ return [dirent('2026-06-08T15-18-34', true)];
+ });
+ await expect(listSnapshots('/dest')).rejects.toMatchObject({
+ code: 'BACKUP_INVENTORY_UNAVAILABLE',
+ message: `Backup inventory unavailable: read-namespace (${code})`,
+ });
+ spy.mockRestore();
+ });
+
+ it('accepts missing snapshots only under a readable destination', async () => {
+ const missing = Object.assign(new Error('private path'), { code: 'ENOENT' });
+ const spy = vi.spyOn(fs, 'readdir').mockImplementation(async path => {
+ if (String(path) === '/dest') return [];
+ throw missing;
+ });
+ expect(await listSnapshots('/dest')).toEqual([]);
+ spy.mockRejectedValue(missing);
+ await expect(listSnapshots('/dest')).rejects.toMatchObject({
+ code: 'BACKUP_INVENTORY_UNAVAILABLE',
+ context: { operation: 'read-destination', filesystemCode: 'ENOENT' },
+ });
+ spy.mockRestore();
+ });
+
+ it('skips a namespace removed during enumeration', async () => {
+ const spy = vi.spyOn(fs, 'readdir').mockResolvedValueOnce([dirent('disappeared', true)])
+ .mockRejectedValueOnce(Object.assign(new Error('gone'), { code: 'ENOENT' }));
+ expect(await listSnapshots('/dest')).toEqual([]);
+ spy.mockRestore();
+ });
+
it('returns [] for a falsy destPath without touching the filesystem', async () => {
const readdirSpy = vi.spyOn(fs, 'readdir');
expect(await listSnapshots('')).toEqual([]);