apply_patch Update File can modify an existing file and still report "Failed to apply patch"
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 Fileagainst an existing workspace file would sometimes show an edit summary first- then immediately end with
Failed to apply patch - in the same session,
Add Fileon 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:
- existing file targeted with
Update File - Codex output shows something like
Edited <file> (+N -M) - then the tool still ends with
Failed to apply patch - as a control,
Add Fileto 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:
- Run
apply_patchwith*** Update File:against an existing file in the workspace. - 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.
- Observe that Codex may first report an edit summary such as:
Edited <file> (+N -M)
- Then observe the same operation still ending with:
Failed to apply patch
- Immediately after, try an
Add Fileprobe in the same directory tree; that succeeds.
- In my session, moving the old file aside and then creating a replacement with
Add Filealso succeeded, which further suggests the failure is specific to theUpdate Filepath 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 Filebug and filed it as #18534. - This report is intentionally separate because the failure shape is different:
Delete Fileconsistently fails on disposable files- this issue affects
Update Fileon 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.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