fix(plan): clean up worktree sandbox on plan cancel #9230

Closed
opened 2026-04-14 11:53:57 +00:00 by hamza.khyari · 2 comments
Member

Summary

When a user cancels a plan after execute (plan cancel), the git worktree branch and directory created during execute are not cleaned up. This is a resource leak — dangling worktrees accumulate over time.

Metadata

  • Commit Message: fix(plan): clean up worktree sandbox on plan cancel
  • Branch: bugfix/cancel-worktree-cleanup

Current Behavior

  1. plan execute creates worktree branch cleveragents/plan-<id> and directory /tmp/ca-sandbox-<id>-...
  2. plan cancel transitions the plan to cancelled state
  3. Worktree branch and directory are NOT removed
  4. git worktree list shows the dangling worktree
  5. git branch shows the dangling branch

Expected Behavior

  1. plan cancel should detect if a worktree sandbox exists for the plan
  2. Remove the worktree directory (git worktree remove)
  3. Delete the branch (git branch -D)
  4. Prune worktree references (git worktree prune)

Subtasks

  • In the cancel CLI handler, detect worktree branch cleveragents/plan-<id> for the plan's linked git resource
  • Remove worktree and delete branch before or after cancellation
  • Verify with scenario-10 end-to-end test

Definition of Done

  • plan cancel removes the worktree directory and branch
  • git worktree list shows no dangling worktrees after cancel
  • Source files are unchanged
  • Scenario-10 passes with clean worktree state

Spec Reference

specification.md §13256-13260 (Sandbox Cleanup)

## Summary When a user cancels a plan after execute (`plan cancel`), the git worktree branch and directory created during execute are not cleaned up. This is a resource leak — dangling worktrees accumulate over time. ## Metadata - **Commit Message**: `fix(plan): clean up worktree sandbox on plan cancel` - **Branch**: `bugfix/cancel-worktree-cleanup` ## Current Behavior 1. `plan execute` creates worktree branch `cleveragents/plan-<id>` and directory `/tmp/ca-sandbox-<id>-...` 2. `plan cancel` transitions the plan to cancelled state 3. Worktree branch and directory are **NOT removed** 4. `git worktree list` shows the dangling worktree 5. `git branch` shows the dangling branch ## Expected Behavior 1. `plan cancel` should detect if a worktree sandbox exists for the plan 2. Remove the worktree directory (`git worktree remove`) 3. Delete the branch (`git branch -D`) 4. Prune worktree references (`git worktree prune`) ## Subtasks - [x] In the cancel CLI handler, detect worktree branch `cleveragents/plan-<id>` for the plan's linked git resource - [x] Remove worktree and delete branch before or after cancellation - [x] Verify with scenario-10 end-to-end test ## Definition of Done - `plan cancel` removes the worktree directory and branch - `git worktree list` shows no dangling worktrees after cancel - Source files are unchanged - Scenario-10 passes with clean worktree state ## Spec Reference `specification.md` §13256-13260 (Sandbox Cleanup)
hamza.khyari added this to the v3.5.0 milestone 2026-04-14 11:53:57 +00:00
Owner

@hamza.khyari Thank you for this bug report.

Acknowledgment — Issue #9230

This issue has been received. The reported behavior — plan cancel leaving dangling git worktree branches and directories (resource leak) — is a valid bug that should be fixed.

Labels applied: Type/Bug, Priority/Medium, State/Unverified, MoSCoW/Must have

Current status: State/Unverified — this will be reviewed by the project owner for verification and prioritization.


Automated by CleverAgents Bot
Supervisor: Human Liaison | Agent: human-liaison-pool-supervisor
Worker: [AUTO-HUMAN-9]

@hamza.khyari Thank you for this bug report. **Acknowledgment — Issue #9230** This issue has been received. The reported behavior — `plan cancel` leaving dangling git worktree branches and directories (resource leak) — is a valid bug that should be fixed. **Labels applied**: Type/Bug, Priority/Medium, State/Unverified, MoSCoW/Must have **Current status**: State/Unverified — this will be reviewed by the project owner for verification and prioritization. --- **Automated by CleverAgents Bot** Supervisor: Human Liaison | Agent: human-liaison-pool-supervisor Worker: [AUTO-HUMAN-9]
Owner

Triage: Verified [AUTO-OWNR-1]

Valid bug: When a plan is cancelled after plan execute, the git worktree branch (cleveragents/plan-<id>) and sandbox directory (/tmp/ca-sandbox-<id>-...) are not cleaned up. This is a resource leak — dangling worktrees and branches accumulate over time, consuming disk space and polluting the git repository.

The fix is straightforward: plan cancel should detect the worktree sandbox and clean it up (remove worktree directory, delete branch, prune references).

Assigning to v3.5.0 (Autonomy Hardening) as sandbox lifecycle management is part of the plan execution infrastructure. Priority Medium — resource leak, but not immediately critical.

MoSCoW: Must Have — proper resource cleanup is essential for production use. Dangling worktrees will cause issues in long-running deployments.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Triage: Verified** [AUTO-OWNR-1] Valid bug: When a plan is cancelled after `plan execute`, the git worktree branch (`cleveragents/plan-<id>`) and sandbox directory (`/tmp/ca-sandbox-<id>-...`) are not cleaned up. This is a resource leak — dangling worktrees and branches accumulate over time, consuming disk space and polluting the git repository. The fix is straightforward: `plan cancel` should detect the worktree sandbox and clean it up (remove worktree directory, delete branch, prune references). Assigning to **v3.5.0** (Autonomy Hardening) as sandbox lifecycle management is part of the plan execution infrastructure. Priority **Medium** — resource leak, but not immediately critical. MoSCoW: **Must Have** — proper resource cleanup is essential for production use. Dangling worktrees will cause issues in long-running deployments. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#9230
No description provided.