diff --git a/changelog.d/fixed-tracker-closed-issue-names-merged-closer.md b/changelog.d/fixed-tracker-closed-issue-names-merged-closer.md new file mode 100644 index 0000000000..fb675b7210 --- /dev/null +++ b/changelog.d/fixed-tracker-closed-issue-names-merged-closer.md @@ -0,0 +1 @@ +- Activity tracker: a follow-up or duplicate PR opened against an issue an earlier merge already delivered now reads `closed by #N` (the merged PR GitHub records as the closer, never an open PR with `Fixes #N`), or `closed · this PR unmerged` when no merged closer is known, instead of a bare `closed` chip that read as if the issue had been closed before its fix merged; docs state the rule that the hive closes an issue only after its PR merges diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index 1d09f03f6e..623c3de13c 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -1037,6 +1037,8 @@ When the blocked sweep or the review-backlog block reconciler lifts `blocked` it A pull request whose `Fixes #N` issue has already closed (auto-closed by a bot, or closed by hand) while the PR is still open is live work, not a stale line: the row is anchored on the PR ([#14655](https://github.com/hivecommons/hive/issues/14655)). The PR's own icon, number and title lead the row at full width, its stage drives the strip and its timestamps sort it — closing the issue is not a regression of the PR — and the closed issue shrinks to a muted `closes #N · closed` chip linking to it. +The chip names the closer when it can. The server asks GitHub which *merged* pull request closed the issue (`closedByPullRequestsReferences`; the hive's own merged ledger is the fallback) and the slot reads `closed by #N`, linking to that PR — the open PR on the row is then a follow-up or a duplicate, and merging it will not close anything. An open PR whose body says `Fixes #N` is listed under the same GitHub relation but is never named: it has closed nothing. When no merged closer is known the chip reads `closed · this PR unmerged`, with the hover spelling out that a person or another merged PR closed the issue; it never reads as a bare `closed`, which looked like the issue had been closed before its fix merged (hive's #15422 under follow-up #15425, #15058 under #15431). The hive itself closes an issue only after its PR has merged (see [Issues close only after the merge](hive-merge.md#issues-close-only-after-the-merge)). + An issue closed as *not planned* adds an `issue closed (not planned)` chip so the reader can tell the PR may be moot. At 090 such a row still counts under *Needs attention*: the human has a merge to click. When the PR closes or merges too, the row leaves the list as before (a merged PR shows in *Recently merged* for its retention window). #### Row gutter diff --git a/src/docs/hive-merge.md b/src/docs/hive-merge.md index eea1248866..927bda097b 100644 --- a/src/docs/hive-merge.md +++ b/src/docs/hive-merge.md @@ -624,6 +624,34 @@ report them. If the branch's commits cannot be read at merge time, the hive falls back to GitHub's default message rather than risk dropping a sign-off. Switch it off with `auto_merge.credit_issue_authors: false` (#14581). +### Issues close only after the merge + +The hive never closes an issue for a pull request that has not merged. The +only PR-driven close path is close-on-merge (`CloseOnMergeLedgerSweep`, +`close_on_merge.go`), which reads the PR back from the forge and returns +`pr_not_merged` without touching the issue unless `merged_at` is set (or +`merged` is true); opening a PR, admitting it to the merge train or the +pre-merge soak, and a `Fixes #N` in its body change nothing on the issue. On +GitHub's default branch GitHub itself closes the issue in the same instant +the PR merges, attributed to whoever pressed merge; on a release line the +hive's sweep does it on the next pass, with a "Fixed by #N (merged …)" +comment. Every such close goes through the central `CloseIssue` (which +refuses tracking issues and honours the reporter-confirmation gate) and is +counted by the direct-write ratchet, so no other code path can grow a close +of its own. + +The tracker shows the consequence honestly. A follow-up or duplicate PR whose +body names an issue an *earlier* PR already delivered — `Refs #15422` on +#15425 after #15426 merged, `extending #15058` on #15431 after #15068 merged — +sits under the struck-through issue with the chip **closed by #N**, linking +to the merged PR GitHub records as the closer +(`closedByPullRequestsReferences`, with the hive's merged ledger as the +fallback). Only a merged PR is ever named: an open PR with `Fixes #N` is +listed under the same relation and has closed nothing. When no merged closer +can be found the chip reads **closed · this PR unmerged**, never a bare +`closed` that could be read as the issue having been closed before its fix +merged. + ### Stage labels Every sweep cycle also writes the hive-owned `stage/NNN-*` label for each PR diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 23d32a2d4d..fa4948ce73 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -2886,8 +2886,13 @@ const ( // or pr when the number names a pull request; ok is false for a failed GET. type stageTrackerLinkInfo struct { title, state string - pr, ok bool - at time.Time + // stateReason and closedBy are set on a closed issue when the forge + // reports them: GitHub's stateReason and the merged PR that closed it + // (never an open PR, whatever its body says). + stateReason string + closedBy int + pr, ok bool + at time.Time } // stageTrackerLinkMemo memoises link lookups keyed by owner/repo#number. @@ -2934,6 +2939,11 @@ func (in stageTrackerLinkInfo) ttl() time.Duration { // reference titled (soft refs / title / mention links, and closing keywords // hive read from the PR text) a title and state, from one issues GET per // distinct same-repo number, memoised across rebuilds (stageTrackerLinkMemo). +// A closed issue also gets its stateReason and the merged PR that closed it +// (ClosedBy, from GitHub's closedByPullRequestsReferences), so a follow-up +// PR opened against an issue an earlier merge already delivered reads +// `closed by #N` rather than a bare `closed` that looks like the issue was +// closed before any PR merged (hivecommons/hive#15232 for the ledger path). // A number that turns out to be a pull request, open or closed (`Supersedes // #N`, an adoption's "close #N"), is dropped: it is not an issue the PR // covers (hivecommons/hive#14667). A failed or skipped lookup leaves the link @@ -2961,8 +2971,8 @@ func (s *Server) stageTrackerEnrichSoftLinks(items []StageTrackerItem, qualify f in, hit := s.stageTrackerLinks.get(key, now) if !hit && lookups < stageTrackerLinkLookups && ctx.Err() == nil { lookups++ - title, state, isPR, err := s.deps.GHClient.IssueTitleState(ctx, owner, name, li.Number) - in = stageTrackerLinkInfo{title: title, state: state, pr: isPR, ok: err == nil} + facts, err := s.deps.GHClient.IssueLinkState(ctx, owner, name, li.Number, pr.Number) + in = stageTrackerLinkInfo{title: facts.Title, state: facts.State, stateReason: facts.StateReason, closedBy: facts.ClosedBy, pr: facts.IsPR, ok: err == nil} // Running out of this rebuild's budget says nothing // about the issue: leave it for the next rebuild. if err == nil || ctx.Err() == nil { @@ -2974,6 +2984,9 @@ func (s *Server) stageTrackerEnrichSoftLinks(items []StageTrackerItem, qualify f } if in.ok { li.Title, li.State = in.title, in.state + if in.state == "closed" { + li.StateReason, li.ClosedBy = in.stateReason, in.closedBy + } } } kept = append(kept, li) diff --git a/src/pkg/dashboard/stage_tracker_test.go b/src/pkg/dashboard/stage_tracker_test.go index 598098c32a..924895903a 100644 --- a/src/pkg/dashboard/stage_tracker_test.go +++ b/src/pkg/dashboard/stage_tracker_test.go @@ -1061,12 +1061,20 @@ func TestStageTrackerClosedIssueAnchor(t *testing.T) { // (`Supersedes #14592`, an adoption's "close #14592"), is dropped rather than // drawn as an issue "(title unavailable)". func TestStageTrackerEnrichSoftLinks(t *testing.T) { - var gets atomic.Int32 + var gets, closerReads atomic.Int32 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost && strings.HasSuffix(r.URL.Path, "/graphql") { + // The closer lookup a closed issue costs: #14576 was closed by + // the merge of #14570; #14590 (open, body says Fixes #14576) + // is listed under the same relation and must not be named. + closerReads.Add(1) + fmt.Fprint(w, `{"data":{"repository":{"issue":{"closedByPullRequestsReferences":{"nodes":[{"number":14590,"merged":false},{"number":14570,"url":"https://github.com/hivecommons/hive/pull/14570","merged":true,"mergedAt":"2026-10-27T12:00:00Z"}]}}}}}`) + return + } gets.Add(1) switch r.URL.Path { case "/repos/hivecommons/hive/issues/14576": - fmt.Fprint(w, `{"number":14576,"title":"Runner stalls","state":"closed"}`) + fmt.Fprint(w, `{"number":14576,"title":"Runner stalls","state":"closed","state_reason":"completed"}`) case "/repos/hivecommons/hive/issues/14577": fmt.Fprint(w, `{"number":14577,"title":"A PR","state":"open","pull_request":{}}`) case "/repos/hivecommons/hive/issues/14592": @@ -1100,11 +1108,14 @@ func TestStageTrackerEnrichSoftLinks(t *testing.T) { if len(links) != 3 { t.Fatalf("links = %+v, want the PR numbers 14577 and 14592 dropped", links) } - if got := links[0]; got.Number != 14576 || got.Title != "Runner stalls" || got.State != "closed" { - t.Fatalf("refs link = %+v, want titled and closed", got) + if got := links[0]; got.Number != 14576 || got.Title != "Runner stalls" || got.State != "closed" || got.StateReason != "completed" || got.ClosedBy != 14570 { + t.Fatalf("refs link = %+v, want titled, closed (completed) by merged #14570", got) + } + if got := items[1].LinkedIssues[0]; got.Title != "Runner stalls" || got.State != "closed" || got.ClosedBy != 14570 { + t.Fatalf("second PR's refs link = %+v, want closed by #14570 (never the open #14590)", got) } - if got := items[1].LinkedIssues[0]; got.Title != "Runner stalls" || got.State != "closed" { - t.Fatalf("second PR's refs link = %+v", got) + if n := closerReads.Load(); n != 1 { + t.Fatalf("closer reads = %d, want 1 (closed issues only, memoised)", n) } if got := links[1]; got.Number != 14578 || got.Title != "" || got.State != "" { t.Fatalf("failed lookup = %+v, want untouched", got) diff --git a/src/pkg/dashboard/stage_tracker_ui_test.go b/src/pkg/dashboard/stage_tracker_ui_test.go index 7c82279e35..f8caa76cab 100644 --- a/src/pkg/dashboard/stage_tracker_ui_test.go +++ b/src/pkg/dashboard/stage_tracker_ui_test.go @@ -641,14 +641,14 @@ assert.strictEqual(titles(row, 'Fix sort'), 1); // body still says Fixes #N): the issue slot keeps "#N title" as a link, // struck through under a "closed" chip, so the pairing reads at a glance. row = stageTrackerRowHtml({ repo: 'acme/console', number: 111, kind: 'pr', title: 'Docs', stage: 95, linked_issues: [{ number: 13409, state: 'closed', title: 'Usage on --help', url: 'https://x/13409' }] }, stages, ctx); -assert.strictEqual(lead(row), '#13409 Usage on --help closed', lead(row)); +assert.strictEqual(lead(row), '#13409 Usage on --help closed · this PR unmerged', lead(row)); assert.ok(/