Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

fix: incorrect line number in output snippet for str_replace and insert#110

Merged
ryanhoangt merged 3 commits into
mainfrom
fix-incorrect-line-num-str-replace-insert
Apr 11, 2025
Merged

fix: incorrect line number in output snippet for str_replace and insert#110
ryanhoangt merged 3 commits into
mainfrom
fix-incorrect-line-num-str-replace-insert

Conversation

@ryanhoangt
Copy link
Copy Markdown
Contributor

@ryanhoangt ryanhoangt commented Apr 9, 2025

Description

Currently, we don't have tests for editing commands on large files (where outputs will be just a snippet in the 4-line window) so we didn't catch this error previously. I investigated a bit and it seems in an old PR to reduce memory consumption, we (and OpenHands) messed up with the line numbers when making the output snippet for str_replace and insert commands, as some places they are 0-based and in other places they are 1-based.

This PR adds a test for it and fixes that bug. We might want to run an eval to see how this affects performance.

CC: @enyst if you have some extra thoughts on this issue.

Related Issue

OpenHands/OpenHands#7724

@ryanhoangt ryanhoangt requested a review from xingyaoww April 9, 2025 14:56
Copy link
Copy Markdown
Collaborator

@xingyaoww xingyaoww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!! 😭 This is tricky but important to get right

@xingyaoww
Copy link
Copy Markdown
Collaborator

Can you release openhands-aci and bump the version on OpenHands repo once this merged?

@enyst
Copy link
Copy Markdown
Contributor

enyst commented Apr 9, 2025

Awesome, thank you! Yes, it will be interesting to see an eval, because the LLM really did get confused by the shifting line numbers.

In the swe-bench instance from which I posted the snippet, Gemini gave up on using str_replace_editor when it saw the unexpected line numbers, and tried its luck with sed. 😂

@ryanhoangt
Copy link
Copy Markdown
Contributor Author

ryanhoangt commented Apr 11, 2025

I ran an eval on 100 instances and it seems that we get comparable results to the old version, not better (55/100 vs. 56/100). Merging it now!

@ryanhoangt ryanhoangt merged commit 5ef3dcd into main Apr 11, 2025
3 checks passed
@ryanhoangt ryanhoangt deleted the fix-incorrect-line-num-str-replace-insert branch April 11, 2025 10:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants