Skip to content

Detect and reject overlapping edit ranges in streaming_edit_file_tool#48547

Merged
rtfeldman merged 18 commits intomainfrom
fix-overlapping-edits
Feb 6, 2026
Merged

Detect and reject overlapping edit ranges in streaming_edit_file_tool#48547
rtfeldman merged 18 commits intomainfrom
fix-overlapping-edits

Conversation

@rtfeldman
Copy link
Contributor

@rtfeldman rtfeldman commented Feb 6, 2026

In streaming_edit_file_tool.rs, edits are sorted in reverse order and applied sequentially. If the LLM produces overlapping edit ranges, the first applied edit shifts the buffer, and the second edit's range targets stale offsets, leading to incorrect results.

This adds a windows(2) check on the sorted (descending by start) edits that verifies each earlier-in-file range's end does not exceed the next later-in-file range's start. The validation is done before entering the buffer update closure so the error can propagate cleanly via anyhow::bail!.

Release Notes:

  • Fixed bug where streaming edits could apply edits incorrectly if the model requested overlapping edit regions.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 6, 2026
@rtfeldman rtfeldman force-pushed the fix-overlapping-edits branch from 22f3e18 to 0ef67f1 Compare February 6, 2026 01:59
@zed-industries-bot
Copy link
Contributor

zed-industries-bot commented Feb 6, 2026

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against 0a6d76b

@rtfeldman rtfeldman marked this pull request as ready for review February 6, 2026 02:24
@rtfeldman rtfeldman requested a review from agu-z February 6, 2026 02:33
@zelenenka zelenenka added the staff Pull requests authored by a current member of Zed staff label Feb 6, 2026
@rtfeldman rtfeldman enabled auto-merge (squash) February 6, 2026 16:07
@rtfeldman rtfeldman disabled auto-merge February 6, 2026 16:13
…atch error to use line numbers

- Compute first_edit_line from the sorted edits list so the emitted
  location always points to the earliest edited line in the file,
  regardless of the order edits were provided.

- Convert byte offsets to 1-indexed line numbers in the ambiguous
  match error message so the LLM gets accurate line references
  instead of raw byte offsets.
@rtfeldman rtfeldman merged commit 35459f0 into main Feb 6, 2026
26 checks passed
@rtfeldman rtfeldman deleted the fix-overlapping-edits branch February 6, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants