Skip to content

fix(tools): edit a symlink's target instead of replacing the link - #6358

Merged
VascoSch92 merged 2 commits into
OpenHands:mainfrom
yftx293:fix/file-editor-preserve-symlink
Nov 2, 2026
Merged

VascoSch92 merged 2 commits into
OpenHands:mainfrom
yftx293:fix/file-editor-preserve-symlink

Conversation

@yftx293

@yftx293 yftx293 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

Fixed the symlink-replacement bug from #6348. I reviewed the diff and the test; editing through a symlink must keep the link and edit its target.


AGENT:

Why

FileEditor._atomic_write renamed a temp file onto path with Path.replace, and a rename onto a symlink path replaces the link itself with a regular file. Any edit (str_replace, insert, create) performed through a symlink therefore destroyed the link and silently rewrote the wrong file, leaving the original target untouched.

Summary

  • Resolve a symlink path to its target at the top of _atomic_write, so the temp file is created beside — and renamed onto — the target, and the link survives. One change covers every command that routes through write_file; atomicity is preserved relative to the target's directory.
  • Port the pinned test test_str_replace_through_symlink_edits_target 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: "atomic write replaces a symlink with a regular file")

How to Test

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

Before this change the test fails (link.txt is no longer a symlink and target.txt still reads hello); after, it passes — the link stays a symlink and the target reads bye — 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. The test uses symlink_or_skip, so it runs for real wherever symlink creation is permitted.

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 relative links, chained links, undo through a link and create on a dangling link. The link survives and the target keeps its permissions.

@VascoSch92
VascoSch92 enabled auto-merge (squash) November 2, 2026 11:42
@VascoSch92
VascoSch92 merged commit 80d2e5f 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.

2 participants