reaper-edge-case

Reaper edge case: protect target/ of worktrees in active wg retry

Metadata

Statusdone
Assignedagent-823
Agent identityf51439356729d112a6c404803d88015d5b44832c6c584c62b96732b63c2b0c7e
Created2026-04-27T19:11:54.714369991+00:00
Started2026-04-27T19:13:02.195395624+00:00
Completed2026-04-27T19:45:28.315875888+00:00
Tagseval-scheduled
Eval score0.89
└ blocking impact0.90
└ completeness0.90
└ coordination overhead0.88
└ correctness0.95
└ downstream usability0.80
└ efficiency0.80
└ intent fidelity0.80
└ style adherence0.92

Description

Description

Found while smoke-testing worktree-target-dirs reaper:

When agent-772's task fails and is retried as agent-806, agent-806 runs in agent-772's preserved worktree (the wg retry-in-place flow). However, the registry entry for 'agent-772' shows status=failed/dead with a stale heartbeat. The new agent-806 has its own registry entry but the directory is named 'agent-772/'.

reap_dead_target_dirs looks up liveness by directory name (agent-772), so it will reap target/ from under an actively-building wg retry agent.

Smoke-tested 2026-04-27: my own target/ in agent-772/ was reaped while agent-806 was actively using the worktree. No data loss (cargo rebuilds, source files preserved), but it forces a slow rebuild on resume.

Required

The reaper should detect 'is this worktree currently in use' beyond just looking at the original-owner registry entry. Two options:

  1. Walk the registry for ANY agent whose worktree_path matches; treat the worktree as live if any such agent is_live().
  2. Add a 'current_occupant' / 'worktree_lease' field set by spawn that the reaper checks.

Option 1 is simpler if AgentEntry already has a worktree_path field. Option 2 is more explicit.

Files

  • src/commands/service/worktree.rs (reap_dead_target_dirs)
  • src/service/registry.rs (add lookup helper if needed)

Validation

  • Failing test first: register agent-A (dead) and agent-B (live) where both list the same worktree path; assert reaper skips that worktree
  • Existing tests still pass (skip-live, idempotent, orphan)
  • Live smoke: trigger wg retry on a failed task, run wg sweep --reap-targets while retry-agent is building; assert target/ survives

Depends on

Required by

Log