Worktree Retry Cleanup
Trigger
Before re-dispatching a coder for a task that already has a lane (any prior dispatch status).
Protocol
- Prefer built-in provisioning cleanup. Re-dispatch normally through the standard coder/worktree path. Provisioning pre-cleans stale same-lane worktrees/branches when ownership is safe and the existing lane is clean.
- If provisioning blocks: Treat the error as signal. Dirty lanes, lanes active in another worktree, and lanes owned by another active session must be surfaced to the user instead of deleted.
- If manual cleanup is explicitly required: Do the ownership check FIRST. Confirm the lane is not owned by another ACTIVE session: read
.swarm/session/state.jsonand verify no other session'sdelegationChainsreference<session>/<task>. If another active session owns it, STOP. - Remove only the specific lane. Target
.swarm-worktrees/<session>/<task>, never the session parent. Prefergit worktree remove .swarm-worktrees/<session>/<task>and thengit worktree prune. - Delete only confirmed stale branches.
git branch -d swarm/lane/<session>/<task>is allowed after confirming the branch is not checked out and contains no needed commits. Use force deletion only with explicit human approval. - Verify:
git branch --list "swarm/lane/<session>/<task>"returns empty before retrying.
Root cause
Stale same-lane worktrees and branches used to require manual cleanup before retry. Provisioning now handles the safe clean/stale cases automatically and fails closed for dirty, active, or cross-session-owned lanes.