Skip to content

Bad apply_patch error message "Invalid patch: The first line of the patch must be '*** Begin Patch'" results in agent looping #35361

Description

@DanTup

What version of Codex CLI is running?

codex-cli 0.145.0

What subscription do you have?

N/A

Which model were you using?

gemma4 (google/gemma-4-31B-it, bf16) via vllm

What platform is your computer?

Linux 7.0.0-28-generic x86_64 unknown (Ubuntu multipass VM running on Ubuntu)

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

tmux

Codex doctor report

What issue are you seeing?

gemma4 tried to modify a file using the update_patch tool. It got back the error "Invalid patch: The first line of the patch must be '*** Begin Patch'" however the string it provided does start with that, so it just continued to loop passing the same arguments again and again until I stopped it.

I'm not familiar with the apply_patch tool, so I'm assuming that maybe the arguments are not in the right format (should it just be a string being passed, or an object with named parameters?). If the arguments are not correct, then the error message should be clearer and explain this, and not just say that the patch is incorrect. If the arguments are correct, then it's not clear why it would get this message.

Here's a slightly condensed version of the output I see:

• Ran apply_patch '{"command":["apply_patch","*** Begin Patch\n*** Update File: .github/workflows/build-and-test.yml
  │ … +1 lines
  └ Invalid patch: The first line of the patch must be '*** Begin Patch'

• Ran apply_patch '{"command":["apply_patch","*** Begin Patch\n*** Update File: .github/workflows/build-and-test.yml
  │ … +1 lines
  └ Invalid patch: The first line of the patch must be '*** Begin Patch'

• Ran apply_patch '{"command":["apply_patch","*** Begin Patch\n*** Update File: .github/workflows/build-and-test.yml
  │ … +1 lines
  └ Invalid patch: The first line of the patch must be '*** Begin Patch'

• Ran apply_patch '{"command":["apply_patch","*** Begin Patch\n*** Update File: .github/workflows/build-and-test.yml
  │ … +1 lines
  └ Invalid patch: The first line of the patch must be '*** Begin Patch'

And here's a screenshot of it in the CLI:

Image

What steps can reproduce the bug?

I suspect it will be hard to reproduce on-demand, but the above output will hopefully make the issue clear.

What is the expected behavior?

The error message should be clear enough that the agent can resolve it. When it thinks it's calling the tool correctly and the error message only describes something it is already doing, it may just loop trying the same thing over and over.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIIssues related to the Codex CLIbugSomething isn't workingcustom-modelIssues related to custom model providers (including local models)tool-callsIssues related to tool calling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions