Skip to content

Diff-fenced format fails to match long lines - could Aider support search/replace shorter than a full line? #4716

Description

@ottok

Issue

While working on a project that has a lot of human written text in Markdown files with long lines, the LLM fails to match the diff-fenced format because it does not return the full line.

Returning the full line would be a full paragraph of text, so it makes sense the LLM only returns a full sentece. That should be enough to fully search-replace the improved version.

Currently however Aider always expects a full line, and thus it refuses to do search-replace on results like these:

The LLM did not conform to the edit format.
https://aider.chat/docs/troubleshooting/edit-errors.html

# 2 SEARCH/REPLACE blocks failed to match!

## SearchReplaceNoExactMatch: This SEARCH block failed to exactly match lines in content/post/web-browser-tab-tips/index.md
<<<<<<< SEARCH
All popular browsers support defining customer keywords so that what you type in the address bar can take you where you are going even faster.
=======
All popular browsers support defining custom keywords so that what you type in the address bar can take you where you are going even faster.
>>>>>>> REPLACE


## SearchReplaceNoExactMatch: This SEARCH block failed to exactly match lines in content/post/web-browser-tab-tips/index.md
<<<<<<< SEARCH
No more wasting time on skimming through unrelevant search result pages!
=======
No more wasting time on skimming through irrelevant search result pages!
>>>>>>> REPLACE

The SEARCH section must exactly match an existing block of lines including all white space, comments, indentation, docstrings, etc

# The other 2 SEARCH/REPLACE blocks were applied successfully.
Don't re-send them.
Just reply with fixed versions of the blocks above that failed to match.

I wonder if it would be feasible for Aider to have this kind of logic in the search/replace action:

  1. Attempt search/replace with full line (like now)
  2. If 1 fails, but the search value is big (e.g. 60+ characters) and likely unique, attempt search/replace with the it without ^ prefixed and $ suffixed so that partial matches on a line are allowed

Version and model info

Aider v0.86.1
Model: openrouter/moonshotai/kimi-k2 with diff edit format
Git repo: .git with 80 files
Repo-map: using 4096 tokens, manual refresh

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions