Skip to content

worktree-reaper: a stale registration is never pruned — prune runs only when another tree is reaped in the same primary #6547

Closed

Description

@dezren39

Summary

infra/worktree-reaper/bin/worktree_reaper.py detects a worktree whose directory has already been deleted — evaluate_tree returns action stale-registration (worktree_reaper.py:417) — but nothing ever removes that registration. The only git worktree prune call in the script (worktree_reaper.py:599-600) is gated on removed_any, which is set only when a candidate tree is successfully reaped in the same primary in the same run (worktree_reaper.py:570, :584). A primary whose only dead trees are already-deleted directories therefore accumulates stale registrations forever: every run logs them as kept (stale-registration) and exits 0. The parser even records git's prunable flag (worktree_reaper.py:182, :194-195) and no code ever reads it.

Evidence (verified this run, laptop primary at origin/main 2bcd46e)

Probe ~/git/fleet/probe-reaper-stale/probe.py drives the real worktree_reaper.main() (in-process, --no-fetch, temp config/state under the probe dir) against a scratch primary:

  1. Create a linked worktree wt1, then delete its directory out from under git (the fleet reality this tool exists for: trees removed by hand, by a crashed cleaner, or by a disk cleanup).
  2. git worktree list --porcelain before: the wt1 path is present and marked prunable.
  3. Run the reaper (not dry-run): exit 0; summary evaluated: 1, candidates: 0, reaped: 0, kept: {"stale-registration": 1}.
  4. git worktree list --porcelain after the reaper: the stale registration is still present.
  5. Control: a manual git worktree prune in the same primary removes it immediately — the remedy exists and works; the reaper just never invokes it on this path.

Why it matters

The reaper is the fleet's only automatic worktree hygiene (README: born when the standing population grew 187 → 1,511 in five days). Stale registrations are the cheapest dead trees to clear — no gates, no content at risk, the directory is already gone — yet they are the one class it can never clear on its own. They pile up in git worktree list, in the reaper's own evaluated/kept counts every run, and in any other tooling that iterates registered worktrees, and they only disappear if some other, unrelated tree happens to be reaped in the same primary in the same run (the removed_any side effect) or a human prunes by hand.

Acceptance criteria

  • A run that finds a stale registration in a primary (and is not --dry-run) leaves that primary with the registration pruned, even when no candidate tree was reaped in that primary.
  • --dry-run still changes nothing on disk, and stale registrations found in dry-run are reported as would-prune (or an equivalent explicit action), not silently folded into kept counts.
  • Prune remains fail-safe: it runs only for primaries that were successfully inventoried this run (the existing fail-closed fetch/list behaviour is unchanged), and a prune failure is surfaced in the run summary/errors rather than swallowed.
  • Existing gate semantics are untouched: primaries are never reaped, locked/denied/dirty/unpushed trees keep exactly as today; the post-reap prune behaviour for candidate reaps is preserved.
  • Regression coverage in infra/worktree-reaper/tests/test_worktree_reaper.py: a primary whose only worktree is a deleted-directory (prunable) registration is pruned by a non-dry-run pass, and is untouched by a dry-run pass.

Distinct from

Activity

  1. developing-today commented on Nov 6, 2026

    @developing-today
    Contributor
  2. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    on Nov 6, 2026
  3. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (lane A, slug new-issue-creator-code-a)
    • Session / ID: cron new-issue-creator-code-a, run 2026-11-06 09:35 CST
    • Found via: filed this run
    • Task: Filed after verifying against the real reaper on the laptop: probe ~/git/fleet/probe-reaper-stale/probe.py drove worktree_reaper.main() on a scratch primary whose only linked worktree directory was deleted — run exited 0 with kept {"stale-registration": 1} and the prunable registration still present afterwards; a manual git worktree prune control removed it immediately.
    • Expectation: effort s; done when triage confirms and a fix makes a non-dry-run pass prune stale registrations for an inventoried primary (dry-run reports would-prune and changes nothing), with regression coverage in tests/test_worktree_reaper.py.
    • Links: probe ~/git/fleet/probe-reaper-stale/probe.py (laptop); queue packet packet-triage-6547.json (enqueued to repo-health-code-pilot this run)
  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 6, 2026
  5. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off to opencode claimant

  6. 40 remaining items

  7. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  8. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  9. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off (task 13120, lane code-k)

  10. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 10, 2026
  11. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    lane: code-w
    task: 11393
    issue: #6547
    stage: handed_off
    note: Task 11393 (small_fix, issue #6547) handed off to the opencode claimant: lane assignment row 3661 is opencode (re-confirmed this claim). Issue #6547 OPEN, no hard-stop labels, no status/needs-triage (fresh, lane code-w 2026-11-10). Attempts 4/6. Handoff reason: scheduled shift is time-bounded; claimant is the persistent execution session. Next: claimant launches the bound opencode session.

  12. added
    priority/lowNice to have; do when convenient
    and removed
    priority/normalOrdinary priority (the default)
    on Nov 11, 2026
  13. added a commit that references this issue on Nov 11, 2026
  14. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Agent note — task 11393 done (fixed_merged)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/worktree-reaperinfra/worktree-reaperkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobstatus:donetask/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions