Skip to content

fix(runtime): resolve codex .cmd shim path so Windows spawns don't fail#105

Merged
AbirAbbas merged 1 commit into
mainfrom
fix/codex-cmd-shim-windows-spawn
Jul 22, 2026
Merged

fix(runtime): resolve codex .cmd shim path so Windows spawns don't fail#105
AbirAbbas merged 1 commit into
mainfrom
fix/codex-cmd-shim-windows-spawn

Conversation

@AbirAbbas

Copy link
Copy Markdown
Collaborator

Summary

On Windows, every codex harness call fails instantly with [WinError 2] The system cannot find the file specified. _run_codex_cli_with_stdin in swe_af/runtime/codex_harness_patch.py spawns the bare "codex" name via asyncio.create_subprocess_exec, but CreateProcess does no PATHEXT resolution and npm installs the codex CLI only as a .cmd shim — so the spawn never finds it, even though the shell does.

The AgentField SDK already ships the fix for exactly this (agentfield.harness._cli.resolve_cli_command, which resolves the shim's real path via shutil.which and is a no-op on POSIX), but this monkeypatch bypasses the SDK's spawn path and never picked it up. Mac/Linux never hit the bug, which is how it went unnoticed.

Symptoms

  • Any reasoner using the codex runtime on a Windows node fails in ~500ms with its fallback result (e.g. retry advisor returns "Retry advisor agent failed to produce a valid analysis").
  • Node log shows Schema validation retry N/2: The output file was NOT created. followed by Schema retry N provider error: [WinError 2] The system cannot find the file specified.

Changes Made

  • Route cmd[0] through the SDK's resolve_cli_command before create_subprocess_exec (no-op on POSIX and for paths that already carry a separator).
  • Regression test asserting the spawn receives the resolved command, with args and stdin passthrough unchanged.

Test Plan

  • make check green (1130 passed, 1 skipped) on Python 3.12
  • Verified on a real Windows node: with this patch applied to the installed package, run_retry_advisor invoked with ai_provider=codex / model=gpt-5.6-luna returns real structured advice through the codex CLI (previously the instant WinError 2 fallback)

🤖 Generated with Claude Code

On Windows, npm installs the codex CLI only as a .cmd shim, and
create_subprocess_exec (CreateProcess) does no PATHEXT resolution —
_run_codex_cli_with_stdin spawned the bare "codex" name and failed with
FileNotFoundError ([WinError 2]) on every codex harness call. Each schema
attempt then surfaced as "Schema retry N provider error: [WinError 2]"
and reasoners fell back to their advisor-failure defaults in ~500ms.

Route cmd[0] through the AgentField SDK's resolve_cli_command, which
resolves the shim's real path via shutil.which and is a no-op on POSIX.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@AbirAbbas
AbirAbbas merged commit 5b4bf2b into main Jul 22, 2026
3 checks passed
@AbirAbbas
AbirAbbas deleted the fix/codex-cmd-shim-windows-spawn branch July 22, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant