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: uniform parent PID output parsing across platforms for liveness probe

[._.]/ Adam Eivy3f2e6e2a5807
diff --git a/server/lib/README.md b/server/lib/README.md
index 4f5e1e9847..1daa6fbc9f 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -386,7 +386,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `prDisposition.js` | `resolvePrCompletion(metadata)` resolves the explicit `review-then-merge` / `merge-on-green` / `leave-open` policy, with legacy `reviewLoop` fallback; `leavesPrForHuman(task)` + `PR_STAYS_OPEN_TASK_TYPES` keep JIRA hand-offs open. Shared by the agent prompt builder and `agentWorktreeCleanup` so both halves agree. `resolvePrCreation({taskOpenPR, agentOwnsPr, prClaimVerified})` → a `PR_CREATION` tri-state (`never` / `if-missing` / `always`) naming who opens the change request for a completing worktree agent, so the runner, TUI, and direct-CLI completion paths cannot drift into double-firing `gh pr create`. |
| `shellCd.js` | `buildCdCommand(path, shell)` + `formatShellCommandLine(command, args, shell)` + `detectShellFlavor(shell, platform?)` + `quoteForShell(value, flavor, position?)` — build `cd` and arbitrary command-token lines for the shell a PTY session is ACTUALLY running (`cmd.exe` → Windows-escaped double quotes, PowerShell → doubled single quotes with `&` for a quoted command token, everything else → POSIX `shellQuote`). The Shell page's "cd to app" picker used to hard-code the POSIX form, which on Windows both mis-quoted the path and silently refused to cross drives (a bare `cd` does not switch drive). Flavor comes from the shell binary name, not the platform, so git-bash on Windows still gets POSIX quoting. `formatShellCommandLine` joins a command + argv into one quoted line and is shared by `agentTuiSpawning.js#buildTuiSpawnConfig` and the AI Providers page's "Launch in Shell" deep link, so a hand-launched TUI provider is quoted exactly the way the CoS runner would quote it. Renders the LINE only; the Enter byte that submits it is `SUBMIT_KEY` in `tuiHandshake.js`. |
| `shellExit.js` | `buildRunThenExitCommand(commandLine, shell)` — "run this CLI, then close the shell with its status", in the dialect the session speaks. An agent TUI shell exists only to host one CLI and must die with it. The POSIX `cmd; exit $?` was applied everywhere and is actively wrong off-POSIX: in PowerShell `$?` is a BOOLEAN, so `exit $?` reports success as 1 and failure as 0 (inverted) — use `$LASTEXITCODE`, pre-seeded to 1 so a command that never ran still exits non-zero; in cmd.exe `;` is an argument separator, so the CLI is handed `;`/`exit`/`$?` as arguments — use `& exit`. Verified against node-pty on Windows 11 for pwsh 7, PowerShell 5.1 and cmd.exe. |
-| `shellLivenessProbe.js` | `buildLivenessProbeCommand(shellPid, platform?)` + `parseLivenessProbeOutput(stdout, shellPid, platform?)` + `shellHasLiveChild(shellPid, opts?)` — platform-aware process-liveness probe for a launched TUI command in a persistent PTY shell. POSIX (`ps -Ao ppid=`) / Windows (`Get-CimInstance Win32_Process -Filter "ParentProcessId = <pid>"` via PowerShell). Resolves true (assume alive) when the probe fails or cannot run. |
+| `shellLivenessProbe.js` | `buildLivenessProbeCommand(shellPid, platform?)` + `parseLivenessProbeOutput(stdout, shellPid)` + `shellHasLiveChild(shellPid, opts?)` — platform-aware process-liveness probe for a launched TUI command in a persistent PTY shell. POSIX (`ps -Ao ppid=`) / Windows (`Get-CimInstance Win32_Process \| Select-Object -ExpandProperty ParentProcessId` via PowerShell). Resolves true (assume alive) when the probe fails or cannot run. |
| `shellQuote.js` | `shellQuote(value)` — POSIX single-quote escaping for values interpolated into shell command strings (display command lines, copy-paste blocks in agent prompts). Bare-safe tokens pass through; everything else is single-quoted. Canonical escaper — don't hand-roll. |
| `shellReadinessProbe.js` | `buildReadinessProbe(nonce, shell)` — the round-trip "can this shell actually run commands yet?" probe `createShellSession`'s `waitForPromptReady` sends and watches for, in the dialect the session speaks: POSIX `printf '%s\n' 'PORTOSRDY''<nonce>'` (unchanged), PowerShell `Write-Output ('PORTOSRDY' + '<nonce>')`, `cmd.exe` → `null` (no split-literal concatenation operator exists there, so the caller skips straight to the bounded fallback timer instead of risking an always-matching probe). The split-literal property is load-bearing in every dialect: the probe source never contains the assembled marker, so seeing it in the output can only mean the shell executed the probe. |
| `sidecarProcess.js` | `runSidecarProcess({bin,args,env,signal,onStage,onProcess})` + `parseSidecarResult(stdout)` — the shared Python-sidecar STAGE:/RESULT: wire-protocol runner (spawn, tail-capped stdout/stderr, per-STAGE-line callback, abort/SIGTERM → `canceled`, non-zero exit → stderr-tail reason). Used by `pipeline/musicGen.js` (all music backends) and `audioMidiTranscription.js` (MuScriptor). |
diff --git a/server/lib/shellLivenessProbe.js b/server/lib/shellLivenessProbe.js
index dbceaa5d95..e9d53c4cb5 100644
--- a/server/lib/shellLivenessProbe.js
+++ b/server/lib/shellLivenessProbe.js
@@ -14,7 +14,7 @@
* The probe is executed host-side via `execFile` from Node.js (not inside the PTY):
* • POSIX host (macOS / Linux): `ps -Ao ppid=` (lists parent PIDs)
* • Windows host: `powershell -NoProfile -NonInteractive -Command ...`
- * using `Get-CimInstance Win32_Process` filtered by ParentProcessId.
+ * using `Get-CimInstance Win32_Process | Select-Object -ExpandProperty ParentProcessId`.
*
* Resolves true (assume alive) if the probe fails or cannot run, so an environment
* glitch never blocks an otherwise-healthy run.
@@ -25,11 +25,11 @@ import { execFile } from './childProcess.js';
/**
* Build the file + argv for probing children of `shellPid`.
*
- * @param {number} shellPid - PID of the hosting shell process
+ * @param {number} _shellPid - PID of the hosting shell process
* @param {string} [platform=process.platform] - OS platform
* @returns {{ file: string, args: string[] }}
*/
-export function buildLivenessProbeCommand(shellPid, platform = process.platform) {
+export function buildLivenessProbeCommand(_shellPid, platform = process.platform) {
if (platform === 'win32') {
return {
file: 'powershell',
@@ -37,7 +37,7 @@ export function buildLivenessProbeCommand(shellPid, platform = process.platform)
'-NoProfile',
'-NonInteractive',
'-Command',
- `Get-CimInstance Win32_Process -Filter "ParentProcessId = ${shellPid}" | Select-Object -ExpandProperty ProcessId`,
+ 'Get-CimInstance Win32_Process | Select-Object -ExpandProperty ParentProcessId',
],
};
}
@@ -50,21 +50,12 @@ export function buildLivenessProbeCommand(shellPid, platform = process.platform)
/**
* Parse the output of the liveness probe.
*
- * @param {string} stdout - raw stdout from the probe command
+ * @param {string} stdout - raw stdout from the probe command (lines of PPIDs)
* @param {number} shellPid - PID of the hosting shell process
- * @param {string} [platform=process.platform] - OS platform
* @returns {boolean} true if child process(es) were found
*/
-export function parseLivenessProbeOutput(stdout, shellPid, platform = process.platform) {
- if (!stdout) return false;
- if (platform === 'win32') {
- return String(stdout)
- .split('\n')
- .some((line) => {
- const num = parseInt(line.trim(), 10);
- return Number.isFinite(num) && num > 0;
- });
- }
+export function parseLivenessProbeOutput(stdout, shellPid) {
+ if (!stdout || !shellPid) return false;
return String(stdout)
.split('\n')
.some((line) => {
@@ -90,7 +81,7 @@ export function shellHasLiveChild(shellPid, { platform = process.platform, execF
resolve(true);
return;
}
- resolve(parseLivenessProbeOutput(stdout, shellPid, platform));
+ resolve(parseLivenessProbeOutput(stdout, shellPid));
});
});
}
diff --git a/server/lib/shellLivenessProbe.test.js b/server/lib/shellLivenessProbe.test.js
index 202f01044a..ae110645a2 100644
--- a/server/lib/shellLivenessProbe.test.js
+++ b/server/lib/shellLivenessProbe.test.js
@@ -13,7 +13,7 @@ describe('buildLivenessProbeCommand', () => {
'-NoProfile',
'-NonInteractive',
'-Command',
- 'Get-CimInstance Win32_Process -Filter "ParentProcessId = 1234" | Select-Object -ExpandProperty ProcessId',
+ 'Get-CimInstance Win32_Process | Select-Object -ExpandProperty ParentProcessId',
]);
});
@@ -39,23 +39,16 @@ describe('buildLivenessProbeCommand', () => {
});
describe('parseLivenessProbeOutput', () => {
- it('parses POSIX ps output matching the shell pid', () => {
- expect(parseLivenessProbeOutput('1\n1\n1234\n999', 1234, 'darwin')).toBe(true);
- expect(parseLivenessProbeOutput('1\n1\n999', 1234, 'darwin')).toBe(false);
+ it('parses output matching the shell pid', () => {
+ expect(parseLivenessProbeOutput('1\n1\n1234\n999', 1234)).toBe(true);
+ expect(parseLivenessProbeOutput('1\n1\n999', 1234)).toBe(false);
});
- it('parses Windows powershell output returning child pids', () => {
- expect(parseLivenessProbeOutput('5678\n', 1234, 'win32')).toBe(true);
- expect(parseLivenessProbeOutput('5678\n9012\n', 1234, 'win32')).toBe(true);
- expect(parseLivenessProbeOutput('', 1234, 'win32')).toBe(false);
- expect(parseLivenessProbeOutput(' \n', 1234, 'win32')).toBe(false);
- expect(parseLivenessProbeOutput('ProcessId\n---------\n', 1234, 'win32')).toBe(false);
- });
-
- it('returns false for empty stdout on all platforms', () => {
- expect(parseLivenessProbeOutput('', 1234, 'darwin')).toBe(false);
- expect(parseLivenessProbeOutput(null, 1234, 'darwin')).toBe(false);
- expect(parseLivenessProbeOutput('', 1234, 'win32')).toBe(false);
+ it('returns false for empty or garbage output', () => {
+ expect(parseLivenessProbeOutput('', 1234)).toBe(false);
+ expect(parseLivenessProbeOutput(null, 1234)).toBe(false);
+ expect(parseLivenessProbeOutput(' \n', 1234)).toBe(false);
+ expect(parseLivenessProbeOutput('ProcessId\n---------\n', 1234)).toBe(false);
});
});
@@ -75,7 +68,7 @@ describe('shellHasLiveChild', () => {
expect(result).toBe(true);
});
- it('resolves true when POSIX ps detects a live child process', async () => {
+ it('resolves true when probe detects a live child process on POSIX', async () => {
const mockExec = vi.fn((_file, _args, _opts, cb) => cb(null, '1\n1234\n999\n'));
const result = await shellHasLiveChild(1234, {
platform: 'darwin',
@@ -84,7 +77,7 @@ describe('shellHasLiveChild', () => {
expect(result).toBe(true);
});
- it('resolves false when POSIX ps detects no child process', async () => {
+ it('resolves false when probe detects no child process on POSIX', async () => {
const mockExec = vi.fn((_file, _args, _opts, cb) => cb(null, '1\n999\n'));
const result = await shellHasLiveChild(1234, {
platform: 'darwin',
@@ -93,10 +86,10 @@ describe('shellHasLiveChild', () => {
expect(result).toBe(false);
});
- it('resolves true when Windows probe returns child processes', async () => {
+ it('resolves true when probe detects a live child process on Windows', async () => {
const mockExec = vi.fn((file, args, _opts, cb) => {
expect(file).toBe('powershell');
- cb(null, '4567\n');
+ cb(null, '1\n1234\n999\n');
});
const result = await shellHasLiveChild(1234, {
platform: 'win32',
@@ -105,10 +98,10 @@ describe('shellHasLiveChild', () => {
expect(result).toBe(true);
});
- it('resolves false when Windows probe returns empty stdout', async () => {
+ it('resolves false when probe detects no child process on Windows', async () => {
const mockExec = vi.fn((file, args, _opts, cb) => {
expect(file).toBe('powershell');
- cb(null, '\n');
+ cb(null, '1\n999\n');
});
const result = await shellHasLiveChild(1234, {
platform: 'win32',