codex - 💡(How to fix) Fix Apply Patch Bug [2 comments, 3 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#17517Fetched 2026-04-12 13:27:12
View on GitHub
Comments
2
Participants
3
Timeline
9
Reactions
0
Author
Timeline (top)
labeled ×3commented ×2mentioned ×2subscribed ×2

Fix Action

Fix / Workaround

• Subject: functions.apply_patch fails with ENOENT while shell apply_patch works

I’m reporting a reproducible issue with the MCP functions.apply_patch tool.

functions.apply_patch fails immediately with:

RAW_BUFFERClick to expand / collapse

What version of Codex CLI is running?

codex-cli 0.120.0

What subscription do you have?

Business

Which model were you using?

5.3

What platform is your computer?

Ubuntu

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

kitty

What issue are you seeing?

• Subject: functions.apply_patch fails with ENOENT while shell apply_patch works

Hi Codex Technical Team,

I’m reporting a reproducible issue with the MCP functions.apply_patch tool.

Summary

functions.apply_patch fails immediately with:

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

However, the underlying apply_patch executable exists and works correctly when invoked directly from shell with the same patch content.

Environment

  • Repo path: /opt/bot_last_version
  • Date observed: 2026-04-12
  • Shell: bash
  • Sandbox mode in session: danger-full-access
  • Approval policy: never

Reproduction

  1. Call functions.apply_patch with minimal payload:

    • *** Begin Patch
    • *** Add File: .apply_patch_probe
    • +probe
    • *** End Patch
  2. Observe immediate failure:

    • Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })
  3. In shell, run equivalent patch:

    cat <<'PATCH' | apply_patch *** Begin Patch *** Add File: .apply_patch_probe_shell +probe *** End Patch PATCH

  4. Observe success:

    • File created successfully.

Additional verification

  • command -v apply_patch resolves to: /home/utente3/.codex/tmp/arg0/codex-arg0wFKksz/apply_patch
  • That path is a symlink to: /opt/npm-global/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/codex/codex
  • Binary exists and is executable.
  • Other write operations in session work (file edits, lint/format checks).

Expected behavior

functions.apply_patch should apply valid patches exactly as shell apply_patch does.

Actual behavior

Only the MCP functions.apply_patch call fails with ENOENT; shell invocation succeeds.

Impact

  • Breaks standard patch-edit workflow via tool API.
  • Forces fallback to shell editing, reducing reliability and traceability of expected tool usage.

Please investigate the MCP tool bridge/runtime wrapper path handling for functions.apply_patch in this environment.

Thanks.

What steps can reproduce the bug?

Uploaded thread: 019d6bc2-859e-7350-a509-feaab54c57b9

Use this exact repro sequence:

  1. Confirm Codex version:

    • codex --version
    • Expected in our case: codex-cli 0.120.0
  2. Trigger functions.apply_patch with a minimal patch:

    • Payload:
      • *** Begin Patch
      • *** Add File: .apply_patch_probe
      • +probe
      • *** End Patch
    • Result: fails with Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })
  3. Verify binary exists:

    • command -v apply_patch
    • ls -l "$(command -v apply_patch)"
    • (In our run it resolved to /home/utente3/.codex/tmp/arg0/.../apply_patch symlinked to Codex binary)
  4. Run equivalent patch directly in shell:

    cat <<'PATCH' | apply_patch *** Begin Patch *** Add File: .apply_patch_probe_shell +probe *** End Patch PATCH

    • Result: succeeds, file is created.
  5. (Optional cleanup)

    • rm -f .apply_patch_probe .apply_patch_probe_shell

This reproduces the mismatch: MCP tool path fails, shell invocation works.

What is the expected behavior?

• Expected behavior:

  • functions.apply_patch should successfully apply any valid patch payload (same grammar accepted by the CLI apply_patch command).
  • Behavior should be equivalent to shell apply_patch for the same patch text:
    • file create/update/delete should succeed,
    • return success with affected file list,
    • fail only for invalid patch syntax/content (not with ENOENT when binary/path exists).

In short: MCP functions.apply_patch and shell apply_patch should be functionally identical for valid input.

Additional information

No response

extent analysis

TL;DR

The most likely fix is to investigate and adjust the MCP tool's bridge/runtime wrapper path handling for functions.apply_patch to ensure it correctly resolves the apply_patch executable path.

Guidance

  • Verify that the apply_patch executable is correctly symlinked and accessible within the environment where functions.apply_patch is called.
  • Check the runtime environment and path handling of the MCP tool to ensure it matches the shell environment where apply_patch is successfully invoked.
  • Compare the execution paths and environments between the MCP tool and the shell to identify any discrepancies that could lead to the ENOENT error.
  • Consider temporarily modifying the MCP tool's configuration or environment to mimic the shell environment where apply_patch works, to isolate the issue.

Example

No specific code example is provided due to the lack of direct code references in the issue, but adjusting the path handling in the MCP tool based on the command -v apply_patch output could be a starting point.

Notes

The issue seems to be related to the path resolution and environment setup of the MCP tool versus the shell. Ensuring that both environments have the same access to the apply_patch executable and that the paths are correctly resolved is crucial.

Recommendation

Apply a workaround by adjusting the MCP tool's path handling or environment setup to match the shell environment until a permanent fix is available, as the root cause seems to be related to the tool's interaction with its environment rather than a version-specific issue.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Apply Patch Bug [2 comments, 3 participants]