Repository navigation
delegate_task: opt-in safe cleanup of settled child worktrees #34610
mohammedaltoyan
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Request
Add an opt-in cleanup policy for worktrees created by
delegate_task(isolation="worktree"): keep by default, with a project default and per-delegate override for removal when safe.Short-lived child tasks can leave many checkouts behind. Parent prompts currently have to manage their disposition. This request is specifically for the delegate lifecycle, rather than a retroactive orphan-worktree sweep.
Suggested behavior
Reuse the existing lifecycle and Storage cleanup machinery. After the task and all descendants fully settle, preserve the result and evaluate only that task's exact disposable checkout. The parent/backend owns removal; a child must never delete its live working directory.
Remove only when all checks are current:
Preserve branches, source history, task history, and evidence links. Any uncertainty, offline remote, ownership conflict, or removal failure means KEEP with a reason. No age-based or unclaimed-worktree purge follows from this option. Reopening a cleaned task must prepare an explicit owned workspace rather than silently falling back to the project root.
Acceptance
Default/hold preserves; one fully safe settled task removes only its checkout; dirty/untracked/unique-ignored content, active descendants, lease conflicts, path mismatch, and stale remote proof preserve; duplicate completion events and removal failures are harmless.
Related: #25843 (manually created orphan worktrees), #32628 (worktree-to-thread ownership lookup), and #31533 (cleanup timing). This proposal adds a scoped opt-in delegate-settlement policy and should reuse their shared safety checks.
All reactions