BUG: Error "edit does not conform to the edit format" stucks Aider in a loop, cannot continue
Issue
I'm stuck in a loop where Aider cannot pass an edit because it says that the edit diff does not conform to the edit format. No matter what I do, this error always pops up and stops me from continuing:
> The LLM did not conform to the edit format.
> https://aider.chat/docs/troubleshooting/edit-errors.html
> # 1 SEARCH/REPLACE block failed to match!
>
> ## SearchReplaceNoExactMatch: This SEARCH block failed to exactly match lines in src/ptree/ptree.py
> <<<<<<< SEARCH
> if config.disable_output:
> return objs[0] if len(objs) == 1 and kwargs['pass_back'] else None
>
> try:
> with TimeoutContext(kwargs['timeout']):
> objs_copy = _safe_copy_objects(objs, kwargs['file'])
>
> if kwargs['output_format']:
> set_output_format(kwargs['output_format'])
>
> string_io = io.StringIO()
> output_file = string_io if kwargs['return_string'] or kwargs['save_output'] else kwargs['file']
>
> tree_printer = TreePrinter(**kwargs, file=output_file)
>
> if not objs:
> return "No objects provided to ptree"
>
> content = _generate_content(objs_copy, tree_printer, sep=kwargs['sep'])
> result = ''.join(filter(None, content))
>
> if kwargs['save_output']:
> save_to_file(result, kwargs['file_name'], kwargs['output_format'] or OUTPUT_FORMAT)
>
> if not kwargs['return_string'] and not kwargs['save_output']:
> print(result, file=kwargs['file'], end='', flush=kwargs['flush'])
>
> if kwargs['return_string']:
> return result
> elif kwargs['pass_back']:
> return objs[0] if len(objs) == 1 else objs
> else:
> return None
>
> except TimeoutError:
> print("Alert: ptree execution timed out.", file=kwargs['file'])
> return objs[0] if len(objs) == 1 and kwargs['pass_back'] else objs if kwargs['pass_back'] else None
> except Exception as e:
> print(f"Error in ptree: {str(e)}", file=kwargs['file'])
> return objs[0] if len(objs) == 1 and kwargs['pass_back'] else objs if kwargs['pass_back'] else None
> =======
> if config.disable_output:
> return objs[0] if len(objs) == 1 and pass_back else None
>
> try:
> with TimeoutContext(timeout):
> objs_copy = _safe_copy_objects(objs, file)
>
> if output_format:
> set_output_format(output_format)
>
> string_io = io.StringIO()
> output_file = string_io if return_string or save_output else file
>
> tree_printer = TreePrinter(depth=depth, annotated=annotated, width=width,
> file_width=file_width, sep=sep, end=end,
> file=output_file, flush=flush,
> save_to_file=save_output,
> output_format=output_format)
>
> if not objs:
> return "No objects provided to ptree"
>
> content = _generate_content(objs_copy, tree_printer, sep=sep)
> result = ''.join(filter(None, content))
>
> if save_output:
> save_to_file(result, file_name, output_format or OUTPUT_FORMAT)
>
> if not return_string and not save_output:
> print(result, file=file, end='', flush=flush)
>
> if return_string:
> return result
> elif pass_back:
> return objs[0] if len(objs) == 1 else objs
> else:
> return None
>
> except TimeoutError:
> print("Alert: ptree execution timed out.", file=file)
> return objs[0] if len(objs) == 1 and pass_back else objs if pass_back else None
> except Exception as e:
> print(f"Error in ptree: {e}", file=file)
> return objs[0] if len(objs) == 1 and pass_back else objs if pass_back else None
> >>>>>>> REPLACE
>
> Did you mean to match some of these actual lines from src/ptree/ptree.py?
>
> ```
> - For HTML content, it automatically converts to Markdown format.
> - When save_output is True, the output is saved to a file instead of being printed.
> - Dataclass instances are printed with detailed information about their attributes,
> methods, properties, and special methods.
> """
> if DISABLE_OUTPUT:
> return objs[0] if len(objs) == 1 and kwargs['pass_back'] else None
>
> try:
> with TimeoutContext(kwargs['timeout']):
> objs_copy = _safe_copy_objects(objs, kwargs['file'])
>
> if kwargs['output_format']:
> set_output_format(kwargs['output_format'])
>
> string_io = io.StringIO()
> output_file = string_io if kwargs['return_string'] or kwargs['save_output'] else kwargs['file']
>
> tree_printer = TreePrinter(**kwargs, file=output_file)
>
> if not objs:
> return "No objects provided to ptree"
>
> content = _generate_content(objs_copy, tree_printer, sep=kwargs['sep'])
> result = ''.join(filter(None, content))
>
> if kwargs['save_output']:
> save_to_file(result, kwargs['file_name'], kwargs['output_format'] or OUTPUT_FORMAT)
>
> if not kwargs['return_string'] and not kwargs['save_output']:
> print(result, file=kwargs['file'], end='', flush=kwargs['flush'])
>
> if kwargs['return_string']:
> return result
> elif kwargs['pass_back']:
> return objs[0] if len(objs) == 1 else objs
> else:
> return None
>
> except TimeoutError:
> print("Alert: ptree execution timed out.", file=kwargs['file'])
> return objs[0] if len(objs) == 1 and kwargs['pass_back'] else objs if kwargs['pass_back'] else None
> except Exception as e:
> print(f"Error in ptree: {str(e)}", file=kwargs['file'])
> return objs[0] if len(objs) == 1 and kwargs['pass_back'] else objs if kwargs['pass_back'] else None
>
> def _safe_copy_objects(objs, file):
> objs_copy = []
> for obj in objs:
> try:
> ```
>
> Are you sure you need this SEARCH/REPLACE block?
> The REPLACE lines are already in src/ptree/ptree.py!
>
> The SEARCH section must exactly match an existing block of lines including all white space, comments, indentation, docstrings, etc
> Only 3 reflections allowed, stopping.
Here is the full chat transcript + source script: aider chat history + source.zip
Is there a way to fix or bypass this?
Version and model info
No response
I'm having the same issue with php code when trying to delete whole blocks and I fail to see the actual difference that make aider trips.
Thanks for trying aider and filing this issue. This doc may be helpful:
https://aider.chat/docs/troubleshooting/edit-errors.html
I'm going to close this issue for now, but feel free to add a comment here and I will re-open or file a new issue any time.
I also face this fail many times:
The SEARCH section must exactly match an existing block of lines including all white space, comments, indentation, docstrings, etc
I am not sure the best way to minimize these fails and avoid consuming token, I keep reaching my daily limit with sonnet due to these fails. Here are a few suggestion,
- use different models for search and replace operations, if the search operation cannot find an exact match, the replace method is not called. In current behavior, it seems it creates the whole search/replace block and then it fails to find the exact match and all the tokens for the rest of the operation is kinda wasted.
- separating models used for search operation and replace operation can help choosing a model that is much better at needle-in-a-haystack problem and an optimal model for the replace operation as it needs more reasoning capability.
- from my bioinformatic background, a sequence alignment algorithm may help find matches that are not exact and can produce a partial match score, if the match score drops below %80 (can be calculated dynamically) the model stops and avoids producing the token that will be wasted.
To give context, I am trying to use aider to develop ideas and instead of working on the source code, it works on a markdown file that develops an idea in English not Python. There might be much less fails like what I described if it is working on small python source code files. I am not sure.
@hadi-nayebi, instead of using SEARCH/REPLACE blocks (which can consume a lot of tokens sometimes), we could try a more concise way to describe the changes.
This is a serious issue now in the latest release, especially with deepseek coder. Cannot run changes to javascript without seeing:
The SEARCH section must exactly match an existing block of lines including all white space, comments, indentation, docstrings, etc
Only 3 reflections allowed, stopping
I'm using architect mode. Here is my yaml config:
check-update: true
model: gpt-4o
editor-model: deepseek/deepseek-coder
weak-model: gpt-4o-mini
chat-mode: architect
cache-prompts: true
Are there any settings that can be tweaked to fix this or discussion topics on this issue?
also with mistral-large-latest gives the error. the llm provides diff code but it's set Model: mistral/mistral-large-latest with whole edit format, infinite output. Changing with other edit format can solve
// Change the greeting to a casual tone
console.log("Hey there! Let's see our planets orbiting around the Sun!");
// ... rest of code...
Tokens: 2.6k sent, 300 received.
Committing path/to/filename.js before applying edits.
The LLM did not conform to the edit format.
https://aider.chat/docs/troubleshooting/edit-errors.html
'// ... rest of code...' is not in the subpath of '/Users/kr.mao/workspace/architect'
Only 3 reflections allowed, stopping.
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
architect>
^C again to exit
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
architect>
^C KeyboardInterrupt
same here
FYI: I could circumvent this error by using --diff-mode=udiff option.
I also face similar problems here. I’ve especially seen it where it returns multiple search replace, and the first block makes changes that then make the second block change and thus not match.
Ive then seen at times where if the search is part of the replace, and it repeats, then has duplicate code sections. Definitely super finicky.
I’ll try out diff mode and see if it helps