codex-plugin-cc
codex-plugin-cc copied to clipboard
fix: use a deterministic Windows shell for broker spawns (#236)
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.cmdshims. - #178 (for #138) changed it to
process.env.SHELL || true. The outer spawnshelloption only resolves the codex executable; it has no bearing on the shell Codex uses internally for its command tool (SHELLalready flows throughenvpassthrough), so #138's actual concern was unaffected by this option — but the change exposed the wrapper to arbitrarySHELLvalues. - During review of this fix, we found
shell: trueis itself not deterministic: Node resolves it viaprocess.env.ComSpec, so a nonstandard ComSpec (PowerShell, git-bash) reproduces the hang through a second env var.
Fix (2 commits)
- Stop honoring
SHELLfor the spawn wrapper (revert to platform-boolean). - 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). Explicitoptions.shelloverrides inrunCommandare preserved; non-win32 behavior unchanged.SHELLstill reaches Codex via env passthrough, so internal shell selection (#138) is unaffected.
Verification
- Windows 11, codex-cli 0.144.0: multi-variant spawn repro (
SHELLunset / 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.