Skip to content

fix: match_edit_to_diff strategy-c misses small-portion Write tool calls #14

Description

@mattfogel

Severity: P2 (provenance miss → silent staging accumulation)
Source: Phase 1 code review (adversarial)

Problem

In match_edit_to_diff (hook.rs around line 573):

  • exact_window_match_str filters empty lines from the needle, which causes blank-line-bearing edits to fail strategies A and B.
  • Strategy C (line-range proximity overlap) requires 50% overlap. A Write tool call where the agent rewrote a 50-line file but only 3 lines actually changed has capture range [1, 50] and added range e.g. [27, 29] — overlap = 3, captured_len = 50, 3*2 < 50 → no match.

Result: such edits stay staged for the 14d TTL and may mis-attach to a future unrelated commit whose diff happens to add the same content.

Suggested fix

Two parts (both substantial):

  1. Handle blank lines in the needle/haystack matching — either preserve them, or use a structural LCS-style approach.
  2. For Write tool, derive a tighter capture range than [1, file_line_count]. Track which lines actually differ from the prior content (compare before vs after) at staging time and store only the changed ranges.

Why deferred

Match-strategy redesign overlaps with U9 (history-rewrite handling) which will rework the same code paths. Better grouped there.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase-1-followupFollow-up from Phase 1 code review

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions