Skip to content

[BUG] apply_diff's ":start_line:" hint causes misleading failure when file has grown since line number was obtained #985

Description

@lowlight-ua

Describe the bug
When :start_line: is provided to apply_diff and the file has been modified (grown significantly) in the same session since the line number was obtained, the tool fails with a low similarity score error even though the SEARCH text is present verbatim in the file, just at a different line. The error message does not indicate that the text was found elsewhere in the file, making the failure misleading and hard to diagnose.

The bug mostly affects the "edit large Markdown docs" use case. Long Markdown files are more likely to trigger it because: (a) insertions are large (whole paragraphs), causing large line shifts; and (b) the agent is more likely to plan several diffs upfront using line numbers from a single initial read, rather than re-reading between each edit. In contrast, with code files edits are typically smaller (a few lines), shifts are minor, and the fuzzy window around :start_line: is usually wide enough to still find the match. In long Markdown with large block insertions, the shift can be hundreds of lines – well outside any reasonable fuzzy window.

To Reproduce

  • Create a file with N lines containing several section headings and no body content.
  • Have agent call apply_diff with :start_line:X pointing to heading A, and replace it with heading A + a large block of content. This succeeds and the file grows by M lines.
  • Have agent call apply_diff again with :start_line:X+M_old pointing to heading B (where X+M_old was the correct line before step 2, but is now stale). The SEARCH text is the exact text of heading B, present verbatim in the file.

Observe: the tool reports a low similarity score (e.g. 31%) and fails, even though the SEARCH text exists exactly in the file.

Expected behavior
Honestly, no idea; the issue seems to be on the design/requirements level of the tool. Could be: When :start_line: is provided but the SEARCH text is not found near that line, the tool should fall back to a full-file search and find the exact match elsewhere, then succeed (or at minimum warn that the match was found at a different line).

What version of zoo are you running
Version: 3.70.0 (ce7f7dc)

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions