Skip to content

status reports stale task branches; guard against accidental closing references #310

Closed

Description

@davison

Goal

status names each remote task/-… branch whose task is closed with the same delete-or-keep verdict milestone close would give it, computed by the same code; the implementer contract forbids a closing keyword before any ref but the task's own, and task finish notes every issue the PR's closing references would close besides the task, before the merge. Adopts #295 and #303.

Requirements

M15-R5

Adopts

Plan

First half — status reports stale task branches (#295).

  1. internal/cli/branches.go: sweepItem gains a TaskOpen bool, set by staleBranchAction on the arm where the task issue is still open. The sweep's own output is unchanged (it still prints stale branch <name>: kept (<ref> is open)); the field only lets a second caller tell that arm apart from a real keep without matching on reason prose.
  2. internal/cli/branches.go: new planStaleReport(t, repo, defaultBranch) ([]sweepItem, bool, error) — one prefix-filtered TaskBranches listing for the one repo, taskNumber off each name, and staleBranchAction for the verdict. It is the same function planStaleSweep calls for the close's second pass, so the report and the sweep cannot disagree. It carries hasNextPage back to the caller rather than wording it, because the sweep's wording ("a later close reaches the rest") is not true of a report.
  3. internal/cli/status.go: statusReport reads RepoInfo(c.current) once — it already reads it for the delete-on-merge note — and, when that read succeeded, prints the stale-branch lines under it, before the contract-drift block. Per branch: stale branch: <name> — <ref> is closed; <reason> — the next milestone close would delete it or … — kept by the next milestone close. A branch whose task is open is skipped (TaskOpen). A branch whose task could not be read prints staleBranchAction's own note: line verbatim, exactly as the sweep does. A truncated listing adds note: <repo> carries more task branches than one listing holds; this report saw <n> of them. An unreadable listing is one note: and status carries on — every check under the board is advisory and none of them may fail the verb.
  4. Nothing to report prints nothing. Recorded as a Decision: the two notes beside it print only when they have something to say, and a line saying a repo is clean would appear on every run of the verb an operator runs most.
  5. The repo is c.current alone. Recorded as a Decision with its reasons.

Second half — the closing-reference guard (#303).

  1. internal/tracker/tracker.go + github.go: new ClosingReferences(repo string, number int) ([]TitledIssue, error) — GraphQL pullRequest.closingIssuesReferences with number, title and repository { nameWithOwner }, so the note can name the issue. TitledIssue already carries exactly ref + title.
  2. internal/cli/dryrun.go: plan gains notes []string and a remark(...) method, printed between the gates and the actions. The existing note attaches to a gate; this line is not a gate's.
  3. internal/cli/task.go: planFinish, after every gate has passed and beside the adoptions read, calls ClosingReferences and records note: this PR would also close <ref> (<title>) — not the task for every reference that is not the task. p.remark puts it in the dry run's listing; run prints the same strings before the merge. A note, never a refusal: GitHub has already parsed the body, and no new code joins SPEC §10.
  4. .codecrew/roles/implementer.md "Open the PR": the task's own number is the only closing keyword, and no closing word (close/closes/closed/fix/fixes/fixed/resolve/resolves/resolved) may precede any other #ref anywhere in the body, because GitHub's PR-body parser reads prose — cite Backlog capture: PR body prose can create unintended closing references from example refs #303 and PR feat(task): task new --adopts and task finish closing the adopted captures (#270) #294, and name the gh pr view <n> --json closingIssuesReferences check after opening.
  5. .codecrew/roles/reviewer.md: a "Review against" bullet — the PR's closingIssuesReferences names the task alone. The contracts are embedded straight out of .codecrew/roles/ by assets.go, so both edits ship in the binary and roles diff stays clean; verified with the built binary.

Docs.

  1. SPEC §6: the status row gains the stale-branches sentence beside the drift and delete-on-merge one; the task finish row gains the closing-references note.
  2. docs/introduction.md's verb summary says only "notes" for status and does not enumerate them, so it needs no change. Recorded rather than left silent.
  3. CHANGELOG entry under ## [Unreleased], (#310).

Tests.

  1. status_test.go (statusFake grows the branch-side methods): a stale branch listed with the verdict branchAction gives it; an open task's branch omitted; an unreadable task's note:; the partial-listing note when the flag is set; nothing printed when there is nothing to report.
  2. dryrun_test.go (finishFake grows ClosingReferences): the dry run's listing and the live run both print the note for an extra closing reference, and neither prints anything when the PR closes only the task.
  3. go test ./..., go vet ./..., gofmt -l . clean; roles diff run from the built binary for both edited contracts.

Ask-the-human points

None. The one judgment the brief left open — what status says when it has nothing to report — is an ordinary engineering call and is recorded as a Decision.

Activity

  1. added
    cc:task
    on Sep 6, 2026
  2. radiusred-cody commented on Sep 7, 2026

    @radiusred-cody
    Contributor

    Started by @radiusred-cody[bot].

  3. radiusred-cody commented on Sep 7, 2026

    @radiusred-cody
    Contributor

    Decision: status reports the stale task branches of c.current — the repo the verb runs in — and walks no other.
    Trade-off: A hub operator running status in the hub sees the hub's own stale branches and not a spoke's, so a spoke that accumulates them is still invisible until someone runs status there or a milestone closes. That is the price of a report that costs one listing.
    Why here: status has no repo set to walk that is both complete and cheap. The hub's routing table names roles, not repos, so there is no register of spokes to read; the open milestones' tasks name repos, but the report has to work between milestones too — that quiet period is exactly when #295 says a skipped sweep goes unseen, and it is when the board is empty. Walking every repo the open milestones happen to name would multiply the cost of the verb an operator runs most often (one prefix-filtered listing plus one issue read per task branch, each), and would still miss a spoke with no open task. milestone close's second pass already covers the hub-plus-task-repos set at the moment it matters; the report covers the repo you are standing in, which is also the only one whose branches you were about to act on.
    Rejected: walking m.Tasks's repos the way planStaleSweep does — the same set, at a much higher rate, with the wrong coverage between milestones.

  4. radiusred-cody commented on Sep 7, 2026

    @radiusred-cody
    Contributor

    Decision: when there is no stale branch to report, status prints nothing at all — no "no stale task branches" line.
    Trade-off: an operator cannot tell, from the output alone, a repo with nothing stale from a listing the verb could not read. The unreadable case is covered instead: it prints its own note: line, so silence means clean and a failure is never silent.
    Why: the two checks this report sits beside — contract drift and delete-on-merge — both print only when they have something to say, and status is the verb run most often in a project. A permanent clean line on every run is the kind of output an operator stops reading, which is precisely how the line that does matter gets missed.

  5. radiusred-cody commented on Sep 7, 2026

    @radiusred-cody
    Contributor

    Deviation: the closing-reference note names the issue as a fully qualified ref — note: this PR would also close radiusred/gh-codecrew#42 (An example ref in the prose) — not the task — where the task's brief wrote the shape as a bare #<n>.
    Why: GitHub's closing keywords accept owner/repo#n, so a pull request can genuinely carry a closing reference to another repository's issue, and ClosingReferences reads each node's own nameWithOwner rather than assuming the PR's. A bare number would name the wrong issue in exactly the case the note exists to catch. Every other issue this codebase prints is a qualified IssueRef too, so the line reads like the rest of the verb's output — and it still contains #42 for anyone scanning for the number.

  6. 8 remaining items

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