fix(server): distinguish missing cwd from missing binary in codex version check#1961
fix(server): distinguish missing cwd from missing binary in codex version check#1961sachssem wants to merge 1 commit intopingdotgg:mainfrom
Conversation
…sion check assertSupportedCodexCliVersion passes the project directory as cwd to spawnSync. When that directory no longer exists, Node emits ENOENT which the existing check misattributes to the Codex CLI binary being missing, producing the misleading "Codex CLI (codex) is not installed or not executable" error. When an ENOENT-class error occurs, verify whether the cwd is accessible before blaming the binary. This avoids a racy preflight check while still producing a clear "Working directory '…' does not exist or is not accessible" message for deleted or moved project folders. Adds a regression test that starts a session against a non-existent cwd and asserts the corrected error message. Fixes pingdotgg#975, fixes pingdotgg#1932
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved Straightforward bug fix that improves error message accuracy when a working directory doesn't exist during codex version check. The change is limited to an error handling path, doesn't affect normal runtime behavior, and includes a test to verify the new behavior. You can customize Macroscope's approvability policy. Learn more. |
What Changed
assertSupportedCodexCliVersionnow disambiguates ENOENT errors before blaming the binary. WhenspawnSyncfails with an ENOENT-class error, the handler checks whether the working directory is accessible. If the cwd is
the problem, the error message reports
"Working directory '…' does not exist or is not accessible"insteadof
"Codex CLI (codex) is not installed or not executable".The check runs only in the error path (not as a preflight), so there is no TOCTOU race.
Single-file production change in
codexAppServerManager.ts. One regression test added.Why
assertSupportedCodexCliVersionpasses the project directory ascwdtospawnSync. When that directory hasbeen deleted or moved, Node emits ENOENT. The existing error handler treats any ENOENT as a missing binary,
producing the misleading message
"Codex CLI (codex) is not installed or not executable"— even when the CLIis installed and on PATH.
This is confusing for users who see a "not installed" banner after simply moving a project folder.
Fixes #975, fixes #1932
Before / After
Before:

After:

Validation
bun fmt— cleanbun lint— cleancodexAppServerManagertests pass (1 new)Checklist
Note
Low Risk
Low risk: change is limited to the Codex CLI version-check error path and adds a single regression test; main behavior only differs when
spawnSyncfails with ENOENT-like errors.Overview
Improves
assertSupportedCodexCliVersionto disambiguate ENOENT-style failures by checkingcwdaccessibility before reporting a missing/unexecutable Codex CLI binary, surfacing a clearer “working directory does not exist or is not accessible” error when appropriate.Adds a regression test in
codexAppServerManager.test.tsto ensurestartSessionemitssession/startFailedand throws the new cwd-specific error when the providedcwdis missing.Reviewed by Cursor Bugbot for commit 2d0d25b. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix
assertSupportedCodexCliVersionto distinguish missing working directory from missing binaryWhen the Codex CLI version check fails with an ENOENT-like error, it was not clear whether the binary or the working directory was missing. Now, codexAppServerManager.ts checks
cwdaccessibility viafs.accessSyncbefore concluding the binary is absent, throwing a specific'Working directory ... does not exist or is not accessible.'error when the directory is the problem. A corresponding test case is added in codexAppServerManager.test.ts.Macroscope summarized 2d0d25b.