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 resource queue totals unknown when agent census fails (#10726)
Adam Eivy3d267710ed45
diff --git a/client/src/components/system-resources/StoragePanel.test.jsx b/client/src/components/system-resources/StoragePanel.test.jsxindex 10e1a8a901..331871b80e 100644--- a/client/src/components/system-resources/StoragePanel.test.jsx+++ b/client/src/components/system-resources/StoragePanel.test.jsx@@ -148,3 +148,10 @@ it('labels both filesystem gauges and preserves unavailable data capacity', () =expect(screen.getByLabelText('Runtime data disk status unavailable')).toHaveTextContent('Unavailable');expect(screen.queryByRole('meter', { name: /Runtime data disk/ })).not.toBeInTheDocument();});+++it('shows a census-only unavailable-source warning', () => {+ const report = { ...makeReport('2026-08-16T00:00:00.000Z'), sourceErrors: ['agent-census'] };+ render(<MemoryRouter><StoragePanel report={report} loading={false} onRunReport={vi.fn()} onReport={vi.fn()} cleanup={cleanup} /></MemoryRouter>);+ expect(screen.getByText(/Some sources were unavailable: agent-census/)).toHaveTextContent('Other totals remain usable.');+});diff --git a/server/services/systemResources.js b/server/services/systemResources.jsindex c592b5a6c0..63b09691b4 100644--- a/server/services/systemResources.js+++ b/server/services/systemResources.js@@ -340,6 +340,24 @@ function loadedModelInventory({ ollamaLoaded, lmStudioLoaded }) {];}+// Remember transitions across report/cache refreshes without logging private errors.+let agentCensusUnavailable = false;++function readAgentCensus() {+ return cos.getAgents().then((agents) => {+ if (agentCensusUnavailable) console.log('✅ Resource probe recovered (source=agent-census)');+ agentCensusUnavailable = false;+ return agents;+ }).catch((error) => {+ if (!agentCensusUnavailable) {+ const code = typeof error?.code === 'string' && /^[A-Z][A-Z0-9_]{0,31}$/.test(error.code) ? error.code : 'unknown';+ console.error(`❌ Resource probe unavailable (source=agent-census, code=${code})`);+ }+ agentCensusUnavailable = true;+ return null;+ });+}+/*** Queue depth vs work in flight, settled against the agent list.*@@ -352,18 +370,19 @@ function loadedModelInventory({ ollamaLoaded, lmStudioLoaded }) {*/function agentQueueSummary(tasks, status, agents) {if (!tasks) return null;+ const censusAvailable = agents != null;const runningAgents = runningAgentsByTaskId(agents);const pendingUser = tasks.user?.grouped?.pending || [];const pendingSystem = tasks.cos?.grouped?.pending || [];const spawningUser = countSpawningTasks(pendingUser, runningAgents);const spawningSystem = countSpawningTasks(pendingSystem, runningAgents);return {- pendingUser: pendingUser.length - spawningUser,- pendingSystem: pendingSystem.length - spawningSystem,+ pendingUser: censusAvailable ? pendingUser.length - spawningUser : null,+ pendingSystem: censusAvailable ? pendingSystem.length - spawningSystem : null,awaitingApproval: tasks.cos?.awaitingApproval?.length || 0,- inProgress: (tasks.user?.grouped?.in_progress?.length || 0)+ inProgress: censusAvailable ? (tasks.user?.grouped?.in_progress?.length || 0)+ (tasks.cos?.grouped?.in_progress?.length || 0)- + spawningUser + spawningSystem,+ + spawningUser + spawningSystem : null,activeAgents: status ? status.activeAgents || 0 : null,pausedAgents: status ? status.pausedAgents || 0 : null,daemonRunning: status?.running ?? null,@@ -432,7 +451,7 @@ export async function buildSystemResourceReport() {dirSize(PATHS.browserDownloads, { strict: true }).catch(() => null),cos.getAllTasks().catch(() => null),cos.getStatus().catch(() => null),- cos.getAgents().catch(() => null),+ readAgentCensus(),scanModelDuplicates().catch(() => ({ pinokioDetected: null, items: [], totalReclaimableBytes: 0, error: 'Duplicate model scan unavailable' })),]);@@ -584,16 +603,17 @@ export async function buildSystemResourceReport() {...(lmStudioResidencyError ? ['lmstudio-residency'] : []),...(cosTasks == null ? ['agent-queue'] : []),...(cosStatus == null ? ['agent-status'] : []),+ ...(cosAgents == null ? ['agent-census'] : []),])];const managedReclaimableBytes = sumBytes(cleanupCandidates.filter((candidate) => candidate.risk === 'low' && candidate.action).map((candidate) => candidate.estimatedBytes));- const queuedAgents = agentQueue+ const queuedAgents = agentQueue && cosAgents != null// Awaiting-approval tasks are already part of pendingSystem. Keep the// review count as a useful breakdown without counting those tasks twice in// the top-line queued total.? agentQueue.pendingUser + agentQueue.pendingSystem- : 0;+ : null;// Every full scan heals the persisted manifest, so Models → Status has a fresh// answer to fall back on next time without walking the model stores again, and@@ -616,8 +636,8 @@ export async function buildSystemResourceReport() {modelBytes,managedReclaimableBytes,loadedModels: loadedModels.length,- queuedJobs: agentQueue ? mediaQueue.queued + queuedAgents : null,- runningJobs: agentQueue ? mediaQueue.running + agentQueue.inProgress : null,+ queuedJobs: queuedAgents != null ? mediaQueue.queued + queuedAgents : null,+ runningJobs: agentQueue?.inProgress != null ? mediaQueue.running + agentQueue.inProgress : null,},storageAreas,dataCategories: categories,diff --git a/server/services/systemResources.test.js b/server/services/systemResources.test.jsindex d7d3938049..39d9fab08a 100644--- a/server/services/systemResources.test.js+++ b/server/services/systemResources.test.js@@ -1,4 +1,4 @@-import { beforeEach, describe, expect, it, vi } from 'vitest';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';vi.mock('./modelDeduplication.js', () => ({ scanModelDuplicates: vi.fn(async () => ({ pinokioDetected: false, items: [], totalReclaimableBytes: 0 })) }));@@ -133,6 +133,7 @@ const {} = await import('./systemResources.js');describe('system resource reporting', () => {+ afterEach(() => vi.restoreAllMocks());beforeEach(() => {vi.clearAllMocks();resetSystemResourceReportCache();@@ -316,6 +317,56 @@ describe('system resource reporting', () => {expect(report.summary).toMatchObject({ queuedJobs: 3, runningJobs: 2 });});+ it('keeps failed census reconciliation unknown and restores spawn-window counts on recovery', async () => {+ const errors = vi.spyOn(console, 'error').mockImplementation(() => {});+ const logs = vi.spyOn(console, 'log').mockImplementation(() => {});+ const tasks = {+ user: { grouped: { pending: [{ id: 'user/42', status: 'pending' }], in_progress: [] } },+ cos: { grouped: { pending: [{ id: 'approval-1', approvalRequired: true }], in_progress: [] }, awaitingApproval: [{ id: 'approval-1' }] },+ };+ cos.getAllTasks.mockResolvedValueOnce(tasks).mockResolvedValueOnce(tasks).mockResolvedValueOnce(tasks);+ cos.getStatus.mockResolvedValueOnce({ running: true, paused: false, activeAgents: 1, pausedAgents: 2 });+ const failure = Object.assign(new Error('private census path'), { code: 'EIO' });+ cos.getAgents.mockRejectedValueOnce(failure).mockRejectedValueOnce(failure)+ .mockResolvedValueOnce([{ id: 'agent-1', taskId: 'user/42', status: 'running', startedAt: new Date().toISOString() }]);++ const failed = await buildSystemResourceReport();+ expect(failed.sourceErrors).toEqual(['agent-census']);+ expect(failed.queues.agents).toEqual({+ pendingUser: null, pendingSystem: null, inProgress: null, awaitingApproval: 1,+ activeAgents: 1, pausedAgents: 2, daemonRunning: true, daemonPaused: false,+ });+ expect(failed.queues.media).toMatchObject({ queued: 3, running: 1 });+ expect(failed.summary).toMatchObject({ queuedJobs: null, runningJobs: null });+ const prompt = buildSystemResourceTriagePrompt(failed);+ expect(prompt).toContain('"unavailableSources": [\n "agent-census"');+ expect(prompt).toContain('"queuedJobs": null');+ expect(prompt).toContain('"runningJobs": null');+ expect(prompt).not.toContain('private census path');++ await buildSystemResourceReport();+ expect(errors).toHaveBeenCalledExactlyOnceWith('❌ Resource probe unavailable (source=agent-census, code=EIO)');+ const recovered = await buildSystemResourceReport();+ expect(recovered.sourceErrors).not.toContain('agent-census');+ expect(recovered.queues.agents).toMatchObject({ pendingUser: 0, pendingSystem: 1, inProgress: 1 });+ expect(recovered.summary).toMatchObject({ queuedJobs: 4, runningJobs: 2 });+ expect(logs).toHaveBeenCalledExactlyOnceWith('✅ Resource probe recovered (source=agent-census)');+ await buildSystemResourceReport();+ expect(logs).toHaveBeenCalledTimes(1);+ });++ it('treats a successful empty census as measured persisted-task counts', async () => {+ cos.getAllTasks.mockResolvedValueOnce({+ user: { grouped: { pending: [], in_progress: [{ id: 'user/42' }] } },+ cos: { grouped: { pending: [], in_progress: [] }, awaitingApproval: [] },+ });+ cos.getAgents.mockResolvedValueOnce([]);+ const report = await buildSystemResourceReport();+ expect(report.sourceErrors).not.toContain('agent-census');+ expect(report.queues.agents).toMatchObject({ pendingUser: 0, pendingSystem: 0, inProgress: 1 });+ expect(report.summary).toMatchObject({ queuedJobs: 3, runningJobs: 2 });+ });+it('preserves failed agent queue and status probes as unknown', async () => {cos.getAllTasks.mockRejectedValueOnce(new Error('task store unavailable'));cos.getStatus.mockRejectedValueOnce(new Error('daemon status unavailable'));