paul-gauthier / aider

aider is AI pair programming in your terminal
https://aider.chat/
Apache License 2.0
18.7k stars 1.73k forks source link

"Malformed response" is still applied and committed, resulting in mangled output #588

Closed lukewlms closed 3 months ago

lukewlms commented 4 months ago

Issue

After seeing a "Malformed" error response from Aider, which didn't like Claude's answer, Aider still applied the updates. When Claude immediately sent a second, "corrected" set of updates at Aider's requests, these were also applied (and accepted without complaint). But the resulting code is clearly erroneous, with duplicated lines, unreachable code, and missing variables.

Related notes:

Example of unreachable code:

(These mistakes caught my attention since I've used Opus quite a bit directly in the web interface and it has never produced obvious, compile-preventing errors, as happened multiple times in a row here. I am pretty sure it is due to how the diff is being applied.)

   if (import.meta.env.SHOULD_INCLUDE_IMAGES !== "1") {
     html("img").remove();
   }

   return html.html();

   const finalContent = unelidedFull.html();

Aiden's log during conversation:

Malformed response #1, retrying...
https://aider.chat/docs/faq.html#aider-isnt-editing-my-files
InvalidEditBlock: edit failed!

index.ts does not contain the *exact chunk* of SEARCH lines you specified.
Try again.
DO NOT skip blank lines, comments, docstrings, etc!
The SEARCH block needs to be EXACTLY the same as the lines in index.ts with nothing missing!

index.ts does not contain these 22 exact lines in a row:

...
Malformed response #1, retrying...
https://aider.chat/docs/faq.html#aider-isnt-editing-my-files
InvalidEditBlock: edit failed!

index.ts does not contain the *exact chunk* of SEARCH lines you specified.
Try again.
DO NOT skip blank lines, comments, docstrings, etc!
The SEARCH block needs to be EXACTLY the same as the lines in index.ts with nothing missing!

index.ts does not contain these 1 exact lines in a row:

...

Version and model info

Aider v0.31.1 Models: claude-3-opus-20240229 with diff edit format, weak model claude-3-haiku-20240307 Git repo: .git with 9 files Repo-map: using 1024 tokens


I hope it's an easy fix, this seems like quite a promising tool!


Edit: I've verified this again trying to make changes in a different code base. So far about half of responses have been identified as Malformed. Here is a partial log of the Aider output. I canceled the "correction" response but verified that the original "malformed" response was nevertheless applied.


src/ImportHtml/HtmlFileUploadControl.tsx

<<<<<<< SEARCH const { pageIds, sectionIds, joplinNoteIds, joplinFolderIds } = getIdsFromTags(groupTag);

 const { pageIds, sectionIds, joplinNoteIds, joplinFolderIds } =
   getIdsFromTags([groupTag]);

REPLACE

These changes should resolve the errors related to the updated return value of getIdsFromTags. The callers now destructure the returned object and access the appropriate properties to get the desired IDs.

Please let me know if you have any further questions or if there are any other issues you need assistance with.

Malformed response #1, retrying... https://aider.chat/docs/faq.html#aider-isnt-editing-my-files InvalidEditBlock: edit failed!

src/ImportHtml/HtmlFileUploadControl.tsx does not contain the exact chunk of SEARCH lines you specified. Try again. DO NOT skip blank lines, comments, docstrings, etc! The SEARCH block needs to be EXACTLY the same as the lines in src/ImportHtml/HtmlFileUploadControl.tsx with nothing missing!

src/ImportHtml/HtmlFileUploadControl.tsx does not contain these 2 exact lines in a row:

    const { pageIds, sectionIds, joplinNoteIds, joplinFolderIds } =
      getIdsFromTags(groupTag);

I apologize for the confusion. Let me provide the correct changes for the callers of getIdsFromTags in the src/ImportHtml/HtmlFileUploadControl.tsx file.

src/ImportHtml/HtmlFileUploadControl.tsx src/ImportHtml/HtmlFileUploadControl.tsx

<<<<<<< SEARCH const allIdsToRemove = getIdsFromTags(ta

^C again to exit

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── src/Components/getPatch.test.tsx src/ImportHtml/HtmlFileUploadControl.tsx src/Joplin/JoplinShared.ts

paul-gauthier commented 4 months ago

Thanks for trying aider and filing this issue.

Have you read the FAQ entry that is linked from the errors? https://aider.chat/docs/faq.html#aider-isnt-editing-my-files

Have you added a lot of source code to the chat, more than just the file(s) that needs to be edited?

lukewlms commented 4 months ago

@paul-gauthier Thanks for the reply.

paul-gauthier commented 3 months ago

I recently made some improvements for partially applied edits. The change is available in the main branch. You can get it by installing the latest version from github:

python -m pip install --upgrade git+https://github.com/paul-gauthier/aider.git

If you have a chance to try it, let me know if it works better for you.

paul-gauthier commented 3 months ago

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.