codex icon indicating copy to clipboard operation
codex copied to clipboard

Nested Codex does not reuse inherited arg0 helper aliases after helper setup failure

Open schrepa opened this issue 7 months ago • 8 comments

What version of Codex CLI is running?

codex-cli 0.120.0

What subscription do you have?

pro

Which model were you using?

gpt-5.4 xhigh

What platform is your computer?

Linux 5.15.167.4-microsoft-standard-WSL2 x86_64 x86_64 Ubuntu 24.04.4 LTS

What terminal emulator and version are you using (if applicable)?

WSL2 Ubuntu on Windows TERM=xterm-256color

What issue are you seeing?

Nested Codex invocations can emit a PATH setup warning, or lose the preferred helper paths, when the child process cannot create a fresh arg0 helper directory even though the parent Codex process already provided valid helper aliases on PATH.

Codex uses arg0-dispatched helper aliases such as:

  • apply_patch
  • applypatch
  • codex-execve-wrapper
  • codex-linux-sandbox

These aliases point back to the main Codex executable. A parent Codex process can create and prepend this helper directory to PATH, but a nested Codex process may run in a more restricted environment where creating a new helper directory fails.

Current behavior treats the helper setup failure as final and proceeds with a warning:

WARNING: proceeding, even though we could not update PATH: ...

In my WSL2 environment, this warning is reproducible when helper setup cannot write under the selected CODEX_HOME:

$ mkdir -p /tmp/codex-issue-home
$ CODEX_HOME=/tmp/codex-issue-home codex --version
WARNING: proceeding, even though we could not update PATH: Refusing to create helper binaries under temporary dir "/tmp" (codex_home: "/tmp/codex-issue-home")
codex-cli 0.120.0

The same warning appears when launching the Linux sandbox path:

$ CODEX_HOME=/tmp/codex-issue-home codex sandbox linux echo
WARNING: proceeding, even though we could not update PATH: Refusing to create helper binaries under temporary dir "/tmp" (codex_home: "/tmp/codex-issue-home")

The bug is not that Codex refuses to create fresh helper aliases under /tmp; that part appears intentional. The issue is that after fresh helper setup fails, a nested child process does not try to reuse a complete helper set that was already inherited on PATH.

What steps can reproduce the bug?

The practical failure shape is:

  1. Parent Codex creates arg0 helper aliases.
  2. Child Codex starts inside a restricted environment.
  3. Child cannot create a fresh helper directory.
  4. Parent helper aliases are still on PATH.
  5. Child warns or falls back instead of reusing those aliases.

A synthetic repro is:

  1. Start from a Codex process that has valid helper aliases on PATH.
  2. Launch a nested Codex process with CODEX_HOME set to an existing directory where fresh helper setup is refused or unavailable.
  3. Observe that the child still emits the helper setup warning instead of validating and reusing the inherited helper aliases.

The aliases that matter are:

  • apply_patch
  • applypatch
  • codex-execve-wrapper
  • codex-linux-sandbox

They should all resolve to the same Codex executable as the child process.

What is the expected behavior?

Expected behavior:

If fresh arg0 helper setup fails, Codex should check whether PATH already contains a complete, trustworthy helper directory from the current Codex executable.

It should only reuse the existing helper directory if every required alias resolves to the currently running executable:

  • apply_patch resolves to the current Codex executable
  • applypatch resolves to the current Codex executable
  • codex-execve-wrapper resolves to the current Codex executable
  • codex-linux-sandbox resolves to the current Codex executable on Linux

If that validation fails, Codex should keep the current warning behavior.

Additional information:

Root-cause hypothesis: arg0_dispatch() currently calls prepend_path_entry_for_codex_aliases(). If that fails, it warns and returns None.

For nested invocations, this misses a valid recovery path: the parent process may already have created the helper aliases and prepended them to PATH.

Potential fix:

  1. On Unix, when prepend_path_entry_for_codex_aliases() fails, scan existing PATH entries.
  2. Look for a directory containing the expected arg0 helper aliases.
  3. Canonicalize each alias.
  4. Reuse the directory only if every alias points to the current executable.
  5. Otherwise preserve the existing warning or fallback behavior.

I tested a local patch with this behavior.

Validation:

  • CODEX_SKIP_VENDORED_BWRAP=1 cargo test -p codex-arg0
  • CODEX_SKIP_VENDORED_BWRAP=1 cargo clippy -p codex-arg0 --all-targets -- -D warnings
  • Built patched codex-cli and verified:
    • missing CODEX_HOME without reusable aliases still prints the warning
    • missing CODEX_HOME with trusted aliases on PATH exits successfully without the warning

