Repository navigation
fix(agent-server): remove a deleted local conversation's worktree, keep its branch - #5547
Conversation
…ep its branch Deleting a host-local conversation started with worktree=true left its git worktree on disk and registered in the user's repository. Remove the checkout and prune git's record of it; the openhands/<id> branch with the agent's commits is kept.
|
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
|||||||||||||||||||||||||
…real git Replace the mocked EventService with a local-mode server configured by environment, and cover the failure paths: uncommitted work, a missing source repository, a link planted in place of the worktree dir, other conversations' and the user's own worktrees, and conversations without a worktree.
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Reviewed head f9ec3438db45705a3744e9c171b3180d8c63fc0b (matches the requested SHA) against base main, with the repo AGENTS.md and .agents/skills/custom-codereview-guide.md.
Scope: this belongs in this repository (the Agent Server owns local conversation storage), and #5553 is ready-for-dev / priority:medium, so the direction is clear. The change addresses the reported bug: delete_conversation now removes conversation_worktree_root/<id>/ and prunes the source repo's git registration, keeping the openhands/<id> branch.
Verification on this head: CI is green; tests/agent_server/test_local_storage.py passes 6/6 in the workspace, and test_conversation_service.py + test_conversation_router.py (237 tests) still pass. The _git invocation is hardened (--no-optional-locks, core.fsmonitor=false, sanitized_env) and the symlink guard is sound.
One material finding on the fork path, described inline: a forked conversation shares its source's worktree, so deleting the source now deletes the live fork's workspace.
🔄 CHANGES REQUESTED
A fork works in its source's worktree, so deleting the source removed the fork's checkout. Delete now resolves the worktree dir from the conversation's workspace and removes it only when no remaining conversation uses it, so the last of a source and its forks to be deleted cleans it up.
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Reviewed head 031b68e6ff6af05b96bb20db481d4cf645857e7a against base main, with the repo AGENTS.md and .agents/skills/custom-codereview-guide.md.
Scope: this belongs in this repository (the Agent Server owns local conversation storage), and #5553 is ready-for-dev / priority:medium. The change fixes the reported bug: delete_conversation removes the conversation's worktree and prunes the source repo's git registration, keeping the openhands/<id> branch.
The prior material finding is addressed. Forks persist their source's worktree path (LocalConversation.fork passes workspace=self.workspace, and ForkConversationRequest has no workspace field), so the new conversation_worktree_dir + _conversation_records ownership check now removes the worktree only when no remaining conversation still references it, with test_a_fork_keeps_the_shared_worktree_until_it_is_deleted covering the delete-source-then-delete-fork sequence. The helper's rel.parts[0] shape is correct, including the relative-workspace case and the root.resolve() symlink handling (.resolve() on a relative working_dir is consistent with the absolute root, since it is never under root).
Verification on this head: all 30 CI checks pass; tests/agent_server/test_local_storage.py plus test_conversation_service.py and test_conversation_router.py pass (238 tests) in the workspace. No material correctness, security, or compatibility issue remains.
✅ APPROVED
neubig
left a comment
There was a problem hiding this comment.
The current head addresses the shared-worktree regression, includes real server and git coverage, and has no unresolved review threads or material code issues. Approved for merge. This review was submitted by an AI agent (OpenHands) on behalf of Graham Neubig.
Worktree cleanup on delete landed on main (#5547), and the Docker knobs stay env-only for now, so misc_settings.runtime has nothing left to carry.
Worktree cleanup on delete landed on main (#5547), and the Docker knobs stay env-only for now, so misc_settings.runtime has nothing left to carry.
Deleting a Docker conversation ran `git branch -D openhands/<id>` on the host, so commits the agent made in its worktree became unreachable. A deleted local conversation keeps its branch (OpenHands#5547). Reuse remove_conversation_worktree for every worktree under the conversation's runtime worktrees dir. It keeps branches, runs git with core.fsmonitor disabled (the repository config is agent-writable), and also unregisters worktrees of child conversations launched with worktree isolation, which the previous cleanup missed. The cleanup no longer needs to rebuild the repository path or the inner server's worktree layout.
HUMAN:
Deleting a local conversation started with worktree=true left its git worktree on disk and registered in the repo forever (I reproduced it). Deleting the conversation now removes the worktree; the
openhands/<id>branch with the agent's commits is kept. Uncommitted changes in the worktree are deleted with the conversation.AGENT:
Why
Deleting a host-local conversation removes only its conversation directory. When it was started with
worktree=true, its git worktree underconversation_worktree_root/<id>/(default/tmp/conversation-worktrees) stays on disk forever, still registered in the user's repository (git worktree list).This is the delete fix from #5433, split out as Engel suggested there: it needs no reclaimer, so it does not have to wait for the rest of the storage stack.
Summary
delete_conversationnow callsremove_conversation_worktree(conversation_worktree_root, id)after removing the conversation directory.conversation_worktree_root/<id>/and runsgit worktree prunein each source repository. Theopenhands/<id>branch, with the agent's commits, is kept.core.fsmonitor=falseand--no-optional-locks, because the repository config is agent-writable. A symlinked conversation directory is left alone.Issue Number
Fixes #5553
How to Test
The tests start a real local-mode server (configured through
OH_*environment variables, as the CLI does) and use real git repositories; nothing is mocked. Each checks what must survive as well as what must go:openhands/<id>branch keeps the agent's commit; the user's checkout stays clean onmain.worktree=trueleaves the repository alone.Mutation-checked, each makes the expected tests fail: no removal on delete (1, 2, 3, 5), following a planted link (4), skipping
git worktree prune(1, 5), deleting the agent's branch (1, 2), removing the whole worktree root (5).Video/Screenshots
N/A (server-side).
Type
Notes
🐳 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:031b68e-pythonRun
All tags pushed for this build
About Multi-Architecture Support
031b68e-python) is a multi-arch manifest supporting both amd64 and arm64031b68e-python-amd64) are also available if needed