Skip to content

bug: apply_diff mishandles :start_line: markers in REPLACE sectionΒ #4013

@KJ7LNW

Description

@KJ7LNW

The apply_diff tool incorrectly handles cases where :start_line: or :end_line: markers are present within the REPLACE section of a diff block. This problem is particularly prevalent with Gemini 2.5, which frequently places these markers incorrectly.

Current Behavior

Currently, if a diff includes :start_line: markers in the REPLACE section (after the ======= separator), they are treated as literal text to be inserted into the file rather than being rejected as improperly formatted diff content:

<<<<<<< SEARCH
:start_line:996
-------
}))

...
{task ? (
=======
:start_line:996    <<<<<< PROBLEM - This should be rejected
-------
}))

return (
<div className={isHidden ? "hidden" : "fixed top-0 left-0 right-0 bottom-0 flex flex-col overflow-hidden"}>
{showAnnouncement && <Announcement hideAnnouncement={hideAnnouncement} />}
{task ? (
>>>>>>> REPLACE

Expected Behavior

The apply_diff tool should validate that metadata markers like :start_line: and :end_line: only appear in their designated positions before the ------- separator in the SEARCH section, and should produce an error if these markers are found in the REPLACE section.

Issue Location

This validation should be added to the validateMarkerSequencing function in src/core/diff/strategies/multi-search-replace.ts.

Additional Context

This issue is a frequent problem when using Gemini 2.5, which has a tendency to place these metadata markers in the REPLACE section. When this happens, the markers are inserted as literal text rather than being reported as formatting errors, causing incorrect file modifications.

Metadata

Metadata

Assignees

Labels

Issue - In ProgressSomeone is actively working on this. Should link to a PR soon.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions