Skip to content

fix(edit_file): always retry fuzzy fallback on first search miss#2154

Open
donglovejava wants to merge 1 commit into
Hmbown:mainfrom
donglovejava:fix/edit_file-fuzz-automatic
Open

fix(edit_file): always retry fuzzy fallback on first search miss#2154
donglovejava wants to merge 1 commit into
Hmbown:mainfrom
donglovejava:fix/edit_file-fuzz-automatic

Conversation

@donglovejava
Copy link
Copy Markdown

@donglovejava donglovejava commented May 26, 2026

The optional fuzz parameter was required to attempt the leading-indentation fuzzy fallback when exact search found zero matches. This forced the model to make two calls on every edit that needed fuzzy matching (first without fuzz -> error -> second with fuzz: true), causing a round-trip delay.

Fix: remove the fuzz gate from the count == 0 branch. The tool now automatically retries with indentation-tolerant fuzzy matching when exact search produces no results. The fuzz parameter is kept in the schema for backward compatibility but marked deprecated.

Changes:

  • crates/tui/src/tools/file.rs: if count == 0 && fuzz -> if count == 0 (always retry fuzzy fallback)
  • crates/tui/src/tools/file.rs: removed dead else if count == 0 { error } branch
  • crates/tui/src/tools/file.rs: updated description to note automatic fuzzy fallback
  • crates/tui/src/tools/file.rs: marked fuzz parameter as deprecated in schema

Greptile Summary

This PR removes the fuzz gate from the zero-match branch in EditFileTool::execute, so the indentation-tolerant and punctuation-normalised fuzzy fallbacks now fire automatically whenever an exact search finds nothing. The fuzz schema parameter is retained and marked deprecated for backward compatibility.

  • The conditional if count == 0 && fuzz is simplified to if count == 0, and the now-redundant else if count == 0 { error } branch is deleted.
  • Tool description and schema description for fuzz are updated to reflect the new automatic-fallback behaviour.

Confidence Score: 4/5

Safe to merge; the behavioural change is intentional and the fallback error paths are preserved. The only code-quality gap is a now-unused variable that will emit a compiler warning.

The core logic change is small and correct — the fuzzy fallback paths were already there and tested, and the removed branch was made entirely redundant by the restructured condition. The fuzz variable is still parsed but never read, which will generate a Rust unused variable warning on every build.

crates/tui/src/tools/file.rs — the fuzz binding at line 543 should be prefixed with _ to suppress the compiler warning.

Important Files Changed

Filename Overview
crates/tui/src/tools/file.rs Removes the fuzz gate so indentation- and punctuation-tolerant fuzzy fallbacks are always tried on an exact-match miss. The fuzz binding is now unused, producing a compiler warning. Logic and error paths are otherwise correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[edit_file called] --> B{exact match count}
    B -- count > 0 --> C[replace all occurrences]
    B -- "count == 0\n(was: count==0 && fuzz)" --> D[indentation fuzzy match]
    D -- 1 match --> E[replace_range + fuzz_kind = indentation]
    D -- 0 matches --> F[punctuation fuzzy match]
    D -- 2+ matches --> G[Error: ambiguous fuzzy match]
    F -- 1 match --> H[replace_range + fuzz_kind = punctuation]
    F -- 0 matches --> I[Error: search string not found]
    F -- 2+ matches --> J[Error: ambiguous punctuation match]
    C --> K[write file + unified diff]
    E --> K
    H --> K
    B -. removed branch .-> L[was: Error if count==0 and fuzz=false]
    style L stroke-dasharray: 5 5,fill:#ffcccc
Loading

Comments Outside Diff (1)

  1. crates/tui/src/tools/file.rs, line 543 (link)

    P2 The fuzz value is parsed into a binding but never referenced after this change. Rust will emit an unused variable: fuzz warning for every compilation. Prefix the binding with an underscore to signal intentional discard (while still calling optional_bool to validate the incoming JSON).

    Fix in Codex Fix in Claude Code Fix in Cursor

Fix All in Codex Fix All in Claude Code Fix All in Cursor

Reviews (1): Last reviewed commit: "fix(edit_file): always retry fuzzy fallb..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the EditFileTool to automatically attempt fuzzy matching when an exact search match is not found, deprecating the explicit fuzz parameter. A review comment correctly points out that the fuzz variable is now unused and should be removed to prevent compiler warnings.


let count = contents.matches(search).count();
let (updated, count, fuzz_kind) = if count == 0 && fuzz {
let (updated, count, fuzz_kind) = if count == 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

With the removal of the fuzz check here, the fuzz variable defined on line 543 (let fuzz = optional_bool(&input, "fuzz", false);) is now completely unused. This will trigger an unused_variables compiler warning (or error if warnings are treated as errors in CI).\n\nTo fix this, please remove the unused fuzz variable declaration on line 543.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant