codex - 💡(How to fix) Fix Codex tool runtime intermittently loses `apply_patch` path and fails with `No such file or directory` [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#17240Fetched 2026-04-10 03:43:31
View on GitHub
Comments
1
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×3commented ×1unlabeled ×1

During a single Codex session, the apply_patch tool intermittently becomes unavailable. Calls that previously worked start failing with No such file or directory, and the resolved path to apply_patch appears to change between invocations.

Similar failures also occasionally affect other shell-based tool calls, even when the referenced files definitely exist.

Error Message

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

Root Cause

  • apply_patch should remain callable for the full session
  • tool resolution should be stable within a session
  • patch execution should not fail with No such file or directory when the target file exists and the tool was previously available
  • shell-based tool invocations should not fail on valid existing paths because of runtime instability

Fix Action

Workaround

Temporary workaround:

  1. Run which apply_patch
  2. Use the newly returned path manually for patch application
  3. Continue until the path becomes stale again This workaround restores functionality temporarily, but does not solve the underlying issue.

Code Example

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

---

Rejected("Failed to create unified exec process: No such file or directory (os error 2)")

---

exec_command failed for `/usr/bin/bash -lc "sed -n '1,220p' ansible/host_vars/pts-onedev-r1/main.yml"`: CreateProcess { message: "Rejected(\"Failed to create unified exec process: No such file or directory (os error 2)\")" }

---

exec_command failed for `/usr/bin/bash -lc "sed -n '1,260p' README.md"`: CreateProcess { message: "Rejected(\"Failed to create unified exec process: No such file or directory (os error 2)\")" }

---

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

---

~/.codex/tmp/arg0/codex-arg0c1jJCG/apply_patch

---

~/.codex/tmp/arg0/codex-arg09jUUn5/apply_patch
RAW_BUFFERClick to expand / collapse

What version of the IDE extension are you using?

Version 26.406.31014

What subscription do you have?

Plus

Which IDE are you using?

VSCode

What platform is your computer?

Linux 6.18.21-1-cachyos-lts x86_64 unknown

What issue are you seeing?

Summary

During a single Codex session, the apply_patch tool intermittently becomes unavailable. Calls that previously worked start failing with No such file or directory, and the resolved path to apply_patch appears to change between invocations.

Similar failures also occasionally affect other shell-based tool calls, even when the referenced files definitely exist.

Environment

  • Long-lived Codex session
  • Multiple repositories used in the same session
  • Repository paths were moved/changed earlier during the workflow
  • Files and directories referenced by the commands did exist and were readable

What happened

I was working across repositories in the same session and using apply_patch normally. At some point:

  • built-in patch application started failing
  • error reported No such file or directory
  • files targeted by the patch definitely existed
  • later, running which apply_patch returned a different path than before
  • manually invoking the newly discovered apply_patch path worked again

There were also moments where ordinary shell commands failed with No such file or directory even though the files and directories were present and accessible.

Exact error messages

Primary apply_patch/runtime error:

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

Shell/tool process creation error:

Rejected("Failed to create unified exec process: No such file or directory (os error 2)")

Example full shell-tool failures:

exec_command failed for `/usr/bin/bash -lc "sed -n '1,220p' ansible/host_vars/pts-onedev-r1/main.yml"`: CreateProcess { message: "Rejected(\"Failed to create unified exec process: No such file or directory (os error 2)\")" }
exec_command failed for `/usr/bin/bash -lc "sed -n '1,260p' README.md"`: CreateProcess { message: "Rejected(\"Failed to create unified exec process: No such file or directory (os error 2)\")" }

Repeated low-level failure:

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

Evidence of unstable apply_patch path

At different moments in the same session, which apply_patch returned different paths, for example:

~/.codex/tmp/arg0/codex-arg0c1jJCG/apply_patch

and later:

~/.codex/tmp/arg0/codex-arg09jUUn5/apply_patch

This suggests that the previously resolved temporary tool path became invalid and a new one appeared during the same session.

Workaround

Temporary workaround:

  1. Run which apply_patch
  2. Use the newly returned path manually for patch application
  3. Continue until the path becomes stale again This workaround restores functionality temporarily, but does not solve the underlying issue.

Why this looks like a Codex/runtime bug

  • The repositories and files were valid.
  • The issue was not tied to a specific target file.
  • The executable path to apply_patch appeared unstable within the same session.
  • The problem could be worked around by rediscovering the current apply_patch path.
  • Similar instability appeared in shell-based command execution as well. This suggests session-local tool path rotation, stale tool path caching, or invalidation of the unified execution environment during long sessions.

Suggested areas to investigate

  • Session-local temporary tool path lifecycle
  • Stale tool path caching between tool invocations
  • Context or repository switching effects on developer tool execution
  • Unified exec process environment invalidation during long sessions
  • Whether temporary tool directories are being rotated without downstream consumers refreshing their resolved paths

What steps can reproduce the bug?

Steps to reproduce

These are the closest reproducible conditions observed during the session:

  1. Start a long-lived Codex session on Linux.
  2. Work across multiple repositories in the same session.
  3. Use apply_patch successfully several times.
  4. Change context between repositories and continue editing files.
  5. Attempt another patch or shell-based file read/edit operation.
  6. Observe that a previously working tool invocation may now fail with No such file or directory.
  7. Run which apply_patch.
  8. Notice that the resolved path may differ from the one used earlier in the same session.
  9. Manually invoke the newly resolved apply_patch path and observe that it works again temporarily.

Observed behavior details

  • Built-in patch application starts failing unexpectedly.
  • The failure is not tied to one specific file.
  • The targeted files exist.
  • The path to apply_patch appears unstable within a single session.
  • The issue can sometimes be worked around by rediscovering the current apply_patch path.

What is the expected behavior?

Expected behavior

  • apply_patch should remain callable for the full session
  • tool resolution should be stable within a session
  • patch execution should not fail with No such file or directory when the target file exists and the tool was previously available
  • shell-based tool invocations should not fail on valid existing paths because of runtime instability

Actual behavior

  • apply_patch works initially
  • later fails with No such file or directory
  • re-checking the executable location gives a different temporary path
  • manually using the updated path restores functionality temporarily
  • some shell/tool executions also fail with process creation errors even when the repository files exist

Additional information

No response

extent analysis

TL;DR

The most likely fix or workaround for the intermittent apply_patch tool unavailability is to investigate and address the session-local temporary tool path lifecycle, stale tool path caching, or invalidation of the unified execution environment during long sessions.

Guidance

  • Investigate the session-local temporary tool path lifecycle to determine why the apply_patch path appears to change between invocations.
  • Check for stale tool path caching between tool invocations and consider implementing a mechanism to refresh the resolved paths.
  • Examine the effects of context or repository switching on developer tool execution to identify potential causes of the instability.
  • Verify that the unified exec process environment is not being invalidated during long sessions, causing the tool failures.
  • Consider implementing a workaround that periodically refreshes the apply_patch path, similar to the temporary workaround described in the issue.

Example

No code snippet is provided as the issue does not explicitly mention a specific code change that can fix the problem.

Notes

The root cause of the issue is unclear, but it appears to be related to the temporary tool path rotation, stale tool path caching, or invalidation of the unified execution environment during long sessions. Further investigation is needed to determine the exact cause and implement a permanent fix.

Recommendation

Apply a workaround that periodically refreshes the apply_patch path, as this has been shown to temporarily restore functionality. This can be done by running which apply_patch and using the newly returned path manually for patch application. A permanent fix will require further investigation into the session-local temporary tool path lifecycle, stale tool path caching, or invalidation of the unified execution environment during long sessions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

  • apply_patch should remain callable for the full session
  • tool resolution should be stable within a session
  • patch execution should not fail with No such file or directory when the target file exists and the tool was previously available
  • shell-based tool invocations should not fail on valid existing paths because of runtime instability

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING