Repository navigation
Description
Goal
M14-R4 in full; same file family as #271 (branches.go), land after it. sweepBranches gains a second pass over the repo's task/- branches: a branch whose task issue is closed and which is merged into or empty against the default branch is deleted and reported in the closing comment; a branch with unmerged commits, or whose task is open, is named and left; --dry-run lists them beside the milestone's own. SPEC §6 milestone close row. Closes #167 with the PR.
Requirements
M14-R4
Plan
The shape. milestone close gains a second branch pass, run straight after the milestone's own sweep and before the close itself, on the same "only ever deletes a merged or empty branch, so a close that fails after it loses nothing" footing (#133).
Repos swept. The hub (where the milestone issue lives) plus every repo the milestone's tasks name, deduped, hub first. A stale branch accumulates wherever tasks are cut, and the hub is the one repo every close can be certain about.
The candidate set. One listing per repo, prefix-filtered at the server: a new Tracker.TaskBranches(repo) reading GraphQL refs(refPrefix: "refs/heads/task/", first: 100), so a repo's other branches never enter the sweep and the ceiling is 100 task branches rather than 100 branches. Names come back with the prefix stripped, so the implementation restores it. The task number is read off task/<n>-<slug>; a name that carries no number is skipped. Skipped too: the default branch, and every branch the milestone's own pass already considered (keyed by repo and name, and by the milestone's own task refs) — so pass one's verdicts are never restated or overridden.
The delete conditions do not change. Each candidate is judged by the same branchAction the milestone's own branches meet: its PR merged and the tip still at the merged commit, or no open PR and nothing beyond the default branch. Anything else is named and left, with the reason. This is what #167 asked for ("the change is the candidate set"), and it is the only test that catches a rebase-merged branch, whose commits are rewritten and so are never ahead == 0.
Bounded API use. One branch listing and one RepoInfo per repo; per candidate, one issue read (Task) — and a candidate whose task is open costs exactly that and stops there. Only a candidate whose task is closed goes on to ClosingPRs + PRInfo + BranchAhead, the lookups the delete conditions need. A branch that vanished between the listing and the check is skipped silently, as pass one does.
Reporting. The live verb prints the stale group under its own heading, each line reading stale branch <name>: deleted (<reason>) / kept (<reason>). The closing comment gains its own sentence, Swept from earlier closes: a, b., beside the existing Swept N task branch(es): …. --dry-run lists them beside the milestone's own as would delete stale branch … / would keep stale branch …, and writes nothing.
Files. internal/tracker/tracker.go (interface), internal/tracker/github.go (TaskBranches), internal/cli/branches.go (taskNumber, planStaleSweep, sweepItem.Stale, executeSweep's prefix), internal/cli/milestone.go (the second pass, the dry-run lines, the closing comment), SPEC.md §6's milestone close row, CHANGELOG.md.
Tests (internal/cli/branches_test.go, internal/cli/dryrun_test.go, fakes extended with TaskBranches and a closed/open Task): a stale merged branch of a closed task is swept and reported; an empty one is swept; one with unmerged commits is kept and named; one whose task is still open is kept and named after a single issue read; the milestone's own branches are untouched by the second pass; a listing failure is a note, not an abort; the dry run names them and writes nothing.
Ask-the-human points
None.
Activity
radiusred-cody commentedon Sep 6, 2026
Started by @radiusred-cody[bot].
radiusred-cody commentedon Sep 6, 2026
Decision: the second pass lists the hub the milestone issue lives in, plus every repo the milestone's tasks name, deduped and hub first.
Trade-off: the brief left the choice open between "the hub and each spoke a task of this milestone lives in" and "just the repos the milestone's tasks name". The two differ only for a milestone whose tasks are all in spokes, where the second would never sweep the hub. The hub is where every milestone issue lives and where the record is read, so it is the one repo a close can always be certain about, and it is the repo a solo project's stale branches accumulate in — #167's own evidence is
radiusred/numberguess, a solo hub. One extra prefix-filtered listing is the whole cost.Rejected: every repo in the org or in
.codecrew/config.yml's spoke list — a close would then reach repos this milestone never touched, and the sweep would stop being something the closing operator can predict from the milestone in front of them.radiusred-cody commentedon Sep 6, 2026
Decision: the delete conditions are unchanged — every stale candidate meets the same
branchActionthe milestone's own branches meet — so a candidate whose task is closed costsClosingPRs+PRInfo+BranchAheadon top of the one issue read.Trade-off: the cheaper test the bound suggests, "one branch listing per repo, one issue read per candidate", would have to be
ahead == 0alone. That misses the merged case entirely: this project rebase-merges, so a merged branch's commits are rewritten and it is neverahead == 0— only "its PR merged and the tip still at the merged commit" catches it, and that needs the PR. #167 asked for exactly this ("the delete conditions do not change... the change is the candidate set"), and reusingbranchActionandprByHeadmeans the two passes can never drift apart. The bound is kept where it matters: the listing is one prefix-filtered GraphQL call per repo, and a candidate whose task is still open stops after its single issue read.Rejected: reading the PRs out of the branch listing itself via
Ref.associatedPullRequests, which would have made the whole pass one call per repo. It would duplicatePRInfo's shape inside the listing and give theTrackerseam a second, richer PR type for one caller's benefit.radiusred-cody commentedon Sep 6, 2026
Decision: a
task/<n>-…branch is a candidate on its name alone; the sweep does not require issue<n>to carrycc:task, and it names kept branches in the verb's output and the dry run but not in the closing comment.Trade-off: the name is what
task startwrites and what the first pass already reconstructs from the convention, so requiring the label would make the sweep miss a branch whose task was relabelled while gaining nothing — the delete conditions still refuse anything with unmerged work or an open PR, so the worst case for a mislabelled candidate is an empty branch removed. An issue number that resolves to nothing at all is anote:and a skip, never a delete. Naming kept branches in the output only mirrors what the milestone's own pass does; putting every kept stale branch in the closing comment would grow the comment without end on a repo that has one branch nobody will ever sweep.feat(tracker): list a repo's task branches, filtered at the server by…
feat(milestone): close sweeps the task branches earlier closes left b…
docs: the second branch sweep in SPEC §6, the changelog and the intro…
radiusred-cody commentedon Sep 6, 2026
Decision: the second pass will not delete a branch that is the head of any open pull request, checked with one
OpenPRsForBranchlookup made only for a candidate about to go on the grounds that no PR is open at all.Trade-off:
branchAction's "no PR, nothing beyond the default branch" arm is only as good as the PR set it is handed, andClosingPRsfinds the PRs that close<n>— so a PR opened on a task branch without aCloses #<n>line is invisible to it, and deleting the branch would close that PR. Pass one's candidates come from the task's own PRs and one conventional name, so its exposure is narrow; pass two makes everytask/<n>-…branch in the hub and in each task's repo a candidate, which is wider than the arm was written for (checky's finding 2 on PR #293, taken as required by the coordination layer). The guard costs at most one extra call per candidate, and none at all for a branch already known to have a PR or already being kept. It fails closed: a lookup that errors is anote:and the branch stands.Rejected: widening the PR set for every candidate, which would cost the lookup on branches that are being kept anyway; and leaving it to the Decision text, which was the reviewer's non-blocking suggestion — a guard that only exists in prose is the shape finding 1 was about.
radiusred-cody commentedon Sep 6, 2026
Decision:
Tracker.TaskBranchesreturns atruncatedflag read from the listing'spageInfo.hasNextPage, and the sweep emits anote:naming the repo rather than paging.Trade-off: one page is a hundred task branches, which no repo in this project approaches, and successive closes do make progress through a longer list — so paging would buy correctness nobody can currently reach, at the cost of an unbounded walk in a verb whose whole design claim is a bounded one. The flag costs one GraphQL field and turns a silent partial sweep into a reported one, which is the property the operator actually needs (checky's finding 4 on PR #293).
feat(tracker): list a repo's task branches, filtered at the server by…
feat(milestone): close sweeps the task branches earlier closes left b…
docs: the second branch sweep in SPEC §6, the changelog and the intro…
1 remaining item
fix(milestone): the stale sweep never deletes a branch under an open …
docs: the stale sweep's two guards and its truncation note in SPEC §6…
feat(tracker): list a repo's task branches, filtered at the server by…
feat(milestone): close sweeps the task branches earlier closes left b…
docs: the second branch sweep in SPEC §6, the changelog and the intro…
test(milestone): a candidate the stale sweep cannot judge is a note, …
fix(milestone): the stale sweep never deletes a branch under an open …
docs: the stale sweep's two guards and its truncation note in SPEC §6…
feat(tracker): list a repo's task branches, filtered at the server by…
feat(milestone): close sweeps the task branches earlier closes left b…
docs: the second branch sweep in SPEC §6, the changelog and the intro…
test(milestone): a candidate the stale sweep cannot judge is a note, …
fix(milestone): the stale sweep never deletes a branch under an open …
docs: the stale sweep's two guards and its truncation note in SPEC §6…