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

[Bug]: Editing does not work on lines that contain \n #3650

Open
2 tasks done
neubig opened this issue Aug 29, 2024 · 11 comments · May be fixed by #3904
Open
2 tasks done

[Bug]: Editing does not work on lines that contain \n #3650

neubig opened this issue Aug 29, 2024 · 11 comments · May be fixed by #3904
Assignees
Labels
bug Something isn't working severity:critical Affecting all users
Milestone

Comments

@neubig
Copy link
Contributor

neubig commented Aug 29, 2024

Is there an existing issue for the same bug?

Describe the bug

I have found an easy-to-reproduce error in our editing pipeline that should be a big win if we can fix it: editing seems to break on lines that contain \n.

Here's an example:

Current OpenHands version

c875a5fb777fcdb387df13d78789a5597f3d29e3

Installation and Configuration

make build; make run

Model and Agent

  • Model: claude-3-5-sonnet
  • Agent: CodeActAgent

Operating System

Mac OS

Reproduction Steps

No response

Logs, Errors, Screenshots, and Additional Context

Part of #3231

@neubig neubig added the bug Something isn't working label Aug 29, 2024
@neubig neubig changed the title [Bug]: Editing breaks on lines that contain \n [Bug]: Editing does not work on lines that contain \n Aug 29, 2024
@neubig neubig added the severity:critical Affecting all users label Aug 29, 2024
@shubhamofbce
Copy link
Contributor

I tried it using gpt-4o and it worked for me. Intendation was broken after the edit but it fixed that by itself.
image
Output:
image

@neubig
Copy link
Contributor Author

neubig commented Aug 30, 2024

Interesting! So it may be a claude problem to some extent. But actually @shubhamofbce it didn't really work with gpt-4o either, because gpt-4o deleted the newlines entirely (which was not requested).

@shubhamofbce
Copy link
Contributor

I see the problem now, It removed the newlines(\n) completely. I will take a look at this once i get some time.
I am currently working on #3575

@neubig
Copy link
Contributor Author

neubig commented Aug 30, 2024

Awesome, thanks!

@xingyaoww
Copy link
Contributor

I think this may also be fixed if @RajWorking can implement a EditAction using the Aider Diff format

@shubhamofbce
Copy link
Contributor

Then we can assign this to @RajWorking and I will look into something else.

@shubhamofbce shubhamofbce removed their assignment Aug 30, 2024
@tobitege
Copy link
Collaborator

tobitege commented Sep 5, 2024

This is being worked on by @RajWorking

@RajWorking
Copy link
Contributor

I am working on this. Thanks!

@tobitege
Copy link
Collaborator

tobitege commented Sep 16, 2024

@neubig - this issue is important to get fixed asap, imo.
cc @RajWorking @xingyaoww @enyst

Earlier today I was running ~15 instances of the Aider bench (which previously also failed) and was wondering why the edit_file_by_replace was often not successful in finding the text-to-be-replaced without apparent reason (no text cut off).

As raised in this very issue, the \n is converted incorrectly:

LLM (Sonnet) action:

15:54:00 - openhands:DEBUG: stream.py:134 - Adding IPythonRunCellAction id=7 from AGENT
15:54:00 - openhands:INFO: agent_controller.py:489
ACTION
**IPythonRunCellAction**
THOUGHT: Thank you for the update. Let's continue refactoring the code. We'll now update the `format_entries` function to use the new `Currency` class and improve its structure:
CODE:
edit_file_by_replace(
    'ledger.py',
    to_replace="""def format_entries(currency, locale, entries):
    if locale == 'en_US':
        # Generate Header Row
        table = 'Date'
        for _ in range(7):
            table += ' '
        table += '| Description'
        for _ in range(15):
            table += ' '
        table += '| Change'
        for _ in range(7):
            table += ' '

        while len(entries) > 0:
            table += '\n'

            # Find next entry in order
            min_entry_index = -1

OBSERVATION with error (sorry, but the formatting gets a bit disrupted here):

15:54:00 - openhands:DEBUG: stream.py:134 - Adding IPythonRunCellObservation id=8 from AGENT
15:54:00 - openhands:INFO: agent_controller.py:215
OBSERVATION
**IPythonRunCellObservation**
[No exact match found in ledger.py for
"""
def format_entries(currency, locale, entries):
    if locale == 'en_US':
        # Generate Header Row
        table = 'Date'
        for _ in range(7):
            table += ' '
        table += '| Description'
        for _ in range(15):
            table += ' '
        table += '| Change'
        for _ in range(7):
            table += ' '

        while len(entries) > 0:
            table += '
'

            # Find next entry in order
            min_entry_index = -1
"""

This looks like a common contributor for failed instances just because the step-limits fail and/or loop detection gets triggered?

@tobitege tobitege linked a pull request Sep 16, 2024 that will close this issue
2 tasks
@enyst
Copy link
Collaborator

enyst commented Sep 17, 2024

Ah, I see the issue with '\n'. But the indentation is actually correct?

@tobitege
Copy link
Collaborator

It was a formatting issue in the comment, changed some triple-backticks, looks little better now 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working severity:critical Affecting all users
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

7 participants
@neubig @enyst @tobitege @xingyaoww @shubhamofbce @RajWorking and others