Skip to content

Leave the repo clean: delete merged task branches at finish and sweep at close #129

Closed

Description

@radiusred-cody

Goal

Adopts backlog capture #128. Fifty stale task branches sat on the hub at M6 (one on www): every task start cuts a linked branch and nothing ever removes it — task finish merges with gh pr merge --rebase and no --delete-branch, and delete_branch_on_merge is off on both repos (a per-repo setting the framework cannot set for adopters and does not mention). Three layers, all Free-tier: (1) task finish deletes the head branch after a successful merge, the counterpart of task start creating it; (2) milestone close sweeps the linked branches of the milestone's closed tasks before the document gate — deleting only where the branch's PR merged or the branch is zero commits ahead of the default branch (rebase-merge rewrites commits, so "tip is an ancestor of main" is the wrong test: 43 of the 50 merged tips were not ancestors), reporting and never deleting anything else, and printing what it removed as part of the close's record; (3) status notes when delete_branch_on_merge is off, the way it notes contract drift, so adopters learn the setting exists. The decision function (merged / zero-ahead / keep) is pure and tested; the sweep is exercised against a fake tracker; milestone close 6 is the first live proof. The one-off backlog was swept by the operator on 2026-08-26 under the same two criteria (log on #128).

Requirements

M6-R8

Plan

  1. The decision, pure: branchAction(merged, openPR bool, ahead int) (delete bool, reason string) — delete when the branch's PR merged, or when no PR is open and the branch is zero commits ahead of the default branch; keep (and say why) otherwise. Rebase-merge rewrites commits, so ancestry of the tip is never the test. Table-tested.
  2. Tracker seams (internal/tracker): PR gains HeadRef and Merged; LinkedBranches(ref) (GitHub's linked-branch relation, which task start creates through gh issue develop — so the sweep sees exactly the branches the protocol made, whatever they were named); BranchAhead(repo, branch) via the compare API against the repo's default branch; DeleteBranch(repo, branch); RepoInfo(repo) for the default branch and delete_branch_on_merge. gh api throughout, Free-tier.
  3. task finish deletes the head branch after a successful merge on both paths (ordinary and --bypass), prints deleted branch task/…; a deletion failure is a note, never an error — the merge has happened and the record must say so first.
  4. milestone close sweeps after the verdict gates and before the record is gathered: for every task, every linked branch → PR merged? delete; no PR and zero ahead? delete; else keep and report. Prints one line per branch either way, so the close output is the record of what was removed and what was left and why; the closing comment carries the count. Idempotent: a refused close that already swept prints nothing the next time. milestone close 6 is the first live proof (the branch of Decide the protocol-version story before 1.0 #114 is waiting for it).
  5. status notes when the repo's delete_branch_on_merge is off, beside the contract-drift note — advisory, and an API failure is silently skipped as routing is.
  6. Docs: SPEC §6's task finish and milestone close rows; the quickstart's step 5 ("the branch is gone") and step 8; the introduction's "What exists" sentence for status. The adopter's own setting is described as what it is — GitHub's, per repo, optional once the verbs clean up.
  7. Tests ride (feat: request review from the reviewer-role holder #46): branchAction; the sweep against a fake tracker (an embedded-interface fake with the four methods the sweep uses — the cli package has none today, this task adds the minimal one); PRInfo parsing for the new fields. go test ./... before the PR; the reviewer seat by dispatch; task finish 129 — its own first live use of step 3.

Ask-the-human points

None identified yet — the implementer adds any before starting.

Activity

  1. added
    cc:task
    on Aug 26, 2026
  2. radiusred-cody commented on Aug 26, 2026

    @radiusred-cody
    ContributorAuthor

    Started by @radiusred-cody[bot].

  3. radiusred-cody commented on Aug 26, 2026

    @radiusred-cody
    ContributorAuthor

    Deviation: plan step 7 named a parsing test for PRInfo's new fields (HeadRef, Merged); none rides. Why: PRInfo shells to gh pr view --json and decodes in place — there is no seam to feed it JSON without restructuring internal/tracker/github.go, which no task has done and this one should not do on the side. The fields were verified live instead (PR #127: head=task/114-…, merged=true, open=false), and the sweep's use of them is tested against the fake. A tracker-level fake or a decode seam is captured for the backlog.

  4. radiusred-cody commented on Aug 26, 2026

    @radiusred-cody
    ContributorAuthor

    Deviation: plan step 2 assumed GitHub's linked-branch relation would let the sweep "see exactly the branches the protocol made". It does not: the relation is dropped when the issue closes — live, LinkedBranches(#114) (closed, branch still present) is empty while (#129) (open) lists its branch — and closed tasks are the whole target of the sweep. Why: verified by execution before the PR was reviewed, not after. The sweep now derives candidates from three sources — the relation (open tasks), the head refs of the task's PRs, and the conventional task/<n>-<slug> name task start used (tasks that never had a PR) — and skips silently any candidate that no longer exists. Dry-run live over #114, #72, #129: task/114-…: deleted (PR merged); #72's branch silent (swept by hand earlier); task/129-…: kept (open PR). The first PR description overstated the relation's coverage; corrected in the same minute.

  5. radiusred-cody commented on Aug 26, 2026

    @radiusred-cody
    ContributorAuthor

    Deviation (superseding the previous Deviation's premise): the linked-branch relation is dropped once a PR attaches to the issue, not when the issue closes — LinkedBranches(#129) listed its branch before PR #130 existed and is empty after (checky's reproduction on #130; my earlier observation was taken minutes before the PR opened). Why: the relation therefore contributes only for PR-less tasks; the candidate set stays the three-source union with the PR heads carrying every task that had a PR. Also from the review, three deletion paths closed: a merged PR's head is deleted only while its tip still equals the PR's frozen headRefOid (commits pushed after the merge are kept, with the reason); when several PRs share a head the one that forbids deletion wins (open over merged over closed) instead of the last one the API listed; a fork's head and the repository's default branch are never candidates. The sweep now runs after the last gate, so it is the successful close that records what was removed — and its failures are notes, never an abort of a close that passed every gate.

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

    cc:task

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions