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: surface failed CoS queue and agent-census probes in system health (#9747)

[._.]/ Adam Eivy5dcbde0b93c4
diff --git a/client/src/components/SystemHealthWidget.jsx b/client/src/components/SystemHealthWidget.jsx
index b2b9b041c0..9723865da2 100644
--- a/client/src/components/SystemHealthWidget.jsx
+++ b/client/src/components/SystemHealthWidget.jsx
@@ -70,6 +70,8 @@ const SystemHealthWidget = memo(function SystemHealthWidget({ dashboardState })
const { overallHealth, warnings, system, processes, apps, cos } = health;
const diskProbeUnavailable = warnings.some(warning => warning.type === 'probe-unavailable' && warning.source === 'disk');
const cosProbeUnavailable = warnings.some(warning => warning.type === 'probe-unavailable' && warning.source === 'cos');
+ const cosQueueUnavailable = warnings.some(warning => warning.type === 'probe-unavailable' && warning.source === 'cos-queue');
+ const cosAgentsUnavailable = warnings.some(warning => warning.type === 'probe-unavailable' && warning.source === 'cos-agents');
const pm2ProbeUnavailable = warnings.some(warning => warning.type === 'probe-unavailable' && warning.source === 'pm2');
const healthStyle = HEALTH_STYLE[overallHealth] || { color: 'text-gray-400', bg: 'bg-gray-400/10', icon: Activity };
@@ -309,10 +311,14 @@ const SystemHealthWidget = memo(function SystemHealthWidget({ dashboardState })
</div>
{cos?.running && !cosProbeUnavailable && (
<div className="flex items-center gap-3 text-xs text-gray-500">
- {cos.activeAgents > 0 && (
+ {cosAgentsUnavailable ? (
+ <span className="text-port-warning">Agents unavailable</span>
+ ) : cos.activeAgents > 0 && (
<span className="text-port-accent">{cos.activeAgents} agent{cos.activeAgents !== 1 ? 's' : ''}</span>
)}
- {cos.queuedTasks > 0 && (
+ {cosQueueUnavailable || cosAgentsUnavailable ? (
+ <span className="text-port-warning">Queue unavailable</span>
+ ) : cos.queuedTasks > 0 && (
<span>{cos.queuedTasks} queued</span>
)}
</div>
diff --git a/client/src/components/SystemHealthWidget.test.jsx b/client/src/components/SystemHealthWidget.test.jsx
index 9e96a874cb..a07bfecfa4 100644
--- a/client/src/components/SystemHealthWidget.test.jsx
+++ b/client/src/components/SystemHealthWidget.test.jsx
@@ -103,6 +103,32 @@ describe('SystemHealthWidget', () => {
expect(screen.queryByText('Stopped')).not.toBeInTheDocument();
});
+ it('shows unavailable queue and agent telemetry without marking the daemon stopped', () => {
+ const warnings = [
+ { type: 'probe-unavailable', source: 'cos-queue', status: 'unavailable', severity: 'warning', message: 'Chief of Staff queue unavailable', dismissible: false },
+ { type: 'probe-unavailable', source: 'cos-agents', status: 'unavailable', severity: 'warning', message: 'Chief of Staff agent census unavailable', dismissible: false },
+ ];
+ renderWidget({ health: { ...HEALTH, warnings, cos: { running: true, paused: false, activeAgents: 0, queuedTasks: null } }, refetchHealth: vi.fn() });
+
+ expect(screen.getByText('Chief of Staff').parentElement).toHaveTextContent('Active');
+ expect(screen.getByText('Queue unavailable')).toBeInTheDocument();
+ expect(screen.getByText('Agents unavailable')).toBeInTheDocument();
+ expect(screen.queryByText('Stopped')).not.toBeInTheDocument();
+ });
+
+ it('shows only the queue as unavailable when agents are readable, and clears on recovery', () => {
+ const warnings = [{ type: 'probe-unavailable', source: 'cos-queue', status: 'unavailable', severity: 'warning', message: 'Chief of Staff queue unavailable', dismissible: false }];
+ const { rerender } = renderWidget({ health: { ...HEALTH, warnings, cos: { running: true, paused: true, activeAgents: 2, queuedTasks: null } }, refetchHealth: vi.fn() });
+
+ expect(screen.getByText('Queue unavailable')).toBeInTheDocument();
+ expect(screen.getByText('2 agents')).toBeInTheDocument();
+ expect(screen.queryByText('Agents unavailable')).not.toBeInTheDocument();
+
+ rerender(<MemoryRouter><SystemHealthWidget dashboardState={{ health: { ...HEALTH, warnings: [], cos: { running: true, paused: true, activeAgents: 2, queuedTasks: 3 } } }} /></MemoryRouter>);
+ expect(screen.queryByText('Queue unavailable')).not.toBeInTheDocument();
+ expect(screen.getByText('3 queued')).toBeInTheDocument();
+ });
+
it('keeps memory neutral while honoring configured disk thresholds', () => {
const health = {
...HEALTH,
diff --git a/server/routes/health.test.js b/server/routes/health.test.js
index 7ecde92a32..3affe0f26b 100644
--- a/server/routes/health.test.js
+++ b/server/routes/health.test.js
@@ -854,23 +854,39 @@ describe('System Health Routes', () => {
expect(response.body.cos).toMatchObject({ activeAgents: 2, queuedTasks: 1 });
});
- it('falls back to the daemon tally when the agent list cannot be read', async () => {
+ it('keeps the queue unknown and warns when the agent census cannot be read', async () => {
getPendingTaskIds.mockResolvedValueOnce(['user/42']);
- getAgents.mockRejectedValueOnce(new Error('state unreadable'));
+ getAgents.mockRejectedValueOnce(Object.assign(new Error('state unreadable'), { code: 'EIO' }));
const response = await request(app).get('/api/system/health/details');
- // No claim set to subtract, so the queue over-reports rather than hiding
- // work — the safe direction — and active falls back rather than reading 0.
- expect(response.body.cos).toMatchObject({ activeAgents: 1, queuedTasks: 1 });
+ // No claim set to subtract, so a reconciled queue count cannot be measured;
+ // active falls back to the daemon tally and daemon state stays accurate.
+ expect(response.body.cos).toMatchObject({ running: true, paused: false, activeAgents: 1, queuedTasks: null });
+ expect(response.body.overallHealth).not.toBe('healthy');
+ expect(response.body.warnings).toContainEqual(
+ { type: 'probe-unavailable', source: 'cos-agents', status: 'unavailable', severity: 'warning', message: 'Chief of Staff agent census unavailable', dismissible: false }
+ );
});
- it('reports an unreadable pending list as unknown rather than as an empty queue', async () => {
+ it('reports an unreadable pending list as unknown with a non-dismissible warning, then recovers', async () => {
getPendingTaskIds.mockRejectedValueOnce(new Error('task file unreadable'));
+ getAgents.mockResolvedValueOnce([]);
- const response = await request(app).get('/api/system/health/details');
+ const failed = await request(app).get('/api/system/health/details');
+
+ expect(failed.body.cos).toMatchObject({ running: true, queuedTasks: null });
+ expect(failed.body.overallHealth).not.toBe('healthy');
+ expect(failed.body.warnings).toContainEqual(
+ { type: 'probe-unavailable', source: 'cos-queue', status: 'unavailable', severity: 'warning', message: 'Chief of Staff queue unavailable', dismissible: false }
+ );
+
+ getPendingTaskIds.mockResolvedValueOnce([]);
+ getAgents.mockResolvedValueOnce([]);
+ const recovered = await request(app).get('/api/system/health/details');
- expect(response.body.cos.queuedTasks).toBeNull();
+ expect(recovered.body.cos.queuedTasks).toBe(0);
+ expect(recovered.body.warnings.filter((w) => w.source === 'cos-queue' || w.source === 'cos-agents')).toEqual([]);
});
});
});
diff --git a/server/services/systemHealthSnapshot.js b/server/services/systemHealthSnapshot.js
index f3b96425f2..8b8303d9b6 100644
--- a/server/services/systemHealthSnapshot.js
+++ b/server/services/systemHealthSnapshot.js
@@ -67,6 +67,19 @@ async function loadHealthSettings() {
};
}
+// Last observed availability per CoS read ('cos-queue' / 'cos-agents'), so a
+// persistent failure logs once on entry and once on recovery, not on every read.
+const cosProbeAvailability = new Map();
+
+const probeErrorCode = (error) => (typeof error?.code === 'string' && /^[A-Z][A-Z0-9_]{0,31}$/.test(error.code) ? error.code : 'unknown');
+
+function noteCosProbe(source, available, error) {
+ if (cosProbeAvailability.get(source) === available) return;
+ cosProbeAvailability.set(source, available);
+ if (available) console.log(`✅ CoS health probe recovered (source=${source})`);
+ else console.error(`❌ CoS health probe unavailable (source=${source}, code=${probeErrorCode(error)})`);
+}
+
const patchHealth = (current, patch) => ({ ...current, health: { ...(current.health || {}), ...patch } });
export async function getSystemHealthSnapshot() {
@@ -89,8 +102,14 @@ export async function getSystemHealthSnapshot() {
// such field — `cosStatus.queueLength` never existed, so the widget's
// "N queued" was dead and always rendered 0. Both reads ride the same
// `loadState()`/parse caches `getStatus()` above already warmed.
- cos.getPendingTaskIds().catch(() => null),
- cos.getAgents().catch(() => null),
+ cos.getPendingTaskIds().then(
+ (ids) => { noteCosProbe('cos-queue', true); return ids; },
+ (error) => { noteCosProbe('cos-queue', false, error); return failedProbe; }
+ ),
+ cos.getAgents().then(
+ (agents) => { noteCosProbe('cos-agents', true); return agents; },
+ (error) => { noteCosProbe('cos-agents', false, error); return failedProbe; }
+ ),
getSelf().catch(() => null),
checkHealth().catch(() => ({ connected: false, hasSchema: false, error: 'Health check failed' })),
getCurrentVersion().catch(() => null),
@@ -193,6 +212,16 @@ export async function getSystemHealthSnapshot() {
if (cosStatus === failedProbe) {
rawWarnings.push({ type: 'probe-unavailable', source: 'cos', status: 'unavailable', severity: 'warning', message: 'Chief of Staff status unavailable', dismissible: false });
}
+ // Queue and agent reads fail independently of getStatus(); only meaningful
+ // while the daemon status itself was readable (otherwise 'cos' already warns).
+ if (cosStatus !== failedProbe) {
+ if (cosPendingTaskIds === failedProbe) {
+ rawWarnings.push({ type: 'probe-unavailable', source: 'cos-queue', status: 'unavailable', severity: 'warning', message: 'Chief of Staff queue unavailable', dismissible: false });
+ }
+ if (cosAgents === failedProbe) {
+ rawWarnings.push({ type: 'probe-unavailable', source: 'cos-agents', status: 'unavailable', severity: 'warning', message: 'Chief of Staff agent census unavailable', dismissible: false });
+ }
+ }
if (pm2Processes === null) {
rawWarnings.push({ type: 'probe-unavailable', source: 'pm2', status: 'unavailable', severity: 'warning', message: 'Process manager (PM2) status unavailable', dismissible: false });
}
@@ -324,14 +353,18 @@ export async function getSystemHealthSnapshot() {
// A task a live agent already holds is active, not queued (lib/cosSpawnWindow.js).
// An unreadable list degrades to null — unknown, which the widget hides —
// rather than to a manufactured zero.
- const heldByRunningAgent = runningAgentsByTaskId(cosAgents);
+ const agentsReadable = cosAgents !== failedProbe;
+ const queueReadable = cosPendingTaskIds !== failedProbe;
+ const heldByRunningAgent = agentsReadable ? runningAgentsByTaskId(cosAgents) : null;
const cosInfo = cosStatus && cosStatus !== failedProbe ? {
running: cosStatus.running,
paused: cosStatus.paused,
- activeAgents: cosAgents
+ activeAgents: agentsReadable
? cosAgents.filter((agent) => agent?.status === 'running').length
: (cosStatus.activeAgents || 0),
- queuedTasks: cosPendingTaskIds ? unclaimedTaskIds(cosPendingTaskIds, heldByRunningAgent).length : null
+ // Without the agent census the spawn-window subtraction is impossible, so
+ // the count is unknown rather than an over-reported "reconciled" figure.
+ queuedTasks: queueReadable && agentsReadable ? unclaimedTaskIds(cosPendingTaskIds, heldByRunningAgent).length : null
} : null;
const uptime = process.uptime();