Additional information

No response

schrepa avatar Apr 11 '26 16:04 schrepa

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #17367

Powered by Codex Action

github-actions[bot] avatar Apr 11 '26 16:04 github-actions[bot]

I’m seeing this on macOS with Codex CLI 0.142.4.

Inside an active Codex-managed thread:

codex --version
codex help debug
codex debug prompt-input 'hi'

I get:

WARNING: proceeding, even though we could not create PATH aliases: Operation not permitted (os error 1)

--version and help commands still succeed after the warning, but:

codex debug prompt-input 'hi'

fails with:

Error: Operation not permitted (os error 1)

The outer thread’s sandbox allows writes only to the workspace, /tmp, and the session temp dir. ~/.codex is readable but not writable.

Based on the PATH entry and existing helper dirs, the failing target seems to be:

~/.codex/tmp/arg0/codex-arg0*/

Running codex debug --help outside the Codex-managed sandbox works without the warning, so this looks like nested Codex trying to create/refresh arg0 aliases instead of reusing the existing parent-provided aliases on PATH.

rocky-m avatar Jun 29 '26 17:06 rocky-m

Same warning, different trigger, and no nested Codex involved: Homebrew cask installs hit this on every upgrade.

brew upgrade --cask codex prints it three times, once per shell the cask generates completions for:

==> Linking Binary 'codex' to '/opt/homebrew/bin/codex'
WARNING: proceeding, even though we could not create PATH aliases: Refusing to create helper binaries under temporary dir "/private/tmp" (codex_home: AbsolutePathBuf("/private/tmp/homebrew-cask-sandbox20260811-93178-u2vsy/home/.codex"))

Reproduces without Homebrew on 0.147.0, exit code 0 in both cases:

$ mkdir -p /private/tmp/faux/home
$ TMPDIR=/private/tmp HOME=/private/tmp/faux/home codex --version
WARNING: proceeding, even though we could not create PATH aliases: Refusing to create helper binaries under temporary dir "/private/tmp" ...
codex-cli 0.147.0

codex completion zsh behaves the same way, and that is what the cask actually runs.

Homebrew sets both variables on purpose: HOME to a scratch directory so the child cannot read the user's real home, and TMPDIR to HOMEBREW_TEMP, which is /private/tmp on macOS. CODEX_HOME then resolves under the temp root and the prefix check refuses (line 343 on main today).

The difference from the nested case in this issue: there is no parent Codex here, so there are no inherited aliases to reuse. That remedy would not reach this trigger unless it were broadened.

A complementary change that would quieten the early-exit paths in both environments: skip alias preparation for narrowly recognised invocations such as --version and completion. Neither looks up apply_patch, and completion is what Homebrew calls. That would leave inherited-alias reuse to handle the nested commands that genuinely need aliases, like the codex debug prompt-input failure above.

Nistrul avatar Aug 11 '26 08:08 Nistrul

Additional confirmed Homebrew cask reproduction on Apple Silicon:

  • Codex CLI 0.147.0
  • Homebrew 6.0.17
  • macOS 26.5.2 (25F84)
  • arm64

During brew install --cask codex, the binary links successfully and installation completes, but completion generation prints the same warning three times:

==> Linking Binary codex to /opt/homebrew/bin/codex
WARNING: proceeding, even though we could not create PATH aliases: Refusing to create helper binaries under temporary dir "/private/tmp" (codex_home: AbsolutePathBuf("/private/tmp/homebrew-cask-sandbox20260813-8942-lo8och/home/.codex"))
WARNING: proceeding, even though we could not create PATH aliases: Refusing to create helper binaries under temporary dir "/private/tmp" (codex_home: AbsolutePathBuf("/private/tmp/homebrew-cask-sandbox20260813-8942-lo8och/home/.codex"))
WARNING: proceeding, even though we could not create PATH aliases: Refusing to create helper binaries under temporary dir "/private/tmp" (codex_home: AbsolutePathBuf("/private/tmp/homebrew-cask-sandbox20260813-8942-lo8och/home/.codex"))

The final installer message is:

codex was successfully installed!

This confirms the same non-nested Homebrew completion path described above. The installed binary works and codex --version reports codex-cli 0.147.0.

banshee avatar Aug 13 '26 23:08 banshee

Confirming the macOS read-only-command case on Codex CLI 0.153.4, tested 2026-09-08. This matches the help/version behavior already reported in this thread, so I am adding current evidence rather than filing a duplicate.

