Problem
DMC worktrees can outlive the agent/minion session that created or used them. In the recent cleanup fleet, duplicate/incorrect minion sessions kept editing after replacement sessions were spawned, and multiple PRs were opened for the same issue (#214 has both #219 and #220). We had to manually infer which worktrees were dead from Discord threads, PR state, branch names, and local git status.
DMC currently tracks lifecycle metadata for worktrees, but it does not have enough agent/session state to answer: is this worktree still actively owned by a live agent, has the agent stopped, has it opened a PR, or is this duplicate work that should be cleanup-eligible?
Expected
DMC should account for agent-owned worktree liveness so stale/dead minion worktrees can be classified safely and cleaned up without guesswork.
Proposed shape
Record agent/session metadata when a worktree is created or refreshed:
- originating site URL
- Discord channel/thread ID when available
- Kimaki/OpenCode session ID when available
- agent name/model when available
- task/issue URL or identifier when supplied
- last_seen/heartbeat timestamp
- terminal state: active, stopped, archived, pr_opened, merged, abandoned, failed
- PR URL/head branch when opened
Expose detection/reporting:
workspace worktree list and hygiene report should show agent/session state when present.
- Cleanup inventory should classify stale agent-owned worktrees separately from missing metadata.
- Duplicate detection should flag multiple live worktrees/PRs for the same issue/task URL.
- A stopped/archived session with no dirty work and no unpushed local-only commits can become cleanup-eligible after a hold period.
- Dirty or ambiguous worktrees remain protected with reason codes.
How to know a worktree is dead
A worktree is high-confidence dead only when at least one authoritative terminal signal exists:
- its owning session/thread was explicitly stopped or archived;
- the worktree metadata records
pr_opened and the local checkout is clean;
- the PR was merged/closed and the branch no longer needs local state;
- the session heartbeat is stale beyond a configured TTL and no active thread/session is mapped;
- the controller marks the worktree abandoned.
A worktree is not dead solely because it is old or missing metadata. Those should remain protected/unknown until reconciled.
Acceptance criteria
- DMC records agent/session identifiers in worktree lifecycle metadata when available.
- DMC can surface live/stopped/stale/unknown ownership in
worktree list/hygiene output.
- DMC has a bounded classification path for agent-dead worktrees with reason codes.
- Duplicate task/issue detection reports multiple active worktrees or PRs for the same task.
- Cleanup never deletes dirty, unpushed, or ownership-unknown worktrees without explicit operator force.
Refs: #213, #214, #215, #216, #217, #218, #219, #220
Problem
DMC worktrees can outlive the agent/minion session that created or used them. In the recent cleanup fleet, duplicate/incorrect minion sessions kept editing after replacement sessions were spawned, and multiple PRs were opened for the same issue (#214 has both #219 and #220). We had to manually infer which worktrees were dead from Discord threads, PR state, branch names, and local git status.
DMC currently tracks lifecycle metadata for worktrees, but it does not have enough agent/session state to answer: is this worktree still actively owned by a live agent, has the agent stopped, has it opened a PR, or is this duplicate work that should be cleanup-eligible?
Expected
DMC should account for agent-owned worktree liveness so stale/dead minion worktrees can be classified safely and cleaned up without guesswork.
Proposed shape
Record agent/session metadata when a worktree is created or refreshed:
Expose detection/reporting:
workspace worktree listand hygiene report should show agent/session state when present.How to know a worktree is dead
A worktree is high-confidence dead only when at least one authoritative terminal signal exists:
pr_openedand the local checkout is clean;A worktree is not dead solely because it is old or missing metadata. Those should remain protected/unknown until reconciled.
Acceptance criteria
worktree list/hygiene output.Refs: #213, #214, #215, #216, #217, #218, #219, #220