gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Circular Replace Tool errors...

Open Jkith-dev opened this issue 1 year ago • 3 comments

What happened?

Gemini tried to replace text to fix a bug but it keeps getting "Failed to edit, 0 occurrences found for old_string" Then it says "I will now read the file to get its current, exact content, and then I will re-issue the replace command with the correct old_string to fix the bug." and then back to the first error,.. this happened over 5 times in a loop before I manually stopped it.

What did you expect to happen?

I expected the replace tool to work, and I expected that if it got an error, it would be able to understand why it got an error in the replace tool and solve it.

Client information

  • CLI Version: 0.1.17
  • Git Commit: 99ba2f64 (local modifications)
  • Operating System: win32 v22.17.0
  • Sandbox Environment: no sandbox
  • Model Version: gemini-2.5-pro
  • Memory Usage: 199.0 MB

Login information

Google Account with Standard Subscription to Gemini Code

Anything else we need to know?

Version 16 bugs seem to be fixed, but this is a NEW bug that didn't happen to me in other versions.

Jkith-dev avatar Aug 05 '25 13:08 Jkith-dev

I can confirm, seen this behaviour as well, gemini tries multiple times to use the replace tool, ultimately it fails and reverts to reading the entire file and then changing something in memory and then re-writing the file.

I've also seen it fail occassionally with that step as well, as it may corrupt the file if it's too large to handle by it's memory (?)... I know that sounds kinda weird cause it's context window is so large, but apperently it still happens for some reason.

Interestingly enough gemini is capable of detecting the corruption. But once too much code is duplicate it gives up and tries to revert the file via a git command, git revert or restore or something ? weird behaviour at this point I stopped it cause it would loose to many already done changes to the file.

SkybuckFlying avatar Aug 06 '25 21:08 SkybuckFlying

Thanks for reporting this! We are testing a new experimental version of the Edit tool. Would you mind testing it and give your feedback? Please see: https://github.com/google-gemini/gemini-cli/discussions/7758

silviojr avatar Sep 08 '25 12:09 silviojr

Hi, we are hearing from most users that the above change made significant improvements in this space. Since we haven't heard back in a while, I'm closing this issue. Please file a new issue if you are still seeing problems.

Thanks for your feedback !

srithreepo avatar Oct 02 '25 05:10 srithreepo