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: keep the PM2 probe warning non-dismissible and fix the health widget crash (#8431)

[._.]/ Adam Eivyf58cdaa94c91
diff --git a/client/src/components/SystemHealthWidget.jsx b/client/src/components/SystemHealthWidget.jsx
index c6c0b171d1..be9167771e 100644
--- a/client/src/components/SystemHealthWidget.jsx
+++ b/client/src/components/SystemHealthWidget.jsx
@@ -50,7 +50,7 @@ const SystemHealthWidget = memo(function SystemHealthWidget({ dashboardState })
const norm = (pct) => Math.max(0.18, Math.min(1, (pct ?? 0) / 100));
cells[0] = norm(memPct);
cells[1] = norm(cpuPct);
- cells[2] = processes && procTotal ? Math.max(0.25, procOnline / procTotal) : 0.25;
+ cells[2] = procTotal ? Math.max(0.25, procOnline / procTotal) : 0.25;
cells[3] = appTotal ? Math.max(0.25, appOnline / appTotal) : 0.25;
cells[4] = norm(diskPct);
for (let row = 1; row < 5; row++) {
@@ -60,7 +60,7 @@ const SystemHealthWidget = memo(function SystemHealthWidget({ dashboardState })
}
}
return cells;
- }, [memPct, cpuPct, diskPct, procOnline, procTotal, appOnline, appTotal, processes]);
+ }, [memPct, cpuPct, diskPct, procOnline, procTotal, appOnline, appTotal]);
// Don't render if no data
if (!health) {
diff --git a/client/src/pages/SystemHealthPage.jsx b/client/src/pages/SystemHealthPage.jsx
index 50b921b1ed..c8946221eb 100644
--- a/client/src/pages/SystemHealthPage.jsx
+++ b/client/src/pages/SystemHealthPage.jsx
@@ -299,7 +299,7 @@ function SystemHealthOverview() {
</h3>
{health.topProcesses === null ? (
<p role="status" className="text-gray-400 text-sm">
- Process manager (PM2) status unavailable. <Link to="/system-resources/overview" className="text-port-accent hover:text-port-accent/80">Check health →</Link>
+ Process manager (PM2) status unavailable.
</p>
) : health.topProcesses && health.topProcesses.length > 0 ? (
<div className="space-y-1">
diff --git a/server/lib/validation.js b/server/lib/validation.js
index 1b53bfe29e..da316679ff 100644
--- a/server/lib/validation.js
+++ b/server/lib/validation.js
@@ -1654,10 +1654,8 @@ export const databaseExportSchema = z.object({
});
// Dismissible system health warnings — see server/routes/systemHealth.js.
-// Probe failures ('probe-unavailable') are intentionally marked dismissible: false,
-// so they cannot be suppressed by the dismiss endpoint; 'probe-unavailable' is listed
-// here so it passes schema validation for requests that might include it.
-export const SYSTEM_HEALTH_WARNING_TYPES = ['memory', 'cpu', 'disk', 'process', 'restarts', 'apps', 'database', 'forge', 'code-review', 'health-settings', 'probe-unavailable'];
+// Probe failures are intentionally excluded: a missing measurement cannot be dismissed.
+export const SYSTEM_HEALTH_WARNING_TYPES = ['memory', 'cpu', 'disk', 'process', 'restarts', 'apps', 'database', 'forge', 'code-review', 'health-settings'];
export const systemHealthWarningParamsSchema = z.object({ type: z.enum(SYSTEM_HEALTH_WARNING_TYPES) });
export const systemHealthWarningDismissSchema = z.object({ message: z.string().trim().min(1).max(500) });
diff --git a/server/routes/health.test.js b/server/routes/health.test.js
index 9b839e9ec7..47f637bdd1 100644
--- a/server/routes/health.test.js
+++ b/server/routes/health.test.js
@@ -187,6 +187,20 @@ describe('System Health Routes', () => {
}
});
+ it('reports an unreadable PM2 as unavailable rather than zero processes (#8431)', async () => {
+ listProcessesStrict.mockResolvedValueOnce(null);
+ checkHealth.mockResolvedValueOnce({ connected: true, hasSchema: true });
+
+ const response = await request(app).get('/api/system/health/details');
+ expect(response.status).toBe(200);
+ expect(response.body.processes).toBeNull();
+ expect(response.body.topProcesses).toBeNull();
+ expect(response.body.overallHealth).toBe('warning');
+ expect(response.body.warnings).toContainEqual(
+ { type: 'probe-unavailable', source: 'pm2', status: 'unavailable', severity: 'warning', message: 'Process manager (PM2) status unavailable', dismissible: false }
+ );
+ });
+
it('serves the running build on its own route (#4694)', async () => {
const response = await request(app).get('/api/system/build');
diff --git a/server/routes/systemHealth.js b/server/routes/systemHealth.js
index abd2ce68dc..355d453fea 100644
--- a/server/routes/systemHealth.js
+++ b/server/routes/systemHealth.js
@@ -1,7 +1,7 @@
import { Router } from 'express';
import os from 'os';
import { statfs } from 'fs/promises';
-import { listProcesses, listProcessesStrict } from '../services/pm2.js';
+import { listProcessesStrict } from '../services/pm2.js';
import { getAppStatusSummary, annotateExpectedExit } from '../services/appProcessStatus.js';
import * as cos from '../services/cos.js';
import { getSelf } from '../services/instanceIdentity.js';
diff --git a/server/services/pm2.js b/server/services/pm2.js
index b5f7314b05..f46e6de2d1 100644
--- a/server/services/pm2.js
+++ b/server/services/pm2.js
@@ -19,7 +19,7 @@ const jlistInflight = new Map();
const cacheKey = (pm2Home) => pm2Home || '_default';
// Track PM2 read failures per home so we log only on state change or reason change
-const jlistFailureState = new Map(); // home -> { lastError: string, lastLogged: number }
+const jlistFailureState = new Map(); // home -> { lastError: string }
/**
* Invalidate the jlist TTL cache (e.g. after mutations like start/stop/delete).
@@ -47,7 +47,7 @@ function logJlistFailure(pm2Home, errorReason) {
// Log only if no prior state, or if the reason changed
if (!state || state.lastError !== errorReason) {
console.error(`❌ PM2 read failed (home=${homeDesc}): ${errorReason}`);
- jlistFailureState.set(key, { lastError: errorReason, lastLogged: Date.now() });
+ jlistFailureState.set(key, { lastError: errorReason });
}
}
diff --git a/server/services/pm2.readFailureLog.test.js b/server/services/pm2.readFailureLog.test.js
new file mode 100644
index 0000000000..4ea76bd290
--- /dev/null
+++ b/server/services/pm2.readFailureLog.test.js
@@ -0,0 +1,38 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+const mocks = vi.hoisted(() => ({ connect: vi.fn(), list: vi.fn(), disconnect: vi.fn() }));
+vi.mock('pm2', () => ({ default: mocks }));
+import { clearJlistCache, listProcessesStrict } from './pm2.js';
+
+afterEach(() => {
+ vi.clearAllMocks();
+ vi.restoreAllMocks();
+ clearJlistCache();
+});
+
+// PM2 calls back asynchronously; a synchronous mock would resolve before the
+// in-flight entry is registered.
+const later = (fn) => (cb) => setImmediate(() => fn(cb));
+const readLines = (spy, marker) => spy.mock.calls.map(([line]) => line).filter((line) => line.includes(marker));
+
+describe('PM2 read failure logging (#8431)', () => {
+ it('logs a persistent failure once, a changed reason again, and one recovery line', async () => {
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
+ mocks.connect.mockImplementation(later((cb) => cb(new Error('connect ECONNREFUSED'))));
+
+ for (let i = 0; i < 3; i++) expect(await listProcessesStrict()).toBeNull();
+ expect(readLines(errorSpy, 'PM2 read failed')).toHaveLength(1);
+
+ mocks.connect.mockImplementation(later((cb) => cb(new Error('daemon timeout'))));
+ await listProcessesStrict();
+ expect(readLines(errorSpy, 'PM2 read failed')).toHaveLength(2);
+
+ mocks.connect.mockImplementation(later((cb) => cb(null)));
+ mocks.list.mockImplementation(later((cb) => cb(null, [])));
+ expect(await listProcessesStrict()).toEqual([]);
+ clearJlistCache();
+ await listProcessesStrict();
+ expect(readLines(logSpy, 'PM2 read recovered')).toHaveLength(1);
+ });
+});