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: preserve storage snapshots and show unavailable reads (#9446)

[._.]/ Adam Eivya48ba3ff410a
diff --git a/client/src/pages/DataManager.jsx b/client/src/pages/DataManager.jsx
index b1bf938ecc..3ff0ff43a5 100644
--- a/client/src/pages/DataManager.jsx
+++ b/client/src/pages/DataManager.jsx
@@ -343,7 +343,7 @@ function CategoryRow({ onMaintenanceComplete, cat, maxSize, onExpand, expanded,
function BackupsSection({ backups, loading, onDelete }) {
const { isConfirming, requestDelete, cancelDelete, confirmDelete } = useConfirmDelete();
if (loading) return null;
- if (!backups.length) return null;
+ if (!backups?.length) return null;
return (
<div className="mt-6">
@@ -401,7 +401,11 @@ function BackupsSection({ backups, loading, onDelete }) {
export default function DataManager() {
const [overview, setOverview] = useState(null);
- const [backups, setBackups] = useState([]);
+ const [backups, setBackups] = useState(null);
+ const [overviewError, setOverviewError] = useState(false);
+ const [backupsError, setBackupsError] = useState(false);
+ const [overviewPending, setOverviewPending] = useState(false);
+ const [backupsPending, setBackupsPending] = useState(false);
const [loading, setLoading] = useState(true);
const [expandedCat, setExpandedCat] = useState(null);
const [detail, setDetail] = useState(null);
@@ -415,22 +419,48 @@ export default function DataManager() {
const overviewRequestRef = useRef(0);
const overviewReadRef = useRef(null);
- const fetchOverview = useCallback(() => {
+ const backupsRequestRef = useRef(0);
+ const fetchStorageOverview = useCallback(() => {
const token = ++overviewRequestRef.current;
- const read = Promise.all([
- api.getDataOverview().catch(() => null),
- api.getDataBackups().catch(() => [])
- ]).then(([data, bk]) => {
+ setOverviewPending(true);
+ const read = api.getDataOverview({ silent: true }).then(data => {
if (token !== overviewRequestRef.current) return;
setOverview(data);
- setBackups(bk);
- setLoading(false);
+ setOverviewError(false);
+ }, () => {
+ if (token === overviewRequestRef.current) setOverviewError(true);
+ }).finally(() => {
+ if (token === overviewRequestRef.current) setOverviewPending(false);
});
overviewReadRef.current = read;
return read.finally(() => { if (overviewReadRef.current === read) overviewReadRef.current = null; });
}, []);
- useEffect(() => { fetchOverview(); }, [fetchOverview]);
+ const fetchBackups = useCallback(() => {
+ const token = ++backupsRequestRef.current;
+ setBackupsPending(true);
+ return api.getDataBackups({ silent: true }).then(data => {
+ if (token !== backupsRequestRef.current) return;
+ setBackups(data);
+ setBackupsError(false);
+ }, () => {
+ if (token === backupsRequestRef.current) setBackupsError(true);
+ }).finally(() => {
+ if (token === backupsRequestRef.current) setBackupsPending(false);
+ });
+ }, []);
+
+ const fetchOverview = useCallback(() => Promise.all([
+ fetchStorageOverview(), fetchBackups()
+ ]).then(() => setLoading(false)), [fetchStorageOverview, fetchBackups]);
+
+ useEffect(() => {
+ fetchOverview();
+ return () => {
+ overviewRequestRef.current++;
+ backupsRequestRef.current++;
+ };
+ }, [fetchOverview]);
// Detail fetches are per-row and can land out of order — expanding A then B,
// or an archive/purge on A finishing after the user moved to B, could leave
@@ -588,7 +618,7 @@ export default function DataManager() {
const looseBytes = Math.max(0, (overview?.totalSize || 0) - categoryBytes);
// Older servers omit totalFileCount; the category sum then undercounts only
// the files sitting directly in data/.
- const totalFiles = overview?.totalFileCount !== undefined ? overview.totalFileCount
+ const totalFiles = !overview ? null : overview.totalFileCount !== undefined ? overview.totalFileCount
: categories.some(c => c.fileCount == null) ? null : categories.reduce((sum, c) => sum + c.fileCount, 0);
const presentKinds = DATA_KIND_ORDER.filter((k) => categories.some((c) => dataKindOf(c) === k));
const selectedCat = categories.find((c) => c.key === expandedCat) || null;
@@ -610,11 +640,12 @@ export default function DataManager() {
</div>
<div className="flex items-center gap-4">
<div className="hidden sm:block text-right">
- <div className="text-lg font-mono font-bold text-white">{formatBytes(overview?.totalSize || 0)}</div>
+ <div className="text-lg font-mono font-bold text-white">{overview ? formatBytes(overview.totalSize) : 'Storage unavailable'}</div>
<div className="text-xs text-gray-500">total in <code className="text-gray-400">{overview?.dataDir}/</code></div>
</div>
<button
- onClick={() => { setLoading(true); fetchOverview(); }}
+ onClick={fetchOverview}
+ disabled={overviewPending || backupsPending}
className="p-2 text-gray-400 hover:text-white hover:bg-port-card rounded transition-colors"
title="Refresh" aria-label="Refresh"
>
@@ -625,15 +656,27 @@ export default function DataManager() {
{/* Content */}
<div className="flex-1 min-h-0 overflow-auto p-4">
+ {[
+ { failed: overviewError, snapshot: overview, label: 'Storage overview', pending: overviewPending, retry: fetchStorageOverview },
+ { failed: backupsError, snapshot: backups, label: 'Backups', pending: backupsPending, retry: fetchBackups },
+ ].filter(resource => resource.failed).map(resource => (
+ <div key={resource.label} role="alert" className="mb-3 flex flex-wrap items-center gap-3 rounded border border-port-warning/40 bg-port-card p-3 text-sm text-port-warning">
+ <span>{resource.label} unavailable.{resource.snapshot ? ' Showing last successful snapshot; values may be stale.' : ' No successful snapshot loaded.'}</span>
+ <button onClick={resource.retry} disabled={resource.pending} className="rounded border border-port-border px-3 py-1 disabled:opacity-50">
+ {resource.pending ? 'Retrying' : 'Retry'} {resource.label.toLowerCase()}
+ </button>
+ </div>
+ ))}
+
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_20rem] items-start">
<div className="min-w-0 space-y-3">
{/* Totals + kind legend */}
<div className="flex flex-wrap items-center gap-x-4 gap-y-1.5 text-xs">
<span className="text-gray-300">
- <span className="font-mono text-white">{formatBytes(overview?.totalSize || 0)}</span>
+ <span className="font-mono text-white">{overview ? formatBytes(overview.totalSize) : 'Storage unavailable'}</span>
{' · '}{totalFiles == null ? 'File count unavailable' : `${formatCount(totalFiles)} files`}
- {' · '}{formatCount(categories.length, { fallback: '0' })} categories
- {' · '}{formatCount(backups.length, { fallback: '0' })} backups
+ {' · '}{overview ? `${formatCount(categories.length)} categories` : 'Category count unavailable'}
+ {' · '}{backups ? `${formatCount(backups.length)} backups` : 'Backup count unavailable'}
</span>
<span className="flex flex-wrap items-center gap-x-3 gap-y-1 sm:ml-auto">
{presentKinds.map((k) => (
@@ -646,13 +689,13 @@ export default function DataManager() {
</div>
{/* Disk-usage map — click a tile to select it and nest its entries */}
- <DataTreemap
+ {overview && <DataTreemap
categories={categories}
looseBytes={looseBytes}
selectedKey={expandedCat}
detail={detail}
onSelect={handleExpand}
- />
+ />}
{/* Category list — the action surface for the selection */}
<div className="space-y-2">
@@ -688,14 +731,14 @@ export default function DataManager() {
</div>
<div className="min-w-0 space-y-4 lg:sticky lg:top-0">
- <DataSelectionPanel
+ {overview && <DataSelectionPanel
overview={overview}
totalFiles={totalFiles}
selected={selectedCat}
detail={detail}
onSelect={selectCategory}
onShowActions={showSelectedActions}
- />
+ />}
<TombstoneGcSection />
</div>
</div>
diff --git a/client/src/pages/DataManager.test.jsx b/client/src/pages/DataManager.test.jsx
index c47f5e28ca..d4698c627f 100644
--- a/client/src/pages/DataManager.test.jsx
+++ b/client/src/pages/DataManager.test.jsx
@@ -345,7 +345,7 @@ describe('DataManager full-width shell (#4145)', () => {
expect(bar.className).not.toMatch(/overflow-(auto|y-auto|scroll)/);
});
- it('reserves the same shell in the loading skeleton', () => {
+ it('reserves the same shell in the loading skeleton', async () => {
// Never resolves — hold the page in its loading state.
getDataOverview.mockReset().mockReturnValue(new Promise(() => {}));
const { container } = render(<DataManager />);
@@ -355,6 +355,7 @@ describe('DataManager full-width shell (#4145)', () => {
const skeletonScrollers = [...skeleton.children].filter((el) => /overflow-y-auto/.test(el.className));
expect(skeletonScrollers).toHaveLength(1);
expect(skeletonScrollers[0].className).toContain('p-4');
+ await act(async () => {});
});
});
@@ -612,3 +613,66 @@ it('prevents overlapping item cleanup and an already-open bucket purge', async (
expect(screen.getByRole('button', { name: 'Archive' })).toBeDisabled();
await act(async () => finish({ category: 'messages', subPath: 'example-account' }));
});
+
+
+describe('DataManager independent read failures (#9446)', () => {
+ let getDataBackups;
+ const archive = { name: 'example-backup.tar.gz', size: 5000, created: '2025-01-01T10:00:00Z' };
+ beforeEach(async () => {
+ getDataBackups = (await import('../services/api')).getDataBackups;
+ getDataBackups.mockReset().mockResolvedValue([archive]);
+ getDataOverview.mockReset().mockResolvedValue(overview);
+ });
+
+ it('shows unavailable measurements on initial failure and recovers measured empty snapshots', async () => {
+ getDataOverview.mockRejectedValueOnce(new Error('offline')).mockResolvedValue({ totalSize: 0, totalFileCount: 0, categories: [] });
+ getDataBackups.mockRejectedValueOnce(new Error('offline')).mockResolvedValue([]);
+ render(<DataManager />);
+ await screen.findByRole('button', { name: 'Retry storage overview' });
+ expect(screen.getByRole('button', { name: 'Retry backups' })).toBeInTheDocument();
+ expect(screen.getByText(/Backup count unavailable/)).toBeInTheDocument();
+ expect(screen.queryByText(/0 files|0 categories|0 backups|0 B/)).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'Retry storage overview' }));
+ await screen.findByText(/0 files · 0 categories/);
+ expect(screen.getByRole('button', { name: 'Retry backups' })).toBeInTheDocument();
+ expect(getDataBackups).toHaveBeenCalledTimes(1);
+ fireEvent.click(screen.getByRole('button', { name: 'Retry backups' }));
+ await screen.findByText(/0 backups/);
+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();
+ expect(getDataOverview).toHaveBeenCalledWith({ silent: true });
+ expect(getDataBackups).toHaveBeenCalledWith({ silent: true });
+ });
+
+ it.each(['overview', 'backups'])('keeps the healthy resource usable when initial %s fails', async resource => {
+ (resource === 'overview' ? getDataOverview : getDataBackups).mockRejectedValue(new Error('offline'));
+ render(<DataManager />);
+ await screen.findByRole('alert');
+ if (resource === 'overview') {
+ expect(screen.getByText(archive.name)).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Delete backup' })).toBeEnabled();
+ expect(screen.queryByText(UNKNOWN_DESCRIPTION)).not.toBeInTheDocument();
+ } else {
+ expect(screen.getByText(UNKNOWN_DESCRIPTION)).toBeInTheDocument();
+ expect(screen.queryByText(archive.name)).not.toBeInTheDocument();
+ expect(screen.getByText(/Backup count unavailable/)).toBeInTheDocument();
+ }
+ });
+
+ it.each(['overview', 'backups'])('preserves the last successful %s snapshot on failed refresh and retries only it', async resource => {
+ render(<DataManager />);
+ await screen.findByText(archive.name);
+ const failed = resource === 'overview' ? getDataOverview : getDataBackups;
+ const healthy = resource === 'overview' ? getDataBackups : getDataOverview;
+ failed.mockRejectedValueOnce(new Error('offline'));
+ fireEvent.click(screen.getByRole('button', { name: 'Refresh' }));
+ const banner = await screen.findByRole('alert');
+ expect(banner).toHaveTextContent('Showing last successful snapshot; values may be stale.');
+ expect(screen.getByText(archive.name)).toBeInTheDocument();
+ expect(screen.getByText(UNKNOWN_DESCRIPTION)).toBeInTheDocument();
+ expect(screen.getAllByText(formatBytes(3000)).length).toBeGreaterThan(0);
+ const healthyCalls = healthy.mock.calls.length;
+ fireEvent.click(screen.getByRole('button', { name: resource === 'overview' ? 'Retry storage overview' : 'Retry backups' }));
+ await waitFor(() => expect(screen.queryByRole('alert')).not.toBeInTheDocument());
+ expect(healthy).toHaveBeenCalledTimes(healthyCalls);
+ });
+});
diff --git a/client/src/services/apiSystem.js b/client/src/services/apiSystem.js
index 14d1bb03e4..dd02488fd6 100644
--- a/client/src/services/apiSystem.js
+++ b/client/src/services/apiSystem.js
@@ -370,7 +370,7 @@ export const deleteBackupSnapshot = (snapshotId, source, options = {}) => {
};
// Data Manager
-export const getDataOverview = () => request('/data');
+export const getDataOverview = (options) => request('/data', options);
export const getDataCategory = (key, options = {}) => request(`/data/${key}${options.measure ? '?measure=1' : ''}`, options);
export const archiveDataCategory = (key, opts) => request(`/data/${key}/archive`, { method: 'POST', body: JSON.stringify(opts || {}) });
export const purgeDataCategory = (key, opts, options = {}) => request(`/data/${key}`, {
@@ -378,7 +378,7 @@ export const purgeDataCategory = (key, opts, options = {}) => request(`/data/${k
body: JSON.stringify(opts || {}),
...options,
});
-export const getDataBackups = () => request('/data/backups');
+export const getDataBackups = (options) => request('/data/backups', options);
export const deleteDataBackup = (filename) => request(`/data/backups/${filename}`, { method: 'DELETE' });
// Notifications