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(cos): auto-restart errored PM2 processes during health check

Adam Eivy8a2f0d626c00
diff --git a/.changelog/v0.13.x.md b/.changelog/v0.13.x.md
index b46bbe6334..f28ba0d709 100644
--- a/.changelog/v0.13.x.md
+++ b/.changelog/v0.13.x.md
@@ -115,6 +115,12 @@ This release expands the genome dashboard with comprehensive cancer predispositi
- **Enabled `job-github-repo-maintenance`** — activated the unified GitHub repo maintenance job for weekly automated audits covering security alerts, stale dependencies, missing CI/README/license, uncommitted local changes, and stale branches
- Cleaned up stale `job-git-maintenance` data entry left behind after the merge
+### CoS Health Check — Auto-restart Errored PM2 Processes
+- **Automated recovery for errored PM2 processes** — the health check now auto-restarts any process in `errored` state instead of just reporting it as an issue
+- Attempts `pm2 restart <name>` for each errored process and logs success/failure per process
+- Failed restarts surface as `error` issues; successful restarts surface as `warning` issues so the UI reflects what happened
+- Eliminates manual intervention for transient crashes (e.g., bituniverse) that PM2's built-in `max_restarts` has already exhausted
+
### PM2 Standardizer Reliability
- **Fixed timeout race condition** in `executeCliAnalysis` — the promise could be rejected twice (once by timeout, once by the killed child's close event); now uses a `settled` guard and clears the timer on completion
- **Increased default timeout** from 120s to 180s for both CLI and API providers — CLI LLM analysis of projects without existing ecosystem configs often exceeds 2 minutes
diff --git a/server/services/cos.js b/server/services/cos.js
index e3f946e3f1..c48999366e 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -1968,14 +1968,40 @@ export async function runHealthCheck() {
});
}
- // Check for errored processes
+ // Check for errored processes and auto-restart them
const erroredProcesses = pm2Processes.filter(p => p.pm2_env?.status === 'errored');
if (erroredProcesses.length > 0) {
- issues.push({
- type: 'error',
- category: 'processes',
- message: `${erroredProcesses.length} errored PM2 processes: ${erroredProcesses.map(p => p.name).join(', ')}`
- });
+ const names = erroredProcesses.map(p => p.name);
+ emitLog('warn', `🔄 ${names.length} errored PM2 process(es) detected: ${names.join(', ')} — attempting restart`);
+
+ const restartResults = await Promise.all(names.map(async (name) => {
+ const result = await execAsync(`pm2 restart ${name} 2>&1`).catch(e => ({ stdout: '', stderr: e.message }));
+ const failed = result.stderr && !result.stdout;
+ if (failed) {
+ emitLog('error', `❌ Failed to restart ${name}: ${result.stderr}`);
+ } else {
+ emitLog('success', `✅ Auto-restarted errored process: ${name}`);
+ }
+ return { name, success: !failed };
+ }));
+
+ const failedRestarts = restartResults.filter(r => !r.success);
+ if (failedRestarts.length > 0) {
+ issues.push({
+ type: 'error',
+ category: 'processes',
+ message: `${failedRestarts.length} errored PM2 process(es) failed to auto-restart: ${failedRestarts.map(r => r.name).join(', ')}`
+ });
+ }
+
+ const succeededRestarts = restartResults.filter(r => r.success);
+ if (succeededRestarts.length > 0) {
+ issues.push({
+ type: 'warning',
+ category: 'processes',
+ message: `Auto-restarted ${succeededRestarts.length} errored PM2 process(es): ${succeededRestarts.map(r => r.name).join(', ')}`
+ });
+ }
}
// Check memory usage per process