apply_patch Update File can modify an existing file and still report "Failed to apply patch"

Open 💬 1 comment Opened Apr 19, 2026 by rinarakaki

What version of Codex CLI is running?

codex-cli 0.121.0

Which model were you using?

gpt-5.4

What platform is your computer?

Linux 6.12.76-linuxkit aarch64

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

bash

What issue are you seeing?

In one session, apply_patch behaved inconsistently for existing-file updates:

  • Update File against an existing workspace file would sometimes show an edit summary first
  • then immediately end with Failed to apply patch
  • in the same session, Add File on disposable temp paths in the same directories still succeeded

The notable part is that this did not look like the normal hunk verification failure (Failed to find expected lines) and did not look like the separate reproducible Delete File bug.

Instead, the observed shape was closer to:

  1. existing file targeted with Update File
  2. Codex output shows something like Edited <file> (+N -M)
  3. then the tool still ends with Failed to apply patch
  4. as a control, Add File to a temp probe path in the same area succeeds right after

I saw this on both:

  • a very small existing-file update (removing a few comment lines / changing a small import block)
  • a much larger delete-heavy update hunk on an existing file

That makes it look less like “large patch only” and more like an existing-file update-path issue.

What steps can reproduce the bug?

I do not yet have a fully minimized disposable repro like I do for the Delete File issue. What I can report precisely is the repeated failure shape from one real session:

  1. Run apply_patch with *** Update File: against an existing file in the workspace.
  2. Use either:
  • a small in-place edit near the top of the file, or
  • a larger delete-heavy in-place edit later in the file.
  1. Observe that Codex may first report an edit summary such as:
Edited <file> (+N -M)
  1. Then observe the same operation still ending with:
Failed to apply patch
  1. Immediately after, try an Add File probe in the same directory tree; that succeeds.
  1. In my session, moving the old file aside and then creating a replacement with Add File also succeeded, which further suggests the failure is specific to the Update File path on existing files.

What is the expected behavior?

If apply_patch has already modified the file successfully, it should return success rather than Failed to apply patch.

If the update path is actually failing verification after making changes, it should either:

  • roll back cleanly, or
  • return a more specific error explaining what failed after the edit summary

Additional information

A few details that may help isolate it:

  • In the same broader environment, I separately reproduced a deterministic Delete File bug and filed it as #18534.
  • This report is intentionally separate because the failure shape is different:
  • Delete File consistently fails on disposable files
  • this issue affects Update File on existing files and can appear after an edit summary is already shown
  • I am not including any project-specific code or file contents here; the signal is about the tool behavior, not the target repository.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