Skip to content

Commit 8b49e99

Browse files
committed
fix: stop wrapping Windows spawns in process.env.SHELL
openai#236 reports the app-server broker hanging indefinitely at "Initializing..." on Windows with no error surfaced. The direct spawn path (used by the broker itself to launch `codex app-server`, and by runCommand for utilities like taskkill) wraps the child process with process.env.SHELL on win32, trusting whatever shell the user happens to have configured (git-bash, a WSL bash.exe shim, an unresolvable literal POSIX path, etc.) to correctly proxy a JSON-RPC stdio pipe. That is unpredictable: it can silently swallow the handshake, fail with ENOENT, or otherwise misbehave depending on what SHELL resolves to, and the broker's own cleanup logic already assumed the spawned child was cmd.exe (see the terminateProcessTree comment in app-server.mjs), which breaks when SHELL points elsewhere. process.env.SHELL was added in openai#178 to fix openai#138, but that fix targeted the wrong layer: the outer spawn wrapper only resolves the codex executable itself (npm installs ship a .cmd shim that CreateProcess cannot exec directly) and has no bearing on what shell Codex uses internally for its own command-execution tool, since SHELL is already passed straight through via the `env` option regardless of this wrapper. Reverting to a deterministic cmd.exe wrapper on Windows fixes the hang without reopening openai#138. Verified: baseline test suite has 6 pre-existing failures including "cancel sends turn interrupt to the shared app-server before killing a brokered task" (a taskkill/terminateProcessTree test whose process tree assumptions broke exactly the way described above); with this fix that test passes and no other test regresses (5 failures remain, all pre-existing and unrelated: platform-mismatch path assertions, npm/setup env assumptions, Claude-session-transfer path assumptions). A live headless round trip against `codex app-server` (broker start, initialize, thread/start, turn/start, turn/completed, clean shutdown) also passes end to end.
1 parent db52e28 commit 8b49e99

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎plugins/codex/scripts/lib/app-server.mjs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,15 @@ class SpawnedCodexAppServerClient extends AppServerClientBase {
191191
cwd: this.cwd,
192192
env: this.options.env ?? process.env,
193193
stdio: ["pipe", "pipe", "pipe"],
194-
shell: process.platform === "win32" ? (process.env.SHELL || true) : false,
194+
// Always use the deterministic Windows shell (cmd.exe) to wrap this spawn, never
195+
// process.env.SHELL. This wrapper only resolves the codex executable (npm installs
196+
// ship a .cmd shim that CreateProcess cannot exec directly); it has no bearing on
197+
// what shell Codex uses internally for its own command-execution tool, since SHELL
198+
// is passed through via `env` above regardless of this option. Trusting an arbitrary
199+
// user-configured SHELL here (git-bash, WSL's bash.exe shim, an unresolvable literal
200+
// path, etc.) to wrap a JSON-RPC stdio pipe is unpredictable and can hang the
201+
// handshake indefinitely with no surfaced error (#236). See also #138/#178.
202+
shell: process.platform === "win32",
195203
windowsHide: true
196204
});
197205

‎plugins/codex/scripts/lib/process.mjs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export function runCommand(command, args = [], options = {}) {
99
input: options.input,
1010
maxBuffer: options.maxBuffer,
1111
stdio: options.stdio ?? "pipe",
12-
shell: options.shell ?? (process.platform === "win32" ? (process.env.SHELL || true) : false),
12+
// See app-server.mjs for why this stays off process.env.SHELL: an arbitrary
13+
// user-configured shell is not a safe or predictable wrapper for spawning
14+
// subprocesses on Windows (#236).
15+
shell: options.shell ?? process.platform === "win32",
1316
windowsHide: true
1417
});
1518

0 commit comments

Comments
 (0)