Skip to content

fix(login): harden Windows Codex launcher resolution#142

Merged
Loongphy merged 20 commits into
mainfrom
issue-139
Jun 7, 2026
Merged

fix(login): harden Windows Codex launcher resolution#142
Loongphy merged 20 commits into
mainfrom
issue-139

Conversation

@Loongphy
Copy link
Copy Markdown
Owner

@Loongphy Loongphy commented Jun 5, 2026

Summary

Closes #139.

Windows codex-auth login now resolves Codex launchers from the verified installation paths:

  • WinGet: prefer codex.exe
  • npm: use codex.cmd when available, otherwise fall back to codex.ps1
  • ignore the bare codex shell script on Windows
  • respect PATH order, and within a directory respect the relevant PATHEXT order between codex.exe and codex.cmd
  • launch codex.cmd through cmd.exe /D /C
  • launch codex.ps1 through powershell.exe -NoLogo -NoProfile -File, falling back to pwsh.exe when needed
  • keep non-Windows behavior unchanged and continue launching bare codex

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 5, 2026

Open in StackBlitz

@loongphy/codex-auth-darwin-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-darwin-arm64@b7995d3

@loongphy/codex-auth-darwin-x64

npx https://pkg.pr.new/@loongphy/codex-auth-darwin-x64@b7995d3

@loongphy/codex-auth-linux-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-linux-arm64@b7995d3

@loongphy/codex-auth-linux-x64

npx https://pkg.pr.new/@loongphy/codex-auth-linux-x64@b7995d3

@loongphy/codex-auth-win32-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-win32-arm64@b7995d3

@loongphy/codex-auth-win32-x64

npx https://pkg.pr.new/@loongphy/codex-auth-win32-x64@b7995d3

@loongphy/codex-auth

npx https://pkg.pr.new/@loongphy/codex-auth@b7995d3

commit: b7995d3

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 5, 2026

Greptile Summary

This PR adds Windows-specific Codex launcher resolution to codex-auth login, scanning PATH for codex.exe, codex.cmd, codex.bat, and codex.ps1 in priority order (native binaries before PowerShell scripts globally), and driving .ps1 scripts through powershell.exe with an automatic fallback to pwsh.exe on AccessDenied.

  • src/cli/login.zig: New collectWindowsCodexPathsAlloc / buildWindowsCodexLaunchAlloc machinery; non-Windows path is unchanged.
  • src/cli/output.zig: New user-facing hint for the PowerShellNotFound error case.
  • tests/: New fake-codex binary, unit tests for resolution priority, and Windows-only integration tests covering all four launcher kinds.

Confidence Score: 4/5

Safe to merge for the .exe and .ps1 launch paths; the .cmd/.bat direct-launch branch has outstanding reliability concerns flagged in prior review threads that remain unaddressed.

The non-Windows path is unchanged. The .exe and .ps1 (powershell.exe → pwsh.exe) paths are correctly implemented with sound memory management and good test coverage. The .cmd/.bat direct-launch branch was challenged in previous review threads and those concerns are still present in the code, making the batch-file launch paths unreliable on Windows without a cmd.exe wrapper.

src/cli/login.zig — specifically the .cmd/.bat branches in buildWindowsCodexLaunchAlloc and shouldRetryWindowsCodexLaunch

Important Files Changed

Filename Overview
src/cli/login.zig Core Windows launcher resolution logic; .ps1 path (PowerShell → pwsh fallback) and .exe path appear correct, but the .cmd/.bat direct-launch branch has unresolved reliability issues noted in prior review threads.
src/cli/output.zig Adds PowerShellNotFound hint; text is accurate for the cases where it is actually shown.
tests/fake_codex.zig New test helper PE executable for the .exe launcher integration tests; correctly writes launcher/argv/home artefacts.
tests/cli_integration_test.zig Adds Windows-only integration tests for each launcher kind (cmd, bat, ps1, exe) and the ps1-before-exe priority scenario.
tests/cli_behavior_test.zig Adds unit tests for path resolution priority, hint rendering, and finalRetryableWindowsCodexLaunchFailure tiebreak logic.
src/workflows/preflight.zig Adds error.PowerShellNotFound to handled CLI errors; minimal and correct change.
build.zig Adds fake-codex test helper executable to the build graph; wired correctly into the test-helpers step.
tests/workflows_live_test.zig Adds a live test confirming error.PowerShellNotFound is a handled CLI error.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[runCodexLogin on Windows] --> B[collectWindowsCodexPathsAlloc\nscan PATH for codex.*]
    B --> C{Any candidates?}
    C -- No --> D[hint: FileNotFound\nreturn error]
    C -- Yes --> E[Iterate candidates\n.exe / .cmd / .bat first\n.ps1 last globally]
    E --> F[buildWindowsCodexLaunchAlloc]
    F -- .exe / .cmd / .bat --> G[argv: path login args]
    F -- .ps1 --> H[buildWindowsPowerShellCodexLaunchAlloc\nprefer powershell.exe]
    G --> I[std.process.spawn]
    H --> I
    I -- Success --> J[child.wait → ensureCodexLoginSucceeded]
    J --> K[return nil / exit code error]
    I -- AccessDenied + ps1 + powershell.exe --> L[rebuild with pwsh.exe]
    L -- pwsh found --> I
    L -- pwsh not found --> M[last_retryable_build_error\ncontinue candidate_loop]
    I -- FileNotFound or AccessDenied other --> N[last_retryable_spawn_error\ncontinue candidate_loop]
    I -- other error --> O[hint + return error]
    E -- all candidates exhausted --> P[finalRetryableWindowsCodexLaunchFailure]
    M --> P
    N --> P
    P --> Q[write hint + return error]
Loading

Reviews (9): Last reviewed commit: "fix(login): bypass PowerShell script pol..." | Re-trigger Greptile

Comment thread src/cli/login.zig
Comment thread src/cli/login.zig
@Loongphy Loongphy merged commit 23f3857 into main Jun 7, 2026
13 checks passed
@Loongphy Loongphy deleted the issue-139 branch June 7, 2026 05:25
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.

bug: codex-auth login panics on Windows when codex is installed via npm

1 participant