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/added-tracker-lineage-chip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The activity monitor's tracker now says where an adopted PR came from: the hive's copy wears a compact `adopted from @author's #N · 6h` chip beside its number, linked to the original, with a plain-words hover on why the hive took it over (CI red and the contributor's agent silent, a maintainer's request, a DCO / rebase re-home); a still-open original reads `superseded by #M`. The `lineage` field behind it is also what the *Let hive decide* preview and the row hover use to add *(adopted from #N)* after the PR number, so an issue covered by an adopted PR no longer looks like the hive took a contributor's PR for no reason.
2 changes: 1 addition & 1 deletion src/docs/api-reference/dashboard-misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f
| `GET` | `/api/budget-ignore` | Dashboard auth/session | Budget Ignore Get | `pkg/dashboard/api.go:172` |
| `POST` | `/api/budget-ignore` | Owner only | Budget Ignore Set | `pkg/dashboard/api.go:173` |
| `GET` | `/api/summaries` | Dashboard auth/session | Summaries | `pkg/dashboard/api.go:185` |
| `GET` | `/api/stage-tracker` | Dashboard auth/session | Stage Tracker: every open issue and pull request of the watched repos for the Hive activity monitor — actionable, held, claimed, in-progress, covered-by-PR, filtered (`needs-*`), draft and exempt-labelled items alike, each with `stage`, `stage_since`, `labels`, `created_at`, `author_kind`, `modifiers`, (PRs) `sentinel_alert` / `sentinel_findings` / `sentinel_reason` when the sentinel flagged the PR, `decision_needed` on a row parked on a person (085 / 045 / 015, the needs-human pill; mirrored onto the issue's `linked_prs[]` entry): `{question, asked_by, since, blocker, blocker_reason, options: [{action, label, enabled, reason_if_disabled}]}` — the reviewer's own decision question when the verdict record has one, the blocker in plain words, and the applicable actions under the row context menu's action ids (`decide:delegate` first), and (issues) `linked_prs`; items with no stage yet report stage `0` "Open"; `needs_human_labels` is the "a person must act" label set behind the monitor's Needs human facet (the same list as `/api/status.labelPresets[needs-human]`); `recently_merged` lists the PRs (`repo`, `number`, `merged_at`) whose `pr_merged` audit entry is under 30 minutes old, so a client diffing two payloads can tell a merge from a close. Served from a server-side cache rebuilt at most every `dashboard.stage_tracker.cache_ttl_s` (default `governor.eval_interval_s`) from the spoke's existing snapshot — a request never calls GitHub. Carries `generated_at`, `source` (`cache` or `fresh`), `cache_ttl_s`, an `ETag` and `Cache-Control: private, max-age=<remaining>`; `If-None-Match` yields 304. Each hit is recorded under REST caller `dashboard:stage-tracker` so `/api/gh-rate-limits` shows it charged nothing. | `pkg/dashboard/api.go:186` |
| `GET` | `/api/stage-tracker` | Dashboard auth/session | Stage Tracker: every open issue and pull request of the watched repos for the Hive activity monitor — actionable, held, claimed, in-progress, covered-by-PR, filtered (`needs-*`), draft and exempt-labelled items alike, each with `stage`, `stage_since`, `labels`, `created_at`, `author_kind`, `modifiers`, (PRs) `sentinel_alert` / `sentinel_findings` / `sentinel_reason` when the sentinel flagged the PR, `decision_needed` on a row parked on a person (085 / 045 / 015, the needs-human pill; mirrored onto the issue's `linked_prs[]` entry): `{question, asked_by, since, blocker, blocker_reason, options: [{action, label, enabled, reason_if_disabled}]}` — the reviewer's own decision question when the verdict record has one, the blocker in plain words, and the applicable actions under the row context menu's action ids (`decide:delegate` first), (PRs) `lineage` on the hive's copy of an adopted PR — `{kind: adopted|superseded|rebased-by-hive, from_number, from_url, from_author, from_author_kind, to_number, to_url, at, reason}`, derived from the stage store's adoption record or the `hive/adopt-<n>` head branch, mirrored onto the issue's `linked_prs[]` entry; absent on every other row — and (issues) `linked_prs`; items with no stage yet report stage `0` "Open"; `needs_human_labels` is the "a person must act" label set behind the monitor's Needs human facet (the same list as `/api/status.labelPresets[needs-human]`); `recently_merged` lists the PRs (`repo`, `number`, `merged_at`) whose `pr_merged` audit entry is under 30 minutes old, so a client diffing two payloads can tell a merge from a close. Served from a server-side cache rebuilt at most every `dashboard.stage_tracker.cache_ttl_s` (default `governor.eval_interval_s`) from the spoke's existing snapshot — a request never calls GitHub. Carries `generated_at`, `source` (`cache` or `fresh`), `cache_ttl_s`, an `ETag` and `Cache-Control: private, max-age=<remaining>`; `If-None-Match` yields 304. Each hit is recorded under REST caller `dashboard:stage-tracker` so `/api/gh-rate-limits` shows it charged nothing. | `pkg/dashboard/api.go:186` |
| `POST` | `/api/prs/{owner}/{repo}/{number}/queue-automerge` | Merger/owner role | Queue PRAuto Merge | `pkg/dashboard/api.go:187` |
| `GET` | `/api/inference/models/{backend}` | Dashboard auth/session | Inference Models | `pkg/dashboard/api.go:363` |
| `GET` | `/api/hive-id` | Dashboard auth/session | Hive IDGet | `pkg/dashboard/api.go:425` |
Expand Down
2 changes: 2 additions & 0 deletions src/docs/dashboard-sections.md
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,8 @@ The same renderer serves issue decisions and every PR verdict (adopt, approve, c

**Adoption pairs.** When the delegate adopts in supersede mode and hive opens its copy, the tracker shows the pair explicitly rather than two unrelated PR sub-rows: the original is dimmed — *Adopted → #15123 · superseded (hive re-authored with sign-off)* — with no action chevron and no needs-human styling; the new PR carries the single active chevron and a chip *↳ adopted from #15029 · you approved 17:51*; the issue row's pill follows the new PR. Once the original is closed it drops out of the open-PR projection, so it renders as one dimmed line from the adoption record — *#15029 <cached title> · closed · superseded by #15123* — with no chevron track; never a blank numbered row.

**Lineage chip (where an adopted PR came from).** Whenever a PR row is the hive's copy of a contributor PR it adopted — whether the operator decided it or the contributor lane adopted on its own after CI went red and the contributor's agent stayed silent — the PR number carries a compact chip, *adopted from @thatguywob's #15226 · 6h*, linked to the original; the original author's kind (human / clanker / hive) is drawn as the usual author icon, never as a word. Its hover says why in plain words: *Hive took this PR over after CI went red and @thatguywob's agent didn't respond. Original commits kept.* (other reasons: at a maintainer's request, DCO / sign-off / rebase / push re-home). Issue #15198 once showed its covering PR #15308 as *Fixing* with nothing saying #15308 was adopted, so routing the fix to a hive agent read as the hive taking a clanker's PR for no reason. The chip is drawn on a top-level PR row, on an issue row's single covering PR and on each sub-row; a still-open original (close-first off) wears the reverse, *superseded by #15308 · 6h*. Behind it is the optional `lineage` field of the payload — `{kind: adopted|superseded|rebased-by-hive, from_number, from_url, from_author, from_author_kind, to_number, to_url, at, reason}` — derived from the stage store's adoption record or the `hive/adopt-<n>` head branch, never a GitHub call; the SPA helper `stageTrackerLineageClause(item)` yields the one clause *(adopted from #15226)* any caption or preview adds after the PR number (the *Let hive decide* preview and the row hover's *Covering PR* line already do).

**A decision wins over a stale label.** Recording any decision (approve, direction, adopt, delegate-resolved) removes `needs-human` and the 045/085 *needs-decision* stage labels in the same write (`liftDelegatedParkLabels`; `pr_decision_operator.go`), and the projection never places a row in 085 while a decision exists for the current head — the row sits where hive actually is, and the popover leads with *You chose Let hive decide · hive decided: fix then merge*, not with the stale ask.

**One vocabulary.** Every operator-facing string — event lines, popovers, toasts, pills — uses the chevron's stage vocabulary through one shared mapping (`stage_tracker_vocabulary.go`; `STAGE_TRACKER_STAGE_PHRASE` in the page): *its PR is review passed · waiting for merge admission*, never *PR at 060 reviewed* or *moved to stage/085-needs-decision*. A guard test scans rendered event-line fixtures for raw stage codes and fails on any.
Expand Down
11 changes: 11 additions & 0 deletions src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dashboard

import (
Expand Down Expand Up @@ -460,6 +460,11 @@
// 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"`
// Lineage is, on the hive's copy of an adopted PR, where it came from
// (adopted from @x's #N, when, why) and, on a still-open original,
// which copy superseded it (stage_tracker_lineage.go). Optional; a
// row with no adoption history carries none.
Lineage *StageTrackerLineage `json:"lineage,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 @@ -620,6 +625,8 @@
AdoptedBy int `json:"adopted_by,omitempty"`
AdoptedByState string `json:"adopted_by_state,omitempty"`
AdoptedFrom *StageTrackerAdoptedFrom `json:"adopted_from,omitempty"`
// Lineage mirrors the nested PR's own row field.
Lineage *StageTrackerLineage `json:"lineage,omitempty"`
// State is "closed" for an adopted original the hive (or a person)
// closed once its copy existed (hivecommons/hive#15126): the sub-row
// is one dimmed line "#N <title> · closed · superseded by #M" with no
Expand Down Expand Up @@ -2082,6 +2089,7 @@
prState := s.stageTrackerPRStateResolver(status, resp.RecentlyMerged)
prOpen := func(repo string, number int) bool { return prState(repo, number) == blockedOnPRStateOpen }
supersedes := stageTrackerSupersedesIndex(store, status.GitHubBaseURL)
lineage := stageTrackerLineageIndex(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 @@ -2200,6 +2208,7 @@
if sup, ok := supersedes[stagelabels.Key(repoName, pr.Number)]; ok {
it.Supersedes = &sup
}
it.Lineage = stageTrackerLineageFor(lineage, repoName, pr.Number, pr.HeadRef, status.GitHubBaseURL)
info, found := superseded[github.ReviewQueueKey(qualifyRepo(repoName), pr.Number)]
if !found {
info, found = superseded[github.ReviewQueueKey(repoName, pr.Number)]
Expand Down Expand Up @@ -2258,6 +2267,7 @@
}
resp.OpenIssues, resp.OpenPRs = stageTrackerOpenCounts(resp.Items)
stageTrackerMergeTrainPostPass(resp.Items)
stageTrackerLineageFillAuthors(resp.Items)
s.applyOperatorActions(resp.Items, now)
s.applyDecidedProjection(resp.Items, now)
applyRebaseAttempts(resp.Items)
Expand Down Expand Up @@ -3005,6 +3015,7 @@
lp.Rework = pr.Rework
lp.Takeover = pr.Takeover
lp.Supersedes = pr.Supersedes
lp.Lineage = pr.Lineage
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
191 changes: 191 additions & 0 deletions src/pkg/dashboard/stage_tracker_lineage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
package dashboard

import (
"strconv"
"strings"
"time"

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

// Lineage on a tracker row (hivecommons/hive: issue #15198 showed PR
// #15308 "Fixing" with nothing saying #15308 was the hive's copy of
// @thatguywob's #15226, adopted after CI went red and the contributor's
// agent stayed silent — so routing the fix to a hive agent read as the
// hive taking over a clanker's PR for no reason). The superseding PR's
// row now carries `lineage`: where it came from, whose it was, when and
// why; the closed original (when it is still rendered, close_first off)
// carries the reverse. Everything is read from the stage store's adoption
// record (MarkAdopted / MarkSupersededClosedFirst — the same facts the
// "Supersedes #N" body line was written from) or, with no record, from the
// hive/adopt-<n> head branch. Nothing is fetched from GitHub.

// Lineage kinds.
const (
lineageAdopted = "adopted"
lineageSuperseded = "superseded"
lineageRebasedByHive = "rebased-by-hive"
)

// Lineage reason slugs the SPA words its hover from.
const (
lineageReasonCIRedOffline = "ci-red-contributor-offline"
lineageReasonCIRedUnregistered = "ci-red-contributor-unregistered"
lineageReasonOperatorAsked = "operator-asked"
)

// StageTrackerLineage is the optional `lineage` field of a PR row: on the
// hive's copy, kind adopted / rebased-by-hive with the original in
// from_*; on the original, kind superseded with the copy in to_*.
type StageTrackerLineage struct {
Kind string `json:"kind"`
// FromNumber / FromURL / FromAuthor / FromAuthorKind name the original
// PR on the hive's copy (author kind human / clanker / hive, "" when
// unknown).
FromNumber int `json:"from_number,omitempty"`
FromURL string `json:"from_url,omitempty"`
FromAuthor string `json:"from_author,omitempty"`
FromAuthorKind string `json:"from_author_kind,omitempty"`
// ToNumber / ToURL name the hive's copy on the original.
ToNumber int `json:"to_number,omitempty"`
ToURL string `json:"to_url,omitempty"`
// At is when the hive adopted; Reason a short slug
// (ci-red-contributor-offline, operator-asked, dco-rehome, …).
At *time.Time `json:"at,omitempty"`
Reason string `json:"reason,omitempty"`
}

// stageTrackerLineageReason folds the adoption record's AdoptReason into
// the lineage slug. An empty reason is the oldest path: CI red, nudged,
// contributor offline.
func stageTrackerLineageReason(adoptReason string) string {
switch adoptReason {
case "", automerge.AdoptReasonOffline, automerge.AdoptReasonGrace:
return lineageReasonCIRedOffline
case automerge.AdoptReasonUnregistered:
return lineageReasonCIRedUnregistered
case automerge.AdoptReasonOperator, automerge.AdoptReasonOperatorForced:
return lineageReasonOperatorAsked
}
return adoptReason
}

// stageTrackerLineageAuthorKind guesses the original author's kind when
// the original is not a row any more: an adoption after a relay went
// offline means a registered relay existed (clanker); an unregistered
// author has no agent here (human). "" when the reason says nothing.
func stageTrackerLineageAuthorKind(adoptReason string) string {
switch adoptReason {
case "", automerge.AdoptReasonOffline, automerge.AdoptReasonGrace:
return authorKindClanker
case automerge.AdoptReasonUnregistered:
return authorKindHuman
}
return ""
}

// stageTrackerLineageIndex maps store keys to lineage: the hive's copy
// (adopted / rebased-by-hive, from the original's AdoptedBy or
// SupersededBy) and the original (superseded). In-place adoptions name no
// second PR and get no lineage. When several originals name the same copy
// the lowest-numbered one wins.
func stageTrackerLineageIndex(store *stagelabels.Store, baseURL string) map[string]StageTrackerLineage {
out := map[string]StageTrackerLineage{}
if store == nil {
return out
}
for _, key := range store.Keys() {
rec, ok := store.Get(key)
if !ok {
continue
}
by := rec.SupersededBy
if by <= 0 {
if rec.AdoptMode == stagelabels.AdoptModeInPlace {
continue
}
by = rec.AdoptedBy
}
if by <= 0 {
continue
}
repo, numText, found := strings.Cut(key, "#")
number, err := strconv.Atoi(numText)
if !found || err != nil || number <= 0 || repo == "" {
continue
}
copyKey := stagelabels.Key(repo, by)
if prev, dup := out[copyKey]; dup && prev.FromNumber > 0 && prev.FromNumber <= number {
continue
}
kind := lineageAdopted
if rec.AdoptReason == automerge.AdoptReasonRebaseRehome {
kind = lineageRebasedByHive
}
var at *time.Time
for _, t := range []time.Time{rec.AdoptedAt, rec.SupersededAt} {
if !t.IsZero() {
tt := t
at = &tt
break
}
}
reason := stageTrackerLineageReason(rec.AdoptReason)
out[copyKey] = StageTrackerLineage{Kind: kind, FromNumber: number, FromURL: overviewItemURL("", repo, number, "pr", baseURL),
FromAuthor: rec.Author, FromAuthorKind: stageTrackerLineageAuthorKind(rec.AdoptReason), At: at, Reason: reason}
out[key] = StageTrackerLineage{Kind: lineageSuperseded, ToNumber: by, ToURL: overviewItemURL("", repo, by, "pr", baseURL), At: at, Reason: reason}
}
return out
}

// stageTrackerLineageFromHead reads the original's number off a
// hive/adopt-<n> head branch, for a copy whose store record is gone.
func stageTrackerLineageFromHead(repo, headRef, baseURL string) *StageTrackerLineage {
rest, ok := strings.CutPrefix(headRef, "hive/adopt-")
if !ok {
return nil
}
n, err := strconv.Atoi(rest)
if err != nil || n <= 0 {
return nil
}
return &StageTrackerLineage{Kind: lineageAdopted, FromNumber: n, FromURL: overviewItemURL("", repo, n, "pr", baseURL), Reason: lineageReasonCIRedOffline}
}

// stageTrackerLineageFor is the lineage of repo#number from the index,
// else from its head branch; nil when it has none.
func stageTrackerLineageFor(idx map[string]StageTrackerLineage, repo string, number int, headRef, baseURL string) *StageTrackerLineage {
if l, ok := idx[stagelabels.Key(repo, number)]; ok {
return &l
}
return stageTrackerLineageFromHead(repo, headRef, baseURL)
}

// stageTrackerLineageFillAuthors completes from_author / from_author_kind
// on each copy whose original is itself a row (close_first off): the
// row's own author fields beat the record's guess.
func stageTrackerLineageFillAuthors(items []StageTrackerItem) {
prs := map[string]*StageTrackerItem{}
for i := range items {
if items[i].Kind == "pr" {
prs[stagelabels.Key(items[i].Repo, items[i].Number)] = &items[i]
}
}
for i := range items {
l := items[i].Lineage
if l == nil || l.FromNumber <= 0 {
continue
}
orig := prs[stagelabels.Key(items[i].Repo, l.FromNumber)]
if orig == nil {
continue
}
if orig.Author != "" {
l.FromAuthor = orig.Author
}
if orig.AuthorKind != "" {
l.FromAuthorKind = orig.AuthorKind
}
}
}
Loading
Loading