agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

[Bug]: Windows: Codex resolver prefers `codex.cmd` from anywhere on PATH over `codex.exe`, but supervise cannot launch `.cmd` — session exits silently in ~1.5 s with no child process

Open faogomes opened this issue 4 months ago • 6 comments

Summary

Two defects that only fail in combination, making every Codex session on an affected Windows machine exit silently ~1.5 s after spawn, with nothing run:

  1. Resolution: AO's Codex binary resolution searches the whole PATH for codex.cmd before codex.exe. Any codex.cmd anywhere on the daemon's PATH wins — even when a directory containing the native codex.exe comes first in PATH order. (A VS Code extension shim at %USERPROFILE%\.local\bin\codex.cmd is enough to trigger it.)
  2. Launch: AO's supervised launch chain (ao pty-host → ao agent-process supervise → <agent>) cannot start a .cmd child at all. A 100 ms process monitor during a real spawn shows pty-host and supervise starting and the ConPTY being created (conhost --headless), then no child process of any kind — no cmd.exe, no codex.exe. Supervise reports process-exited ~200 ms later; that exit is the session's only signal, so the session shows exited with nothing executed.

Notably, the daemon's own preflight (codex login status) runs the same .cmd fine — the defect is specific to the supervised agent launch.

Steps to reproduce

  1. Windows, AO 0.11.2, a daemon PATH where some directory contains codex.cmd (e.g. a VS Code extension shim or npm shim), and the native codex.exe directory listed earlier in PATH.
  2. Spawn a Codex worker session.
  3. Session exits ~1.5 s after spawn; first_signal_at equals the exited timestamp; no hooks fire, no file changes.

Proof by inversion: start the daemon with a PATH containing the native codex.exe directory and no codex.cmd anywhere → the same spawn goes working (hooks firing), completes its task, and ao session kill returns cleanly.

Ruled out by direct test: codex.exe stays alive ≥20 s under ao pty-host alone, under pty-host + supervise, with AO's full argv (hooks + trust_level + ~7 KB developer_instructions), in a git-worktree cwd, with and without a live daemon. Codex requires a TTY and AO's ConPTY provides one — a ConPTY-dimensions hypothesis was refuted.

Expected behavior

On Windows, prefer the native codex.exe over any .cmd shim (or at minimum honor PATH directory order); a resolved agent binary that supervise cannot launch should surface a launch error, not a silent instant exit.

Actual behavior

Session state exited ~1.5 s after spawn, no child process ever created, no error surfaced to the user.

AO version

0.11.2 (desktop app; bundled daemon resources\daemon\ao.exe)

Environment

Windows 10 Pro (10.0.19045) x64; ConPTY runtime; native codex.exe install plus a VS Code-extension codex.cmd shim elsewhere on PATH

Logs / extra context

  • Related: #2582 fixed .exe-vs-.cmd shadowing in the auth probe resolution; this report is the inverse preference (.cmd first) in the session launch path, plus the supervise layer's inability to start .cmd children at all.
  • A caution against fixing this by wrapping .cmd launches in cmd.exe /c: with the npm claude .cmd shim, Go's os/exec runs it through cmd.exe /c, and cmd.exe truncates AO's multi-line --append-system-prompt argument at the first newline — the agent then fails with Error: Input must be provided either through stdin or as a prompt argument when using --print. With the native claude.exe the same argv survives intact (verified on the live process command line). So .cmd shims are a bad launch target on Windows in general; preferring native .exe fixes both.
  • Duplicate search: #2582, #3396, #3326, #2832 — none cover the launch-path .cmd preference or the supervise .cmd launch failure.

faogomes avatar Jul 31 '26 19:07 faogomes

I've started investigating this. From the issue description, it looks like there are two separate behaviors involved:

The Windows resolver prefers a codex.cmd found anywhere on PATH over a native codex.exe. The supervised launch path cannot execute the resolved .cmd target, causing the session to exit immediately.

I'll trace the resolver and launch path to confirm where the .cmd preference is introduced before proposing a fix

dhruvil-codes avatar Aug 01 '26 08:08 dhruvil-codes

I've traced the Windows resolver to backend/internal/adapters/agent/codex/codex.go and added a regression test locally that models the reported PATH ordering (codex.exe in an earlier PATH directory, codex.cmd in a later one).

From the current resolver logic, it appears PATH precedence is violated because exec.LookPath is called separately for codex.cmd and codex.exe, allowing a later .cmd shim to win before an earlier native executable is considered.

I'm validating the behavior before proposing a fix.

dhruvil-codes avatar Aug 01 '26 08:08 dhruvil-codes

I opened a PR implementing a directory-first Windows PATH scan while preserving the existing native executable resolution logic. I'd appreciate any feedback on whether this matches the intended fix for #3409.

dhruvil-codes avatar Aug 01 '26 09:08 dhruvil-codes

Thanks for contributing to Agent Orchestrator.

This issue is being picked up by the current external contributor on-call pair:

  • @illegalcall
  • @pulkit7070

If someone is already working on this, please continue as usual. The on-call pair is added for visibility, tracking, and support, not to take over the work. If you need help with review, direction, reproduction, or next steps, please tag @illegalcall and @pulkit7070 here.

For faster context or live questions, you can also join the AO Discord.

Join the session here: https://discord.gg/H6ZDcUXmq

Come by if you want to see what is being built, ask questions, or just hang around with the community.

somewherelostt avatar Aug 01 '26 15:08 somewherelostt

Closing as a duplicate of #5323. Windows Codex resolution and shim launch remain tracked there.

Rishet11 avatar Oct 13 '26 20:10 Rishet11

i checked this on windows and found that ao can pick codex.cmd ahead of codex.exe even when the exe comes first in path. my codex session did not exit as described, so i can confirm the path ordering part from my side, but not the launch failure.

codebanditssss avatar Oct 29 '26 16:10 codebanditssss