Bug: Gemini 3 Pro Preview doesn't use edit_tool correctly
What happened?
Gemini 3 Pro Preview took 8 minutes editing a huge file and then spat out the following. It was asked to move all the 'inline code' it added to a function into its own function.
x Edit {"old_string":"import React, { useState, useEffect } from 'react';\nimport { Box, Text } from 'ink';\nimport { theme } from '../semantic-colors.js';\nimport type {\n LoadableSettingScope,\n LoadedSettings,\n Settings,\n} from '../../config/settings.js';\nimport { SettingScope } from '../../c… │
│ │
│ Invalid regular expression: │
│ /^(\s*)import\s*React,\s*\{\s*useState,\s*useEffect\s*\}\s*from\s*'react';\s*import\s*\{\s*Box,\s*Text\s*\}\s*from\s*'ink';\s*import\s*\{\s*theme\s*\}\s*from\s*'\.\./semantic-colors\.js';\s*import\s*type\s*\{\s*LoadableSettingScope,\s*LoadedSettings,\s*Settings,\s*\}\s*from\s*'\.\./\.\./config/settings\ │
│ .js';\s*import\s*\{\s*SettingScope\s*\}\s*from\s*'\.\./\.\./config/settings\.js';\s*import\s*\{\s*getScopeItems,\s*getScopeMessageForSetting,\s*\}\s*from\s*'\.\./\.\./utils/dialogScopeUtils\.js';\s*import\s*\{\s*RadioButtonSelect\s*\}\s*from\s*'\./shared/RadioButtonSelect\.js';\s*import\s*\{\s*getDialog │
│ SettingKeys,\s*setPendingSettingValue,\s*getDisplayValue,\s*hasRestartRequiredSettings,\s*saveModifiedSettings,\s*getSettingDefinition,\s*isDefaultValue,\s*requiresRestart,\s*getRestartRequiredFromModified,\s*getDefaultValue,\s*setPendingSettingValueAny,\s*getNestedValue,\s*getEffectiveValue,\s*\}\s*fro │
│ m\s*'\.\./\.\./utils/settingsUtils\.js';\s*import\s*\{\s*useVimMode\s*\}\s*from\s*'\.\./contexts/VimModeContext\.js';\s*import\s*\{\s*useKeypress\s*\}\s*from\s*'\.\./hooks/useKeypress\.js';\s*import\s*chalk\s*from\s*'chalk';\s*import\s*\{\s*cpSlice,\s*cpLen,\s*stripUnsafeCharacters,\s*getMatchPositions, │
│ \s*toCodePoints,\s*\}\s*from\s*'\.\./utils/textUtils\.js';\s*import\s*\{\s*type\s*SettingsValue,\s*TOGGLE_TYPES,\s*\}\s*from\s*'\.\./\.\./config/settingsSchema\.js';\s*import\s*\{\s*debugLogger\s*\}\s*from\s*'@google/gemini-cli-core';\s*import\s*\{\s*keyMatchers,\s*Command\s*\}\s*from\s*'\.\./keyMatcher │
│ s\.js';\s*interface\s*SettingsDialogProps\s*\{\s*settings\s*:\s*LoadedSettings;\s*onSelect\s*:\s*\(\s*settingName\s*:\s*string\s*\|\s*undefined,\s*scope\s*:\s*SettingScope\s*\)\s*=\s*>\s*void;\s*onRestartRequest\?\s*:\s*\(\s*\)\s*=\s*>\s*void;\s*availableTerminalHeight\?\s*:\s*number;\s*\}\s*const\s*max │
│ ItemsToShow\s*=\s*8;\s*export\s*function\s*SettingsDialog\s*\(\s*\{\s*settings,\s*onSelect,\s*onRestartRequest,\s*availableTerminalHeight,\s*\}\s*:\s*SettingsDialogProps\s*\)\s*:\s*React\.JSX\.Element\s*\{\s*//\s*Get\s*vim\s*mode\s*context\s*to\s*sync\s*vim\s*mode\s*changes\s*const\s*\{\s*vimEnabled,\s* │█
│ toggleVimEnabled\s*\}\s*=\s*useVimMode\s*\(\s*\)\s*;\s*//\s*Focus\s*state\s*:\s*'settings'\s*or\s*'scope'\s*const\s*\[\s*focusSection,\s*setFocusSection\s*\]\s*=\s*useState\s*<\s*'settings'\s*\|\s*'scope'\s*>\s*\(\s*'settings',\s*\)\s*;\s*//\s*Scope\s*selector\s*state\s*\(\s*User\s*by\s*default\s*\)\s*c │
│ onst\s*\[\s*selectedScope,\s*setSelectedScope\s*\]\s*=\s*useState\s*<\s*LoadableSettingScope\s*>\s*\(\s*SettingScope\.User,\s*\)\s*;\s*//\s*Active\s*indices\s*const\s*\[\s*activeSettingIndex,\s*setActiveSettingIndex\s*\]\s*=\s*useState\s*\(\s*0\s*\)\s*;\s*//\s*Scroll\s*offset\s*for\s*settings\s*const\s* │
│ \[\s*scrollOffset,\s*setScrollOffset\s*\]\s*=\s*useState\s*\(\s*0\s*\)\s*;\s*const\s*\[\s*showRestartPrompt,\s*setShowRestartPrompt\s*\]\s*=\s*useState\s*\(\s*false\s*\)\s*;\s*//\s*Filter\s*mode\s*state\s*const\s*\[\s*isFiltering,\s*setIsFiltering\s*\]\s*=\s*useState\s*\(\s*false\s*\)\s*;\s*const\s*\[\s │
│ *filterQuery,\s*setFilterQuery\s*\]\s*=\s*useState\s*\(\s*''\s*\)\s*;\s*const\s*\[\s*matchedIndices,\s*setMatchedIndices\s*\]\s*=\s*useState\s*<\s*number\s*\[\s*\]\s*>\s*\(\s*\[\s*\]\s*\)\s*;\s*const\s*\[\s*currentMatchIndex,\s*setCurrentMatchIndex\s*\]\s*=\s*useState\s*\(\s*0\s*\)\s*;\s*//\s*Local\s*pe │
│ nding\s*settings\s*state\s*for\s*the\s*selected\s*scope\s*const\s*\[\s*pendingSettings,\s*setPendingSettings\s*\]\s*=\s*useState\s*<\s*Settings\s*>\s*\(\s*\(\s*\)\s*=\s*>\s*//\s*Deep\s*clone\s*to\s*avoid\s*mutation\s*structuredClone\s*\(\s*settings\.forScope\s*\(\s*selectedScope\s*\)\s*\.settings\s*\)\s
What did you expect to happen?
It seems to struggle with editing files / figuring out spaces / refactoring files.
Client information
- CLI Version: 0.18.0-nightly.20251118.86828bb56
- Git Commit: 1e8ae5b9d
- Session ID: e899f90c-00ed-491a-bdf9-fef962cb16a8
- Operating System: darwin v24.2.0
- Sandbox Environment: no sandbox
- Model Version: gemini-3-pro-preview
- Memory Usage: 336.9 MB
Login information
No response
Anything else we need to know?
No response
Found possible duplicate issues:
- #4502
- #5937
If you believe this is not a duplicate, please remove the status/possible-duplicate label.
Hi! thanks for reporting this.
This is an unusual error yes. Have you seen it happening often? Do you have any advice on how to reproduce it?
@silviojr The above was in fact an edit made to the gemini cli codebase. I wanted to experiment on improving the Settings screen so:
- I asked Gemini 3 Pro Preview to make a certain improvement to the Settings dialog screen
- After it completed the work, it had added code rather clumsily all inline and somewhat didn't care about the overall file's structure
- I pressed escape (since it kept going for a very long time making other weird edits to the unit tests that I hadn't asked it to do just yet) and told gemini to
extract the inline code into a separate function, make sure the code is more organized and follows the existing structure - It then attempted to extract a dozen+ lines of code into a separate method it seems when it spent 8 minutes trying and then spat out the above (which told me it kept trying and kept failing).
It seems to trip over spacings within file, curly brackets and so on (the same issues I experienced with Gemini 2.5 using the gemini cli).
In comparison Codex seems to generate a python script on the fly when it's editing files and is unable to cleanly edit them - rarely fails.
The old_string related errors (with the edit tool) are so off putting that it made it impossible for me to use Gemini CLI for more than a couple of minutes before it would enter into a loop of failed attempts (with gemini 2.5 pro). Gemini 3 Pro Preview seems to be slightly better but still takes forever to edit files, keeps retrying a times, enters into a loop or just tries to do more than it was originally asked (such as building the project, writing unit tests and so on). I'm genuinely rooting for Gemini CLI to improve.
I should add - around this time is when I ran out of my daily quota (I'm on Gemini Ultra) which is a pity because I hardly got any work done. It seems to have consumed all its tokens retrying for several minutes behind the scenes.
😄