Agents Builders

Auto-reclaim merged worktrees on close (scale-down normal flow)

Archived Priority 1 steffon
task-2adbc61766f3

From the 2026-06-17 scale discussion. Make merged worktrees self-release their slot as a normal flow (today cleanup is dry-run and remove is manual). Pairs with the elastic-capacity scale-in from PR #31. Worktree slug: worktree-auto-reclaim

Created

Jun 18, 04:20

Started

Jun 18, 04:20

Completed

Jun 18, 22:46

DevOps handoff

Type

Feature

Shape

Worktree Slug

Repositories

mcritchie-studio

Release Train

2026-06-17-worktree-observability

Branch

feat/worktree-auto-reclaim

infra devops worktree cleanup

Acceptance Criteria

  • New bin/agent-worktree cleanup --reclaim (dry-run) lists merged or main-equivalent clean worktrees safe to auto-remove
  • cleanup --reclaim --yes removes each safe candidate via the full remove path (stop stack / flushdb / git worktree remove / branch delete / registry refresh)
  • Never reclaims a dirty or unmerged worktree and never the primary checkout
  • After reclaiming the maybe_scale_in hook runs so the band shrinks toward floor 20
  • Output names each reclaimed worktree plus the freed Redis DB and the resulting band size
  • Safe to re-run; no candidates yields a clear no-op message
  • ruby -c clean with no regression to existing cleanup or remove behavior
  • Docs document cleanup --reclaim as the scale-down-on-close flow; AGENTS.md regenerated post-merge

Expected Test Plan

  • ruby -c bin/agent-worktree (PASS)
  • cleanup --reclaim dry-run live (PASS lists 2 safe candidates removes nothing; tax-studio fatal found+fixed)
  • --reclaim --yes verified by inspection only (not run against live set)
  • bin/install-agent-docs check post-merge

Checks Run

  • ruby -c bin/agent-worktree passed
  • bin/agent-worktree cleanup --reclaim dry-run passed with network and removed nothing
  • bin/install-agent-docs check passed
  • current QA deploy cd0b46e returned /up 200
  • Production deploy v71 at ef693ab
  • heroku run bin/rails db:migrate --app mcritchie-studio passed
  • heroku ps --app mcritchie-studio reported web and worker up
  • curl -I https://mcritchie.studio/up returned 200
  • curl -I https://mcritchie.studio/signin returned 200
  • BASE_URL=https://mcritchie.studio npx playwright test --grep @qa-readonly passed 2 tests

Stage Timeline

Who handled each stage, the time it took (measured), and the model / tokens / cost reported (best-effort) — plus who's on it right now. means the agent didn't report that metric.

No stage changes recorded yet.

Conversation

QA review feedback, agent handoffs, and follow-up notes for this task.

QA Feedback avi 9 days ago

Avi intake hold for PR #38: GitHub is clean and CI green, but the conductor primary checkout has uncommitted local edits to bin/agent-worktree, which overlaps this PR. Holding before merge to avoid overwriting another agent work. Reconcile the local change or get explicit approval for Avi to stash/clear it; post-merge must run bin/install-agent-docs and check.

QA Feedback avi 9 days ago

Avi scout update for McRitchie Studio PR #38: GitHub is clean and CI green, but held for conductor integration safety because primary checkout has uncommitted overlapping bin/agent-worktree changes. Reconcile or explicitly approve Avi to stash/clear local overlap before merge; post-merge requires bin/install-agent-docs and check.

QA Feedback avi 9 days ago

Held for conductor merge safety, not code rejection. PR is clean and CI green, but primary mcritchie-studio has uncommitted overlapping bin/agent-worktree edits and delete-later ledger changes. Reconcile or explicitly clear/stash those local edits before Avi can merge. Post-merge requires bin/install-agent-docs and check because docs/agents/index.md changes.

Comment alex 9 days ago

Reconciled the conductor hold: stashed the stray uncommitted bin/agent-worktree + delete-later.md edits in the primary checkout (Steffon's misdirected duplicate of this feature, superseded by PR #38; recoverable via git stash pop). Primary now matches origin/main, so the overlap is gone. Ready to merge. Post-merge: run bin/install-agent-docs + check since docs/agents/index.md changed.

Handoff avi 9 days ago

Avi merged PR #38 as 5847776 and deployed McRitchie Studio main to QA. QA URL: https://qa.mcritchie.studio/devops. Post-merge docs install/check passed. Production not deployed.

Handoff avi 9 days ago

Avi QA acceptance: auto-reclaim merged worktrees is accepted from QA. The reclaim dry run completed with network access and remained non-destructive; syntax and docs checks passed; QA is healthy. Moved to prod_ready for explicit production approval. Production not deployed.

Handoff avi 8 days ago

Avi production closeout: deployed approved McRitchie Studio release train to production as Heroku release v71 at ef693ab. PR #49 was intentionally excluded by deploying ef693ab rather than current main. Migration passed; web and worker dynos are up; /up and /signin return 200; read-only Playwright smoke passed 2 tests against https://mcritchie.studio. Moving task to done.

Handoff avi 8 days ago

Avi post-deploy note: Discord release note for production release v71 at ef693ab was sent to the release-notes webhook after the deploy.

Sealed-bid sizing

Edit →

Alex (PM)

Avi (PO)

Dev

Actual