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([issue-2991]): stop a quit game window from being relaunched or alerted on

[._.]/ Adam Eivy02bf97467374
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 1e2ef227a4..6bc56b1e2e 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -30,6 +30,10 @@
- **[issue-3014] See how many of the loop's approved proposals actually got delivered** — the Proposal outcomes panel showed only how many hand-offs succeeded *once attempted*, which read as a perfect score even when most approved proposals were sitting untouched. It now also shows an **approvals delivered** rate measured against every proposal you approved, so work that was approved and then quietly lost is visible instead of hidden behind the attempted-only number. The loop sees the same two rates (overall and per scope) when it reasons about what to propose next, so it can tell "you rejected my ideas" apart from "my ideas were accepted and never landed" and calibrate accordingly.
+## Managed apps
+
+- **[issue-2991] Starting a desktop app now shows what it's doing, and quitting it stays quit** — pressing **Start** on a managed desktop app (a game binary) opens a live panel showing the build output as it compiles and imports assets, so a launch that takes a minute before a window appears no longer looks like nothing happened. The panel switches from "Launching" to "Running" once the app is up, and you can dismiss it any time without stopping the app. Closing or force-quitting the app's window is now treated as the normal end of a session everywhere: PortOS will no longer silently relaunch the window you just closed, and quitting no longer shows up as an errored process or raises a failure alert. Apps that run in their own PM2 instance now stream their logs correctly instead of showing an empty panel.
+
## Music studio
- **[issue-2912] Chiptune score edits on two synced machines now show up as a real conflict** — if you compose a chiptune score for the same track on two federated installs before they sync with each other, that divergence now surfaces in Sharing → Conflicts (so you can review and choose which version to keep) instead of one edit silently overwriting the other.
diff --git a/server/services/apps.js b/server/services/apps.js
index 46871b851c..8b57794a84 100644
--- a/server/services/apps.js
+++ b/server/services/apps.js
@@ -2,7 +2,7 @@ import { join } from 'path';
import { v4 as uuidv4 } from '../lib/uuid.js';
import EventEmitter from 'events';
import { atomicWrite, ensureDir, readJSONFile, PATHS } from '../lib/fileUtils.js';
-import { NON_PM2_TYPES, usesPm2 } from './streamingDetect.js';
+import { NON_PM2_TYPES, usesPm2, isDesktopType } from './streamingDetect.js';
import { listProcessesStrict } from './pm2.js';
import { SELF_IMPROVEMENT_TASK_TYPES } from './taskSchedule.js';
import { sanitizeTaskMetadata } from '../lib/validation.js';
@@ -176,6 +176,32 @@ export async function getActiveApps() {
return getAllApps({ includeArchived: false });
}
+/**
+ * PM2 process names belonging to desktop (portless GUI) apps.
+ *
+ * A desktop process is launched with `autorestart: false` because the user
+ * closing the window is a normal exit — but that alone does NOT stop every
+ * relaunch path. Anything that reacts to an `errored` PM2 status by restarting
+ * it (the CoS health monitor) would reopen the game window, and anything that
+ * alerts on `errored` (proactive alerts) would report a quit as a failure.
+ * A force-quit or a non-zero exit lands in exactly that state, so those
+ * supervisors consult this set and skip desktop processes. See issue #2991.
+ *
+ * Archived apps are included: their PM2 entries can outlive the archive, and a
+ * stale entry must not become auto-restartable just because the app was hidden.
+ *
+ * @returns {Promise<Set<string>>} Process names to exempt from auto-restart/alerts.
+ */
+export async function getDesktopProcessNames() {
+ const apps = await getAllApps();
+ const names = new Set();
+ for (const app of apps) {
+ if (!isDesktopType(app.type)) continue;
+ for (const name of app.pm2ProcessNames || []) names.add(name);
+ }
+ return names;
+}
+
/**
* Summarize PM2-managed app status for dashboards.
*
diff --git a/server/services/apps.test.js b/server/services/apps.test.js
index 638d0852af..43d13d0dff 100644
--- a/server/services/apps.test.js
+++ b/server/services/apps.test.js
@@ -34,7 +34,7 @@ vi.mock('./pm2.js', () => ({
import { atomicWrite, readJSONFile } from '../lib/fileUtils.js';
import { listProcessesStrict } from './pm2.js';
import { resetExecutionHistory } from './taskSchedule.js';
-import { createApp, getAppStatuses, getAppStatusSummary, getReservedPorts, invalidateCache, PORTOS_APP_ID, updateAppTaskTypeOverride } from './apps.js';
+import { createApp, getAppStatuses, getAppStatusSummary, getDesktopProcessNames, getReservedPorts, invalidateCache, PORTOS_APP_ID, updateAppTaskTypeOverride } from './apps.js';
describe('pr-watcher cooldown reset', () => {
beforeEach(() => {
@@ -268,6 +268,57 @@ describe('portless / desktop apps (#2991)', () => {
const game = statuses.find(s => s.name === 'The Game');
expect(game.overallStatus).toBe('online');
});
+
+ // The set the CoS health monitor and proactive alerts consult so a quit game
+ // window is never auto-restarted or reported as a failure.
+ describe('getDesktopProcessNames', () => {
+ it('collects every PM2 name owned by a desktop app', async () => {
+ readJSONFile.mockResolvedValue({
+ apps: {
+ [PORTOS_APP_ID]: { name: 'PortOS', type: 'express', pm2ProcessNames: ['portos-server'] },
+ 'the-game': { name: 'The Game', type: 'desktop', pm2ProcessNames: ['the-game', 'the-game-alt'] },
+ },
+ });
+
+ const names = await getDesktopProcessNames();
+
+ expect(names).toEqual(new Set(['the-game', 'the-game-alt']));
+ // Web processes stay auto-restartable.
+ expect(names.has('portos-server')).toBe(false);
+ });
+
+ it('is empty when no desktop app is registered', async () => {
+ readJSONFile.mockResolvedValue({
+ apps: { [PORTOS_APP_ID]: { name: 'PortOS', type: 'express', pm2ProcessNames: ['portos-server'] } },
+ });
+
+ expect(await getDesktopProcessNames()).toEqual(new Set());
+ });
+
+ it('tolerates a desktop app with no process names', async () => {
+ readJSONFile.mockResolvedValue({
+ apps: {
+ [PORTOS_APP_ID]: { name: 'PortOS', type: 'express' },
+ 'the-game': { name: 'The Game', type: 'desktop' },
+ },
+ });
+
+ expect(await getDesktopProcessNames()).toEqual(new Set());
+ });
+
+ it('still exempts an archived desktop app whose PM2 entry outlived the archive', async () => {
+ // Archiving hides the app from the UI but does not delete its PM2 process;
+ // a leftover entry must not become auto-restartable as a side effect.
+ readJSONFile.mockResolvedValue({
+ apps: {
+ [PORTOS_APP_ID]: { name: 'PortOS', type: 'express' },
+ 'the-game': { name: 'The Game', type: 'desktop', archived: true, pm2ProcessNames: ['the-game'] },
+ },
+ });
+
+ expect(await getDesktopProcessNames()).toEqual(new Set(['the-game']));
+ });
+ });
});
describe('getAppStatusSummary', () => {
diff --git a/server/services/cosHealthMonitor.js b/server/services/cosHealthMonitor.js
index 979fd60f83..31b3cdb121 100644
--- a/server/services/cosHealthMonitor.js
+++ b/server/services/cosHealthMonitor.js
@@ -13,6 +13,7 @@ import { safeJSONParse } from '../lib/fileUtils.js';
import { getMemoryStats } from '../lib/memoryStats.js';
import { loadState, saveState, withStateLock, isDaemonRunning } from './cosState.js';
import { cosEvents, emitLog } from './cosEvents.js';
+import { getDesktopProcessNames } from './apps.js';
const _execFileAsync = promisify(execFile);
const execFileAsync = (cmd, args, opts) => _execFileAsync(cmd, args, { ...opts, windowsHide: true });
@@ -47,12 +48,32 @@ export async function runHealthCheck() {
const pm2Json = jsonStart >= 0 ? pm2Output.slice(jsonStart) : '[]';
const pm2Processes = safeJSONParse(pm2Json, [], { logError: true, context: 'pm2 process list' });
- const erroredProcesses = pm2Processes.filter(p => p.pm2_env?.status === 'errored');
+ // Desktop (GUI) processes are exempt from auto-restart: the user closing or
+ // force-quitting a game window can leave PM2 `errored`, and restarting it would
+ // reopen the window they just closed — the same relaunch loop `autorestart: false`
+ // prevents, arriving by another path. A registry read failure exempts nothing
+ // (empty set), so the pre-existing behavior stands rather than silently
+ // disabling auto-restart for every app. See issue #2991.
+ const desktopProcessNames = await getDesktopProcessNames().catch(err => {
+ console.error(`❌ Health monitor could not read the app registry: ${err.message}`);
+ return new Set();
+ });
+
+ const erroredProcesses = pm2Processes.filter(
+ p => p.pm2_env?.status === 'errored' && !desktopProcessNames.has(p.name)
+ );
+ // A quit game window counted toward `errored` would degrade the health metric
+ // for a normal user action, so desktop exits are reported separately instead of
+ // being folded into the error count (or silently dropped from the totals).
+ const desktopExited = pm2Processes.filter(
+ p => desktopProcessNames.has(p.name) && ['errored', 'stopped'].includes(p.pm2_env?.status)
+ ).length;
metrics.pm2 = {
total: pm2Processes.length,
online: pm2Processes.filter(p => p.pm2_env?.status === 'online').length,
errored: erroredProcesses.length,
- stopped: pm2Processes.filter(p => p.pm2_env?.status === 'stopped').length
+ stopped: pm2Processes.filter(p => p.pm2_env?.status === 'stopped').length,
+ desktopExited
};
// Check for runaway processes (too many)
diff --git a/server/services/cosHealthMonitor.test.js b/server/services/cosHealthMonitor.test.js
index 5da449d512..bda9aaf203 100644
--- a/server/services/cosHealthMonitor.test.js
+++ b/server/services/cosHealthMonitor.test.js
@@ -6,7 +6,18 @@ const mock = vi.hoisted(() => ({
savedState: null,
pm2Stdout: '[]',
restartImpl: null,
- events: []
+ events: [],
+ // PM2 process names belonging to desktop (GUI) apps — exempt from auto-restart.
+ desktopProcessNames: new Set(),
+ desktopLookupError: null
+}));
+
+// Mocked so the health check never reads the real apps registry off disk.
+vi.mock('./apps.js', () => ({
+ getDesktopProcessNames: vi.fn(async () => {
+ if (mock.desktopLookupError) throw mock.desktopLookupError;
+ return mock.desktopProcessNames;
+ })
}));
vi.mock('./cosState.js', () => ({
@@ -47,6 +58,8 @@ describe('cosHealthMonitor.runHealthCheck', () => {
mock.savedState = null;
mock.pm2Stdout = '[]';
mock.events = [];
+ mock.desktopProcessNames = new Set();
+ mock.desktopLookupError = null;
// default execFile success
mock.restartImpl = (cmd, args, opts, cb) => cb(null, { stdout: 'restarted', stderr: '' });
});
@@ -61,7 +74,7 @@ describe('cosHealthMonitor.runHealthCheck', () => {
it('extracts the JSON array from pm2 output prefixed with ANSI noise', async () => {
mock.pm2Stdout = 'warning[{"name":"a","pm2_env":{"status":"online"},"monit":{"memory":1000}}]';
const { metrics } = await runHealthCheck();
- expect(metrics.pm2).toEqual({ total: 1, online: 1, errored: 0, stopped: 0 });
+ expect(metrics.pm2).toEqual({ total: 1, online: 1, errored: 0, stopped: 0, desktopExited: 0 });
});
it('flags a high process count over the configured limit', async () => {
@@ -86,6 +99,88 @@ describe('cosHealthMonitor.runHealthCheck', () => {
expect(mock.events.some(e => e.name === 'health:critical')).toBe(true);
});
+ // Desktop (GUI) processes: closing or force-quitting the window can leave PM2
+ // `errored`, and restarting would reopen the window the user just closed —
+ // the relaunch loop `autorestart: false` prevents, by another path (#2991).
+ describe('desktop (GUI) process exemption', () => {
+ const erroredGame = () => JSON.stringify([
+ { name: 'game', pm2_env: { status: 'errored' }, monit: { memory: 0 } }
+ ]);
+
+ it('never auto-restarts an errored desktop process', async () => {
+ mock.desktopProcessNames = new Set(['game']);
+ mock.pm2Stdout = erroredGame();
+ const restarted = [];
+ mock.restartImpl = (cmd, args, opts, cb) => {
+ restarted.push(args);
+ cb(null, { stdout: 'restarted', stderr: '' });
+ };
+
+ const { issues } = await runHealthCheck();
+
+ expect(restarted).toEqual([]);
+ expect(issues.some(i => /Auto-restarted/.test(i.message))).toBe(false);
+ });
+
+ it('reports a quit game separately instead of as an error', async () => {
+ mock.desktopProcessNames = new Set(['game']);
+ mock.pm2Stdout = erroredGame();
+
+ const { metrics } = await runHealthCheck();
+
+ expect(metrics.pm2.errored).toBe(0);
+ expect(metrics.pm2.desktopExited).toBe(1);
+ });
+
+ it('counts a cleanly stopped desktop process as exited too', async () => {
+ mock.desktopProcessNames = new Set(['game']);
+ mock.pm2Stdout = JSON.stringify([
+ { name: 'game', pm2_env: { status: 'stopped' }, monit: { memory: 0 } }
+ ]);
+
+ const { metrics } = await runHealthCheck();
+
+ expect(metrics.pm2.errored).toBe(0);
+ expect(metrics.pm2.desktopExited).toBe(1);
+ });
+
+ it('still auto-restarts non-desktop processes alongside an exempt one', async () => {
+ mock.desktopProcessNames = new Set(['game']);
+ mock.pm2Stdout = JSON.stringify([
+ { name: 'game', pm2_env: { status: 'errored' }, monit: { memory: 0 } },
+ { name: 'web', pm2_env: { status: 'errored' }, monit: { memory: 0 } }
+ ]);
+ const restarted = [];
+ mock.restartImpl = (cmd, args, opts, cb) => {
+ restarted.push(args[1]);
+ cb(null, { stdout: 'restarted', stderr: '' });
+ };
+
+ const { metrics, issues } = await runHealthCheck();
+
+ expect(restarted).toEqual(['web']);
+ expect(metrics.pm2.errored).toBe(1);
+ expect(issues.some(i => /Auto-restarted 1/.test(i.message))).toBe(true);
+ });
+
+ it('exempts nothing when the registry read fails (pre-existing behavior stands)', async () => {
+ mock.desktopLookupError = new Error('registry unreadable');
+ mock.pm2Stdout = JSON.stringify([
+ { name: 'web', pm2_env: { status: 'errored' }, monit: { memory: 0 } }
+ ]);
+ const restarted = [];
+ mock.restartImpl = (cmd, args, opts, cb) => {
+ restarted.push(args[1]);
+ cb(null, { stdout: 'restarted', stderr: '' });
+ };
+
+ const { metrics } = await runHealthCheck();
+
+ expect(restarted).toEqual(['web']);
+ expect(metrics.pm2.errored).toBe(1);
+ });
+ });
+
it('flags processes over the memory limit', async () => {
const overLimitBytes = 2048 * 1024 * 1024;
mock.pm2Stdout = JSON.stringify([{ name: 'hog', pm2_env: { status: 'online' }, monit: { memory: overLimitBytes } }]);
diff --git a/server/services/proactiveAlerts.js b/server/services/proactiveAlerts.js
index d8670b18ea..df5d3fd850 100644
--- a/server/services/proactiveAlerts.js
+++ b/server/services/proactiveAlerts.js
@@ -16,6 +16,7 @@ import os from 'os';
import { getGoals } from './identity.js';
import { getPerformanceSummary, getLearningSummary } from './taskLearning.js';
import { listProcesses } from './pm2.js';
+import { getDesktopProcessNames } from './apps.js';
import { getUsage } from './usage.js';
import { getCareSummary } from './tribe.js';
import { findUnansweredTribeThreads } from './tribeOutreach.js';
@@ -123,21 +124,26 @@ async function checkSystemHealth() {
});
}
- // PM2 process errors
+ // PM2 process errors. Desktop (GUI) processes are excluded: quitting a game
+ // window is a normal user action that can land PM2 in `errored` (a force-quit
+ // or non-zero exit), and alerting on it would report every play session's end
+ // as a failure. See issue #2991.
const processes = await listProcesses().catch(() => []);
- const errored = processes.filter(p => p.status === 'errored').length;
+ const desktopProcessNames = await getDesktopProcessNames().catch(() => new Set());
+ const alertable = processes.filter(p => !desktopProcessNames.has(p.name));
+ const errored = alertable.filter(p => p.status === 'errored').length;
if (errored > 0) {
alerts.push({
type: 'process_error',
severity: 'high',
title: `${errored} errored process${errored > 1 ? 'es' : ''}`,
- detail: `${errored} of ${processes.length} processes in error state`,
+ detail: `${errored} of ${alertable.length} processes in error state`,
link: '/apps',
- metadata: { errored, total: processes.length }
+ metadata: { errored, total: alertable.length }
});
}
- const crashing = processes.filter(p => (p.unstableRestarts || 0) > 0);
+ const crashing = alertable.filter(p => (p.unstableRestarts || 0) > 0);
if (crashing.length > 0) {
const total = crashing.reduce((sum, p) => sum + (p.unstableRestarts || 0), 0);
alerts.push({
diff --git a/server/services/proactiveAlerts.test.js b/server/services/proactiveAlerts.test.js
new file mode 100644
index 0000000000..004c55eb38
--- /dev/null
+++ b/server/services/proactiveAlerts.test.js
@@ -0,0 +1,97 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+const mock = vi.hoisted(() => ({
+ processes: [],
+ desktopProcessNames: new Set(),
+ desktopLookupError: null
+}));
+
+vi.mock('./identity.js', () => ({ getGoals: vi.fn(async () => []) }));
+vi.mock('./taskLearning.js', () => ({
+ getPerformanceSummary: vi.fn(async () => ({ byType: [] })),
+ getLearningSummary: vi.fn(async () => ({ byType: [] }))
+}));
+vi.mock('./pm2.js', () => ({ listProcesses: vi.fn(async () => mock.processes) }));
+vi.mock('./apps.js', () => ({
+ getDesktopProcessNames: vi.fn(async () => {
+ if (mock.desktopLookupError) throw mock.desktopLookupError;
+ return mock.desktopProcessNames;
+ })
+}));
+vi.mock('./usage.js', () => ({ getUsage: vi.fn(async () => ({ daily: [] })) }));
+vi.mock('./tribe.js', () => ({ getCareSummary: vi.fn(async () => ({ overdueCount: 0, overdue: [] })) }));
+vi.mock('./tribeOutreach.js', () => ({ findUnansweredTribeThreads: vi.fn(async () => []) }));
+// Keep memory/CPU below their warning thresholds so only process alerts surface.
+vi.mock('../lib/memoryStats.js', () => ({
+ getMemoryStats: vi.fn(async () => ({ used: 1, total: 100 }))
+}));
+
+import { generateAlerts } from './proactiveAlerts.js';
+
+const processAlerts = async () => {
+ const { alerts } = await generateAlerts();
+ return alerts.filter(a => a.type === 'process_error');
+};
+
+describe('proactiveAlerts — desktop (GUI) process exemption (#2991)', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ mock.processes = [];
+ mock.desktopProcessNames = new Set();
+ mock.desktopLookupError = null;
+ });
+
+ it('does not alert when the only errored process is a quit game window', async () => {
+ // Force-quitting a game leaves PM2 `errored`; that is a normal end to a play
+ // session, not a failure to notify about.
+ mock.processes = [{ name: 'game', status: 'errored' }];
+ mock.desktopProcessNames = new Set(['game']);
+
+ expect(await processAlerts()).toEqual([]);
+ });
+
+ it('still alerts on a genuinely errored web process', async () => {
+ mock.processes = [{ name: 'web', status: 'errored' }];
+
+ const alerts = await processAlerts();
+ expect(alerts).toHaveLength(1);
+ expect(alerts[0].metadata.errored).toBe(1);
+ });
+
+ it('excludes the desktop process from both the count and the total', async () => {
+ mock.processes = [
+ { name: 'game', status: 'errored' },
+ { name: 'web', status: 'errored' },
+ { name: 'api', status: 'online' }
+ ];
+ mock.desktopProcessNames = new Set(['game']);
+
+ const alerts = await processAlerts();
+ expect(alerts).toHaveLength(1);
+ // 1 of 2 — the game is not part of the denominator either, so the ratio
+ // the user reads is not diluted by an exempt process.
+ expect(alerts[0].metadata).toEqual({ errored: 1, total: 2 });
+ });
+
+ it('does not report a desktop app restart loop as crashing', async () => {
+ mock.processes = [{ name: 'game', status: 'online', unstableRestarts: 3 }];
+ mock.desktopProcessNames = new Set(['game']);
+
+ expect(await processAlerts()).toEqual([]);
+ });
+
+ it('still reports unstable restarts for a non-desktop process', async () => {
+ mock.processes = [{ name: 'web', status: 'online', unstableRestarts: 3 }];
+
+ const alerts = await processAlerts();
+ expect(alerts).toHaveLength(1);
+ });
+
+ it('alerts normally when the registry read fails (exempts nothing)', async () => {
+ mock.processes = [{ name: 'web', status: 'errored' }];
+ mock.desktopLookupError = new Error('registry unreadable');
+
+ const alerts = await processAlerts();
+ expect(alerts).toHaveLength(1);
+ });
+});