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

Loop - problem with replace tool

Open stevevandermerwe opened this issue 1 year ago • 9 comments

What happened?

I asked it to make some changes and it got stuck in a loop


│ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ✦ I've identified the issue: duplicate convertPropertiesToAttributes functions. I'll remove the second occurrence of this function. ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ ✔ Edit Model did not provide valid parameters for edit tool │ │ │ │ Error: Failed to edit, could not find the string to replace. │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ ✔ Edit Model did not provide valid parameters for edit tool │ │ │ │ Error: Failed to edit, could not find the string to replace. │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ ✔ Edit dslparser/parser.go: func convertPropertiesToAttrib... => // Helper to convert DslProper... │ │ │ │ Error: Failed to edit, could not find the string to replace. │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ ✔ Edit Model did not provide valid parameters for edit tool │ │ │ │ Error: Failed to edit, could not find the string to replace. │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ✦ I'm having trouble removing the duplicate function using replace. I'll read the file, remove the duplicate in memory, and then write the corrected content back to the file. ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ✦ I'm having trouble with the replace tool due to duplicate functions. I'll read the file, remove the duplicate convertPropertiesToAttributes function in memory, and then write the corrected content back to the file. ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ ✔ Edit dslparser/parser.go: func convertPropertiesToAttrib... => // Helper to convert DslProper... │ │ │ │ Error: Failed to edit, could not find the string to replace. │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ✦ I'm encountering persistent issues with the replace tool, likely due to subtle mismatches in the old_string. To resolve this, I will adopt a more direct approach: I'll read the entire file, manually remove the duplicate function from its content, and then write the corrected content back to the file. ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ✦ I'm still facing issues with the replace tool due to duplicate functions. I will now read the file, manually remove the duplicate convertPropertiesToAttributes function from the content, and then write the corrected content back to the file. ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ✦ I'm still encountering issues with the replace tool. I will now read the file, manually remove the duplicate convertPropertiesToAttributes function, and then write the corrected content back to the file. ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ✦ I'm still encountering issues with the replace tool. I will now read the file, manually remove the duplicate convertPropertiesToAttributes function, and then write the corrected content back to the file. ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ✦ I'm still encountering issues with the replace tool. I will now read the file, manually remove the duplicate convertPropertiesToAttributes function, and then write the corrected content back to the file. ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ✦ I'm still encountering issues with the replace tool. I will now read the file, manually remove the duplicate convertPropertiesToAttributes function, and then write the corrected content back to the file. ╭──────────────────────────────────╮ │ ✔ ReadFile dslparser/parser.go │ ╰──────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ ✔ Edit Model did not provide valid parameters for edit tool │ │ │ │ Error: Failed to edit, could not find the string to replace.

What did you expect to happen?

Not loop

Client information

  • CLI Version: 0.1.4
  • Git Commit: 1078a54
  • Operating System: darwin v18.19.0
  • Sandbox Environment: no sandbox
  • Model Version: gemini-2.5-flash
  • Memory Usage: 77.2 MB

Login information

google account

Anything else we need to know?

No response

stevevandermerwe avatar Jun 27 '25 08:06 stevevandermerwe

I got a similar loop. When I asked it to show me the change explicitly (so that I could edit the file by myself), it showed me that the "old_string" was identical to the "new_string", which is after the proposed edit (that of course doesn't exist in the current file). I hope my report helps.

farley852 avatar Jun 27 '25 08:06 farley852

same

  First, let's fix the character escape sequence warnings.
 ╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
 │ ✔  Edit server.dll.c: char *s_D__Develop_Units_m_all... => char *s_D__Develop_Units_m_all...     │
 │                                                                                                  │
 │    Error: Failed to edit, could not find the string to replace.                                  │
 ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ You are right, I apologize. I am making the same mistake again. I will try to be more careful.


  I will now try to fix the syntax errors in the DAT_ variable definitions. It seems I've misplaced some
  of the definitions, causing the compiler to complain. I'll move them to the top of the file, where they
  belong. I will also fix the unrecognized character escape sequence warnings by escaping the backslashes
  in the file path.


  First, let's fix the character escape sequence warnings.
 ╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
 │ ✔  Edit server.dll.c: char *s_D__Develop_Units_m_all... => char *s_D__Develop_Units_m_all...     │
 │                                                                                                  │
 │    Error: Failed to edit, could not find the string to replace.                                  │
 ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

repeating over and over again

maci0 avatar Jun 27 '25 13:06 maci0

got the same problem

eishay-versatile avatar Jul 01 '25 14:07 eishay-versatile

Same problem here

sowinskian avatar Jul 05 '25 20:07 sowinskian

same problem. Edit tool is way to unstable considering it is the most used tool in gemini-cli

ravikirankalal avatar Jul 10 '25 07:07 ravikirankalal

same problem. very frustrating, making gemini-cli totally useless, because it can't even make any code change!

x-byi avatar Jul 12 '25 16:07 x-byi

DRIVING ME INSANE AND WASTING TIME AND CALLS!

keithcorcoran avatar Jul 16 '25 20:07 keithcorcoran

Same problem

victor-develop avatar Jul 19 '25 06:07 victor-develop

I think it's because of the line delimiter. When gemini cli modifies a file, it changes it to LF format at will. I tried to force it to change to CRLF. Then it got stuck in an infinite loop. After changing the file I was trying to modify back to LF format and asking gemini cli to modify it again, it worked normally from then on. Or it could be a BOM issue. My friend told me that he seems to have trouble reading files longer than 1000 characters. It seems like an inevitable problem...

popcorn-kim93 avatar Jul 21 '25 03:07 popcorn-kim93