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: stop an unreadable directory and a stale detail fetch from reading as idle (#3342)

[._.]/ Adam Eivyfc15d35cd664
diff --git a/client/src/pages/DataManager.jsx b/client/src/pages/DataManager.jsx
index 4cb1f81e1d..edabd495e9 100644
--- a/client/src/pages/DataManager.jsx
+++ b/client/src/pages/DataManager.jsx
@@ -1,4 +1,4 @@
-import { useState, useEffect, useCallback } from 'react';
+import { useState, useEffect, useCallback, useRef } from 'react';
import { HardDrive, RefreshCw, Archive, Trash2, ChevronDown, ChevronRight, FolderOpen, File, Package } from 'lucide-react';
import * as api from '../services/api';
import { formatBytes } from '../utils/formatters';
@@ -376,21 +376,32 @@ export default function DataManager() {
useEffect(() => { fetchOverview(); }, [fetchOverview]);
+ // Detail fetches are per-row and can land out of order — expanding A then B
+ // could leave A's items (and, since #3342, A's busy state) rendered under B.
+ // Every fetch takes a token and only the newest one is allowed to write.
+ const detailRequestRef = useRef(0);
+
+ const loadDetail = async (key) => {
+ const token = (detailRequestRef.current += 1);
+ const d = await api.getDataCategory(key).catch(() => null);
+ if (detailRequestRef.current === token) setDetail(d);
+ };
+
const handleExpand = async (key) => {
if (expandedCat === key) {
+ detailRequestRef.current += 1;
setExpandedCat(null);
setDetail(null);
return;
}
setExpandedCat(key);
setDetail(null);
- const d = await api.getDataCategory(key).catch(() => null);
- setDetail(d);
+ await loadDetail(key);
};
const refreshAfterAction = async (key) => {
fetchOverview();
- if (expandedCat === key) setDetail(await api.getDataCategory(key).catch(() => null));
+ if (expandedCat === key) await loadDetail(key);
};
const handleArchive = async (key) => {
diff --git a/client/src/pages/DataManager.test.jsx b/client/src/pages/DataManager.test.jsx
index 95752ed48b..c22475fd3f 100644
--- a/client/src/pages/DataManager.test.jsx
+++ b/client/src/pages/DataManager.test.jsx
@@ -196,6 +196,27 @@ describe('DataManager busy categories (#3342)', () => {
expect(screen.queryByRole('button', { name: /Purge/ })).not.toBeInTheDocument();
});
+ // Detail fetches land out of order: a slow response for a row the user has
+ // already collapsed past must not paint its busy state onto the row now open.
+ it('ignores a detail response that a newer expand has superseded', async () => {
+ let resolveSlow;
+ getDataCategory.mockImplementation((key) => (key === 'training-runs'
+ ? new Promise((res) => { resolveSlow = res; })
+ : Promise.resolve({ key, items: [], busy: false, busyReason: null })));
+
+ render(<DataManager />);
+ await waitFor(() => expect(screen.getAllByText('LoRA Training Runs').length).toBeGreaterThan(0));
+
+ expandRow('LoRA Training Runs');
+ expandRow('Messages');
+ await waitFor(() => expect(screen.getByRole('button', { name: /Purge/ })).toBeInTheDocument());
+
+ // The stale training-runs detail arrives last and must be dropped.
+ resolveSlow({ key: 'training-runs', items: [], busy: true, busyReason: BUSY_REASON });
+ await waitFor(() => expect(screen.getByRole('button', { name: /Purge/ })).toBeInTheDocument());
+ expect(screen.queryByText(BUSY_REASON)).not.toBeInTheDocument();
+ });
+
// Older servers omit `busy` entirely — treating anything but an explicit true
// as busy would strip the button from every category on an older peer.
it('treats a missing busy flag as idle', async () => {
diff --git a/server/services/dataManagerBusy.js b/server/services/dataManagerBusy.js
index cac75f568f..c56f53bc3a 100644
--- a/server/services/dataManagerBusy.js
+++ b/server/services/dataManagerBusy.js
@@ -38,7 +38,14 @@ const IDLE = { busy: false, reason: null };
// canceled) has no claim on anything under `data/`.
const IN_FLIGHT_STATUSES = new Set(['queued', 'running']);
-const listDirNames = (dir) => readdir(dir, { withFileTypes: true }).catch(() => []);
+// A directory that isn't there has nothing left to lose, so ENOENT reads as
+// empty. Any OTHER failure means we could not look — rethrow so
+// `resolveCategoryBusy` fails closed rather than reporting a locked or
+// unreadable directory as idle and clearing the way for the purge.
+const listDirEntries = (dir) => readdir(dir, { withFileTypes: true }).catch((err) => {
+ if (err?.code === 'ENOENT') return [];
+ throw err;
+});
/**
* `data/image-clean-tmp` — the pinned set comes from the SAME predicate the
@@ -60,7 +67,7 @@ export async function imageCleanTmpBusy({ jobs = null, entries = null } = {}) {
const pinned = collectActiveCleanBasenames(jobs || listJobs({ kind: 'image' }));
if (pinned.size === 0) return IDLE;
const present = entries
- || (await listDirNames(join(PATHS.data, 'image-clean-tmp'))).filter(e => e.isFile()).map(e => e.name);
+ || (await listDirEntries(join(PATHS.data, 'image-clean-tmp'))).filter(e => e.isFile()).map(e => e.name);
const atRisk = present.filter(name => pinned.has(name));
if (atRisk.length === 0) return IDLE;
return {
@@ -95,9 +102,11 @@ export async function trainingRunsBusy({ jobs = null, runsDir = null } = {}) {
}
const dir = runsDir || join(PATHS.data, 'training-runs');
- const runs = (await listDirNames(dir)).filter(e => e.isDirectory()).map(e => e.name);
+ const runs = (await listDirEntries(dir)).filter(e => e.isDirectory()).map(e => e.name);
+ // Not caught: a probe that cannot answer must reach `resolveCategoryBusy` and
+ // fail closed, not read as "no trainer here".
const surviving = await Promise.all(
- runs.map(name => isDetachedRunning(join(dir, name, '.detached')).catch(() => false))
+ runs.map(name => isDetachedRunning(join(dir, name, '.detached')))
);
if (!surviving.some(Boolean)) return IDLE;
return {
diff --git a/server/services/dataManagerBusy.test.js b/server/services/dataManagerBusy.test.js
index c693580379..9e50709716 100644
--- a/server/services/dataManagerBusy.test.js
+++ b/server/services/dataManagerBusy.test.js
@@ -121,6 +121,14 @@ describe('trainingRunsBusy', () => {
await expect(trainingRunsBusy({ jobs: [], runsDir: join(TEST_ROOT, 'runs-missing') }))
.resolves.toEqual({ busy: false, reason: null });
});
+
+ // "Absent" is safe to read as empty; "could not look" is not. The rejection
+ // reaches resolveCategoryBusy, which fails closed.
+ it('rejects rather than reporting idle when the runs directory cannot be read', async () => {
+ const notADir = join(TEST_ROOT, 'runs-not-a-dir');
+ writeFileSync(notADir, 'not a directory');
+ await expect(trainingRunsBusy({ jobs: [], runsDir: notADir })).rejects.toThrow();
+ });
});
describe('updateDetachedBusy', () => {