Skip to content

fix(tools): surface unreadable patch targets as tool errors - #6372

Merged
VascoSch92 merged 1 commit into
OpenHands:mainfrom
yftx293:fix/apply-patch-unreadable-files
Nov 2, 2026
Merged

VascoSch92 merged 1 commit into
OpenHands:mainfrom
yftx293:fix/apply-patch-unreadable-files

Conversation

@yftx293

@yftx293 yftx293 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

Fixed the unreadable-file crash from #6348. I reviewed the diff and the tests; a patch must return a tool error when its target cannot be read as text.


AGENT:

Why

load_files wrapped only FileNotFoundError in a DiffError. Any other read failure escaped the executor as an exception: a non-UTF-8 file raised UnicodeDecodeError, and a directory raised IsADirectoryError on Linux/macOS (PermissionError on Windows). The agent got a crash instead of an error observation, and on the non-UTF-8 path the file was left untouched but the failure was indistinguishable from a tool bug.

Summary

  • Convert OSError and UnicodeDecodeError from the patch's file read into a DiffError, so the executor returns an error observation like it does for every other invalid patch. The message names the path and the underlying error.
  • Port the pinned tests test_update_non_utf8_file_returns_error_observation and test_update_directory_returns_error_observation from the worktree-test-edge-cases branch (commit f2fcf6e) without their xfail(strict=True) markers, 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-items: "non-UTF-8 file raises UnicodeDecodeError out of the executor" and "updating a directory raises IsADirectoryError out of the executor")

How to Test

uv run pytest tests/tools/apply_patch/test_apply_patch_executor.py -k "non_utf8 or directory"

Before this change both cases raise out of run_exec; after, both return obs.is_error and the non-UTF-8 file's bytes are unchanged. The full tests/tools/apply_patch/ suite is 15 passed. ruff check/format on the touched files are clean.

Type

  • Bug fix

Notes

Windows raises PermissionError for the directory case rather than IsADirectoryError; both are OSError, so the single catch covers the platforms the tests run on.

@VascoSch92
VascoSch92 merged commit bc23a7b into OpenHands:main Nov 2, 2026
38 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