Skip to content

Tool call 'apply_patch' not working on gemini-2.5-pro-preview-03-25 and gemini-2.5-flash-preview-04-17 #24

Open
@TimQuist

Description

@TimQuist

Operating system
MacOs 15

Open-codex version
0.1.30

Models
gemini-2.5-pro-preview-03-25 and gemini-2.5-flash-preview-04-17 (not tested on others)

Problem
Hi,

When running the Gemini models, it seems that the apply_patch tool call does not work as intended.

Especially with multi-line changes, it requests to execute the apply_patch tool with updates, but then it seems to not update anything. Most of the time it will exit abruptly, sometimes with the error message: Invalid Context 0:

I do not have much more errors / logs to offer about this issue (unless there is a log output file somewhere I can share)

When prompted what happened, it replies with:

codex
    You've hit on a good point! The apply_patch tool is quite strict about matching the exact lines before and after the change (the "context").

    Here's the likely sequence of events:

        1. I read the original `README.md`.
        2. I applied the *first* patch successfully, modifying the very first line.
        3. I then tried to apply the *second* patch (to change the "Maven Central" section). However, this patch was based on the line numbers and context of the
    *original* file, not the file *after* the first patch was applied.
        4. Even though the "Maven Central" section itself hadn't changed, the `apply_patch` tool detected that the surrounding context or line numbers didn't perfectly
    match what it expected based on the patch file, causing it to fail with "Invalid Context".

    Essentially, the first successful edit shifted the ground under the second patch attempt.

    To fix this, I need to:

        1. Get the current content of the `README.md` file (which includes the first change).
        2. Create a *new* patch for the "Maven Central" section based on this *current* content.

    Let's get the current content first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions