apply_patch Delete File fails on writable paths even when Add/Update succeed

Open 💬 0 comments 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?

apply_patch can successfully create and update a disposable text file, but the corresponding Delete File patch fails on the same file in the same session.

Observed behavior in one session:

  • Add File succeeds
  • Update File succeeds
  • Delete File fails with:
Failed to delete file /path/to/file

I reproduced this on both:

  • a disposable file inside the workspace
  • a disposable file under /tmp

As a control, normal shell deletion of the same probe files succeeds immediately.

This looks narrower than the generic “patch hunk did not match” case: update mismatches still produce the expected Failed to find expected lines verification error, but Delete File fails even when the target file definitely exists and was just created/updated by apply_patch itself.

What steps can reproduce the bug?

Minimal repro with a disposable file:

  1. Use apply_patch to add a file:
*** Begin Patch
*** Add File: tmp/codex-apply-patch-smoke.txt
+alpha
+beta
*** End Patch
  1. Use apply_patch to update the same file:
*** Begin Patch
*** Update File: tmp/codex-apply-patch-smoke.txt
@@
 alpha
-beta
+beta-updated
+gamma
*** End Patch
  1. Use apply_patch to delete the same file:
*** Begin Patch
*** Delete File: tmp/codex-apply-patch-smoke.txt
*** End Patch
  1. Observe failure:
Failed to delete file /.../tmp/codex-apply-patch-smoke.txt
  1. Verify the file still exists.
  2. Run normal shell deletion (rm -f tmp/codex-apply-patch-smoke.txt) as a control; it succeeds.

I also reproduced the same delete failure with /tmp/codex-apply-patch-smoke.txt, so this did not seem limited to one filesystem path.

What is the expected behavior?

apply_patch should support Delete File on the same writable paths where it already supports Add File and Update File in the same session.

Additional information

A few details that may help isolate it:

  • The session also had a separate Linux sandbox issue for non-escalated shell commands (bwrap: No permissions to create a new namespace), but this delete failure still reproduced as a distinct apply_patch behavior after add/update succeeded.
  • The disposable repro above does not require any project-specific files or private code.
  • I intentionally used throwaway probe files only.

View original on GitHub ↗