Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lukewlms opened this issue May 3, 2024 · 3 comments
Labels
question Further information is requested

Comments

@lukewlms
Copy link

lukewlms commented May 3, 2024

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:

  • I clearly in the conversation made only 3 requests, but aider made 4 commits
  • Two commit messages are extremely long and include the full conversation with Aider, as well as the diff itself making the commit message a whopping 4.5 pages long. Example below. This seems like also a possible mistake since the two other commit messages are concise and do not contain the full conversation with the LLM, including code diff, as part of the message. But this also happened with some subsequent requests, so maybe this is actually a (surprising?) default. I figured out how to change the options so commits wouldn't happen automatically, but the issue still happens (malformed request is immediately applied to the files, but aider also continues to automatically ask the LLM to correct it).
  • I thought this problem might be due to interspersing another commit with Aider's commits, but the external commits did not modify the same files at all so it seems that should not be the problem. I also repro'd the same error (below) without any other commits happening.

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

@lukewlms lukewlms changed the title "Malformed response" is still applied, resulting in mangled output "Malformed response" is still applied and committed, resulting in mangled output May 3, 2024
@paul-gauthier
Copy link
Owner

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?

@paul-gauthier paul-gauthier added the question Further information is requested label May 3, 2024
@lukewlms
Copy link
Author

lukewlms commented May 6, 2024

@paul-gauthier Thanks for the reply.

  • I read the FAQ - I have not tried with a different model than Claude Opus.
  • There were probably ~6-8 pages of code included from the relevant files, but from what I recall it repro'd with less code
  • My read was that changes were being applied despite the malformation, when I would expect Aider to decline to apply changes if the format is incorrect (since it's asking the LLM for a redo)

@paul-gauthier
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants