Repository navigation
fix(agent-server): make safe_rmtree report what it could not remove - #6597
Merged
Merged
Conversation
The rmtree error handler chmod-ed and retried on every error and then swallowed whatever was left, so safe_rmtree returned True while a read-only subdirectory kept the tree on disk, and for a symlink or a plain file it chmod-ed the target to write-only and still reported success. Retry only permission errors, ignore entries that are already gone, and re-raise the rest so the caller gets False.
Closed
75 of 86 tasks
Contributor
Contributor
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
VascoSch92
marked this pull request as ready for review
November 7, 2026 16:24
all-hands-bot
approved these changes
Nov 7, 2026
all-hands-bot
left a comment
Collaborator
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Reviewed fresh at head 65fd3054 (re-fetched current PR state, reviews, and check results before deciding). This is a correct, well-scoped fix for the three pinned #6348 items; I found no material correctness, security, or compatibility defect.
What I verified:
- Handler semantics on Python 3.13 (fd-based
rmtree):PermissionError→ clear the read-only bit and retry (the read-only-file dance is preserved);FileNotFoundError→ ignored, which is equivalent to the oldos.path.exists()tolerance; any other error re-raised and unwound out ofrmtreein a bounded way (no hang), landing insafe_rmtree's existingexcept, which logs and returnsFalse. - Before/after evidence through the real entry point: reproducing the three scenarios against
main's implementation shows symlink →Truewhile the link remains and the target dir is chmod'd; read-only subdir →Truewhile the tree stays on disk; regular file →Truewhile the file stays and is chmod'd to write-only. On this head, all three new tests pass and the result honestly matches whether the tree is gone. - All seven call sites traced (
trash._remove,remove_conversation_worktree,remove_conversation,_create_conversation_worktree, fork cleanup,docker_runtimerouters): none relies on the old swallow-and-True; trash and worktree removal specifically depend on the now-honestFalse. - No compatibility surface touched:
safe_rmtreeis used only insideopenhands-agent-server; no REST/OpenAPI, TypeScript client, or persisted-state change. - Tests: the 3 new tests pass here;
tests/agent_server/storage+test_local_storage.py+test_conversation_service.py(162 passed) anddocker_runtime/test_routes.py(24 passed) are green; CI on this exact head passes (only the draft-PR description validation is skipped, which is a process gate unrelated to the code).
✅ APPROVED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HUMAN:
just fixing a bug
AGENT:
Why
safe_rmtreepasses anonerrorhandler toshutil.rmtreethat, for any error, chmods the path toS_IWRITE, retries, and logs-and-swallows whatever still fails, sormtreeitself never raises andsafe_rmtreereturnsTrue. That hides three failures:rmtreerefuses ("Cannot call rmtree on a symbolic link"), and the handler then chmods the link's target directory to write-only (os.chmodfollows the link). The link remains and the result isTrue.True.Callers rely on the result:
remove_conversation_worktreeskipsgit worktree pruneand trash raisesOSErrorwhen it isFalse.Summary
PermissionError(clear the read-only bit, call the function again), ignoresFileNotFoundError(already gone, as the oldexistsguard did), and re-raises anything else. Anything that still fails propagates to the existingexceptinsafe_rmtree, which logs and returnsFalse.tests/agent_server/test_utils.py, with the file'sneeds_permission_checks/_restore_permissionshelpers.Issue Number
Part of #6348 (items: "safe_rmtree on a symlinked dir chmods the link target to write-only and returns True while the link remains", "safe_rmtree's onerror handler swallows failures, so it returns True while a read-only subdirectory keeps the tree on disk", "safe_rmtree on a regular file returns True, leaves the file, and chmods it to write-only").
How to Test
The three new tests fail on
mainand pass here. The othersafe_rmtreeusers' tests pass too (test_conversation_service.py,docker_runtime/test_routes.py,storage/: 179).Type
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:65fd305-pythonRun
All tags pushed for this build
About Multi-Architecture Support
65fd305-python) is a multi-arch manifest supporting both amd64 and arm6465fd305-python-amd64) are also available if needed