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: keep Vite out of production startup (#8313)
[._.]/ Adam Eivyf7df70fcca9b
diff --git a/README.md b/README.mdindex aadb1c8dd3..e4824842d2 100644--- a/README.md+++ b/README.md@@ -331,7 +331,7 @@ After that, `https://<machine>.<tailnet>.ts.net:5555` is the user-facing URL onThe same walkthrough is always available in **Settings → Setup**. It verifies one runnable AI provider as well as secure remote access, and links directly to every action PortOS cannot perform at the account level. The Dashboard and Instances page surface the same network state; Unix and Windows update scripts retry certificate provisioning and print the guide after every update. See the [complete setup guide](./docs/SETUP.md).-PM2 keeps PortOS running in the background. To configure startup after a reboot, run `npm run pm2:startup` from the repository root and follow the platform-specific instructions it prints, then run `npm run pm2:save` to save the process list. `npm start` already saves the process list, but does not install the startup service.+PM2 keeps PortOS running in the background. To configure startup after a reboot, run `npm run pm2:startup` from the repository root and follow the platform-specific instructions it prints, then run `npm run pm2:save` to save the process list. `npm start`, `npm run pm2:start`, and `npm run pm2:restart` save the selected app set, but do not install the startup service.### Development Mode@@ -340,9 +340,9 @@ npm run setup # Install all dependencies (alias: npm run install:all)npm run dev # Starts PostgreSQL, launches full PM2 ecosystem, and tails logs```-`npm run dev` executes `scripts/dev-start.js` to initialize PostgreSQL, stop existing PM2 processes, and launch the complete PM2 process ecosystem defined in `ecosystem.config.cjs` (`portos-server`, `portos-cos`, `portos-ui`, `portos-autofixer`, `portos-autofixer-ui`, `portos-browser`) while tailing logs. The React frontend runs with Vite hot-reload on `:5554` and the API on `:5555`.+`npm run dev` executes `scripts/dev-start.js` to initialize PostgreSQL, stop existing PM2 processes, and launch the full development process set from `ecosystem.config.cjs` (`portos-server`, `portos-cos`, `portos-ui`, `portos-autofixer`, `portos-autofixer-ui`, `portos-browser`) while tailing logs. The React frontend runs with Vite hot-reload on `:5554` and the API on `:5555`.-`:5554` is the Vite server. In dev it is the active hot-reload frontend; in production (`npm start` / PM2) the React build is served from `:5555` directly, although the PM2 ecosystem still starts Vite on `:5554`.+`:5554` is the Vite development server. Production startup (`npm start`, `npm run pm2:start`, or either update path) selects the PM2 app set without `portos-ui`; startup and updates also remove an older `portos-ui` process. The production React build is served directly from `:5555`.## Network Access@@ -387,7 +387,7 @@ Run these from the repository root after setup. They use the PM2 bundled with Ponpm start # Build the client and start PortOSnpm run pm2:status # View statusnpm run pm2:logs -- portos-server --lines 100 # View server logs-npm run pm2:restart # Restart the PortOS ecosystem+npm run pm2:restart # Restart production apps (without Vite)npm run pm2:stop # Stop the PortOS ecosystemnpm run pm2:save # Save the process list for startup```diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.mdindex d8ff34a057..e6822d115c 100644--- a/docs/CONTRIBUTING.md+++ b/docs/CONTRIBUTING.md@@ -20,14 +20,11 @@ git clone https://github.com/atomantic/PortOS.gitcd PortOSnpm run install:all-# Start development+# Start development, including Vite on :5554npm run dev--# Or with PM2 directly-pm2 start ecosystem.config.cjs```-`npm run dev` executes `scripts/dev-start.js` to initialize PostgreSQL, stop any existing PM2 processes, and start the complete PM2 process ecosystem defined in `ecosystem.config.cjs` (`portos-server`, `portos-cos`, `portos-ui`, `portos-autofixer`, `portos-autofixer-ui`, `portos-browser`) while tailing logs.+`npm run dev` executes `scripts/dev-start.js` to initialize PostgreSQL, stop any existing PM2 processes, and start the full development process set defined in `ecosystem.config.cjs` (`portos-server`, `portos-cos`, `portos-ui`, `portos-autofixer`, `portos-autofixer-ui`, `portos-browser`) while tailing logs.**PostgreSQL is a mandatory dependency** — the server fails fast at boot without a healthy database. `npm run install:all` runs `npm run setup:db`, which provisions either the system PostgreSQL (`:5432`) or a Docker container (`:5561`, via `docker-compose.yml`). See [STORAGE.md](./STORAGE.md) and the [Postgres ADR](./decisions/2026-06-07-postgres-as-primary-datastore.md).diff --git a/docs/PM2.md b/docs/PM2.mdindex 30d6fe36fe..bd1d9042ed 100644--- a/docs/PM2.md+++ b/docs/PM2.md@@ -203,14 +203,17 @@ app uses in `ecosystem.config.cjs`.### Starting/Stopping```bash-# Start all processes defined in ecosystem file-pm2 start ecosystem.config.cjs+# Start production apps only; this also removes an old Vite process+npm run pm2:start-# Restart all processes-pm2 restart ecosystem.config.cjs+# Start development apps, including Vite on :5554+npm run dev++# Restart production apps+npm run pm2:restart# Stop all processes-pm2 stop ecosystem.config.cjs+npm run pm2:stop```### Monitoring@@ -232,13 +235,13 @@ pm2 logs myapp-server2. **Always use ecosystem file** for restart/stop operations:```bash- pm2 restart ecosystem.config.cjs # Correct+ npm run pm2:restart # Production apps onlypm2 restart all # Dangerous - affects all apps```3. **Use `pm2 save`** after changes to persist the process list:```bash- pm2 start ecosystem.config.cjs+ npm run pm2:startpm2 save```diff --git a/docs/PORTS.md b/docs/PORTS.mdindex 2296a9bba6..3e8be1b901 100644--- a/docs/PORTS.md+++ b/docs/PORTS.md@@ -26,7 +26,7 @@ Common port labels:| Port | Process | Label | Description ||------|---------|-------|-------------|| 5553 | portos-server | api-local | Loopback-only HTTP mirror of the API (only listens when HTTPS is active on 5555). Lets `http://localhost:5553` work without cert warnings. Override with `PORTOS_HTTP_PORT`. |-| 5554 | portos-ui | devUi | Vite dev server (React UI) — only present in `npm run dev`; `npm start` serves the built client from :5555 directly. |+| 5554 | portos-ui | devUi | Vite dev server (React UI) — selected only by `npm run dev`; production starts exclude it and remove any stale PM2 entry. || 5555 | portos-server | api | Main API server — **always the user-facing port**. Switches between HTTP and HTTPS based on whether `data/certs/{cert,key}.pem` exists. || 5556 | portos-browser | cdp | Chrome DevTools Protocol || 5557 | portos-browser | health | Browser health check API |@@ -63,7 +63,7 @@ vite dev (npm run dev) ──── :5554 ─ Vite dev server (dev only, separaRules of thumb:1. **`:5555` is the only port a remote user ever needs.** The scheme (HTTP vs HTTPS) flips based on whether a TLS cert is provisioned (`npm run setup:cert`); the port number does not.2. **`:5553` is a convenience for local terminals.** When HTTPS is on, `https://localhost:5555` would trip a cert warning (the cert covers `<machine>.<tailnet>.ts.net`, not `localhost`). The loopback HTTP mirror on `:5553` lets curl/scripts skip TLS entirely. It binds to `127.0.0.1` only — never reachable over the network.-3. **`:5554` is `vite dev` only.** In `npm run dev`, Vite serves the React UI from `:5554` and proxies `/api`, `/data` and `/socket.io` to `:5555`. In `npm start` (production), the React build is served from `:5555` itself; `:5554` is unused.+3. **`:5554` is `vite dev` only.** In `npm run dev`, Vite serves the React UI from `:5554` and proxies `/api`, `/data` and `/socket.io` to `:5555`. Production startup and update recovery select the non-Vite PM2 apps and remove any stale `portos-ui` entry; the React build is served from `:5555` and `:5554` is unused.- **A server-owned path must never be answered by an SPA fallback — and there are two of them.** Neither 404s. In dev, Vite answers an unproxied path with `index.html` and a `200`; in production the fallback in `server/index.js` skips a request only when its path carries a file extension, so an EXTENSIONLESS one falls through the same way. Either shape hands a binary loader HTML, which fails far from the cause (a missing `/data/image-to-3d` proxy entry surfaced as `Unexpected token '<' … is not valid JSON` from the GLB viewer, which took its whole route down), or hands an API client HTML with a success status.- **Dev side:** `/data` is proxied as one wildcard prefix, so a new mount is covered the moment it is added.- **Production side:** `server/lib/assetRoutePrefixes.js` lists the namespaces the server owns (`SERVER_OWNED_PREFIXES`) alongside the exact client routes inside them (`spaPaths` — `/data` itself is the Data Manager page), and `mountAssetRoutes` closes each one with a terminating 404 (#4688).diff --git a/docs/SELF_UPDATE.md b/docs/SELF_UPDATE.mdindex f3cecb4583..98a1c344a9 100644--- a/docs/SELF_UPDATE.md+++ b/docs/SELF_UPDATE.md@@ -107,7 +107,7 @@ The socket path runs `checkPortosUpdatePreflight` itself before it pulls — a rBecause the lock is taken in one place, the two entry points cannot run `update.sh` concurrently — and because that flag is what `subAgentSpawner`, `agentLifecycle` and `persistentMindSupervisor` gate on, holding it also stops a CoS agent from being spawned into a process the script is about to `pm2 delete` (#4124).-`appUpdater` also **skips its own `restart` step** for that case: the script runs `pm2 start ecosystem.config.cjs` itself, so restarting on top of it would be redundant and would race the script.+`appUpdater` also **skips its own `restart` step** for that case: the script starts the production app set from `ecosystem.config.cjs` itself, excluding `portos-ui`, so restarting on top of it would be redundant and would race the script.### Launch and completion are separate phases@@ -123,7 +123,7 @@ A PortOS record carrying a custom `updateCommand`, or a `repoPath` that is not t## Post-update health verification-`pm2 start` exiting 0 is not proof the server came back, and the process that would notice is the one that did not. Both platform scripts therefore close with a `verify` step that polls `/api/system/health` (`scripts/verify-server-health.js`) until it reports `ok` or the budget — `PORTOS_HEALTH_WAIT_MS`, default 120s — runs out. On failure they spend one more `pm2 start ecosystem.config.cjs` and then log the outcome loudly, with the manual recovery command.+`pm2 start` exiting 0 is not proof the server came back, and the process that would notice is the one that did not. Both platform scripts therefore close with a `verify` step that polls `/api/system/health` (`scripts/verify-server-health.js`) until it reports `ok` or the budget — `PORTOS_HEALTH_WAIT_MS`, default 120s — runs out. On failure they retry the production app set with `--only` (excluding Vite), then log the outcome loudly with the manual recovery command.The probe tries the loopback HTTP mirror (`:5553`) first, then the API port over HTTP and HTTPS, because the listening scheme depends on whether a cert is provisioned; `/api/system/health` is in the always-public set, so it works with the optional instance password on. The recovery only fires when the probe fails, so it cannot make a healthy update worse.diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.mdindex 209d086e28..a8dcff1238 100644--- a/docs/TROUBLESHOOTING.md+++ b/docs/TROUBLESHOOTING.md@@ -31,7 +31,7 @@ output is safe to paste into a bug report as-is.**Solution**:```bash-# Find what's using the port+# Find what's using the port (:5554 is only used by npm run dev)lsof -i :5554lsof -i :5555@@ -40,7 +40,7 @@ lsof -i :5555### PM2 Process Not Starting-**Symptom**: `pm2 start ecosystem.config.cjs` shows process but status is `errored`.+**Symptom**: `npm run pm2:start` shows a process but status is `errored`.**Solution**:```bash@@ -72,7 +72,7 @@ cp -r data.reference/* data/**Causes and Solutions**:1. **Tailscale not connected**: Ensure both devices are on same Tailscale network-2. **Firewall blocking**: Check local firewall allows ports 5554-5555+2. **Firewall blocking**: Check local firewall allows port 5555. Port 5554 is needed only while `npm run dev` is running.3. **Server bound to localhost**: PortOS should bind to 0.0.0.0 (default)```bash@@ -88,7 +88,7 @@ netstat -an | grep 5555**Solution**:- Check browser console for WebSocket errors- Verify server is running: `pm2 status`-- Restart server: `pm2 restart ecosystem.config.cjs`+- Restart server: `npm run pm2:restart`## Browser Console Warnings@@ -370,7 +370,7 @@ pm2 stop ecosystem.config.cjs**Solution**:```bash# Restart to pick up changes-pm2 restart ecosystem.config.cjs+npm run pm2:restart# For frontend changes, Vite hot-reload should work# For server changes, PM2 watch mode can help (if enabled)diff --git a/ecosystem.config.cjs b/ecosystem.config.cjsindex 1f7a8bc228..cc2675175f 100644--- a/ecosystem.config.cjs+++ b/ecosystem.config.cjs@@ -184,10 +184,9 @@ module.exports = {// wild is "SIGINT received" 5–30s after an image render completes,// killing in-flight jobs.//- // Code edits are picked up by a manual `pm2 restart ecosystem.config.cjs`- // — that's the documented workflow anyway (pm2 restart doesn't rebuild- // the client; you need npm run build / npm start). So losing the- // auto-restart-on-save behavior costs nothing in practice.+ // Code edits are picked up by `npm run pm2:restart` in production or+ // `npm run dev` during development. Restarting does not rebuild the+ // client; use `npm run build` / `npm start` for production assets.//// To re-enable for ad-hoc dev work: flip this to `watch: ['server']`// and add `'**/data/**'` (plus `'**/node_modules'`, `'**/logs/**'`,@@ -242,6 +241,7 @@ module.exports = {kill_timeout: 30000},{+ // Selected by `npm run dev`; production startup explicitly excludes Vite.name: 'portos-ui',script: path.join(__dirname, 'client', 'node_modules', 'vite', 'bin', 'vite.js'),cwd: path.join(__dirname, 'client'),diff --git a/package.json b/package.jsonindex ed4e39b6d4..88b5fac10f 100644--- a/package.json+++ b/package.json@@ -16,10 +16,10 @@"eval:agent-context": "node scripts/agent-context-eval.js","measure:agent-prompt": "node scripts/measure-agent-prompt.js","build": "npm run build --prefix client",- "start": "node scripts/checkNodeVersion.js && node scripts/checkNpmVersion.js && node scripts/ensure-deps.js && npm run build && node scripts/setup-db.js && node scripts/setup-cert.js && (node ./node_modules/pm2/bin/pm2 delete ecosystem.config.cjs --silent || echo pm2 delete skipped) && node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs && node ./node_modules/pm2/bin/pm2 save",- "pm2:start": "node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs",+ "start": "node scripts/checkNodeVersion.js && node scripts/checkNpmVersion.js && node scripts/ensure-deps.js && npm run build && node scripts/setup-db.js && node scripts/setup-cert.js && (node ./node_modules/pm2/bin/pm2 delete ecosystem.config.cjs --silent || echo pm2 delete skipped) && (node ./node_modules/pm2/bin/pm2 delete portos-ui --silent || echo pm2 delete skipped) && node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs --only \"portos-server,portos-cos,portos-autofixer,portos-autofixer-ui,portos-browser\" && node ./node_modules/pm2/bin/pm2 save",+ "pm2:start": "(node ./node_modules/pm2/bin/pm2 delete portos-ui --silent || echo pm2 delete skipped) && node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs --only \"portos-server,portos-cos,portos-autofixer,portos-autofixer-ui,portos-browser\" && node ./node_modules/pm2/bin/pm2 save","pm2:stop": "node ./node_modules/pm2/bin/pm2 stop ecosystem.config.cjs",- "pm2:restart": "node ./node_modules/pm2/bin/pm2 restart ecosystem.config.cjs",+ "pm2:restart": "(node ./node_modules/pm2/bin/pm2 delete portos-ui --silent || echo pm2 delete skipped) && node ./node_modules/pm2/bin/pm2 restart ecosystem.config.cjs --only \"portos-server,portos-cos,portos-autofixer,portos-autofixer-ui,portos-browser\" && node ./node_modules/pm2/bin/pm2 save","pm2:logs": "node ./node_modules/pm2/bin/pm2 logs","pm2:status": "node ./node_modules/pm2/bin/pm2 status","pm2:save": "node ./node_modules/pm2/bin/pm2 save",diff --git a/scripts/dev-start.js b/scripts/dev-start.jsindex 0e7124f838..79aa077145 100644--- a/scripts/dev-start.js+++ b/scripts/dev-start.js@@ -13,6 +13,14 @@ import { createRequire } from 'module';const require = createRequire(import.meta.url);const __dirname = dirname(fileURLToPath(import.meta.url));const ECO = 'ecosystem.config.cjs';+const DEV_PM2_APPS = [+ 'portos-server',+ 'portos-cos',+ 'portos-ui',+ 'portos-autofixer',+ 'portos-autofixer-ui',+ 'portos-browser'+];// Ensure dependencies are installed BEFORE resolving pm2 path// (pm2 lives in node_modules — require.resolve fails if deps are missing)@@ -43,8 +51,8 @@ try { pm2('delete', ECO); } catch {}// Brief pause for port releaseawait new Promise(r => setTimeout(r, 1500));-// Start fresh and tail logs-pm2('start', ECO);+// Start the full development set, including Vite on :5554, and tail logs.+pm2('start', ECO, '--only', DEV_PM2_APPS.join(','));spawn(process.execPath, [PM2, 'logs'], {stdio: 'inherit',windowsHide: truediff --git a/scripts/pm2-startup-contract.test.js b/scripts/pm2-startup-contract.test.jsnew file mode 100644index 0000000000..e0e7baec41--- /dev/null+++ b/scripts/pm2-startup-contract.test.js@@ -0,0 +1,66 @@+import { describe, expect, it } from 'vitest';+import { readFileSync } from 'fs';+import { createRequire } from 'module';+import { dirname, join } from 'path';+import { fileURLToPath } from 'url';++const require = createRequire(import.meta.url);+const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..');+const read = (file) => readFileSync(join(repoRoot, file), 'utf8');+const packageScripts = JSON.parse(read('package.json')).scripts;+const ecosystem = require(join(repoRoot, 'ecosystem.config.cjs'));+const appNames = ecosystem.apps.map(({ name }) => name);+const productionApps = appNames.filter((name) => name !== 'portos-ui');++describe('PM2 startup app sets', () => {+ it('keeps Vite in the development set and out of every production package command', () => {+ const devStart = read('scripts/dev-start.js');+ const devAppsSource = devStart.match(/const DEV_PM2_APPS = \[([\s\S]*?)\];/);+ const devApps = [...(devAppsSource?.[1] ?? '').matchAll(/'([^']+)'/g)].map(([, name]) => name);++ expect(devAppsSource).not.toBeNull();+ expect(devApps).toEqual(appNames);+ expect(devApps).toContain('portos-ui');+ expect(devStart).toContain("pm2('start', ECO, '--only', DEV_PM2_APPS.join(','));");++ for (const command of ['start', 'pm2:start', 'pm2:restart']) {+ const selection = packageScripts[command].match(/--only "([^"]+)"/);+ expect(selection?.[1].split(','), command).toEqual(productionApps);+ }+ });++ it('removes a stale Vite entry before production startup', () => {+ const start = packageScripts.start;+ expect(start.indexOf('pm2 delete ecosystem.config.cjs')).toBeGreaterThan(-1);+ expect(start.indexOf('pm2 delete ecosystem.config.cjs')).toBeLessThan(start.indexOf('pm2 start ecosystem.config.cjs'));++ for (const command of ['pm2:start', 'pm2:restart']) {+ expect(packageScripts[command].indexOf('pm2 delete portos-ui')).toBeGreaterThan(-1);+ const startAction = command === 'pm2:start' ? 'pm2 start ecosystem.config.cjs' : 'pm2 restart ecosystem.config.cjs';+ expect(packageScripts[command].indexOf('pm2 delete portos-ui')).toBeLessThan(packageScripts[command].indexOf(startAction));+ expect(packageScripts[command].indexOf('pm2 save')).toBeGreaterThan(packageScripts[command].indexOf(startAction));+ }+ });++ it('uses only production apps in both update scripts and their recovery starts', () => {+ const expectedApps = productionApps.join(',');+ const updateSh = read('update.sh');+ const shellStarts = updateSh.split('\n')+ .map((line) => line.trim())+ .filter((line) => line.includes('start ecosystem.config.cjs') && !line.startsWith('#') && !line.startsWith('log '));+ expect(updateSh).toContain(`PRODUCTION_PM2_APPS='${expectedApps}'`);+ expect(updateSh).toContain('delete portos-ui --silent || true');+ expect(shellStarts.length).toBeGreaterThanOrEqual(3);+ expect(shellStarts.every((line) => line.includes('--only "$PRODUCTION_PM2_APPS"'))).toBe(true);++ const updatePs1 = read('update.ps1');+ const powershellStarts = updatePs1.split('\n')+ .map((line) => line.trim())+ .filter((line) => line.includes('Invoke-Logged') && line.includes('start ecosystem.config.cjs'));+ expect(updatePs1).toContain(`$script:ProductionPm2Apps = '${expectedApps}'`);+ expect(updatePs1).toContain('delete portos-ui --silent');+ expect(updatePs1).toContain("@('start', $ecosystem, '--only', $script:ProductionPm2Apps)");+ expect(powershellStarts.length).toBeGreaterThanOrEqual(2);+ expect(powershellStarts.every((line) => line.includes('--only $script:ProductionPm2Apps'))).toBe(true);+ });+});diff --git a/server/services/appUpdater.js b/server/services/appUpdater.jsindex 2d6ff7f05a..1e077188be 100644--- a/server/services/appUpdater.js+++ b/server/services/appUpdater.js@@ -321,10 +321,11 @@ async function _doUpdate(app, emit, {steps.push({ step: 'app-update', success: true });}- // update.sh/update.ps1 close with their own `pm2 start ecosystem.config.cjs`- // (and their own dashboard handoff), so restarting PortOS on top of the- // detached script would be redundant and would race it — the script may not- // have finished re-registering the processes we would be restarting.+ // update.sh/update.ps1 close by starting the production app set from+ // `ecosystem.config.cjs` without `portos-ui` (and perform their own dashboard+ // handoff), so restarting PortOS on top of the detached script would be+ // redundant and would race it — the script may not have finished+ // re-registering the processes we would be restarting.const processNames = detachSelfUpdate ? [] : (app.pm2ProcessNames || []);if (processNames.length > 0) {emit('restart', 'running', 'Restarting app...');diff --git a/update.ps1 b/update.ps1index f390ae964d..fa6823405d 100644--- a/update.ps1+++ b/update.ps1@@ -94,6 +94,7 @@ function Invoke-Logged {# crash-looping app the user can see beats a silently headless machine — and the# recovery only ever runs on a path that was already leaving PortOS down.$script:Pm2AppsDown = $false+$script:ProductionPm2Apps = 'portos-server,portos-cos,portos-autofixer,portos-autofixer-ui,portos-browser'# Which pm2 the recovery can actually reach. It CANNOT assume this checkout's own# copy: Safe-Install wipes root node_modules whenever the pulled update touched@@ -132,7 +133,7 @@ function Restore-Pm2Apps {# a start that exits 0 and then crash-loops is the likely case here, not the# edge case. Never claim a recovery the health probe doesn't confirm.$ecosystem = Join-Path $RootDir 'ecosystem.config.cjs'- $startArgs = $pm2 + @('start', $ecosystem)+ $startArgs = $pm2 + @('start', $ecosystem, '--only', $script:ProductionPm2Apps)Invoke-Logged @startArgsif ($LASTEXITCODE -eq 0) { Invoke-Logged node (Join-Path $RootDir 'scripts/verify-server-health.js') }if ($LASTEXITCODE -eq 0) {@@ -145,7 +146,7 @@ function Restore-Pm2Apps {Write-SafeHost "❌ PortOS is not answering /api/system/health." -ForegroundColor Red# Name the pm2 that actually exists — the checkout's copy may be the# thing a failed install just deleted, so printing it would be a dead end.- Write-SafeHost " Recover with: $($pm2 -join ' ') start $ecosystem" -ForegroundColor Red+ Write-SafeHost " Recover with: $($pm2 -join ' ') start $ecosystem --only $script:ProductionPm2Apps" -ForegroundColor Red}} catch {# A throwing recovery must not replace the real update failure, and must@@ -374,6 +375,8 @@ Step "pm2-stop" "running" "Stopping PortOS apps..."$script:Pm2AppsDown = $trueInvoke-Logged node ./node_modules/pm2/bin/pm2 delete ecosystem.config.cjs --silent$global:LASTEXITCODE = 0+Invoke-Logged node ./node_modules/pm2/bin/pm2 delete portos-ui --silent+$global:LASTEXITCODE = 0Step "pm2-stop" "done" "Apps stopped"Write-SafeHost ""@@ -505,7 +508,9 @@ if ($LASTEXITCODE -eq 0) {$global:LASTEXITCODE = 0Invoke-Logged node ./node_modules/pm2/bin/pm2 delete ecosystem.config.cjs --silent$global:LASTEXITCODE = 0-Invoke-Logged node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs+Invoke-Logged node ./node_modules/pm2/bin/pm2 delete portos-ui --silent+$global:LASTEXITCODE = 0+Invoke-Logged node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs --only $script:ProductionPm2Appsif ($LASTEXITCODE -ne 0) {if (Test-Path "$RootDir\data\update-complete.json") {Remove-Item -Force "$RootDir\data\update-complete.json"@@ -530,7 +535,7 @@ if ($LASTEXITCODE -eq 0) {Step "verify" "done" "PortOS is answering /api/system/health"} else {Write-SafeHost "PortOS did not answer /api/system/health after the restart - re-running pm2 start" -ForegroundColor Yellow- Invoke-Logged node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs+ Invoke-Logged node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs --only $script:ProductionPm2Apps$global:LASTEXITCODE = 0Invoke-Logged node scripts/verify-server-health.jsif ($LASTEXITCODE -eq 0) {@@ -540,7 +545,7 @@ if ($LASTEXITCODE -eq 0) {$verifyFailed = 1Step "verify" "warning" "PortOS is not answering /api/system/health"Write-SafeHost "PortOS is STILL not answering /api/system/health." -ForegroundColor Red- Write-SafeHost " Recover with: node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs" -ForegroundColor Red+ Write-SafeHost " Recover with: node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs --only $script:ProductionPm2Apps" -ForegroundColor Red}}$global:LASTEXITCODE = 0diff --git a/update.sh b/update.shindex 6be277e19e..670e357a9a 100755--- a/update.sh+++ b/update.sh@@ -219,6 +219,7 @@ log ""# crash-looping app the user can see beats a silently headless machine — and the# recovery only ever runs on a path that was already leaving PortOS down.PM2_APPS_DOWN=0+PRODUCTION_PM2_APPS='portos-server,portos-cos,portos-autofixer,portos-autofixer-ui,portos-browser'# Which pm2 the recovery can actually reach. It CANNOT assume this checkout's# own copy: `safe_install .` wipes root node_modules whenever the pulled update@@ -263,7 +264,7 @@ restore_pm2_apps_on_exit() {# verify step below exists) — and this path starts a HALF-INSTALLED tree, so# a start that exits 0 and then crash-loops is the likely case here, not the# edge case. Never claim a recovery the health probe doesn't confirm.- if run "${PM2_CMD[@]}" start ecosystem.config.cjs && run node scripts/verify-server-health.js; then+ if run "${PM2_CMD[@]}" start ecosystem.config.cjs --only "$PRODUCTION_PM2_APPS" && run node scripts/verify-server-health.js; thenrun "${PM2_CMD[@]}" save || truestep "restart" "warning" "Update failed, but PortOS was restarted"log "✅ PortOS is answering /api/system/health again after the failed update."@@ -272,7 +273,7 @@ restore_pm2_apps_on_exit() {log "❌ PortOS is not answering /api/system/health."# Name the pm2 that actually exists — the checkout's copy may be the thing# a failed install just deleted, so printing it would be a dead-end hint.- log " Recover with: ${PM2_CMD[*]} start ecosystem.config.cjs"+ log " Recover with: ${PM2_CMD[*]} start ecosystem.config.cjs --only $PRODUCTION_PM2_APPS"fi# Recovery must never turn a failed update into a reported success.if [ "$status" -eq 0 ]; then status=1; fi@@ -298,6 +299,7 @@ step "pm2-stop" "running" "Stopping PortOS apps..."# that were never deleted is a harmless no-op restart on an already-failing path.PM2_APPS_DOWN=1run node ./node_modules/pm2/bin/pm2 delete ecosystem.config.cjs --silent || true+run node ./node_modules/pm2/bin/pm2 delete portos-ui --silent || truestep "pm2-stop" "done" "Apps stopped"log ""@@ -469,7 +471,8 @@ if run node scripts/pm2-daemon-refresh.js; thenrun node ./node_modules/pm2/bin/pm2 update || truefirun node ./node_modules/pm2/bin/pm2 delete ecosystem.config.cjs --silent || true-if ! run node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs; then+run node ./node_modules/pm2/bin/pm2 delete portos-ui --silent || true+if ! run node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs --only "$PRODUCTION_PM2_APPS"; thenrm -f "$ROOT_DIR/data/update-complete.json"exit 1fi@@ -490,7 +493,7 @@ if run node scripts/verify-server-health.js; thenstep "verify" "done" "PortOS is answering /api/system/health"elselog "⚠️ PortOS did not answer /api/system/health after the restart — re-running pm2 start"- run node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs || true+ run node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs --only "$PRODUCTION_PM2_APPS" || trueif run node scripts/verify-server-health.js; thenstep "verify" "done" "PortOS recovered after a second pm2 start"log "✅ PortOS recovered after a second pm2 start"@@ -498,7 +501,7 @@ elseverify_failed=1step "verify" "warning" "PortOS is not answering /api/system/health"log "❌ PortOS is STILL not answering /api/system/health."- log " Recover with: node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs"+ log " Recover with: node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs --only $PRODUCTION_PM2_APPS"fifilog ""