Skip to content

replace may edit the wrong similar function when approximate matching is used #26975

@Yash1927

Description

@Yash1927

What happened?

When replace falls back to flexible, regex, or fuzzy matching, it can behave too permissively in files that contain very similar functions or blocks.

In the failure case I hit, a file had two highly similar functions and the model was asked to edit one specific function. Because the provided old_string was close but not exact, approximate matching could still select the wrong block instead of failing closed.

That makes a single-target edit risky in cases where two code regions are structurally very similar.

What did you expect to happen?

For single replacements, replace should only succeed when the target is uniquely identified.

Expected behavior:

  • If multiple non-exact matches exist and allow_multiple is not true, the edit should fail with no file changes.
  • Fuzzy recovery should tolerate formatting and small punctuation drift, but it should not retarget an edit to a different similarly shaped function with different identifiers.
  • Ambiguity handling should be consistent across flexible, regex, and fuzzy strategies.

Client information

Client Information
About Gemini CLI

CLI Version                0.44.0-nightly.20260512.g022e8baef
Git Commit                 8cda688fe
Model                      Auto (Gemini 3)
Sandbox                    no sandbox
OS                         win32
Auth Method                Signed in with Google
Tier                       Gemini Code Assist in Google One AI Pro


### Login information

_No response_

### Anything else we need to know?

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/agentIssues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Qualitystatus/need-triageIssues that need to be triaged by the triage automation.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions