Error: Codex gives up after failing to apply patch. Instructs me to do it myself.

Resolved 💬 7 comments Opened Sep 26, 2025 by Alfredo-Sandoval Closed Sep 27, 2025
💡 Likely answer: A maintainer (tibo-openai, collaborator) responded on this thread — see the highlighted reply below.

What version of Codex is running?

0.42

Which model were you using?

gpt-5 high and gpt5 codex high

What platform is your computer?

Linux 6.14.0-29-generic x86_64 x86_64

What steps can reproduce the bug?

Use codex

What is the expected behavior?

Apply a patch - don't fail 5+ times then give up.

What do you see instead?

More screenshots below. Eventually it has to write python to patch the file. a substantial portion of my token usage is now failed patches.

<img width="729" height="183" alt="Image" src="https://github.com/user-attachments/assets/2cb0c85a-5beb-48dc-a158-5ce82f540352" />

<img width="534" height="136" alt="Image" src="https://github.com/user-attachments/assets/606425f7-d1f6-40ed-a34e-b73a42be6af6" />

<img width="698" height="282" alt="Image" src="https://github.com/user-attachments/assets/79c99b98-12dd-4303-a1ad-27c377b03216" />

Additional information

It is currently faster to interrupt codex. Have claude apply the edit. then continue.

View original on GitHub ↗

7 Comments

tibo-openai collaborator · 9 months ago

Thanks Alfredo, there are times where the model can fail to correctly use apply_patch and we're addressing this and actively working on this. It is expected that the model uses other ways to make the edits other than apply_patch, including using Python or Perl. Closing this as we're actively aware of this and continuing to work on token efficiency.

lchabin · 9 months ago

It's not a few times for me, it is an absolute pain in the but. this plus \n\r mis management, mis handling of quotes, etc.... ended up editing myself. The problem is repeated misuse of powershell, whatever I tell it, it makes again and again the same mistakes.

Alfredo-Sandoval · 9 months ago

@lchabin Same. at this point I let it try to make edits. paste the failed apply patches into claude and then continue.

Bummer that so much usage is wasted on failed patches

I'll keep track of them but its probably close to triple digits/day.

Honsal · 7 months ago

this is still happening.

JohnTracyTR · 5 months ago

Wow way to get on this bug, guys. Leran to pritorize cutomer pain points over new features. Here is what i did to fix it: Had codes deveop his own tool that is deterministic:

  • Added deterministic edit tool: utils/edit-file.ps1
  • Committed/pushed on Feb08Work_11: 094f88a [Purple] Add deterministic edit tool for Windows

How to use

  • Replace exact string:
  • .\utils\edit-file.ps1 -Path <file> -ReplaceExact <old> -With <new>
  • Insert after marker:
  • .\utils\edit-file.ps1 -Path <file> -InsertAfter <marker> -Text <text>
  • Insert before marker:
  • .\utils\edit-file.ps1 -Path <file> -InsertBefore <marker> -TextBefore <text>
  • Ensure text exists:
  • .\utils\edit-file.ps1 -Path <file> -EnsureContains <text>

It writes UTF‑8 no BOM and preserves CRLF/LF automatically.

add a rule about using it after a failed apply_patch, you only get 1 reiteration.

vak · 3 months ago

April 2026: bug appeared again

etraut-openai contributor · 3 months ago

@vak, this bug was fixed long ago. If you are seeing a similar behavior, then it's a different issue. Please look for an active bug report or open a new one and provide the details requested in the bug template.

I'm going to lock this issue to prevent additional posts.