fix: honor BROWSE_PARENT_PID=0 with trailing whitespace

The strict string compare `process.env.BROWSE_PARENT_PID === '0'` meant
any stray newline or whitespace (common from shell `export` in a pipe or
heredoc) would fail the check and re-enable the watchdog against the
caller's intent.

Switch to parseInt + === 0, matching the server's own parseInt at
server.ts:760. Handles '0', '0\n', ' 0 ', and unset correctly; non-numeric
values (parseInt returns NaN, NaN === 0 is false) fail safe — watchdog
stays active, which is the safe default for unexpected input.

Surfaced by /ship's adversarial subagent.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-04-17 05:54:17 +08:00
parent 378963f74c
commit d7349a1c6c
+3 -1
View File
@@ -214,7 +214,9 @@ async function startServer(extraEnv?: Record<string, string>): Promise<ServerSta
// BROWSE_PARENT_PID=0 in the environment. Useful for CI, non-interactive
// shells, and short-lived Bash invocations that need the server to outlive
// the spawning CLI. Defaults to the current process PID (watchdog active).
const parentPid = process.env.BROWSE_PARENT_PID === '0' ? '0' : String(process.pid);
// Parse as int so stray whitespace ("0\n") still opts out — matches the
// server's own parseInt at server.ts:760.
const parentPid = parseInt(process.env.BROWSE_PARENT_PID || '', 10) === 0 ? '0' : String(process.pid);
if (IS_WINDOWS && NODE_SERVER_SCRIPT) {
// Windows: Bun.spawn() + proc.unref() doesn't truly detach on Windows —