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
1 change: 1 addition & 0 deletions changelog.d/fixed-tracker-closed-superseded-rows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Activity Monitor: a PR the hive closed when it opened its replacement (close-first supersession) no longer renders under its issue as a bare sub-row with an empty ladder; the live replacement PR carries a small "supersedes #N" chip (hover: when it was closed, link) as the only trace, and the issue's ladder follows the live PR alone.
4 changes: 3 additions & 1 deletion src/pkg/dashboard/delegated_pr_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func delegatedCompetingNumbers(items []StageTrackerItem, repo string, pr *gh.Pul
if !found {
items = append(items, live)
}
stageTrackerResolveLinkedPRs(items)
// The items are a tracker response already filtered to open PRs; a
// link the response kept is kept here too.
stageTrackerResolveLinkedPRs(items, func(string, int) bool { return true })
seen := map[int]bool{}
for _, issue := range items {
if issue.Repo != repo || issue.Kind != "issue" {
Expand Down
7 changes: 6 additions & 1 deletion src/pkg/dashboard/delegated_pr_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ func TestGatherDelegatedRealPRContext(t *testing.T) {
s := newFullServer(t)
s.deps.GHClient = github.NewClient("token", "org", nil, slog.Default(), server.URL)
s.deps.GHClient.SetAppBotLogin("hive[bot]")
s.status = &StatusPayload{Repos: []FrontendRepo{{Full: "org/repo", ActionableIssues: []any{github.Issue{Number: 7, LinkedPRs: []github.IssueLinkedPR{{Number: 8, State: "open"}, {Number: 9, State: "open"}}}}}}}
// Both PRs are open items of the snapshot: a linked PR the
// snapshot does not list is not drawn or counted (closed-first
// supersession left closed originals as bare sub-rows).
s.status = &StatusPayload{Repos: []FrontendRepo{{Full: "org/repo",
ActionableIssues: []any{github.Issue{Number: 7, LinkedPRs: []github.IssueLinkedPR{{Number: 8, State: "open"}, {Number: 9, State: "open"}}}},
OpenPrs: []any{FrontendPR{PullRequest: github.PullRequest{Number: 8, Author: "hive[bot]"}}, FrontendPR{PullRequest: github.PullRequest{Number: 9, Author: "alice"}}}}}}
in, err := s.gatherDelegatedInput(context.Background(), "org/repo", 8, "pr", delegatedDecisionRequest{})
if err != nil {
t.Fatal(err)
Expand Down
47 changes: 43 additions & 4 deletions src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ type StageTrackerItem struct {
// "copy-failed" β€” a close-first copy failed and the original was
// reopened for a person (hivecommons/hive#15135).
AdoptedByState string `json:"adopted_by_state,omitempty"`
// Supersedes names the closed original this PR replaced (the hive's
// close-first supersession, hivecommons/hive#15135). The original is
// closed, unmerged, and never a tracker row; this is the only trace of
// it the tracker draws β€” a small chip on the live PR.
Supersedes *StageTrackerSupersedes `json:"supersedes,omitempty"`
// Adoption is, on a nudged PR at stage/072, whether adoption is due,
// what holds it, and the author's live presence, with the plain-words
// line the row shows instead of a bare "Returned to contributor"
Expand Down Expand Up @@ -597,6 +602,19 @@ type StageTrackerLinkedPR struct {
Presence *StageTrackerPresence `json:"presence,omitempty"`
// Takeover mirrors the nested PR's own row field (hivecommons/hive#15038).
Takeover *StageTrackerTakeover `json:"takeover,omitempty"`
// Supersedes mirrors the nested PR's own row field.
Supersedes *StageTrackerSupersedes `json:"supersedes,omitempty"`
}

// StageTrackerSupersedes is the closed original a live PR replaced
// (StageTrackerItem.Supersedes). ClosedAt is when the hive recorded the
// supersession; Open is true when the original could not be closed (a
// fork PR the App may not close) and was left open with the note.
type StageTrackerSupersedes struct {
Number int `json:"number"`
URL string `json:"url,omitempty"`
ClosedAt *time.Time `json:"closed_at,omitempty"`
Open bool `json:"open,omitempty"`
}

// StageTrackerHold is the row's hold provenance (stagelabels.HoldProvenance
Expand Down Expand Up @@ -1953,6 +1971,8 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
resp.Items = append(resp.Items, it)
}
prState := s.stageTrackerPRStateResolver(status, resp.RecentlyMerged)
prOpen := func(repo string, number int) bool { return prState(repo, number) == blockedOnPRStateOpen }
supersedes := stageTrackerSupersedesIndex(store, status.GitHubBaseURL)
issueFilter := s.issueFilterConfig()
addIssue := func(repoName string, issue github.Issue, bucket, bucketReason string, progress *github.IssueChildren) {
// A closed issue has no stage; a stage label it closed wearing is
Expand Down Expand Up @@ -2009,7 +2029,11 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
it.ClaimantKind = s.stageTrackerClaimantKind(repoName, issue.Number)
}
for _, lp := range issue.LinkedPRs {
if lp.Number > 0 && !lp.Merged && !strings.EqualFold(lp.State, "closed") {
// The claims index may still say "open" for a PR the hive closed
// since (close-first supersession, hivecommons/hive#15135); the
// snapshot and caches are asked before a closed PR becomes a
// sub-row.
if lp.Number > 0 && !lp.Merged && !strings.EqualFold(lp.State, "closed") && !stageTrackerLinkedPRFinished(prState(nonEmpty(lp.Repo, repoName), lp.Number)) {
it.LinkedPRs = append(it.LinkedPRs, StageTrackerLinkedPR{Number: lp.Number, URL: lp.URL})
}
}
Expand Down Expand Up @@ -2054,6 +2078,9 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
it.DeferredModifiers = append([]string{modSentinel}, it.DeferredModifiers...)
}
it.LinkedIssues = stageTrackerPRLinkedIssues(pr, repoName, status.GitHubBaseURL)
if sup, ok := supersedes[stagelabels.Key(repoName, pr.Number)]; ok {
it.Supersedes = &sup
}
info, found := superseded[github.ReviewQueueKey(qualifyRepo(repoName), pr.Number)]
if !found {
info, found = superseded[github.ReviewQueueKey(repoName, pr.Number)]
Expand Down Expand Up @@ -2114,7 +2141,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
stageTrackerMergeTrainPostPass(resp.Items)
s.applyOperatorActions(resp.Items, now)
resp.NeedsHuman, resp.OnHold = stageTrackerHumanCounts(resp.Items)
stageTrackerResolveLinkedPRs(resp.Items)
stageTrackerResolveLinkedPRs(resp.Items, prOpen)
stageTrackerMarkClosedBy(resp.Items, s.mergedLedger().ClosedBy)
stageTrackerResolveActors(resp.Items)
sort.SliceStable(resp.Items, stageTrackerLess(resp.Items))
Expand Down Expand Up @@ -2789,7 +2816,14 @@ func stageTrackerPruneSoftLinks(pr *StageTrackerItem, prs, issues map[string]*St
// side is read too: a PR whose closing references name an open issue in
// the response is nested under that issue even when the issue's own claim
// evidence has not caught up with it, so the pair draws as one row.
func stageTrackerResolveLinkedPRs(items []StageTrackerItem) {
//
// A linked PR with no PR row in the response is not an open PR of this
// snapshot β€” closed (the hive's close-first supersession, hivecommons/
// hive#15135, or the claims index lagging a close) or finished β€” and is
// dropped rather than drawn as a bare sub-row with an empty ladder. open,
// when non-nil, may vouch for one the snapshot lacks (a cross-repository
// PR another repo's open set lists); it is then kept as the bare link.
func stageTrackerResolveLinkedPRs(items []StageTrackerItem, open func(repo string, number int) bool) {
prs := map[string]*StageTrackerItem{}
issues := map[string]*StageTrackerItem{}
for i := range items {
Expand Down Expand Up @@ -2836,13 +2870,18 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem) {
return
}
seen[lp.Number] = true
if pr := prs[it.Repo+"#"+strconv.Itoa(lp.Number)]; pr != nil {
pr := prs[it.Repo+"#"+strconv.Itoa(lp.Number)]
if pr == nil && (open == nil || !open(it.Repo, lp.Number)) {
return
}
if pr != nil {
lp.Title, lp.Author, lp.AuthorKind, lp.Stage = pr.Title, pr.Author, pr.AuthorKind, pr.Stage
lp.StageSince, lp.Caption = pr.StageSince, pr.Caption
lp.SentinelAlert, lp.SentinelReason, lp.Head = pr.SentinelAlert, pr.SentinelReason, pr.Head
lp.Adoption = pr.Adoption
lp.Presence = pr.Presence
lp.Takeover = pr.Takeover
lp.Supersedes = pr.Supersedes
lp.HumanApprover, lp.ManualMerge = pr.HumanApprover, pr.ManualMerge
lp.HumanMergeReason, lp.HumanMergeReasonText = pr.HumanMergeReason, pr.HumanMergeReasonText
lp.AdmittedBy, lp.DCOUnsigned, lp.DCOTotal = pr.AdmittedBy, pr.DCOUnsigned, pr.DCOTotal
Expand Down
43 changes: 43 additions & 0 deletions src/pkg/dashboard/stage_tracker_adoption.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package dashboard

import (
"context"
"fmt"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -214,3 +215,45 @@
}
return head + " β€” " + a.Text
}

// stageTrackerSupersedesIndex maps each superseding PR's store key to the
// closed original it replaced (hivecommons/hive#15135). The original's
// record carries SupersededBy; the tracker never renders that record as a
// row (addPR drops it, and a closed PR has no open item), so the live
// PR's chip is the one trace the tracker keeps. When several originals
// name the same superseder the lowest-numbered one is kept.
func stageTrackerSupersedesIndex(store *stagelabels.Store, baseURL string) map[string]StageTrackerSupersedes {
out := map[string]StageTrackerSupersedes{}
if store == nil {
return out
}
for _, key := range store.Keys() {
rec, ok := store.Get(key)
if !ok || !rec.Superseded() {
continue
}
repo, numText, found := strings.Cut(key, "#")
number, err := strconv.Atoi(numText)
if !found || err != nil || number <= 0 || repo == "" {
continue
}
by := stagelabels.Key(repo, rec.SupersededBy)
if prev, dup := out[by]; dup && prev.Number <= number {
continue
}
sup := StageTrackerSupersedes{Number: number, URL: overviewItemURL("", repo, number, "pr", baseURL), Open: rec.SupersededOpen}
if !rec.SupersededAt.IsZero() {
t := rec.SupersededAt
sup.ClosedAt = &t
}
out[by] = sup
}
return out
}

// stageTrackerLinkedPRFinished reports whether a PR state the caches
// resolved (stageTrackerPRStateResolver) means the PR is no longer open
// work: closed unmerged or merged. Unknown ("") is not finished.
func stageTrackerLinkedPRFinished(state string) bool {
return state == blockedOnPRStateClosed || state == blockedOnPRStateMerged
}
158 changes: 158 additions & 0 deletions src/pkg/dashboard/stage_tracker_adoption_close_first_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"testing"
"time"

"github.com/hivecommons/hive/pkg/config"
"github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/stagelabels"
)

Expand Down Expand Up @@ -60,3 +62,159 @@ func TestStageTrackerCloseFirstCopyFailedSaysWhy(t *testing.T) {
t.Fatalf("after re-adopt adopted_by=%d state=%q", it.AdoptedBy, it.AdoptedByState)
}
}

// A closed original (#15184, closed first when its copy #15247 opened)
// must not ride under its issue as a bare sub-row with an empty ladder:
// the claims index still names it "open" for a while, and the status
// enumeration's bucket reason still names it. The live copy keeps the
// trace as `supersedes` metadata only (hivecommons/hive#15135 follow-up).
func TestStageTrackerClosedSupersededPRNotASubRow(t *testing.T) {
now := time.Date(2026, 10, 29, 2, 30, 0, 0, time.UTC)
s := newTestServer()
store := stagelabels.NewStore("", func() time.Time { return now })
s.stageStore = store
s.deps = &Dependencies{Config: &config.Config{}}
orig := stagelabels.Key("hivecommons/hive", 15184)
store.Observe(orig, stagelabels.AdoptedByHive, "contributor-lane:adopted")
store.MarkAdopted(orig, "bc3a6ea", 15247, now.Add(-30*time.Minute))
store.MarkSupersededClosedFirst(orig, 15247, false, now.Add(-16*time.Minute))
store.Observe(stagelabels.Key("hivecommons/hive", 15247), stagelabels.Fixing, "reviewer-verdict:changes_requested")

status := minimalPayload()
status.HiveID = "hive"
status.Repos = []FrontendRepo{{
Name: "hive", Full: "hivecommons/hive",
ActionableIssues: []any{github.Issue{Number: 15183, Title: "api-reference.md decision row is stale", Author: "pat", Labels: []string{"stage/040-covered-by-pr"},
// The claims index lags the close: it still reports #15184 open.
LinkedPRs: []github.IssueLinkedPR{{Number: 15184, State: "open", URL: "https://github.com/hivecommons/hive/pull/15184", Closing: true}}}},
// Only the copy is an open PR of the snapshot; the closed original is not.
OpenPrs: []any{FrontendPR{PullRequest: github.PullRequest{Number: 15247, Title: "πŸ“– docs: refresh operator decision API reference", Author: "hivecommons-hive[bot]", AppAuthored: true, HeadSHA: "8464bac", Labels: []string{"stage/070-fixing"},
LinkedIssues: []github.PRLinkedIssue{{Number: 15183, State: "open"}}}}},
}}
s.UpdateStatus(status)

resp := s.buildStageTracker(status, store, now)
for _, it := range resp.Items {
if it.Kind == "pr" && it.Number == 15184 {
t.Fatalf("closed original rendered as a row: %+v", it)
}
}
issue := trackerItem(t, resp, "issue", 15183)
if len(issue.LinkedPRs) != 1 || issue.LinkedPRs[0].Number != 15247 {
t.Fatalf("issue 15183 linked_prs = %+v (want only the live copy #15247)", issue.LinkedPRs)
}
lp := issue.LinkedPRs[0]
if lp.Stage != 70 || lp.Title == "" {
t.Fatalf("live sub-row not resolved from its PR row: %+v", lp)
}
if lp.Supersedes == nil || lp.Supersedes.Number != 15184 || lp.Supersedes.URL != "https://github.com/hivecommons/hive/pull/15184" || lp.Supersedes.Open || lp.Supersedes.ClosedAt == nil || !lp.Supersedes.ClosedAt.Equal(now.Add(-16*time.Minute)) {
t.Fatalf("sub-row supersedes = %+v", lp.Supersedes)
}
pr := trackerItem(t, resp, "pr", 15247)
if pr.Supersedes == nil || pr.Supersedes.Number != 15184 || pr.NestedUnder != 15183 {
t.Fatalf("pr 15247 supersedes=%+v nested_under=%d", pr.Supersedes, pr.NestedUnder)
}
raw, err := json.Marshal(resp)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(raw), `"supersedes":{"number":15184,"url":"https://github.com/hivecommons/hive/pull/15184","closed_at":`) {
t.Fatalf("payload lacks the supersedes chip metadata: %s", raw)
}
if strings.Contains(string(raw), `{"number":15184,"url":"https://github.com/hivecommons/hive/pull/15184"}`) {
t.Fatalf("payload still carries the closed original as a bare linked PR: %s", raw)
}
}

// The resolver drops a linked PR that has no PR row in the response (not
// open in the snapshot) unless the caller vouches for it as open elsewhere
// (a cross-repository PR listed by another repo's open set).
func TestStageTrackerResolveLinkedPRsDropsUnlistedPRs(t *testing.T) {
items := func() []StageTrackerItem {
return []StageTrackerItem{
{Repo: "acme/console", Number: 9, Kind: "issue", LinkedPR: 77, LinkedPRs: []StageTrackerLinkedPR{{Number: 10}, {Number: 11, URL: "u11"}}},
{Repo: "acme/console", Number: 10, Kind: "pr", Title: "Live PR", Stage: 70, Supersedes: &StageTrackerSupersedes{Number: 11}},
}
}
got := items()
stageTrackerResolveLinkedPRs(got, nil)
if len(got[0].LinkedPRs) != 1 || got[0].LinkedPRs[0].Number != 10 || got[0].LinkedPRs[0].Supersedes == nil || got[0].LinkedPRs[0].Supersedes.Number != 11 {
t.Fatalf("unlisted links kept: %+v", got[0].LinkedPRs)
}
got = items()
stageTrackerResolveLinkedPRs(got, func(repo string, number int) bool { return number == 11 })
if len(got[0].LinkedPRs) != 2 || got[0].LinkedPRs[1].Number != 11 || got[0].LinkedPRs[1].URL != "u11" || got[0].LinkedPRs[1].Title != "" {
t.Fatalf("vouched-for bare link not kept as is: %+v", got[0].LinkedPRs)
}
}

func TestStageTrackerSupersedesIndex(t *testing.T) {
now := time.Date(2026, 10, 29, 2, 0, 0, 0, time.UTC)
store := stagelabels.NewStore("", func() time.Time { return now })
for _, n := range []int{15184, 15170} {
key := stagelabels.Key("hivecommons/hive", n)
store.Observe(key, stagelabels.AdoptedByHive, "contributor-lane:adopted")
store.MarkAdopted(key, "bc3a6ea", 15247, now)
store.MarkSupersededClosedFirst(key, 15247, n == 15170, now)
}
// A plain adoption whose copy has not merged is not a supersession yet.
plain := stagelabels.Key("hivecommons/hive", 15300)
store.Observe(plain, stagelabels.AdoptedByHive, "contributor-lane:adopted")
store.MarkAdopted(plain, "bc3a6ea", 15301, now)

idx := stageTrackerSupersedesIndex(store, "")
if len(idx) != 1 {
t.Fatalf("index = %+v", idx)
}
sup, ok := idx[stagelabels.Key("hivecommons/hive", 15247)]
if !ok || sup.Number != 15170 || !sup.Open || sup.URL != "https://github.com/hivecommons/hive/pull/15170" || sup.ClosedAt == nil || !sup.ClosedAt.Equal(now) {
t.Fatalf("supersedes = %+v", sup)
}
if got := stageTrackerSupersedesIndex(nil, ""); len(got) != 0 {
t.Fatalf("nil store = %+v", got)
}
if stageTrackerLinkedPRFinished("") || stageTrackerLinkedPRFinished(blockedOnPRStateOpen) || !stageTrackerLinkedPRFinished(blockedOnPRStateClosed) || !stageTrackerLinkedPRFinished(blockedOnPRStateMerged) {
t.Fatal("stageTrackerLinkedPRFinished")
}
}

// The SPA draws the trace as one muted chip on the live PR's row (and its
// sub-row), linking to the closed original; nothing without `supersedes`.
func TestStageTrackerSupersedesChipJS(t *testing.T) {
html := indexHTML(t)
for _, want := range []string{
".ham-badge-supersedes {",
"supersedes: lp.supersedes || null",
"stageTrackerSupersedesChipHtml(item, Date.now())",
} {
if !strings.Contains(html, want) {
t.Errorf("index.html lacks %q", want)
}
}
script := strings.Join([]string{
"const assert = require('assert');",
jsFunc(t, html, "esc"),
jsFunc(t, html, "stageTrackerAgoText"),
jsFunc(t, html, "stageTrackerSupersedesTip"),
jsFunc(t, html, "stageTrackerSupersedesChipHtml"),
jsFunc(t, html, "stageTrackerLinkedPRItem"),
jsFunc(t, html, "stageTrackerLinkedPROpen"),
"const STAGE_TRACKER_TERMINAL = 100;",
`
const nowMs = Date.parse('2026-10-29T02:30:00Z');
const live = { kind: 'pr', repo: 'hivecommons/hive', number: 15247, stage: 70, supersedes: { number: 15184, url: 'https://github.com/hivecommons/hive/pull/15184', closed_at: '2026-10-29T02:14:00Z' } };
const chip = stageTrackerSupersedesChipHtml(live, nowMs);
assert.ok(chip.includes('>supersedes #15184<'), chip);
assert.ok(chip.includes('href="https://github.com/hivecommons/hive/pull/15184"'), chip);
assert.ok(chip.includes('closed 16m ago'), chip);
assert.ok(chip.includes('ham-badge-supersedes'), chip);
assert.strictEqual(stageTrackerSupersedesChipHtml({ kind: 'pr', number: 1 }, nowMs), '');
assert.ok(stageTrackerSupersedesTip({ supersedes: { number: 7, open: true } }, nowMs).includes('left open'));
const issue = { kind: 'issue', repo: 'hivecommons/hive', number: 15183, linked_prs: [Object.assign({ title: 'docs' }, live)] };
const sub = stageTrackerLinkedPRItem(issue, issue.linked_prs[0]);
assert.strictEqual(sub.supersedes.number, 15184);
assert.strictEqual(stageTrackerLinkedPRItem(issue, { number: 2 }).supersedes, null);
`,
}, "\n")
runStageTrackerRowActionsScript(t, script)
}
2 changes: 1 addition & 1 deletion src/pkg/dashboard/stage_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func TestStageTrackerIssueFeedPRsAreNotIssues(t *testing.T) {
{Repo: "acme/console", Number: 9, Kind: "issue", LinkedPR: 9, LinkedPRs: []StageTrackerLinkedPR{{Number: 9}, {Number: 10}}},
{Repo: "acme/console", Number: 10, Kind: "pr", Title: "Real PR"},
}
stageTrackerResolveLinkedPRs(items)
stageTrackerResolveLinkedPRs(items, nil)
if len(items[0].LinkedPRs) != 1 || items[0].LinkedPRs[0].Number != 10 || items[0].LinkedPRs[0].Title != "Real PR" {
t.Fatalf("self-link not dropped: %+v", items[0].LinkedPRs)
}
Expand Down
Loading
Loading