Skip to content

Fix editor panic from overlapping V4A diff deltas (WARP-CLIENT-DEV-NYY)#10186

Merged
kevinyang372 merged 3 commits intomasterfrom
kevin/fix-editor-panick-from-bad-v4a-diff
May 5, 2026
Merged

Fix editor panic from overlapping V4A diff deltas (WARP-CLIENT-DEV-NYY)#10186
kevinyang372 merged 3 commits intomasterfrom
kevin/fix-editor-panick-from-bad-v4a-diff

Conversation

@kevinyang372
Copy link
Copy Markdown
Member

@kevinyang372 kevinyang372 commented May 5, 2026

Problem

Sentry issue WARP-CLIENT-DEV-NYY: panic: Invalid edit range 4042..3982 in Buffer::edit.

When the AI agent produces a multi-hunk V4A diff where one hunk's matched range subsumes another's (e.g. a large deletion whose context window overlaps a nearby single-line edit), fuzzy_match_v4a_diffs produces DiffDeltas with overlapping replacement_line_range values. When CodeEditorModel::apply_diffs later converts these to char offsets and feeds them to insert_at_offsets, the editor's Buffer::edit panics on the invalid range.

Confirmed via MAA conversation d71bf84b (request b621adb3): a 17-hunk V4A diff against mod.rs produced overlapping deltas (lines 46..71 subsuming 64..65).

Fix

Diff layer (crates/ai/src/diff_validation/mod.rs):

  • Added deduplicate_overlapping_deltas() — after matching all hunks, sort deltas by start line and drop any delta whose range overlaps with a preceding one.

Editor safeguard (crates/editor/src/content/core.rs):

  • In apply_core_edit_actions(), skip any action whose anchor-resolved range has start > end instead of panicking. Returns EditResult::default() if all actions are skipped.

Tests

  • test_v4a_maa_crash_d71bf84b_no_overlapping_deltas — uses the exact V4A hunks from the crash to verify the subsumed delta is dropped (1 delta survives, not 2).
  • test_insert_at_offsets_overlapping_ranges_skipped — passes inverted char-offset range (4042..3982) to insert_at_offsets and verifies the buffer is unchanged (edit gracefully skipped).

Fixes WARP-CLIENT-DEV-NYY

@cla-bot cla-bot Bot added the cla-signed label May 5, 2026
Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@kevinyang372 kevinyang372 changed the title Fix editor panick from bad V4A diff Fix editor panic from overlapping V4A diff deltas (WARP-CLIENT-DEV-NYY) May 5, 2026
@kevinyang372 kevinyang372 requested a review from harryalbert May 5, 2026 20:57
@kevinyang372 kevinyang372 marked this pull request as ready for review May 5, 2026 20:57
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented May 5, 2026

@kevinyang372

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

delta.replacement_line_range.start < prev.replacement_line_range.end
});
if dominated {
log::warn!(
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.

should this be an error? Just wondering if this is a thing quality should be aware of/worrying about or if it doesn't really matter

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think of error as an unexpected state we shouldn't have gotten into

This is totally a reasonable state that could have happened if LLM outputs the diffs this way. It also self-heals since LLM will see the echoed back resulting state. I am not worried about putting this as warn level

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.

cool, makes sense


// If every action in the batch was skipped (e.g. all had inverted ranges),
// there is nothing to commit — return early.
if new_range_anchors.is_empty() {
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.

could we surface this in some way to the agent (maybe in the form of a failed tool call or something?). Just feels like it should be aware if the edit wasn't applied

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Related to my comment above. The agent will see the resulting file state after the applied diff

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

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

Overview

This change deduplicates overlapping V4A diff deltas before editor application and adds a defensive editor-side skip for inverted ranges.

Concerns

  • Overlap deduplication currently drops every later overlapping delta, even when the later range only partially overlaps or extends beyond the previous accepted range, so requested changes can be lost while the diff is reported as successfully matched.
  • Security pass: no actionable security concerns found.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread crates/ai/src/diff_validation/mod.rs
@kevinyang372 kevinyang372 merged commit b9e2194 into master May 5, 2026
26 checks passed
@kevinyang372 kevinyang372 deleted the kevin/fix-editor-panick-from-bad-v4a-diff branch May 5, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants