OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

[Bug]: AI unable to edit single line in file with non-unique lines

Open createthis opened this issue 10 months ago • 4 comments

Is there an existing issue for the same bug?

  • [x] I have checked the existing issues.

Describe the bug and reproduction steps

I first ran into this issue doing real work on a unit test file that happened to have non unique lines. I did not explicitly tell the AI to modify just one line in this case. The solution was to tell the AI to overwrite the entire file.

Here's what that looked like:

ERROR:
No replacement was performed. Multiple occurrences of old_str `await handler(event, defaultContext, callback);` in lines [43, 60]. Please ensure it is unique.

I've reproduced the issue using a fictitious prompt that forces the AI to edit a single line at a time:

1. Make a file named fluffy.txt containing the words foo and bar, one per line, alternated 25 times.
2. Replace the second foo with bazz. Do not replace the entire file. Do not replace more than one line at a time.

When I was testing this prompt, if I didn't tell the AI to overwrite just one line at a time, it did the right thing and overwrote the entire file. The first time I ran into this in the real world, it did not do the right thing until I stopped it and prompted it to do so.

Here's the transcript of the fictitious prompt: https://www.all-hands.dev/share?share_id=084e0c47c63178210d1c17ed59beb91f645c6a1f123b8b7552f0830752c4a52b

OpenHands Installation

Docker command in README

OpenHands Version

No response

Operating System

None

Logs, Errors, Screenshots, and Additional Context

No response

createthis avatar Feb 22 '25 18:02 createthis

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Mar 27 '25 02:03 github-actions[bot]

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Apr 28 '25 02:04 github-actions[bot]

The current behavior is that for edits, we tell the model to choose unique lines to replace. If it doesn't, we send it an error and tell it to choose unique lines (choose more context around, to make it unique). So next time it can correct itself.

Some LLMs do so easily. Others may have difficulties. Not sure we can fix a lot here, it really depends on the model, it seems to me.

enyst avatar Apr 28 '25 07:04 enyst

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 29 '25 02:05 github-actions[bot]

This issue was closed because it has been stalled for over 30 days with no activity.

github-actions[bot] avatar Jun 06 '25 02:06 github-actions[bot]