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(review): gate max_memory_restart off for desktop apps and broaden single-instance guard (#2991)
[._.]/ Adam Eivy9494bff7aac5
diff --git a/server/routes/apps/lifecycle.js b/server/routes/apps/lifecycle.jsindex b15ddafbdb..adfeb0b938 100644--- a/server/routes/apps/lifecycle.js+++ b/server/routes/apps/lifecycle.js@@ -71,11 +71,13 @@ router.post('/:id/start', loadApp, asyncHandler(async (req, res) => {for (let i = 0; i < processNames.length; i++) {const name = processNames[i];const command = commands[i] || commands[0];- // Single instance: a desktop/GUI process that is already online must not be- // relaunched into a second window — reflect the live process state instead.+ // Single instance: a desktop/GUI process that is already up — or in a+ // transient coming-up state — must not be relaunched into a second window.+ // Match every "already running or about to be" PM2 status, not just the+ // steady `online`, so a click during a slow launch can't spawn a duplicate.if (desktop) {const current = await pm2Service.getAppStatus(name, app.pm2Home).catch(() => null);- if (current?.status === 'online') {+ if (['online', 'launching', 'restarting', 'waiting_restart'].includes(current?.status)) {results[name] = { success: true, alreadyRunning: true };continue;}diff --git a/server/routes/apps/lifecycle.test.js b/server/routes/apps/lifecycle.test.jsindex 48d7283f30..3d45362869 100644--- a/server/routes/apps/lifecycle.test.js+++ b/server/routes/apps/lifecycle.test.js@@ -129,6 +129,27 @@ describe('Apps Lifecycle Routes', () => {// Single instance: no second launch.expect(pm2Service.startWithCommand).not.toHaveBeenCalled();});++ it('treats a transient launching state as already-running (no duplicate window, #2991)', async () => {+ const mockApp = {+ id: 'game-001',+ name: 'The Game',+ type: 'desktop',+ repoPath: '/tmp',+ pm2ProcessNames: ['the-game'],+ startCommands: ['./scripts/game run']+ };+ appsService.getAppById.mockResolvedValue(mockApp);+ // A slow launch is mid-flight — a second Start click must not spawn a duplicate.+ pm2Service.getAppStatus.mockResolvedValue({ status: 'launching' });+ history.logAction.mockResolvedValue();++ const response = await request(app).post('/api/apps/game-001/start');++ expect(response.status).toBe(200);+ expect(response.body.results['the-game']).toEqual({ success: true, alreadyRunning: true });+ expect(pm2Service.startWithCommand).not.toHaveBeenCalled();+ });});describe('POST /api/apps/:id/stop', () => {diff --git a/server/services/pm2.js b/server/services/pm2.jsindex 987d7c8dff..9fe251d62b 100644--- a/server/services/pm2.js+++ b/server/services/pm2.js@@ -501,9 +501,14 @@ export async function startWithCommand(name, cwd, command, options = {}) {watch: false,autorestart,// Restart tuning only matters when autorestart is on; a desktop process- // exiting cleanly should stay stopped, not be nursed back up.- ...(autorestart ? { max_restarts: maxRestarts, min_uptime: '10s', restart_delay: 5000 } : {}),- max_memory_restart: '500M',+ // exiting cleanly should stay stopped, not be nursed back up. This+ // includes max_memory_restart: PM2's memory monitor relaunches the+ // process independently of autorestart, so leaving a 500M cap on a+ // desktop app (a game window routinely exceeds it) would kill and+ // respawn the live window — exactly the relaunch loop this avoids.+ ...(autorestart+ ? { max_restarts: maxRestarts, min_uptime: '10s', restart_delay: 5000, max_memory_restart: '500M' }+ : {}),windowsHide: IS_WIN};