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

Line endings cause error: failed to edit, could not find the string to replace.

Open thatgardnerone opened this issue 1 year ago • 11 comments

Describe the bug When gemini tries to edit a line, it often fails the first time with the following error:

 │ ✔  Edit <path/to/file>:│
 │                                                                                                                                                                                                                                                                                      
 │    Error: Failed to edit, could not find the string to replace.                                                                                                                                                                                                                      

Then Gemini retries:

✦ I see, the previous replacement must have changed the line endings. I'll read the file again to make sure I have the correct content.

And this time the edit usually works.

Client information M3 Max MacBook Pro, macOS Sequoia

│ CLI Version                                  0.1.1
│ Git Commit                                   852210e1 (local modifications)
│ Model                                        gemini-2.5-pro
│ Sandbox                                      no sandbox
│ OS                                           darwin

Additional context

thatgardnerone avatar Jun 25 '25 16:06 thatgardnerone

This is a known issue with the gemini model response (and flagged as something to improve) but outside of the control of gemini-cli. Most of the time the second call to the model fixes the issue.

sethtroisi avatar Jun 25 '25 19:06 sethtroisi

This is happening a lot for me. What would be helpful to know if there is anything we can do to ease this problem... Looks like a gemini self created problem? https://github.com/google-gemini/gemini-cli/issues/1971

RicardoRix avatar Jul 01 '25 08:07 RicardoRix

Image

Stuck in a forever loop.

chriseatontx avatar Jul 06 '25 16:07 chriseatontx

Image Stuck in a forever loop.

Same here

PrathxmOp avatar Jul 15 '25 07:07 PrathxmOp

Same here

sipos-zoli avatar Jul 15 '25 16:07 sipos-zoli

same here

Neragoth avatar Jul 15 '25 22:07 Neragoth

Same here

Edamas avatar Jul 16 '25 10:07 Edamas

Same here

jesusvico avatar Jul 16 '25 21:07 jesusvico

I might have found a minor fix. In case anyone here has downloaded the gemini-cli via git clone, it includes a GEMINI.md which caused those indefinite loops on my end. Now they appear once in a while, but no loops

hoshizora-yoake-no avatar Jul 17 '25 10:07 hoshizora-yoake-no

it's a major flaw of Gemini-cli as it adds minutes to every prompt

lockster-at-secondskin avatar Jul 27 '25 00:07 lockster-at-secondskin

Found possible duplicate issues:\n\n- #1028: (0.9069286584854126)\n- #2101: (0.901364803314209)\n\n

gsquared94 avatar Jul 30 '25 22:07 gsquared94