cleanup-fleet-all

Unattended, all-bucket sibling of /cleanup-fleet — builds, validates, and ships every open cleanup issue across all nine queued audit buckets in one overnight pass. E.g. "/cleanup-fleet-all", "clean u

SKILL.md

GitHub

cleanup-fleet-all

Capability preflight: read workflow-capabilities and bind dispatch, results, waits, cancellation, model tiers and questions to this session’s actual tools before proceeding. Tool names below are conditional examples (Claude Code only); the contract governs adaptation. Keep this skill’s worktree, independent-review, human-review and shipping gates.

Goal: the genuinely unattended sibling of /cleanup-fleet (one bucket, stops for human approval in its default hard mode). This walks all nine queued audit buckets, serially, and ships every issue with no human review gate — replaced by an independent validator agent, so no single agent both builds and ships its own work unchecked. (security is never queued — /codebase-audit self-heals it inline — and cert-drift, /design-sync's other kind, is review-only, never auto-migrated; nothing here touches either.)

Four agents per issue, never fewer:

  1. Build — implement the fix in a forced worktree, run the project's verification gate, then stop before shipping.
  2. Validate — a fresh, independent agent with no memory of the build. Re-runs the verification gate itself and judges, leniently, whether the diff actually addresses the issue.
  3. Execute — ships an already-validated branch: push, PR, CI, merge, tray restart.
  4. Teardown — the terminal step of every lane, whatever the outcome: comments the failure reason + any WIP SHA onto the GitHub issue (non-merged lanes only), removes the worktree via worktree_claim.py remove-worktree, releases the claim, deletes the branch, and runs six verification checks. Four decide residue (worktree list, no leftover sibling directory, this lane's own branch gone, clean tree); two are reported and never halt — a stale .git/index.lock and a primary behind origin/<default> (fleet-config#534). Other lanes' leftover branches are reported too, never residue (fleet-config#572). The worktree list is classified by skills/_lib/worktree_residue.py, not read by eye: a foreign worktree (not created by this run), clean, with its HEAD proven merged, is reported in foreignWorktrees and defers the rest of that repo's work instead of halting (fleet-config#1077).

A failed validation retries the build once (feeding it the validator's feedback verbatim), for a hard cap of 2 rounds; a second failure escalates. Escalation is not "leave the branch for a human" — the open GitHub issue plus the teardown agent's comment on it is the durable record; branch and worktree are torn down like any other lane (fleet-config#518).

One bucket at a time, one repo at a time. Lanes are strictly serial: the next repo does not start until the current lane has run all four agents and its repo is verified clean. At most one worktree exists at any instant. (Within-bucket parallelism + a teardown-free escalation path caused the incident in Notes.)

Halt on residue. If teardown cannot return a repo to a clean state, the run stops there — does not start the next lane. Lanes serial → exactly one repo affected, one command to recover. The rule guards against the run building on its own dirt. A worktree someone else created mid-run is not that. When it is clean and merged, the run reports it, defers that repo's remaining issues and continues. Anything the run created, or anything dirty or unmerged, still halts (fleet-config#1077).

Never a primary checkout. Every build/validate/execute agent forces worktree mode (worktree_claim.py acquire … --force-worktree) for every repo, no exceptions, no special-cased list — a running app or a live junction (e.g. fleet-config's own hooks/+skills/ into every ~/.claude) is not a claim holder, so an unattended agent otherwise wins MODE=primary and edits files a live process is serving (fleet-config#515). Same briefs: a live-e2e guard refusal is a hard STOP — E2E_LIVE=1 or any equivalent override is forbidden.

All retry/ship decision-making lives in .claude/workflows/cleanup-fleet-all.js, the fixed decision script — not this SKILL.md, not a fourth "orchestrator" agent. Retry vs. ship vs. escalate is a fixed lookup on each agent's own schema-validated verdict (verification, retryable, pass, retry-round count); judgment calls happen once, inside Build/Validate, never re-litigated by whatever reads the result. See the script's header comment and docs/model-tiers.md.

Arguments

/cleanup-fleet-all [<bucket>...] — zero or more bucket names, fuzzy-matched via the same synonym table /cleanup-fleet uses (documentation/docs, claude-md-drift/drift, duplication/dupes, stale/dead, maintainability/maint, slop/bloat, bug/bugs, design-drift/design, prompt-drift/prompt).

  • No arguments → all nine queued buckets, the intended unattended shape.
  • One or more bucket names → restrict to just those — use this for an attended dry run of a small slice before trusting a full overnight sweep.

Execution rules (read before running any command)

  • Shell: use the actual execution tool’s declared shell; translate examples without mixing Bash and PowerShell syntax.
  • The orchestrator (this skill) only does cheap, safe work: auth check, the issue fetch, grouping/dedupe (model-side, no jq/python), the rate-gate check, invoking the decision script through an available adapter, and post-flight reporting. It never edits source, commits, pushes, or merges — every write happens inside an agent spawned by the workflow script.
  • Never disturb in-progress work. A repo that is dirty or off its default branch is skipped and reported — never stashed, never force-switched. Skipped is not dropped: it is deferred, retried once after the last bucket, and recorded durably (steps 5, 7b, 8c).
  • Never background a tool call in this skill — the rule that matters most here. Runs headless via run-weekly.bat's one-shot headless agent process (streamed through claude_progress.py), no persistent turn loop, no human, no wake-up mechanism: launching a command and ending the turn to "wait for it" silently kills the run — CLI exits exit_code: 0 (false success) while nothing past that point happens (fleet-config#314, the exact failure /audit-fleet hit twice). Applies to the Workflow call in step 7 exactly as much as a backgrounded Agent dispatch — Workflow also returns immediately and notifies later. Every long-running call, including the rate-gate wait, must run synchronously (foreground) or poll to completion within the same turn (TaskOutput with block: true, re-issued in a loop; or Monitor's until-loop for the rate-gate wait) — never fire-and-forget.
  • Degrade, don't block. A per-repo failure is reported and skipped; only a pre-flight failure stops the whole run. Nothing here waits on an interactive prompt — there's nobody to answer one.

Steps

1. Pre-flight

  • gh auth status — must be authenticated as ferraroroberto. Else stop, and the final report must print the literal line SCHEDULED-RUN-FAILED — not authenticated, run gh auth login (no lane is ever attempted, so this is a delivery failure, not a clean no-op — fleet-config#612).
  • Confirm E:\automation\ exists (the fleet root). Else stop, and the final report must print SCHEDULED-RUN-FAILED — fleet root E:\automation not found.

2. Resolve buckets

Parse args through the synonym table (see "Arguments"). No args → all nine queued canonical labels (documentation, claude-md-drift, duplication, stale, maintainability, slop, bug, design-drift, prompt-drift). security and cert-drift are never in this set — security is self-healed inline by /codebase-audit, and cert-drift is /design-sync's review-only kind (a tailnet-cert migration is never auto-applied unattended). Unrecognized tokens are ignored with a one-line note, not a hard stop.

3. Fetch every bucket — direct Issues API, one repo-scoped call per repo

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/gh_issue_fetch.py fetch

Preferred primary fetch, not gh search issues --owner ferraroroberto (Search-API-backed, eventually consistent — observed reporting issues open 5+ weeks after they closed, fleet-config#623). gh_issue_fetch.py uses the direct Issues API, one gh issue list --repo <owner>/<name> --state open per repo, aggregated into the same shape. Avoids a known-bad source; not proven immune — step 5 still re-checks each selected issue's state before dispatch. Dormant repos (docs/fleet-scope.md) are skipped and named on the SKIPPED_DORMANT= stderr line; add --include-dormant to fetch them.

Read the JSON directly (no jq/python/awk — group and select model-side, same convention as /cleanup-fleet). For each issue, collect every label matching one of this run's resolved bucket names — drop any row carrying audit-meta (the ledger issues, never actionable), and drop any row matching none of the resolved buckets. An issue carrying more than one bucket label legitimately appears in more than one bucket's list; buckets run serially, so it's never worked on twice at once.

If the helper's stderr summary reports ERRORS= greater than zero, note which repos it could not read (printed as ERROR <repo>: <reason> lines) in the final report — those repos are simply absent from this run's candidates, not a run-wide failure.

If nothing survives for any resolved bucket: print No open cleanup issues across the fleet 🎉 and stop. This is a legitimate empty-queue success — do not print the SCHEDULED-RUN-FAILED marker here.

4. Group by (bucket, repo) + enforce one issue per repo per bucket

Within each bucket, group surviving issues by repository.name:

  • Exactly one candidate → that's the issue.
  • More than one → select one, defer the rest (record for the final report). Preference: (1) the audit-managed issue (body contains <!-- audit-managed:), else (2) the smallest/clearest-acceptance one.
  • prompt-drift only: an issue whose body states hard tier is deferred, never dispatched (see Hard rules) — a rewrite that consequential always gets a human.

5. Pre-flight per selected repo

Re-read every selected issue's live state first, in one batch, before any per-repo check below. Step 3's fetch isn't proven immune to every staleness source, and a run can sit for hours — an issue selected at step 4 can close for real while an earlier bucket is still running. Build one JSON array of every selected issue across every bucket ([{"repo": ..., "number": ..., "bucket": ..., ...other fields...}, ...] — repo a bare name like "task-os", never "owner/name": the helper prepends the owner itself, and a prefixed repo produces a doubled-owner gh argv that fails with a network-sounding error unrelated to the network, fleet-config#706) and pipe it through:

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/issue_state_gate.py partition

Read the stdout JSON directly — {"dispatch": [...], "skipped_closed": [...], "unresolved": [...]}. Only dispatch items proceed past this step. Every skipped_closed item is dropped from its bucket's list and recorded in the final report as already closed — dropped, no agent dispatched. Every unresolved item is also dropped — the check could not establish the issue's state, so it is dropped rather than guessed as open — and recorded as state unresolved — dropped, not dispatched (<detail>), distinct from both the closed and the dispatched sets. This must never collapse into "no issues found": the final report's headline must show all three counts (dispatched, already-closed, unresolved).

Then gate every surviving issue on its repo's availability, in one batch. Build a JSON array of every dispatch item ([{"repo": ..., "number": ..., "bucket": ..., ...}, ...]) and pipe it through:

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/repo_preflight.py partition

It resolves each distinct repo exactly once (however many buckets it appears in) and runs the full per-repo check — E:\automation\<repo> exists · status --porcelain empty · HEAD on the default branch · fetch origin · worktree list shows only the primary · every unregistered <repo>-wt-* sibling (the same per-repo glob as teardown check 2) is empty, not a reparse point, and dir_holders.py STATUS=CLEAR. That last check stops a leftover directory that was already there at pre-flight, held live or unprovable, from halting the run hours later at the first teardown in that repo (fleet-config#1082). A zombie-pinned shell still dispatches. Read the stdout JSON directly: {"dispatch": [...], "skipped": [...]}. Each skipped item carries repo_state (missing/dirty/off-branch/worktree/leftover-dir/unknown) and skip_reason; the stderr line gives DISPATCH= SKIPPED_REPOS= SKIPPED_ISSUES= UNKNOWN_REPOS=.

Only dispatch items proceed. The skipped list is this run's deferred set — carry it to step 7b, which re-checks it, and to step 8c, which records whatever is still unavailable. A dirty repo drops every one of its selected issues across all buckets; the helper enforces that by resolving per repo rather than per issue.

unknown (git unreadable) does not dispatch — an unreadable repo is not a repo proven safe to work in — but it is counted separately from a confirmed dirty tree, and the report keeps them apart. A failed fetch origin is recorded in the item's note and never changes the verdict: what makes a repo unsafe to work in is a dirty tree, a wrong branch, or someone else's worktree, not an unreachable network.

The skip criteria are unchanged and never soften — never stash, never force-switch, never remove a worktree you did not create. This gate only changes what the run does with the knowledge that it skipped something.

If candidates existed and dispatch is empty, every one of them was skipped: no lane will run and there is nothing to retry later. Record the deferred set through step 8c, then stop and print in the final report the literal line SCHEDULED-RUN-FAILED — every candidate repo was skipped (<N> repos, <M> issues unprocessed), no lane ran. This is not step 3's empty-queue case: there the queue was genuinely empty, which is a success; here there was real work and the run touched none of it.

Worktrees always — every build agent forces MODE=worktree and works <repo>-wt-<N>, never the primary checkout, for every repo (fleet-config#515). The primary is only ever read (pre-flight above) and, at teardown, checked back to clean. Lanes are serial, so a repo touched by two buckets is never touched by two agents at once, and at most one worktree exists fleet-wide at any moment.

A build agent's handoff is a committed branch, never a dirty tree (fleet-config#641). The build brief's STOP step forbids exactly four actions — push, PR, merge, /issue-finish — committing is not one of them; validate agent's first act is git status --porcelain on the worktree, and a dirty tree is immediate pass: false regardless of the otherwise-lenient default — the one rejection reason that is not a judgement call. Asserted at the boundary because otherwise invisible (execute agent's /issue-finish commits pending work as a safety net, so an uncommitted handoff ships fine and recurs silently): uncommitted work has no SHA for the escalation comment's WIP SHA to point at, and an escalation/crash between build and execute loses the work instead of parking it reflog-recoverable ~90 days. A build that legitimately changed nothing still leaves a clean tree — assertion is on the tree, never the commit count.

6. Rate-gate check

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/rate_gate.py check --pause-cycles 3

DECISION=PAUSE with CLEARS_WITHIN_BUDGET=no → the reset is further away than three capped waits can reach (a weekly reset hours or days out), so waiting cannot change the outcome: wait zero cycles. Invoke no workflow, skip steps 7–7b, record every surviving repo as deferred through step 8c (repo_state session-limit, skip_reason the gate's REASON), and step 10 prints the clean-skip marker. Only no skips; yes, unknown (no signal, unreadable reset, no reset time) and not_paused fall through to the wait below — an unreadable gate is never a skip. Otherwise, DECISION=PAUSE → wait via the Monitor tool's until-loop pattern against the printed WAIT_SECONDS (never RESETS_AT: only WAIT_SECONDS fits the stall watchdog, fleet-config#891) (per the Execution rules above — this must resolve within the same turn), then re-check. Cap: 3 pause cycles. Still PAUSE after the third → invoke no workflow: skip steps 7–7b, record every surviving repo as deferred through step 8c (repo_state session-limit, skip_reason the gate's REASON), and step 10 prints the session-limit failure marker (waited and still blocked, or never got a signal: undelivered work, unlike the clean skip above). OK/UNKNOWN → proceed immediately. Under its scheduled launcher (MODE=unattended) no fresh statusline signal reads PAUSE (REASON=cache_missing|cache_stale|usage_missing), never UNKNOWN — it waits and re-reads rather than proceeding blind (fleet-config#825). Keep every gate line's DECISION/REASON/MODE for step 10.

6b. Arm the run window

Right after step 6 lets the run proceed, before any lane starts:

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/scheduled/run_window.py arm

An unattended run (MODE=unattended) gets WINDOW_ARMED=yes: the run has WINDOW_SECONDS (five hours by default) of wall-clock from now, so a long queue cannot spill into the weekly block chained behind it (fleet-config#2063). An attended run prints WINDOW_ARMED=no and stays unbounded. Pass windowArmed: true to the workflow only on yes (the non-Workflow bridge reads windowArmed from its state file); the script then asks a gate agent before each lane and starts none once the window has closed. If the command fails or prints no WINDOW_ARMED= line in an unattended run, the run cannot be bounded: start no lane and print SCHEDULED-RUN-FAILED — run window could not be armed. Keep WINDOW_ENDS_AT for step 10.

7. Invoke the workflow and collect it to completion

Build issuesByBucket — { "<bucket>": [{ repo, number, title, body }, ...], ... } — from the surviving, pre-flighted issues (step 5's skips already removed).

Choose the available adapter first. If native Workflow plus terminal-result collection are callable, use the specialization below (Claude Code only). Otherwise follow the capability contract’s Cleanup without Workflow path: node <fleet-config>/skills/_lib/cleanup_workflow.cjs <state.json> emits the next exact prompt/schema, dispatch it to a fresh native worker, collect its terminal result, append the matching request ID/result, and repeat until complete. The helper evaluates this same decision script; do not reimplement retry/ship decisions model-side. Native spawn unavailable → stop before starting a lane; this skill forbids orchestrator writes and cannot replace independent validation with self-review. Scheduled process launching is unchanged.

Workflow specialization (Claude Code only):

Invoke with the inline script parameter (paste the full contents of .claude/workflows/cleanup-fleet-all.js), not scriptPath. scriptPath has been observed to fail in this environment — the permission-approval layer rejects it with a false-positive "script contains control characters" error even against a byte-clean file. Read the script file fresh each invocation so edits are picked up.

Workflow({ script: "<full contents of .claude/workflows/cleanup-fleet-all.js>", args: { issuesByBucket, windowArmed } })

This returns a task id immediately. Do not stop and wait for a notification — per the Execution rules, immediately enter a blocking poll loop:

TaskOutput(task_id: <id>, block: true, timeout: 600000)

Re-issue this call (each blocks up to 10 minutes) until the returned status is completed, as consecutive tool calls within this same turn — this may take many calls over several hours for a full run, and that's expected. Serial lanes make a full run slower in wall-clock than the old parallel shape; that is the trade being bought, not a regression to fix.

The workflow's return value is { buckets: [{ bucket, results: [...], skipped? }, ...], halted, deferred, promotions }:

  • each result is { issue, status, round, branch, worktree, residue, residueDetail, indexLock, indexLockDetail, behindOrigin, behindOriginDetail, zombieShells?, foreignBranches?, foreignWorktrees?, restoredUntracked?, recurrence, structural?, pr?, mergeSha?, reason?, wipSha?, alreadyClosed? } — status one of merged/escalated/failed; residue is CLEAN or RESIDUE. indexLock (none/stale/live-held/unknown) and behindOrigin (current/fast-forwarded/unknown) are reported only — never gate a lane, never halt the run, default unknown when teardown died or omitted them. zombieShells names a leftover directory satisfying all five zombie-pinned conditions (step 8b), not counted as residue; foreignBranches names local branches belonging to no lane of this run — also reported, never residue. alreadyClosed: true means an issue step 5's batch check let through turned out closed by the time /issue-start reached it, hours in (fleet-config#623) — lane still escalates and tears down, but teardown skips the usual "unattended lane escalated" comment (noise on an already-resolved thread). Different population from step 5's skipped_closed/unresolved, which never reach results — they never entered issuesByBucket, no lane ran for them.
  • halted is null on a full run, or { bucket, repo, issue, status, detail, remainingInBucket } when a lane's teardown left residue and the run stopped there. A halted run is a loud failure, not a partial success — report it at the top of the final summary, name the one repo, and say exactly what a human must do.
  • stopped is null unless the run window ended: { reason, bucket, repo, issue, detail, notStarted } with reason window-closed (the window ran out; the lane in flight finished and tore down first) or window-unknown (the gate could not read the window twice running — a fact not established, never read as open). It names the first lane not started and every unstarted issue, this bucket's remainder and every later bucket's, is in deferred with that repo_state. It is not a halted run: nothing is left unclean.
  • foreignWorktrees on a result is the classifier's WORKTREE=… CLASS=foreign-merged … lines: a worktree this run did not create, clean, HEAD proven merged, that appeared in the repo after pre-flight. The script defers only on a real WORKTREE= line in the field; prose such as "None" or a check summary is ignored (fleet-config#1453). The lane stays CLEAN, and the script stops starting lanes in that repo for the rest of the run. "Created by this run" is decided by the script, not the teardown agent: it passes the classifier every worktree path and branch a lane of this run reported, plus <repo>-wt-<N> for every issue the run holds in that repo. A registered worktree matching any of them by path or branch is the run's own and halts; the match errs toward own (fleet-config#1077).
  • restoredUntracked on a result is the verbatim RESTORED_UNTRACKED=/KEPT_ASIDE= output of the lane's two fast-forwards — land-primary at ship and check 6 at teardown, both guarded by skills/_lib/untrack_guard.py. A merged change that untracks a machine-local file (git rm --cached + .gitignore, or a rename to .sample) would otherwise delete the live copy from the primary on fast-forward: on 2026-09-28 the automation#144 lane took nine live configs out that way (fleet-config#1086). Reported only, never residue; list each under primary hygiene as 🗂️, and a KEPT_ASIDE path as needing a human.
  • recurrence is the issue body's recurrence stamp as the script read it: recurring, not-recurring or unknown. structural is the validator's verbatim STRUCTURAL= line on a recurring lane, its SCOPE= (and a generalizable check's NAME=) included. List every unknown lane as ❓ recurrence unknown under its bucket in the final summary (fleet-config#1520).
  • promotions lists one { repo, issue, name, path, repoPr } per merged lane whose gate line says SCOPE=generalizable NAME=<rule-name>, decided by the script (promotionOf), never by a model. repoPr is <repo>#<pr-number>, or null when the number could not be read from the lane's pr. Step 8d files them.
  • deferred lists the issues not started for that reason: each is the original issue item plus bucket, repo_state: "foreign-worktree" and a skip_reason naming the foreign worktree. It has the same shape as step 5's skipped items, and joins them in step 7b and step 8c. It is empty on most runs.

7b. Retry the deferred set — one pass, after the last bucket

A repo that was dirty at pre-flight has usually been committed and pushed by the time the last bucket finishes: a full run spans many hours, so step 5's verdict is stale by now. The deferred set gets exactly one more chance, as late as possible.

Skip this step entirely if step 7's halted or stopped is non-null. A halted run has left residue and must not start another lane, and a stopped run's window has ended (or could not be read), so a retry would run past it.

Re-run the same gate over the deferred set — the whole array step 5 skipped, unchanged, plus step 7's deferred items (repos where a foreign worktree appeared mid-run). A foreign worktree that is still registered makes the gate skip that repo again (repo_state: worktree), so it reaches step 8c and is never touched:

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/repo_preflight.py partition

The helper holds no state between calls, so this necessarily re-establishes every fact from the live tree rather than trusting step 5's verdict — a repo that has since become dirty must not be dispatched on an hours-old "available".

Anything now in dispatch gets one retry pass: rebuild issuesByBucket from those issues only, and invoke the workflow a second time exactly as step 7 describes — same selected adapter and terminal-result collection within this turn. The serial-lane invariant holds by construction: this invocation starts only after the first has fully completed, so there is still at most one worktree fleet-wide at any instant.

Merge its buckets results into the report under the same bucket names, marked (retry). Its halted is handled exactly like step 7's. One pass, never a loop — whatever is still unavailable stays deferred and goes to step 8c.

8. Post-flight verification (never trust the agent's self-report)

The teardown agent already verified its own lane. This step is the independent second look — same "a check that can't establish a fact reports unknown, never pass" discipline the global CLAUDE.md requires.

8a. Per-issue tree check. For every issue with status: "merged":

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/dirty_tree_check.py check E:\automation\<repo> --mode merged

STATUS=DIRTY → downgrade from ✅ merged to ⚠️ merged but dirty tree — inspect <repo> and carry the REASON= line.

STATUS=UNKNOWN → the helper has no verdict about that repo: render ❓ merged, tree unverified — <REASON>, never folded into ✅ or ⚠️. Check the path you passed first: the Git Bash backslash trap (a double-quoted Windows path loses its backslashes and never expands the loop variable) once made the helper answer DIRTY for repos that were clean (fleet-config#570). Pass forward slashes.

For every issue with status: "escalated" or "failed" — the teardown agent should have put the repo back on a clean default branch, so check it the same way:

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/dirty_tree_check.py check E:\automation\<repo> --mode merged

STATUS=DIRTY → append ⚠️ post-flight: <REASON> next to the escalation line. STATUS=UNKNOWN → append ❓ post-flight unverified: <REASON> — an escalation whose tree could not be read is not an escalation whose tree is fine.

8b. Fleet-wide residue enumeration — fail loud. Checking only the primaries of touched repos is what let 11 worktrees slip through a run that reported 0 failed. After all buckets finish, enumerate residue across every repo the run touched (Git Bash, read-only):

for r in <every touched repo>; do
  git -C /e/automation/$r worktree list
  ls -d /e/automation/$r-wt-* 2>/dev/null   # per-repo glob, never /e/automation/*-wt-*
  git -C /e/automation/$r branch --format='%(refname:short)'
  git -C /e/automation/$r status --porcelain
  ls -l /e/automation/$r/.git/index.lock 2>/dev/null
  git -C /e/automation/$r fetch origin && git -C /e/automation/$r rev-list --count HEAD..origin/<default>
done

The worktree glob is per repo, inside the loop, and stays that way. A fleet-wide /e/automation/*-wt-* makes one repo's check report another repo's in-flight worktree as residue (app-launcher#709).

A dirty tree, a primary off its default branch, or a branch belonging to this run's lanes is residue. So is a second registered worktree, unless the classifier teardown uses says otherwise. Run it per touched repo with the run's own set, meaning every worktree and branch in results for that repo plus E:\automation\<repo>-wt-<N> for every issue the run held there:

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/worktree_residue.py classify E:/automation/<repo> --own-worktree '<path>' ... --own-branch '<branch>' ...

VERDICT=foreign-deferred is reported as 🧳 <repo> — foreign worktree <path> (clean, merged), not residue, never removed. VERDICT=residue or unknown is residue (fleet-config#1077). Two more exceptions follow, the same ones the teardown agent applies.

A leftover <repo>-wt-<N> directory is not residue when all five hold, each proved by running the command: recursively empty; a real directory, not a reparse point (read the attribute bit via powershell.exe -NoProfile -Command "(Get-Item -Force '<path>').Attributes"); absent from git worktree list; E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/dir_holders.py check '<path>' prints STATUS=CLEAR; and worktree_claim.py remove-worktree was run against it and refused. (Windows keeps the process objects of exited WebKit e2e helpers alive while any handle remains — the empty shell they pin is undeletable until reboot.) Any one condition unestablished is residue: STATUS=LIVE (a running process names the path, printing pid + command line) and STATUS=UNKNOWN (probe couldn't run) are both residue. Never ask which zombie pins which directory — an exited process is simply absent from the process table; a CLEAR verdict is the whole requirement. Report qualifying shells as 🧟 zombie-pinned (not residue) with path and probe verdict; several are expected on a host that hasn't rebooted, nothing keys on count.

That probe is repo-agnostic on purpose — runs from fleet-config's own venv against the Windows process table, needs nothing from the target repo. Requiring each repo's own tests/e2e/_browser_sweep.py made the condition unprovable in every repo lacking one, so any leftover directory halted the run (fleet-config#571); where it exists, running it too is welcome, but its absence proves nothing. Probe reads command lines/executable paths, so a process merely cd-ed into the directory with nothing naming it is invisible — hence unrunnable probe is UNKNOWN, not CLEAR.

Second exception: a foreign branch — a local branch belonging to no lane of this run (earlier day's lane, human session, abandoned experiment). Reported as 🌿 <repo> — foreign branch <name> (PR #N merged, diff vs default empty), never residue, never halts. Teardown's mandate is its own lane — no check may assert a repo-wide property teardown is forbidden to bring about (a lane once halted the run over an earlier lane's already-merged branch — fleet-config#572). Judging "safe to delete" is the helper's job, not a hand-run lookup:

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/branch_residue.py branches E:/automation/<repo> --delete --remote

It prints one BRANCH=… WHERE=local|remote … CLASS=… REASON=… line per ref, then ORPHAN=… lines for unregistered <repo>-wt-* folders, SUMMARY and VERDICT=complete|partial|unknown, then its delete outcomes. The rule (the same one /issue-finish step 5 states): a ref classed landed (no open PR, and either a closed issue with the tip proven merged — ancestor, or a squash whose merge-tree result equals the default tree — or a tip equal to the recorded head of its own PR merged into the default branch, whatever the issue lookup says) or superseded (closed issue, no open PR, tip contained in the merge of another branch's PR that closed the issue) holds no unshipped work, so any run deletes it, foreign or not, local and on origin (lease-pinned to the proven sha; every deletion prints its sha, proof and a RESTORE= command). The helper re-judges each target from a fresh tip, proof and PR lookup immediately before acting and skips anything that moved or changed class. Every other class stays and is reported in the 🌿 line or the lane's foreignBranches: unlanded refs go to a human as one batched question per repo, never one per branch; unknown is its own class (a fact was not established), and a branch with no issue number is deletable only when its tip is contained in the default branch (0 commits ahead, or git cherry all -, no open PR). Not git branch --merged (reports a squash-merged branch as unmerged since the original tip is no ancestor of default). A report that could not run is ❓ branch report not established, never an empty list. ORPHAN= lines are informational; the five conditions above stay the halting authority for a leftover directory.

Residue is never folded into a ✅/📋 line: it gets its own ❌ RESIDUE block in the final summary naming the repo, the leftover path/branch, and the one-line recovery command. If a check could not run at all, report it as ❓ unknown, never as clean.

Neither of the last two probes is residue and neither halts anything (fleet-config#534) — they are reported alongside it:

  • index.lock — present with a live git.exe naming that repo (powershell.exe -NoProfile -Command "Get-CimInstance Win32_Process -Filter \"Name='git.exe'\" | Select-Object ProcessId,CommandLine | Format-List") → report ❓ index.lock held by live git (pid N) — left alone, touch nothing. Present with no live git and mtime older than 5 minutes → report 🔒 <repo> — stale .git/index.lock (<age>, no live git) — left for a human, touch nothing, and report the behind-origin check below as ❓ unknown (it cannot pull past the lock). Anything unestablished → ❓ unknown, leave in place. Never delete a lock — it is another process's file; only a human confirming the holder is dead clears it, exactly as /audit-fleet reports it (global CLAUDE.md; fleet-config#667, #1243).
  • Behind origin — non-zero rev-list --count HEAD..origin/<default> fast-forwarded with E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/untrack_guard.py fast-forward E:/automation/$r --ref origin/<default>, never a bare git pull (a plain pull deletes every live file an incoming merge untracks, fleet-config#1086; never merge/rebase/reset/--force), reported ⬆️ <repo> was N behind — fast-forwarded <before>→<after>. Any RESTORED_UNTRACKED=/KEPT_ASIDE= line it prints is reported as 🗂️ <repo> — kept live files the merge untracked: <paths> (a KEPT_ASIDE path names its stash dir and needs a human). Refused fast-forward (FF=refused), failed fetch, or still-locked index → ❓ unknown with reason, not a silent pass. Never pull over a repo this step already found dirty or off its default branch — report as ❓ unknown instead; mutating it destroys the evidence. A foreign branch is not a reason to withhold the fast-forward — gating on unrelated refs leaves a healthy primary behind (fleet-config#572).

live-held and a refused fast-forward are unknown-class verdicts, not passes — named spellings of "could not establish that this primary is current". Render them with ❓ and never fold them into a ✅.

8c. Record whatever is still deferred — durably, outside this run's stdout

A skip that exists only in one run's stdout is invisible by the following week. Whatever step 7b could not recover goes into the ledger. So do step 7's deferred items when a halt or a window stop skipped 7b. All of it goes into one tracking issue in ferraroroberto/fleet-config, upserted through the same marker-keyed machinery as every other managed issue, so re-running can never file a duplicate.

Still-deferred set non-empty — write the body to a file, then:

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/audit_issue.py upsert \
  --repo ferraroroberto/fleet-config --kind cleanup-deferred --reopen --label chore \
  --title "cleanup-fleet-all deferred repos" --body-file <file>

--reopen is what makes the close-when-clear cycle idempotent: if the last run cleared the set and closed the issue, this reopens that issue rather than filing a second one. Creation already self-assigns (--assignee @me) and chore is the type label — maintenance, not an audit finding, which is also why cleanup-deferred is deliberately not one of audit_issue.py's BUCKET_KINDS.

Body: one row per still-deferred repo — repo · repo_state · skip_reason · the issue numbers that went unprocessed · this run's date. Replace the body wholesale each run; it is a current-state ledger, not an append log.

Still-deferred set empty — close it:

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/audit_issue.py close \
  --repo ferraroroberto/fleet-config --kind cleanup-deferred \
  --comment "Run of <date> cleared the deferred set — every candidate repo was processed."

An open cleanup-deferred issue therefore always means there is unprocessed work, never the last run had nothing to say.

This does not replace the report line: step 10's skipped counts are printed on every run including the zero case. The issue carries live work; the report carries the audit trail that the check ran at all. Never collapse the two.

8d. File scaffold promotions — after step 8's verification

A generalizable check lands only in the repo its lane worked, so the same class of finding returns everywhere else. For every entry in the workflow's promotions, run (the orchestrator, never an agent):

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/audit_issue.py promote-check --name <name> --repo-pr <repoPr> --path <path>

It prints PROMOTION=created|commented|unknown URL=<url>: one project-scaffolding issue per rule name, labelled structural-promotion and keyed by a hidden <!-- structural-promotion: name=<slug> --> marker. An open match gets a comment naming the new repo, PR and path; a closed one gets a comment and is never reopened. The intake side is project-scaffolding's conventions-ratchet doc. An entry with a null repoPr is not run: report it as PROMOTION=unknown REASON=pr number unreadable. Carry every result line into the final summary as its own line, 🧱 for created/commented and ❓ for unknown — a promotion that could not be filed is never dropped.

9. Notify

Per bucket, once all its issues have a final status:

E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/hooks/notify_complete.py \
  --kind cleanup --summary "<bucket> (all-mode)" --merged <merged-count> --review <escalated-count>

(--review here means "escalated after 2 failed validation rounds," reusing the existing --kind cleanup semantics exactly — no code changes needed.) After every bucket has reported: fire one final roll-up call summing merged/escalated across all nine buckets, same --kind cleanup shape with --summary "all buckets".

notify_complete.py is the ONLY sanctioned way to send these pings — never use an MCP chat tool to find a chat or post it, and a silent no-op is correct, not a bug to route around. Why: notify-ping.

10. Final summary

Cleanup-fleet-all complete           (or: HALTED at <repo>#<N> — see below)
  candidates: 9 dispatched, 2 already-closed (skipped, no agent dispatched), 1 unresolved (skipped, state unknown)
  skipped: 3 repos, 11 issues unprocessed (1 repo state unknown) — 1 repo recovered on the end-of-run retry
  documentation:      3 merged, 1 escalated
    ✅ merged:   photo-ocr#44 <pr-url>, reporting#12 <pr-url>, …
    📋 escalate: app-launcher#71 — reason: <validator's last feedback>
                 torn down; findings + WIP SHA commented on the issue
    ❓ recurrence unknown: reporting#12 — structural check not required
    🧱 promotion: rule no-raw-sql from photo-ocr#45 — PROMOTION=created URL=<url>
    ❓ promotion: rule no-bare-except from reporting#13 — PROMOTION=unknown REASON=<reason>
  claude-md-drift:    …
  …
  deferred (extra issue, next run): grocery-shopping#9

  deferred repos (skipped at pre-flight, re-checked after the last bucket):
    ♻️ automation      — was dirty at pre-flight, clean on retry: #88, #91 processed above (retry)
    ⏸️ website         — dirty (working tree not clean) — 7 issue(s) unprocessed: #12, #14, #15, …
    ❓ local-llm-hub   — unknown (git branch --show-current failed: not a git repository) — 4 issue(s) unprocessed
    🧳 facilitation-suite — foreign worktree appeared mid-run: E:/automation/facilitation-suite-wt-nav-41af40a (clean, merged) — 2 issue(s) deferred: #43, #44
    tracked in: https://github.com/ferraroroberto/fleet-config/issues/<N>

  primary hygiene (reported, nothing halted):
    🔒 home-automation — stale .git/index.lock (4h12m old, no live git) — left for a human
    ❓ home-automation — behind check unknown: stale index.lock in place
    ❓ automation      — index.lock held by live git (pid 21884) — left alone
    ⬆️ automation      — was 11 behind origin/main, fast-forwarded a1b2c3d→e4f5a6b
    🗂️ automation      — kept live files the merge untracked: RESTORED_UNTRACKED=system/foldersearcher/foldersearcher.json
    ❓ website         — behind check unknown: fetch failed (no network)
    🧟 app-launcher    — E:\automation\app-launcher-wt-709 empty + zombie-pinned (6 zombies, live=0), not residue
    🌿 pdf-to-markdown — foreign branch fix/68-harden-upload-path-handling (PR #69 merged, diff vs main empty), not residue
                         delete with: git -C E:\automation\pdf-to-markdown branch -D fix/68-harden-upload-path-handling

  ❌ RESIDUE (run halted): local-llm-hub — E:\automation\local-llm-hub-wt-451 would not delete
     <detail from the teardown agent>
     Recover: E:/automation/fleet-config/.venv/Scripts/python.exe C:/Users/rober/.claude/skills/_lib/worktree_claim.py remove-worktree E:\automation\local-llm-hub-wt-451
     Not started because of the halt: 4 issue(s) in maintainability, all of slop/bug/design-drift

SCHEDULED-RUN-FAILED — halted at local-llm-hub#N: E:\automation\local-llm-hub-wt-451 would not delete, 4 issue(s) never started

Next: escalated issues need a human — read the teardown comment on the issue and either re-run it, or close it if it doesn't warrant the work.

A run that halted says so on the first line. Never present a halted run as complete.

The candidates: line is mandatory on every run, even when both extra counts are zero (fleet-config#623, echoing #560/#612) — a run that silently shrank its working set at step 5 otherwise reads as "nothing to do". already-closed and unresolved are two distinct counts, never combined into one "skipped" number.

The skipped: line is mandatory too, even when every count is zero (skipped: 0 repos, 0 issues unprocessed). Two non-interchangeable numbers: repos skipped, and how much live work went unprocessed. Repos whose state couldn't be established are counted apart from confirmed-dirty ones. Retry recovery count belongs on this line too.

The rate gate: line is mandatory too — the step 6 decision and pause cycles used, e.g. rate gate: OK 17.0% (unattended), 0 pauses or rate gate: PAUSE cache_stale (unattended), 3 pauses — no lane started. If step 6 skipped at once on CLEARS_WITHIN_BUDGET=no, the first line reads Cleanup-fleet-all SKIPPED (session limit — reset out of reach), the rate gate: line shows 0 pauses plus the gate's RESET_IN_SECONDS, and the report prints the literal line SCHEDULED-RUN-SKIPPED — session limit: weekly usage <USED_PCT>%, reset in <RESET_IN_SECONDS>s is beyond the <PAUSE_BUDGET_SECONDS>s pause budget, <M> issue(s) deferred. It must not print SCHEDULED-RUN-FAILED: usage this high is a correct "not today", the run exits 0 and raises no job-failed event, and the deferred set is recorded as for any skip. If step 6 exhausted its 3 pause cycles, the first line reads Cleanup-fleet-all SKIPPED (session limit — exceeded pause retries) and the report prints the literal line SCHEDULED-RUN-FAILED — session limit: rate gate still PAUSE (<REASON>) after 3 pause cycles, <M> issue(s) never started.

If every candidate repo was skipped (step 5 left dispatch empty while candidates existed), print the literal line SCHEDULED-RUN-FAILED — every candidate repo was skipped (<N> repos, <M> issues unprocessed), no lane ran — touching none of the real work found is not a clean sweep. Step 3's genuine empty-queue stop stays exempt.

If (and only if) step 7's workflow result carries a non-null halted ({ bucket, repo, issue, status, detail, remainingInBucket }), also print the literal line SCHEDULED-RUN-FAILED — halted at <repo>#<issue>: <detail>, <remainingInBucket + issues in later buckets> issue(s) never started, exactly as shown above, so claude_progress.py maps this run to exit 123 instead of the harness's default exit 0 (fleet-config#612 — a run that halted 1 of 9 lanes reported exit 0, green on the Jobs card). A fully successful run (halted null) must not print this line — opt-in, not a default.

If step 7's result carries a non-null stopped, the run ended on its wall-clock window (fleet-config#2063) and the first line reads Cleanup-fleet-all STOPPED (run window ended); the report names WINDOW_ENDS_AT, the lanes that did run, and the unstarted issues now deferred. For reason window-closed print the literal line SCHEDULED-RUN-STOPPED — run window ended at <WINDOW_ENDS_AT>, <notStarted> issue(s) deferred. It must not print SCHEDULED-RUN-FAILED: a bounded stop is a deliberate "not the rest today" whose work is recorded for the next run, so it exits 0 and raises no job-failed event, exactly like step 6's skip. For reason window-unknown the window could not be read, so it is not a deliberate stop: print SCHEDULED-RUN-FAILED — run window unreadable: <detail>, <notStarted> issue(s) never started.

11. Stop

No follow-up actions and no auto-launch of anything — including no retry of a halted run. A human clears the residue and decides whether to re-run.

Hard rules

Recap of binding constraints not fully restated in the steps above:

  • Gates between the four agents are deterministic workflow-script code, never another LLM call re-interpreting a decided verdict. No parallel(...) over issues, ever; the next lane starts only after the current lane's teardown reports CLEAN; never stack a second worktree on the first.
  • A skipped repo is deferred, never dropped (fleet-config#642) — step 7b retry, step 8c ledger, step 10 report line. Retry re-runs the full pre-flight, never a cached verdict. One retry pass, never a loop, never when halted. An open cleanup-deferred issue always means unprocessed work; a clean run closes it with a comment (audit_issue.py upsert --reopen on the other path). The always-printed report line is a separate fact, never collapsed into the issue.
  • design-drift fixes obey /design-sync's structural rule: auto-fix token/palette/spacing, never re-author navigation or components (reuse the vendored project-scaffolding snippet verbatim); an unresolvable structural finding fails validation and escalates, never auto-merges a hand-rolled rewrite. cert-drift is not a bucket here — never auto-applied.
  • prompt-drift lanes obey /cleanup-fleet's prompt-drift tier rule (its step 5 is the one home — not restated here): this run ships every lane with no human gate, so a prompt-drift issue whose body states hard tier is not dispatched — list it under deferred as hard-tier prompt-drift — needs an attended /cleanup-fleet run. Every prompt-drift lane's validate stage runs .claude/skills/context-purge/check.py --base origin/<default> and walks the directive inventory of each edited instruction file; a FAIL or UNKNOWN is pass: false (retry once, then escalate), never a warning. The decision script owns that brief (validatePrompt).
  • Recurring buckets ship a structural check (fleet-config#1520). A lane whose issue body is stamped <!-- audit-recurrence: state=recurring ... --> (fleet-config#1513) must also ship one structural check that would have caught the class — a lint rule, a static test, a ratchet — declared on its own line in a branch commit body as Structural-check: <repo-relative path>, or Structural-check: not encodable: <why, at least 8 words>. A real check also declares its scope on a commit-body line, Structural-scope: repo-specific: <why, at least 8 words> or Structural-scope: generalizable: <rule-name>; a scaffold-published component or a switched-on existing [conventions_ratchet] rule is scaffold-owned and needs none. The validator runs skills/_lib/audit_issue.py structural-gate and reports its line; the decision script (structuralBlocked) refuses to ship on anything but n/a or a pass carrying an established SCOPE= (a generalizable one with its NAME=), whatever the verdict's pass says, and the PR body carries a ## Structural check section. A merged generalizable check is promoted in step 8d. A state=unknown stamp never gates and is reported as ❓ recurrence unknown.
  • Post-flight dirty-tree check runs here, in this skill, never inside a spawned agent, right before a repo's status is trusted.
  • Second validation failure escalates — never force-merges, never silently drops the issue from the final report.
  • Step 8b's residue enumeration covers every touched repo, not just merged ones, fails loud; a check that can't establish a fact reports unknown, never clean. Teardown judges its own lane's mess, never the repo's (fleet-config#572); a stale index.lock and a behind-origin primary are reported, never halting, never silently repaired.
  • A run that stops with lanes unprocessed must print the literal SCHEDULED-RUN-FAILED marker — pre-flight failure (step 1), every-candidate-repo-skipped stop (step 5), exhausted session-limit pause cycles (step 6), residue halt (step 10, non-null halted), or an unreadable or unarmable run window (steps 6b and 10) — so claude_progress.py maps the run to exit 123 instead of exit 0 (fleet-config#612). The step 3 empty-queue stop is exempt — legitimate success, never prints the marker. So is step 6's immediate skip (CLEARS_WITHIN_BUDGET=no): it prints SCHEDULED-RUN-SKIPPED and exits 0 (fleet-config#2012). So is a run whose window closed (stopped.reason window-closed): it prints SCHEDULED-RUN-STOPPED and exits 0 (fleet-config#2063).
  • No AI attribution; no hard-wrapped issue/PR-body paragraphs (per global CLAUDE.md).

Notes

  • Relationship to /cleanup-fleet: that skill stays exactly as-is, the attended single-bucket human-gated tool — nothing here replaces it. This one is for a scheduled overnight run where nobody is watching.
  • Compose, don't reinvent: the build agent's mechanics reuse /issue-start <N> now; the execute agent's mechanics reuse /issue-finish's push/PR/CI/merge/tray-restart sequence — same as /cleanup-fleet and /issue-finish-batch already do.
  • Two environment bugs are worked around, neither specific to this skill — re-test if the harness changes: scriptPath invocation (step 7), and args arriving as a JSON string rather than a parsed object — .claude/workflows/cleanup-fleet-all.js defensively JSON.parses it when it arrives as a string.
  • Before trusting the full unattended schedule, run one more attended pass covering a bucket with a validator rejection (proves the retry loop, not just the happy path) before wiring run-weekly.bat into a scheduled job.
  • Prior incidents this shape encodes — read before relaxing any rule above: fleet-config#534 (teardown-honesty checks → the two reported-only probes + zombie exception); fleet-config#518 + #515 (parallel fan-out left 11 stray worktrees + two primaries off main reporting 0 failed → serial lanes, Teardown agent, residue halts, forced worktrees, step 8 enumeration); fleet-config#642 (skipped repos dropped not deferred, same shape as #560/#607/#612/#623 → repo_preflight.py, 7b retry, cleanup-deferred issue); fleet-config#612 (a correct halt that never reached the exit code → SCHEDULED-RUN-FAILED marker); fleet-config#1077 (a foreign merged worktree created mid-run by another lane halted a run after 9 of 50 issues → worktree_residue.py, foreignWorktrees, deferred).