Environment: macOS 26.6.2, Darwin 25.6.0, x86_64. Commands ran as child processes inside an active Codex-managed workspace-write sandbox; the Codex configuration directory was readable but not writable. No HOME, CODEX_HOME, TMPDIR, or PATH overrides were introduced for these checks.

Each command was captured separately with subprocess.run(argv, capture_output=True, text=True):

Command Exit code First stdout line
codex --version 0 codex-cli 0.153.4
codex --help 0 Codex CLI
codex mcp --help 0 Manage external MCP servers for Codex

All three emitted exactly this line on stderr:

WARNING: proceeding, even though we could not create PATH aliases: Operation not permitted (os error 1)

The help/version operations succeeded; this is not a report that MCP initialization or normal agent execution failed. I have not verified the completeness or binary identity of inherited aliases in this reproduction, so it does not independently prove the inherited-alias-reuse hypothesis.

This supports the complementary change already suggested above: avoid alias preparation for narrowly recognized invocations that only print version/help (and any other independently verified early-exit paths), while retaining proper helper validation for commands that actually execute work. Do not merely suppress a warning on paths that need the helpers. A regression should exercise an unwritable helper location and verify successful, warning-free help/version output without requiring helper filesystem writes.

egecemkirci avatar Sep 07 '26 22:09 egecemkirci

Additional current macOS reproduction on Codex CLI 0.154.0. This adds evidence that the inherited helper set is complete and points to the active installation when the nested CLI still warns.

Environment:

  • macOS 26.6.2 (25G83), arm64
  • Codex CLI 0.154.0 installed with npm under nodenv
  • Child command launched inside an active Codex-managed workspace-write sandbox
  • No HOME, CODEX_HOME, TMPDIR, or PATH overrides added for the check

The nested command succeeds but emits the warning:

$ codex --version
WARNING: proceeding, even though we could not create PATH aliases: Operation not permitted (os error 1)
codex-cli 0.154.0

The nested process runs as the same user that owns the arg0 root:

process: uid=501 user=<user>
~/.codex/tmp/arg0: owner_uid=501 owner=<user> mode=drwx------

All three expected macOS helpers are already inherited on PATH from one directory:

~/.codex/tmp/arg0/codex-arg0ox2PM9/apply_patch
~/.codex/tmp/arg0/codex-arg0ox2PM9/applypatch
~/.codex/tmp/arg0/codex-arg0ox2PM9/codex-execve-wrapper

Each is a symlink to the same native Codex executable selected by the active npm installation:

<nodenv>/lib/node_modules/@openai/codex/node_modules/@openai/codex-darwin-arm64/vendor/aarch64-apple-darwin/bin/codex

The directory ownership and mode rule out ordinary Unix discretionary permissions. The write is denied by the outer macOS sandbox because ~/.codex is readable but outside its writable roots.

This supports the issue's proposed recovery path: after fresh alias creation fails, validate and reuse a complete inherited helper directory when every alias resolves to the current native executable. It also supports skipping alias preparation for --version, since that command succeeds and does not need the helpers.

Edit to add: just getting into using Codex, so probably spotting things most would ignore. Thought I'd report in case more info helps. No crisis on my end.

purp avatar Sep 15 '26 16:09 purp

We hit this same Read-only file system (os error 30) warning on macOS when codex runs a nested check inside a Seatbelt sandbox where CODEX_HOME (~/.codex) is mounted read-only (originally filed in #54127; closing #54127 in favor of this issue).

When the parent process has already created the codex-arg0 helper directory under $CODEX_HOME/tmp/arg0-<os>, a read-only child invocation can verify that the existing apply_patch / applypatch symlinks in PATH (or under $CODEX_HOME/tmp/arg0-<os>) already point to std::env::current_exe() and reuse that entry in-place without writing to CODEX_HOME or std::env::temp_dir().

Minimal fix + unit tests on current main: https://github.com/trukhinyuri/codex/commit/62d3472d4651df02bf5b494c530e924c21664727

trukhinyuri avatar Oct 15 '26 06:10 trukhinyuri

(Response from codex)

I confirmed that helper setup still warns even with aliases to the current executable on PATH. We can't rely on an inherited directory staying unchanged or outliving the child. I wouldn't make it the trusted fallback for sandbox helpers.

Use a private writable CODEX_HOME for the nested process where the outer policy permits it. Closing automatic reuse of inherited aliases as not planned.

etraut-openai avatar Nov 29 '26 05:11 etraut-openai