apply_patch fails with No such file or directory on existing files in codex-cli 0.118.0

Open 💬 6 comments Opened Apr 4, 2026 by LDighera
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of Codex CLI is running?

codex-cli 0.118.0

What subscription do you have?

Plus

Which model were you using?

gpt-5.4

What platform is your computer?

Linux 6.12.75+rpt-rpi-2712 aarch64 unknown

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

LXTerminal 0,4,1

What issue are you seeing?

Environment:

  • codex-cli 0.118.0
  • Linux
  • observed on April 4, 2026

Problem:

  • apply_patch fails with:

execution error: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })

Verified:

  • Reproduces on a real project file and on a trivial new file.
  • Reproduces with both absolute and relative target paths.
  • The target files exist at patch time.
  • /usr/bin/patch is installed and working locally (GNU patch 2.8).

Environment:

  • codex-cli 0.118.0
  • Linux
  • observed on April 4, 2026

Problem:

  • apply_patch fails with:

execution error: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })

Verified:

  • Reproduces on a real project file and on a trivial new file.
  • Reproduces with both absolute and relative target paths.
  • The target files exist at patch time.
  • /usr/bin/patch is installed and working locally (GNU patch 2.8).

Minimal reproduction:

  1. Create a test file:

printf 'alpha\n' > /root/.codex/memories/apply_patch_probe.txt

  1. Attempt:

* Begin Patch
* Update File: /root/.codex/memories/apply_patch_probe.txt
@@
-alpha
+beta
*** End Patch

  1. Result:

execution error: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })

Also reproduced with:

* Begin Patch
* Update File: .codex/memories/apply_patch_probe.txt
@@
-alpha
+gamma
*** End Patch

Expected:

  • apply_patch should update the file.

Notes:

  • This appears to be a Codex tool/runtime issue rather than a bad patch or missing target file.
  • I have observed the same failure across multiple Codex sessions.

Notes:

  • This appears to be a Codex tool/runtime issue rather than a bad patch or missing target file.
  • I have observed the same failure across multiple Codex sessions.

What steps can reproduce the bug?

Minimal reproduction:

  1. Create a test file:

printf 'alpha\n' > /root/.codex/memories/apply_patch_probe.txt

  1. Attempt:

* Begin Patch
* Update File: /root/.codex/memories/apply_patch_probe.txt
@@
-alpha
+beta
*** End Patch

  1. Result:

execution error: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })

Also reproduced with:

* Begin Patch
* Update File: .codex/memories/apply_patch_probe.txt
@@
-alpha
+gamma
*** End Patch

What is the expected behavior?

Expected:

  • apply_patch should update the file.

Additional information

Notes:

  • This appears to be a Codex tool/runtime issue rather than a bad patch or missing target file.
  • I have observed the same failure across multiple Codex sessions.

View original on GitHub ↗

6 Comments

github-actions[bot] contributor · 3 months ago

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

  • #16102
  • #16444
  • #16407

Powered by Codex Action

LDighera · 3 months ago

Additional verified details from the affected machine:

  • The failure reproduces with both an absolute target path and a relative target path.
  • The target file exists at patch time in both cases.
  • The issue is not limited to one project file; it also reproduces on a trivial probe file created

specifically for testing.

  • /usr/bin/patch is present and working locally:
  • command -v patch -> /usr/bin/patch
  • patch --version -> GNU patch 2.8
  • I have observed the same apply_patch failure across multiple Codex sessions, not just a single

thread.

etraut-openai contributor · 3 months ago

If you're able to repro this, please use /feedback to upload your logs and session details, then post the thread ID here.

vak · 3 months ago

I can reproduce this too on a separate Linux environment with codex-cli 0.118.0.

This does not look sporadic in the affected environment. It triggers on the first minimal apply_patch probe and then keeps reproducing on every subsequent probe I tried.

Additional verified details from this affected session:

  • The shell can create and read the target file immediately before the apply_patch call.
  • The failure reproduces on an existing relative path in the workspace.
  • The failure also reproduces on an existing absolute path in /tmp.
  • The failure also reproduces with *** Add File: into /tmp.
  • In all cases the visible error is:
execution error: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })

Minimal repro from this session:

  1. Create a probe file in the workspace:
printf 'alpha\n' > tmp/apply_patch_probe.txt
sed -n '1,5p' tmp/apply_patch_probe.txt

Observed shell output:

alpha
  1. Attempt:
*** Begin Patch
*** Update File: tmp/apply_patch_probe.txt
@@
-alpha
+beta
*** End Patch
  1. Result:
execution error: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })

I also reproduced the same error with:

*** Begin Patch
*** Update File: /tmp/codex_apply_patch_probe.txt
@@
-one
+two
*** End Patch

and with:

*** Begin Patch
*** Add File: /tmp/codex_apply_patch_new.txt
+hello
*** End Patch

This looks very similar to the old ENOENT signature from #6643, and broader than a pure session-CWD mismatch because an existing absolute /tmp path also fails.

Inference: the apply_patch backend/runtime appears to be resolving a different filesystem namespace/root than the shell session.

pakrym-oai contributor · 3 months ago

@vak does the issue go away with a version pre 118?

Jackten · 3 months ago

Additional verified follow-up on this issue after updating to the latest published CLI.

I checked the current CLI bug report template first (.github/ISSUE_TEMPLATE/3-cli.yml): it says to avoid duplicate issues, make sure the latest version is installed, and include full error text plus thread id if applicable. This comment is a follow-up on the existing issue, not a new report.

Environment

  • Codex CLI version tested: codex-cli 0.120.0
  • Platform: Linux 6.17.0-14-generic x86_64 unknown
  • Model used in the session: gpt-5.4

What I verified locally

  • I updated the machine from 0.118.0 to 0.120.0.
  • /usr/bin/codex --version reports codex-cli 0.120.0.
  • The shell-side apply_patch command still works locally on the same probe files.
  • The tool-level apply_patch path still fails in fresh post-update Codex sessions.

Fresh-session repro evidence

  1. Fresh post-update probe session id: 019d7cea-6173-7d42-aedc-7aa0c2d390ea
  • Probe file created in /root/tmp/codex-fresh-probe/sample.txt
  • Tool-level apply_patch failed.
  • Recorded error text:
Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })
apply_patch verification failed: Failed to read file to update /root/root/tmp/codex-fresh-probe/sample.txt: No such file or directory (os error 2)
  • Note: that path has an unexpected doubled prefix: /root/root/tmp/...
  1. Fresh relative-path probe session id: 019d7ceb-5198-7740-a3c9-29c66ac9dfd6
  • Probe file created in /root/tmp/codex-fresh-probe-rel/sample.txt
  • Tool-level apply_patch used relative path tmp/codex-fresh-probe-rel/sample.txt
  • Result still failed with:
No such file or directory

Observed conclusion

  • This issue is still reproducible after updating to 0.120.0.
  • It is not just a stale in-memory 0.118.0 session problem.
  • At least one failure mode on 0.120.0 looks like path resolution is wrong for absolute paths (/root/root/...).
  • Relative-path tool calls still fail too, so it is not only an absolute-path normalization bug.
  • The fact that shell apply_patch succeeds on the same machine/workspace while tool-level apply_patch fails still points to a tool/runtime path issue rather than a missing target file.

If helpful, I can provide more sanitized reproduction details from those session ids.