Describe the Bug
The Gemini 2.5 Pro model in Cursor frequently encounters issues when using the edit_file
and reapply
tools. These issues stem from two primary problems:
edit_file
Ambiguity: The diff provided byedit_file
after an operation can be ambiguous or not clearly represent the actual change made to the file. While the file modification itself might be correct, the AI model tends to trust the diff at face value. If the diff is misleading, the AI proceeds with incorrect assumptions about the file’s state.reapply
Unpredictable Behavior (Instruction Re-interpretation & Duplication): Thereapply
tool does not consistently behave as a simple “retry” of the last patch. Instead, it often appears to re-interpret the original instruction from the precedingedit_file
call. This is particularly problematic with additive edits (e.g., prepending or appending lines), wherereapply
can duplicate the content if the initialedit_file
call was already successful. This duplication then confuses the AI.
These behaviors cause the AI to misjudge the success or outcome of file operations, leading it to get stuck, make incorrect subsequent edits, or fail the overall task.
Steps to Reproduce
Scenario 1: reapply
Duplication Bug
- Create a test file:
- Use
edit_file
to create a file (e.g.,test_bug.txt
) with a few lines of initial content.
Line 1 Line 2
- Use
- Prepend a line using
edit_file
:- Instruction: “Prepend the line ‘NEW PREPENDED LINE’ to
test_bug.txt
.” code_edit
might look like:NEW PREPENDED LINE\n// ... existing code ...
- At this point,
test_bug.txt
should be:NEW PREPENDED LINE Line 1 Line 2
- Instruction: “Prepend the line ‘NEW PREPENDED LINE’ to
- Call
reapply
:- Execute
reapply
ontest_bug.txt
.
- Execute
- Observe the bug:
- Read
test_bug.txt
. The line “NEW PREPENDED LINE” will likely be duplicated:NEW PREPENDED LINE NEW PREPENDED LINE Line 1 Line 2
- The AI, if it only saw the first
edit_file
as successful, would not expect this duplication fromreapply
.
- Read
Scenario 2: edit_file
Ambiguous Diff (Conceptual)
- Create a file with specific content:
edit_file
to createtest_ambiguity.txt
with:IDENTICAL LINE IDENTICAL LINE Different Line
- Delete one specific identical line using
edit_file
:- Instruction: “Delete the second instance of ‘IDENTICAL LINE’.”
code_edit
might be:IDENTICAL LINE\n// ... existing code ...
(aiming to keep the first and remove the second).
- Observe potentially ambiguous diff:
- The diff returned by
edit_file
might show the first “IDENTICAL LINE” as removed, or present the change in a way that doesn’t clearly confirm which of the two identical lines was targeted and removed, even if the file is now correctly:IDENTICAL LINE Different Line
- The AI might misinterpret this diff, leading to confusion if it needs to act based on which specific line was removed.
- The diff returned by
Expected Behavior
-
For
edit_file
:- The diff returned should accurately and unambiguously reflect the precise changes made to the file.
- If a diff cannot be made perfectly unambiguous (e.g., in cases like modifying code with many similar lines), an ambiguity flag should be returned in the tool’s response. This flag would signal to the AI that the diff might not tell the whole story and that extra verification (like a
read_file
) is advisable. - The tool should reliably apply the edit as per the
code_edit
andinstructions
.
-
For
reapply
:- Predictable Application:
reapply
should have a clearly defined and predictable behavior.- Ideally, it should intelligently attempt to achieve the original instruction’s goal without introducing new errors like duplication. It should be idempotent where possible (i.e., applying it multiple times to an already correct state results in no further changes and no errors).
- If the previous
edit_file
was successful and the file state already reflects the intended change,reapply
should consistently make no changes and report this clearly.
- No Content Duplication:
reapply
should never duplicate content that was already correctly applied by the initialedit_file
operation. - Clear Feedback: The output from
reapply
(diff or status message) must clearly indicate whatreapply
itself did (or didn’t do), rather than just echoing the previous diff or a generic success.
- Predictable Application:
Operating System
MacOS
Current Cursor Version (Menu → About Cursor → Copy)
Version: 1.1.3
VSCode Version: 1.96.2
Commit: 979ba33804ac150108481c14e0b5cb970bda3260
Date: 2025-06-15T06:35:49.230Z
Electron: 34.5.1
Chromium: 132.0.6834.210
Node.js: 20.19.0
V8: 13.2.152.41-electron.0
OS: Darwin arm64 23.4.0
Additional Information
The core issue affecting Gemini 2.5 pro’s performance is its current tendency to:
a. Trust the edit_file
diff output, even if it’s ambiguous.
b. Be unprepared for reapply
’s behavior of re-interpreting instructions, especially the duplication side-effect.
Suggestions for the Cursor Team to consider for tool improvement:
-
edit_file
Tool:- Improve Diff Generation: Prioritize clarity and accuracy in the diff output.
- Introduce an Ambiguity Flag: If the model applying the edit or generating the diff detects a high level of ambiguity in how the change could be interpreted from the diff alone, set a flag in the response. This signals the AI to be cautious.
- (Optional) Richer Feedback: Consider an option for
edit_file
to return the modified section’s full content or the whole file (if small) alongside the diff, for definitive confirmation.
-
reapply
Tool:- Redefine/Refine Behavior:
- Ensure its “smart” re-interpretation logic is robust against issues like content duplication. It must be better at detecting if the original instruction’s intent is already satisfied.
- Consider offering distinct modes (if technically feasible for the AI to choose/understand):
- A “strict patch re-application” mode.
- The current “smart instruction re-interpretation” mode, but significantly improved to avoid errors.
- Accurate Post-Reapply Feedback: The diff/status from
reapply
must reflect changes made byreapply
itself.
- Redefine/Refine Behavior:
-
General (Both Tools):
- Granular Feedback: Provide more detailed status messages that differentiate between various outcomes (e.g., “Edit applied successfully,” “Edit applied, ambiguity detected,” “Reapply: No change needed, state already correct,” “Reapply: Instruction re-applied, resulted in X changes (diff below)”).
Addressing these behaviors will significantly improve the AI’s ability to reliably perform file modifications, especially in multi-step editing scenarios, and reduce user frustration.
Does this stop you from using Cursor
Sometimes - I can sometimes use Cursor