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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TimQuist opened this issue Apr 23, 2025 · 2 comments

Comments

@TimQuist
Copy link

TimQuist commented Apr 23, 2025

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.
@TimQuist
Copy link
Author

Potentially related to #13

@Vlad1mir-D
Copy link

Vlad1mir-D commented May 4, 2025

Potential fix: openai#695

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants