Skip to content

chore: split apply_patch logic out of codex.rs and into apply_patch.rs#1703

Merged
bolinfest merged 1 commit into
mainfrom
pr1703
Jul 28, 2025
Merged

chore: split apply_patch logic out of codex.rs and into apply_patch.rs#1703
bolinfest merged 1 commit into
mainfrom
pr1703

Conversation

@bolinfest

@bolinfest bolinfest commented Jul 28, 2025

Copy link
Copy Markdown
Collaborator

This is a straight refactor, moving apply-patch-related code from codex.rs and into the new apply_patch.rs file. The only "logical" change is inlining #[allow(clippy::unwrap_used)] instead of declaring #![allow(clippy::unwrap_used)] at the top of the file (which is currently the case in codex.rs).


Stack created with Sapling. Best reviewed with ReviewStack.

bolinfest added a commit that referenced this pull request Jul 28, 2025
Apparently `std::env::args()` will panic during iteration if any
argument to the process is not valid Unicode:

https://doc.rust-lang.org/std/env/fn.args.html

Let's avoid the risk and just go with `std::env::args_os()`.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/1698).
* #1705
* #1703
* #1702
* __->__ #1698
* #1697
bolinfest added a commit that referenced this pull request Jul 28, 2025
This introduces some special behavior to the CLIs that are using the
`codex-arg0` crate where if `arg1` is `--codex-run-as-apply-patch`, then
it will run as if `apply_patch arg2` were invoked. This is important
because it means we can do things like:

```
SANDBOX_TYPE=landlock # or seatbelt for macOS
codex debug "${SANDBOX_TYPE}" -- codex --codex-run-as-apply-patch PATCH
```

which gives us a way to run `apply_patch` while ensuring it adheres to
the sandbox the user specified.

While it would be nice to use the `arg0` trick like we are currently
doing for `codex-linux-sandbox`, there is no way to specify the `arg0`
for the underlying command when running under `/usr/bin/sandbox-exec`,
so it will not work for us in this case.

Admittedly, we could have also supported this via a custom environment
variable (e.g., `CODEX_ARG0`), but since environment variables are
inherited by child processes, that seemed like a potentially leakier
abstraction.

This change, as well as our existing reliance on checking `arg0`, place
additional requirements on those who include `codex-core`. Its
`README.md` has been updated to reflect this.

While we could have just added an `apply-patch` subcommand to the
`codex` multitool CLI, that would not be sufficient for the standalone
`codex-exec` CLI, which is something that we distribute as part of our
GitHub releases for those who know they will not be using the TUI and
therefore prefer to use a slightly smaller executable:

https://github.com/openai/codex/releases/tag/rust-v0.10.0

To that end, this PR adds an integration test to ensure that the
`--codex-run-as-apply-patch` option works with the standalone
`codex-exec` CLI.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/1702).
* #1705
* #1703
* __->__ #1702
* #1698
* #1697
Base automatically changed from pr1702 to main July 28, 2025 16:26
@bolinfest bolinfest merged commit 5ebb7dd into main Jul 28, 2025
18 of 19 checks passed
@bolinfest bolinfest deleted the pr1703 branch July 28, 2025 16:51
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants