Skip to content

Windows: unsloth start codex/pi can fail with WinError 193 when npm/pnpm extensionless shim is resolved before .cmd #9167

Closed

Description

@l33t3st

Summary

On Windows, unsloth start codex and unsloth start pi can fail with:

OSError: [WinError 193] %1 is not a valid Win32 application

The Unsloth server starts successfully, but the coding agent fails when subprocess.run() tries to launch the resolved agent executable.

This appears to happen when shutil.which() resolves the extensionless npm/pnpm POSIX shim before the sibling Windows .cmd shim.

Reproduction

For Codex, the installed commands were:

where.exe codex
C:\Program Files\nodejs\codex
C:\Program Files\nodejs\codex.cmd

PowerShell resolves the working wrappers correctly:

Get-Command codex -All

codex.ps1  -> C:\Program Files\nodejs\codex.ps1
codex.cmd  -> C:\Program Files\nodejs\codex.cmd
codex      -> C:\Program Files\nodejs\codex

and:

codex --version
codex-cli 0.147.0

Running:

unsloth start codex

starts the Unsloth server, then fails in unsloth_cli.commands.start._launch() at:

code = subprocess.run(launch_command, env = child_env).returncode

with:

OSError: [WinError 193] %1 is not a valid Win32 application

The same issue occurs with Pi. In that case the PATH contains multiple pnpm/node-managed shims, for example:

C:\Users\user\AppData\Local\pnpm\pi.ps1
C:\Users\user\AppData\Local\pnpm\pi.CMD
C:\Users\user\AppData\Local\pnpm\pi

C:\Users\user\AppData\Local\pi-node\current\pi.ps1
C:\Users\user\AppData\Local\pi-node\current\pi.cmd
C:\Users\user\AppData\Local\pi-node\current\pi

unsloth start pi fails at the same subprocess.run() / CreateProcess path with WinError 193.

Confirmed workaround

Renaming the extensionless shim so Windows/Unsloth resolves the .cmd sibling fixes the issue.

For example, this made Codex launch successfully:

Rename-Item "C:\Program Files\nodejs\codex" "codex.unix-shim"
unsloth start codex

The equivalent workaround also applies to Pi's extensionless pnpm shim.

Likely root cause

start.py already has Windows npm-shim handling in _resolved_launch_command() for .cmd / .bat files. However, _launch() resolves the executable first using shutil.which():

executable = _resolve_or_install_agent(command[0], install_hint, shutil.which)

If that returns the extensionless POSIX npm/pnpm shim, _resolved_launch_command() does not enter its existing .cmd/.bat handling and ultimately returns the extensionless path to subprocess.run(). Windows CreateProcess() then raises WinError 193.

Suggested fix

Before the existing .cmd/.bat handling in _resolved_launch_command(), prefer a sibling .cmd when the resolved Windows executable has no suffix:

if os.name == "nt" and not Path(executable).suffix:
    cmd = Path(str(executable) + ".cmd")
    if not cmd.is_file():
        cmd = Path(str(executable) + ".CMD")
    if cmd.is_file():
        executable = str(cmd)

Then the existing npm shim parser can continue normally.

Alternatively, the same normalization could be added to the common resolver, but doing it in _resolved_launch_command() appears to cover all launch paths and keeps the fix close to the existing Windows shim handling.

Environment

  • Windows
  • Python 3.12 (traceback from C:\Python312\Lib\subprocess.py)
  • Codex CLI 0.147.0
  • Affected commands observed: unsloth start codex, unsloth start pi

Happy to provide the full traceback or test a patch if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions