codex-plugin-cc icon indicating copy to clipboard operation
codex-plugin-cc copied to clipboard

fix: use a deterministic Windows shell for broker spawns (#236)

Open nategarelik opened this issue 4 months ago • 0 comments

Problem

Fixes #236 (broker hangs at "Initializing..." on Windows).

app-server.mjs spawns codex app-server with shell: process.env.SHELL || true on win32 (and lib/process.mjs runCommand has the same pattern). An arbitrary, unvalidated SHELL (git-bash, a WSL shim, an untranslated POSIX literal like /usr/bin/bash) then wraps the JSON-RPC stdio pipe. Depending on the value this yields ENOENT or a wrapped pipe, and it silently breaks terminateProcessTree, whose cleanup logic assumes the direct child is cmd.exe.

Regression chain

  • #55 introduced shell: process.platform === "win32" (deterministic) to fix ENOENT on npm .cmd shims.
  • #178 (for #138) changed it to process.env.SHELL || true. The outer spawn shell option only resolves the codex executable; it has no bearing on the shell Codex uses internally for its command tool (SHELL already flows through env passthrough), so #138's actual concern was unaffected by this option — but the change exposed the wrapper to arbitrary SHELL values.
  • During review of this fix, we found shell: true is itself not deterministic: Node resolves it via process.env.ComSpec, so a nonstandard ComSpec (PowerShell, git-bash) reproduces the hang through a second env var.

Fix (2 commits)

  1. Stop honoring SHELL for the spawn wrapper (revert to platform-boolean).
  2. Harden to a fully deterministic shell: new resolveWindowsShell() returns %SystemRoot%\System32\cmd.exe (SystemRoot is kernel-set, not a dev-tooling convention like SHELL/ComSpec). Explicit options.shell overrides in runCommand are preserved; non-win32 behavior unchanged. SHELL still reaches Codex via env passthrough, so internal shell selection (#138) is unaffected.

Verification

  • Windows 11, codex-cli 0.144.0: multi-variant spawn repro (SHELL unset / POSIX literal / translated path) demonstrated the failure modes before the fix.
  • Test suite: the previously failing cancel sends turn interrupt to the shared app-server before killing a brokered task (taskkill/terminateProcessTree path) flips to passing; no other test status changes.
  • Live headless round trip through the production broker path: ensureBrokerSession -> broker -> codex app-server -> initialize -> thread/start -> turn/start -> turn/completed -> clean shutdown, no orphaned processes.

nategarelik avatar Jul 12 '26 21:07 nategarelik