Skip to content

fix(tools): terminate an unterminated last line before inserting after it - #6357

Merged
VascoSch92 merged 2 commits into
OpenHands:mainfrom
yftx293:fix/file-editor-insert-no-eol
Nov 2, 2026
Merged

VascoSch92 merged 2 commits into
OpenHands:mainfrom
yftx293:fix/file-editor-insert-no-eol

Conversation

@yftx293

@yftx293 yftx293 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

Fixed the no-trailing-newline insert merge from #6348. I reviewed the diff and the test; an insert must start on its own line.


AGENT:

Why

FileEditor.insert copied the file's lines verbatim, so when the file's last line had no trailing newline and the insert landed after it (insert_line == num_lines), the inserted content fused onto that line: editing a\nb with insert_line=2, new_str="x" produced a\nbx\n.

Summary

  • Terminate an unterminated last line before appending the inserted content, so the insert starts on its own line. The guard can only fire on the file's final line, since a line without a trailing newline is by definition the last one.
  • Port the pinned test test_insert_after_last_line_without_trailing_newline from the worktree-test-edge-cases branch (commit f2fcf6e) without its xfail(strict=True) marker, per the [Bug]: Edge-case tests expose ~70 bugs across the SDK, agent server, tools and workspaces #6348 menu's acceptance criteria.

Issue Number

Part of #6348 (menu sub-item: "insert after a last line with no trailing newline merges lines")

How to Test

uv run pytest tests/tools/file_editor/test_basic_operations.py -k test_insert_after_last_line_without_trailing_newline

Before this change the test fails (['a', 'bx']); after, it passes (['a', 'b', 'x']), and the full tests/tools/file_editor/ suite is 168 passed / 1 skipped (platform) with no regression. ruff check/format on the touched files are clean.

Type

  • Bug fix

Notes

None.

@VascoSch92 VascoSch92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! I checked the test fails without the fix, and tried a one-line file, insert at line 0, an empty file and undo locally. All correct.

@VascoSch92
VascoSch92 enabled auto-merge (squash) November 2, 2026 11:31
@VascoSch92
VascoSch92 merged commit 8e1aa22 into OpenHands:main Nov 2, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants