Repository navigation
Description
Is there an existing issue for the same bug?
- I have searched existing issues and this is not a duplicate.
Bug Description
Deleting a host-local conversation (OH_CONVERSATION_RUNTIME=local, the default) that was started with worktree=true removes only its conversation directory. Its git worktree under conversation_worktree_root/<id>/ (default /tmp/conversation-worktrees) stays on disk forever, with its dependencies, and stays registered in the user's repository (git worktree list). Nothing else ever removes it.
In Agent Canvas this happens for local conversations started in the "New worktree" workspace mode (the default is "Local repo", but the last choice is remembered), and for child conversations the agent launches with launch_child_conversation on a local target, whose isolation defaults to "worktree". Each of those leaves its worktree behind when deleted.
Expected Behavior
Deleting the conversation removes its worktree checkout and git's record of it. The openhands/<id> branch, which holds the agent's commits, is kept.
Actual Behavior
After DELETE /api/conversations/{id}:
after delete: worktree dir exists = True
git worktree list:
…/repo 8ecc1c8 [main]
…/conversation-worktrees/5a2edba7-…/repo 8ecc1c8 [openhands/5a2edba7-…]
Steps to Reproduce
- Start the agent-server in local mode.
POST /api/conversationswith"workspace": {"kind": "LocalWorkspace", "working_dir": "<a git repo>"}and"worktree": true.DELETE /api/conversations/{id}.ls /tmp/conversation-worktrees/<id>andgit -C <repo> worktree list: the worktree is still there.
Acceptance Criteria
- Deleting a local conversation removes
conversation_worktree_root/<id>/and prunes it fromgit worktree list. - The
openhands/<id>branch and its commits are kept. - Other conversations' worktrees and the user's own worktrees of the same repository are untouched.
- Delete still succeeds if the source repository is gone; a link planted in place of the worktree dir is not followed.
Installation Method
From source (agent-server via uv run)
SDK Version
1.53.0 (main)
Version Confirmation
- I have confirmed this bug exists on the LATEST version of OpenHands SDK
Python Version
3.13
Model Name (if applicable)
N/A
Operating System
MacOS
Additional Context
Fix: #5547. Related but separate: #5307 (worktrees created across host/container namespaces in Docker mode).
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Root cause is in the agent-server. ConversationService.delete_conversation removes only the conversation directory, while _create_conversation_worktree puts the checkout under conversation_worktree_root/<id>/<repo name> (default /tmp/conversation-worktrees) and registers it in the source repository; nothing removes either on delete. This affects local-runtime conversations (OH_CONVERSATION_RUNTIME=local, the default) created with worktree=true: Agent Canvas's "New worktree" workspace mode and agent-launched child conversations whose local isolation defaults to worktree.
Scope: make delete remove the conversation's own worktree directory and its git worktree registration (prune against the source repository), while preserving the openhands/<id> branch and the commits on it. Other conversations' worktrees and the user's own worktrees of the same repository must be unaffected. Delete must still succeed when the source repository is gone, and must not follow a symlink planted where the worktree directory was.
Non-goals: the Docker-runtime cross-namespace case (#5307) is out of scope; no disk-budget or background reclaimer; no change to worktree creation, branch naming, or the delete API contract. Uncommitted work in the worktree is discarded with the conversation; only committed work on openhands/<id> survives.
Acceptance Criteria
- For a local (
OH_CONVERSATION_RUNTIME=local) conversation created withworktree=true,DELETE /api/conversations/{id}removesconversation_worktree_root/<id>/(default/tmp/conversation-worktrees/<id>/); the directory no longer exists afterward. - After delete,
git -C <source-repo> worktree listno longer lists the deleted conversation's worktree, and its stale entry under<source-repo>/.git/worktrees/is pruned. - The
openhands/<id>branch still exists in the source repository and still points at the conversation's last commit. - Deleting one conversation leaves other conversations' worktrees (including uncommitted changes in them) and the user's own worktrees of the same repository untouched.
- Delete still succeeds, returning the same success result as today, when the source repository has already been removed; the conversation directory is still removed.
- If the conversation's worktree path is a symlink, the target it points to is not modified or removed.
- A conversation created without
worktree=trueleaves the source repository and its worktrees unchanged. - The
DELETE /api/conversations/{id}request/response contract and the generated OpenAPI/TypeScript client surface are unchanged. - Validation exercises a real local agent-server against real git repositories (no mocks): a test deletes a worktree conversation and asserts both the removed artifacts and the surviving branch, per repository testing guidance.
Activity