fix(core): fix panic after codex is updated with npm #6554
+773
−133
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #3051
Closes #4754
Closes #5098
Closes #2928
Summary
Users have been reporting panics when Codex uses the
apply_patchtool.✘ Failed to apply patch └ thread 'main' panicked at linux-sandbox/src/linux_run_main.rs:53:5: Failed to execvp ../lib/node_modules/@openai/.codex-{}/bin/codex-{} (deleted): No such file or directory (os error 2)When you look at the stacktrace, the error is deceptively simple: the Codex binary doesn't exist. However, the root cause is more involved.
When you install or update Codex using npm/bun, the package manager uses a temporary directory mechanism:
On install:
npm install -g @openai/codexOn upgrade:
npm install -g @openai/codex@latestWhy is this not a problem with other Node.js <> Rust CLIs? It is! But the error rate is more pronounced in Codex because:
apply_patchand the Linux sandbox.Reproduction
In the Codex repository:
cargo run --manifest-path codex-rs/Cargo.toml -p codex-tui --bin codex-tui --rm codex-rs/target/debug/codex-tuiSolution
There isn't a lot you can do to prevent this bug from occuring. Instead, we can do some work in Codex to make the failure mode more graceful and informative. (rather than an obscure panic and "not found")
Happy path: Binary was deleted, but another Codex exists on PATH.
Sad path: Binary was deleted, and no alternative exists on PATH.