feat(dev): lab — unified teardown + worktree/branch cleanup [worktrees 2/3] #135

Closed
opened 2026-06-08 00:30:17 +02:00 by dominik.polakovics · 0 comments

Parent

Cloonar/nixos#133 (full settled design).

What to build

Collapse all teardown onto one guarded rule and add the cleanup sweeps, so parked worktrees/branches don't leak.

  • One teardown rule everywhere: reuse the guarded-teardown helper from slice 1 and apply it to the AFK reaper too — success and failure (today success removes the worktree, failure keeps it). Add a superseding note to ADR-0007 (manual Stop now guard-tears-down AFK worktrees; failure-neutrality unchanged). AFK keeps only its outcome accounting (consecutive-failure counter + budget-clock neutrality via afkRunsMu/afkStarts).
  • Startup reconciliation: every orphan worktree (a <project>-<label> worktree with no live <project>~<label> session) gets guarded teardown; every merged lab//afk/ branch + its worktree is deleted.
  • Runtime sweep: piggyback the existing reaper (throttled — not every 30s tick); after a best-effort fetch, git branch --merged origin/<default> → auto-delete merged lab/ and afk/ branches + their clean worktrees. Never touch dirty/unmerged.

This also finally GCs merged afk/<N> branches, which lab currently keeps forever.

Acceptance criteria

  • Stop, the reaper (success+failure), startup reconciliation, and the runtime sweep all route through one guarded-teardown helper.
  • After a simulated crash/reboot (sessions gone, worktrees on disk), startup removes clean orphans and keeps dirty ones.
  • Merged lab/ and afk/ branches + their clean worktrees are deleted at runtime; dirty/unmerged are never auto-removed.
  • AFK still reaps on PR/death/timeout, counts failures, and treats a manual Stop as neutral.
  • ADR-0007 superseding note added; go test ./... passes.

Blocked by

Cloonar/nixos#134

## Parent Cloonar/nixos#133 (full settled design). ## What to build Collapse all teardown onto one guarded rule and add the cleanup sweeps, so parked worktrees/branches don't leak. - **One teardown rule everywhere:** reuse the guarded-teardown helper from slice 1 and apply it to the AFK **reaper** too — success *and* failure (today success removes the worktree, failure keeps it). Add a superseding note to ADR-0007 (manual Stop now guard-tears-down AFK worktrees; failure-neutrality unchanged). AFK keeps only its outcome accounting (consecutive-failure counter + budget-clock neutrality via `afkRunsMu`/`afkStarts`). - **Startup reconciliation:** every orphan worktree (a `<project>-<label>` worktree with no live `<project>~<label>` session) gets guarded teardown; every merged `lab/`/`afk/` branch + its worktree is deleted. - **Runtime sweep:** piggyback the existing reaper (throttled — *not* every 30s tick); after a best-effort fetch, `git branch --merged origin/<default>` → auto-delete merged `lab/` **and** `afk/` branches + their clean worktrees. Never touch dirty/unmerged. This also finally GCs merged `afk/<N>` branches, which lab currently keeps forever. ## Acceptance criteria - [ ] Stop, the reaper (success+failure), startup reconciliation, and the runtime sweep all route through one guarded-teardown helper. - [ ] After a simulated crash/reboot (sessions gone, worktrees on disk), startup removes clean orphans and keeps dirty ones. - [ ] Merged `lab/` and `afk/` branches + their clean worktrees are deleted at runtime; dirty/unmerged are never auto-removed. - [ ] AFK still reaps on PR/death/timeout, counts failures, and treats a manual Stop as neutral. - [ ] ADR-0007 superseding note added; `go test ./...` passes. ## Blocked by Cloonar/nixos#134
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Cloonar/nixos#135
No description provided.