Skip to content

Stale '(deleted)' self-exe path can break apply_patch after binary replacement #16097

Closed as not planned

Description

@rebroad

Summary

apply_patch can fail when the running Codex binary is replaced during an active session, because execution may use a stale self-executable path ending in (deleted).

Why this happens

A tool runtime can receive a previously-captured codex_self_exe path. If the binary is replaced on disk (common in local Codex development), that path may no longer be valid for re-exec.

Repro (Linux)

  1. Start Codex from an installed binary path (for example ~/.cargo/bin/codex).
  2. Replace/reinstall that binary while the session is still running.
  3. Trigger an apply_patch call.

Actual behavior

Sandbox invocation can include a deleted path for the inner command and then fail with ENOENT.
Example shape:
--apply-seccomp-then-exec -- "/home/.../.cargo/bin/codex (deleted)" --codex-run-as-apply-patch ...

Expected behavior

If a captured self-executable path is stale/deleted, runtime should resolve a live executable path and continue.

Current downstream mitigation

Downstream currently mitigates this in apply_patch runtime by rejecting (deleted) self-exe paths and falling back to a live executable resolution path.

Request

Would upstream accept a centralized fix for self-executable resolution (shared utility / single source of truth), so all re-exec callsites are resilient to binary replacement, not only apply_patch?

This seems particularly relevant for developers frequently rebuilding/replacing the Codex binary during active sessions.

Activity

  1. added
    bugSomething isn't working
    CLIIssues related to the Codex CLI
    tool-callsIssues related to tool calling
    sandboxIssues related to permissions or sandboxing
    on Mar 28, 2026
  2. etraut-openai commented on Mar 28, 2026

    @etraut-openai
    Contributor

    Don't delete or replace the codex binary while it's in use.

  3. rebroad commented on Apr 1, 2026

    @rebroad
    Author

    Don't delete or replace the codex binary while it's in use.

    Fair enough! Well, if anyone else finds this useful, I patched it here: 2d5a17909af465cfbd9ee5bb9403030cb164776f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIIssues related to the Codex CLIbugSomething isn't workingsandboxIssues related to permissions or sandboxingtool-callsIssues related to tool calling

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions