Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/docs/dashboard-sections.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/docs/hive-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
23 changes: 17 additions & 6 deletions src/pkg/dashboard/stage_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 11 additions & 9 deletions src/pkg/dashboard/stage_tracker_ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<div class="ham-head-main ham-issue-closed">/.test(row) && /<a class="ham-ref" href="https:\/\/x\/13409"[^>]*>#13409<\/a>/.test(row), 'closed issue stays a link in a struck-through slot: ' + row);
assert.ok(row.includes('<span class="ham-title" title="Usage on --help">Usage on --help</span> <span class="ham-badge ham-issue-closed-chip">closed</span>'), 'title then closed chip: ' + row);
assert.ok(/<span class="ham-title" title="Usage on --help">Usage on --help<\/span> <span class="ham-badge ham-issue-closed-chip" title="Issue #13409 is closed, but this PR is still open and unmerged[^"]*">closed · this PR unmerged<\/span>/.test(row), 'title then closed chip naming the unmerged PR: ' + row);
assert.ok(!row.includes('ham-no-issue-t') && !/<a class="ham-ref"[^>]*title=/.test(row) && prCol(row).length === 1 && prCol(row)[0].includes('#111'), row);
// The same with no title resolvable: a muted "(closed issue)" placeholder, never a blank.
row = stageTrackerRowHtml({ repo: 'acme/console', number: 111, kind: 'pr', title: 'Docs', stage: 95, linked_issues: [{ number: 13409, state: 'closed', url: 'https://x/13409' }] }, stages, ctx);
assert.strictEqual(lead(row), '#13409 (closed issue) closed', lead(row));
assert.ok(row.includes('<span class="ham-title ham-no-issue-t">(closed issue)</span> <span class="ham-badge ham-issue-closed-chip">closed</span>'), row);
assert.strictEqual(lead(row), '#13409 (closed issue) closed · this PR unmerged', lead(row));
assert.ok(/<span class="ham-title ham-no-issue-t">\(closed issue\)<\/span> <span class="ham-badge ham-issue-closed-chip" title="[^"]*">closed · this PR unmerged<\/span>/.test(row), row);
// hivecommons/hive#15232: a PR whose closing link names a closed issue
// (closed_issue set by the server, hivecommons/hive#14655) still puts the
// ISSUE in the left slot — struck through under its chip — and itself in the
Expand All @@ -664,14 +664,16 @@ assert.ok(/<a class="ham-badge ham-issue-closed-chip ham-closed-by-chip" href="h
assert.ok(!row.includes('ham-head-pr-anchor') && !row.includes('closes <s>'), 'the PR no longer takes the issue slot: ' + row);
assert.ok(prCol(row).length === 1 && prCol(row)[0].includes('#15191') && prCol(row)[0].includes('Let hive decide'), 'PR sits in the PR column: ' + prCol(row));
assert.ok(!row.includes('ham-closed-not-planned'), 'completed close: no moot chip');
// Closer unknown: a plain "closed" chip; a not-planned close adds the moot chip.
// Closer unknown: the chip says the issue closed while this PR is unmerged
// (never a bare "closed" that reads as closed-by-this-PR); a not-planned
// close adds the moot chip.
row = stageTrackerRowHtml({ repo: 'acme/console', number: 15191, kind: 'pr', title: 'Let hive decide', stage: 90,
linked_issues: [{ number: 15173, state: 'closed', state_reason: 'not_planned', title: 'Sweep', url: 'https://x/15173' }],
closed_issue: { number: 15173, state: 'closed', state_reason: 'not_planned', title: 'Sweep', url: 'https://x/15173' } }, stages, ctx);
assert.strictEqual(lead(row), '#15173 Sweep closed issue closed (not planned)', lead(row));
assert.ok(row.includes('<span class="ham-badge ham-issue-closed-chip">closed</span> <span class="ham-badge ham-issue-closed-chip ham-closed-not-planned"'), row);
// A closer equal to the row's own PR is not a duplicate: plain chip.
assert.strictEqual(stageTrackerClosedChipHtml({ repo: 'acme/console', number: 500 }, { number: 496, closed_by: 500, title: 'T' }), '<span class="ham-badge ham-issue-closed-chip">closed</span>');
assert.strictEqual(lead(row), '#15173 Sweep closed · this PR unmerged issue closed (not planned)', lead(row));
assert.ok(/<span class="ham-badge ham-issue-closed-chip" title="[^"]*">closed · this PR unmerged<\/span> <span class="ham-badge ham-issue-closed-chip ham-closed-not-planned"/.test(row), row);
// A closer equal to the row's own PR is not a duplicate: the unmerged chip.
assert.ok(/^<span class="ham-badge ham-issue-closed-chip" title="Issue #496 is closed, but this PR is still open and unmerged[^"]*">closed · this PR unmerged<\/span>$/.test(stageTrackerClosedChipHtml({ repo: 'acme/console', number: 500 }, { number: 496, closed_by: 500, title: 'T' })));
assert.deepStrictEqual(stageTrackerPRIssueSlot({ number: 500, linked_issues: [{ number: 496, state: 'closed', title: 'C', url: 'u', closed_by: 501 }] }), { number: 496, title: 'C', url: 'u', closed: true, placeholder: '', closed_by: 501 }, 'closed_by rides the slot');
assert.strictEqual(stageTrackerItemURL('acme/console', 501, 'pull', 'https://ghe.example/acme/console/pull/500'), 'https://ghe.example/acme/console/pull/501', 'closer URL follows the sibling host');
assert.strictEqual(stageTrackerItemURL('acme/console', 501, 'pull', ''), 'https://github.com/acme/console/pull/501');
Expand Down
20 changes: 13 additions & 7 deletions src/pkg/dashboard/static-src/js/tracker-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,26 @@
return { number: 0, text: 'no linked issue' };
}
// Pure: the chip(s) beside a closed issue in a PR row's issue slot.
// `closed` when nothing more is known; `closed by #N` linking to the
// merged PR that closed it (the server's merged ledger) when another PR
// delivered the issue — the open PR on this row is then a duplicate
// (hivecommons/hive#15232). A not-planned close adds an "issue closed
// (not planned)" chip: the PR may be moot (hivecommons/hive#14655).
// `closed by #N` linking to the merged PR that closed it (GitHub's
// closedByPullRequestsReferences, else the server's merged ledger) when
// another PR delivered the issue — the open PR on this row is then a
// follow-up or a duplicate (hivecommons/hive#15232). When no merged
// closer is known the chip still says the issue closed while THIS PR is
// unmerged, so the row cannot read as the issue having been closed by
// an unmerged PR: the hive only ever closes an issue after its PR has
// merged. A not-planned close adds an "issue closed (not planned)"
// chip: the PR may be moot (hivecommons/hive#14655).
function stageTrackerClosedChipHtml(item, slot) {
// Inline (not a module const): the UI test lifts this function alone.
const unmergedTip = 'Issue #' + slot.number + ' is closed, but this PR is still open and unmerged: it did not close the issue. A person or another merged PR did (the hive closes an issue only after its PR merges); this hive could not name the closer.';
const notPlanned = String(slot.state_reason || '') === 'not_planned';
const by = Number(slot.closed_by) || 0;
let chip;
if (by > 0 && by !== Number(item.number)) {
const url = stageTrackerItemURL(item.repo, by, 'pull', item.url);
chip = `<a class="ham-badge ham-issue-closed-chip ham-closed-by-chip" href="${esc(url)}" target="_blank" rel="noopener" title="${esc('Issue #' + slot.number + ' was closed by the merge of #' + by + '; this PR is still open against it')}">closed by #${by}</a>`;
chip = `<a class="ham-badge ham-issue-closed-chip ham-closed-by-chip" href="${esc(url)}" target="_blank" rel="noopener" title="${esc('Issue #' + slot.number + ' was closed by the merge of #' + by + '; this PR is still open against it and merging it will not close anything')}">closed by #${by}</a>`;
} else {
chip = '<span class="ham-badge ham-issue-closed-chip">closed</span>';
chip = `<span class="ham-badge ham-issue-closed-chip" title="${esc(unmergedTip)}">closed · this PR unmerged</span>`;
}
return chip + (notPlanned ? ' <span class="ham-badge ham-issue-closed-chip ham-closed-not-planned" title="The issue this PR closes was closed as not planned; the PR may be moot.">issue closed (not planned)</span>' : '');
}
Expand Down
Loading
Loading