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([issue-968]): surface degraded PM2 status across client + detail endpoint (review: claude, codex)
Adam Eivy74725b1e7bd9
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex efc9cc3bc7..2c7dc1cb62 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,4 +2,4 @@## Fixed-- **[issue-968] A PM2 hiccup no longer makes running apps look offline** — when PortOS briefly can't read process state, affected apps now show as "status unavailable" instead of being silently reported as stopped, and the system health page flags the degraded read rather than quietly counting those apps as never started.+- **[issue-968] A PM2 hiccup no longer makes running apps look offline** — when PortOS briefly can't read process state, affected apps now show "status unavailable" instead of being silently reported as stopped. The Apps list and detail pages replace the (misleading) Start button with a refresh-to-retry control, the dashboard counts these separately, the system health page flags the degraded read, and CyberCity no longer rains on apps whose status simply couldn't be read.diff --git a/client/src/components/apps/AppDetailView.jsx b/client/src/components/apps/AppDetailView.jsxindex b56d3c0bee..1d23ce0b1e 100644--- a/client/src/components/apps/AppDetailView.jsx+++ b/client/src/components/apps/AppDetailView.jsx@@ -1,6 +1,6 @@import { useState, useEffect, useCallback, useMemo } from 'react';import { Link, useParams, useNavigate } from 'react-router-dom';-import { ArrowLeft, Play, Square, RotateCcw, ExternalLink, Hammer } from 'lucide-react';+import { ArrowLeft, Play, Square, RotateCcw, ExternalLink, Hammer, RefreshCw } from 'lucide-react';import DeployPanel from './DeployPanel';import toast from '../ui/Toast';import BrailleSpinner from '../BrailleSpinner';@@ -203,6 +203,18 @@ export default function AppDetailView() {<span className="text-xs">{actionLoading === 'restart' ? 'Restarting...' : 'Restart'}</span></button></>+ ) : (app.degraded || app.overallStatus === 'unknown') ? (+ // PM2 read failed — don't offer a misleading Start; surface the+ // gap and let the user re-check. Mirrors the Apps list page.+ <button+ onClick={fetchApp}+ disabled={actionLoading}+ className="px-2 py-1 bg-port-warning/20 text-port-warning enabled:hover:bg-port-warning/30 transition-colors disabled:opacity-50 flex items-center gap-1"+ title="PM2 status could not be read — refresh to retry"+ >+ <RefreshCw size={14} />+ <span className="text-xs">Status unavailable</span>+ </button>) : (<buttononClick={handleStart}diff --git a/client/src/components/city/CityScene.jsx b/client/src/components/city/CityScene.jsxindex 5e55f34d08..934048cc13 100644--- a/client/src/components/city/CityScene.jsx+++ b/client/src/components/city/CityScene.jsx@@ -105,7 +105,10 @@ export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus,setTransitioning(false);}, []);- const stoppedCount = apps.filter(a => !a.archived && a.overallStatus !== 'online').length;+ // Weather reflects confirmed outages. A PM2-unavailable ('unknown') app's+ // status is simply unknown, not down — excluded so a read blip doesn't+ // conjure rain/lightning over apps that may well be online.+ const stoppedCount = apps.filter(a => !a.archived && a.overallStatus !== 'online' && a.overallStatus !== 'unknown').length;const totalCount = apps.filter(a => !a.archived).length;// Quality presets always express dpr as a [min, max] pair. Cap it to the livediff --git a/client/src/components/city/cityConstants.js b/client/src/components/city/cityConstants.jsindex a56e534319..dd1d2f3f9f 100644--- a/client/src/components/city/cityConstants.js+++ b/client/src/components/city/cityConstants.js@@ -12,6 +12,9 @@ export const CITY_COLORS = {stopped: '#ef4444',not_started: '#8b5cf6',not_found: '#8b5cf6',+ // PM2 read failed — status unavailable. A muted amber-gray so it reads as+ // "unknown," distinct from the purple "never launched" buildings.+ unknown: '#9ca3af',archived: '#64748b',},buildingBody: '#0c0c24',@@ -149,6 +152,7 @@ export const BUILDING_PARAMS = {stopped: 2.5,not_started: 1.5,not_found: 1.5,+ unknown: 1.5,archived: 2.0,},processHeightBonus: 0.8,diff --git a/client/src/components/dashboard/builtins/QuickStatsWidget.jsx b/client/src/components/dashboard/builtins/QuickStatsWidget.jsxindex d56aa82f72..28c360be98 100644--- a/client/src/components/dashboard/builtins/QuickStatsWidget.jsx+++ b/client/src/components/dashboard/builtins/QuickStatsWidget.jsx@@ -8,6 +8,10 @@ export default function QuickStatsWidget({ dashboardState }) {<StatCard label="Online" value={appStats.online} icon="🟢" /><StatCard label="Stopped" value={appStats.stopped} icon="🟡" /><StatCard label="Offline" value={appStats.notStarted} icon="⚪" />+ {/* Only when a PM2 read failed — status unavailable, not confidently offline. */}+ {appStats.unknown > 0 && (+ <StatCard label="Status N/A" value={appStats.unknown} icon="⚠️" />+ )}</div></div>);diff --git a/client/src/pages/Apps.jsx b/client/src/pages/Apps.jsxindex 062e0d900d..8dac9dafdd 100644--- a/client/src/pages/Apps.jsx+++ b/client/src/pages/Apps.jsx@@ -289,6 +289,20 @@ export default function Apps() {<span className="text-xs">{actionLoading[app.id] === 'restart' ? 'Restarting...' : 'Restart'}</span></button></>+ ) : (app.degraded || app.overallStatus === 'unknown') ? (+ // PM2 read failed — status is genuinely unknown, so don't+ // offer a misleading Start. Surface "Status unavailable"+ // and let the user re-check rather than act on bad info.+ <button+ onClick={() => fetchApps()}+ disabled={actionLoading[app.id]}+ className="px-3 py-1.5 bg-port-warning/20 text-port-warning enabled:hover:bg-port-warning/30 transition-colors disabled:opacity-50 flex items-center gap-1 focus:outline-hidden focus:ring-2 focus:ring-port-warning"+ aria-label={`${app.name} status unavailable — refresh`}+ title="PM2 status could not be read — refresh to retry"+ >+ <RefreshCw size={14} aria-hidden="true" />+ <span className="text-xs">Status unavailable</span>+ </button>) : (<buttononClick={() => handleStart(app)}diff --git a/client/src/pages/Dashboard.jsx b/client/src/pages/Dashboard.jsxindex 5d23b9cad3..dca7435248 100644--- a/client/src/pages/Dashboard.jsx+++ b/client/src/pages/Dashboard.jsx@@ -156,6 +156,9 @@ export default function Dashboard() {online: activeApps.filter((a) => a.overallStatus === 'online').length,stopped: activeApps.filter((a) => a.overallStatus === 'stopped').length,notStarted: activeApps.filter((a) => a.overallStatus === 'not_started' || a.overallStatus === 'not_found').length,+ // PM2 read failed for these — status unavailable, NOT confidently stopped.+ // Counted so the buckets sum to `total` instead of silently dropping them.+ unknown: activeApps.filter((a) => a.degraded || a.overallStatus === 'unknown').length,}), [activeApps]);const dashboardState = useMemo(diff --git a/server/routes/apps.js b/server/routes/apps.jsindex b967494eb3..484e3320d1 100644--- a/server/routes/apps.js+++ b/server/routes/apps.js@@ -166,10 +166,17 @@ router.get('/:id', loadApp, asyncHandler(async (req, res) => {let statuses = {};let overallStatus = 'n/a';+ let degraded = false;if (usesPm2(app.type)) {- // Get PM2 status for each process (using app's custom PM2_HOME if set)+ // Get PM2 status for each process (using app's custom PM2_HOME if set).+ // A thrown getAppStatus is a failed read, not a confident "not running" —+ // mark `degraded` so the detail UI can disable lifecycle controls rather+ // than offer a misleading Start. Mirrors the list endpoint's `degraded`.for (const processName of app.pm2ProcessNames || []) {- const status = await pm2Service.getAppStatus(processName, app.pm2Home).catch(() => ({ status: 'unknown' }));+ const status = await pm2Service.getAppStatus(processName, app.pm2Home).catch(() => {+ degraded = true;+ return { status: 'unknown' };+ });statuses[processName] = status;}@@ -209,7 +216,7 @@ router.get('/:id', loadApp, asyncHandler(async (req, res) => {appVersion = pkg?.version || null;}- res.json({ ...app, uiPort, devUiPort, apiPort, overallStatus, pm2Status: statuses, appVersion, hasDeployScript: hasDeployScript(app), xcodeScripts: checkScripts(app) });+ res.json({ ...app, uiPort, devUiPort, apiPort, overallStatus, degraded, pm2Status: statuses, appVersion, hasDeployScript: hasDeployScript(app), xcodeScripts: checkScripts(app) });}));// POST /api/apps/:id/xcode-scripts/install - Install missing management scriptsdiff --git a/server/routes/apps.test.js b/server/routes/apps.test.jsindex 817c02d115..bb1efa5382 100644--- a/server/routes/apps.test.js+++ b/server/routes/apps.test.js@@ -176,6 +176,24 @@ describe('Apps Routes', () => {expect(response.body.pm2Status).toBeDefined();});+ it('returns degraded + unknown when the PM2 status read fails', async () => {+ const mockApp = {+ id: 'app-001',+ name: 'Test App',+ pm2ProcessNames: ['test-app']+ };+ appsService.getAppById.mockResolvedValue(mockApp);+ // Detail endpoint reads per-process status; a thrown read must surface+ // as degraded, not collapse into a confident not_started.+ pm2Service.getAppStatus.mockRejectedValue(new Error('pm2 daemon unreachable'));++ const response = await request(app).get('/api/apps/app-001');++ expect(response.status).toBe(200);+ expect(response.body.overallStatus).toBe('unknown');+ expect(response.body.degraded).toBe(true);+ });+it('should return 404 if app not found', async () => {appsService.getAppById.mockResolvedValue(null);