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

Clamp view_range end to file length and emit warning instead of error (fixes #154)#157

Merged
ryanhoangt merged 6 commits into
mainfrom
fix/154-view-range-clamp
Aug 21, 2025
Merged

Clamp view_range end to file length and emit warning instead of error (fixes #154)#157
ryanhoangt merged 6 commits into
mainfrom
fix/154-view-range-clamp

Conversation

@xingyaoww
Copy link
Copy Markdown
Collaborator

Summary

  • Change OHEditor.view to clamp end_line to the file's length when the provided view_range end is beyond EOF.
  • Preserve -1 semantics (end of file).
  • Append a clear NOTE warning to the output when clamping occurs instead of raising an error.

Why
Fixes #154: Previously, requesting a range beyond EOF raised an error. The desired behavior is to show up to the end of the file and warn the user.

Changes

  • openhands_aci/editor/editor.py
    • Normalize end_line: if -1 use EOF; if > num_lines, cap to num_lines and set a warning message.
    • Ensure end_line >= start_line after normalization.
    • Append a NOTE: We only show up to {num_lines} since there's only {num_lines} lines in this file when clamping occurs.
  • tests/integration/editor/test_error_handling.py
    • Update out-of-bounds test to assert on NOTE warning instead of the old error message.

Testing

  • Ran selective tests due to environment memory constraints:
    • tests/integration/editor/test_error_handling.py: PASS
    • tests/integration/test_oh_editor.py: PASS
    • tests/integration/editor/test_non_utf8_operations.py: PASS
  • pre-commit hooks (ruff, format, mypy) all passed.

Notes

  • Full pytest run hit a container MemoryError unrelated to these changes; the relevant tests covering the change pass.

Co-authored-by: openhands openhands@all-hands.dev

@xingyaoww can click here to continue refining the PR

…error when beyond EOF (fixes #154)

- Normalize end_line by capping to num_lines and allow -1 as before
- Append NOTE: warning to output when clamped
- Update tests to assert on warning text

Co-authored-by: openhands <openhands@all-hands.dev>
Comment thread openhands_aci/editor/editor.py Outdated
Co-authored-by: openhands <openhands@all-hands.dev>
Comment thread openhands_aci/editor/editor.py Outdated
Comment thread openhands_aci/editor/editor.py Outdated
Comment thread tests/integration/editor/test_error_handling.py Outdated
@ryanhoangt ryanhoangt merged commit 8fc0592 into main Aug 21, 2025
4 checks passed
@ryanhoangt ryanhoangt deleted the fix/154-view-range-clamp branch August 21, 2025 09:45
enyst pushed a commit to enyst/openhands-aci that referenced this pull request Aug 22, 2025
…fixes OpenHands#154) (OpenHands#157)

* editor: clamp view_range end to file length, emit warning instead of error when beyond EOF (fixes OpenHands#154)

- Normalize end_line by capping to num_lines and allow -1 as before
- Append NOTE: warning to output when clamped
- Update tests to assert on warning text

Co-authored-by: openhands <openhands@all-hands.dev>

* Prepend warning message instead of appending it

Co-authored-by: openhands <openhands@all-hands.dev>

* Update openhands_aci/editor/editor.py

* Update openhands_aci/editor/editor.py

* bump to 0.3.2

* Update tests/integration/editor/test_error_handling.py

---------

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: Ryan H. Tran <descience.thh10@gmail.com>
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.

We should not error out when agent produces range that's beyond file length

4 participants