From 93e09ded0809df9bdb384bd1e421046392bd33e2 Mon Sep 17 00:00:00 2001 From: mendezr Date: Fri, 30 Oct 2026 18:59:19 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8=20feature:=20show=20abandoned=20c?= =?UTF-8?q?ontributor=20PR=20counts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Expose historical totals and lowercase per-login counts in contributorPool, render recent adoption details on contributor cards, and document counting semantics. Reuse the minimal profile schema from pending #15802; adoption recording remains owned by that PR. Hive-Run: hivecommons/hive#15795 Hive-Plan: contributor-abandoned-status Hive-Spec: hivecommons/hive#15795#acceptance Signed-off-by: mendezr --- .../added-contributor-abandoned-status.md | 1 + dashboard/openapi.json | 24 ++++++ .../api-reference/health-status-events.md | 16 ++++ src/docs/operator-reference.md | 23 ++++++ src/pkg/dashboard/api_contribute.go | 32 ++++++-- .../contributor_abandoned_badge_test.go | 44 +++++++++++ .../contributor_pool_abandoned_test.go | 73 +++++++++++++++++++ .../dashboard/static-src/js/contributors.js | 12 ++- src/pkg/dashboard/static/index.html | 12 ++- 9 files changed, 230 insertions(+), 7 deletions(-) create mode 100644 changelog.d/added-contributor-abandoned-status.md create mode 100644 src/pkg/dashboard/contributor_abandoned_badge_test.go create mode 100644 src/pkg/dashboard/contributor_pool_abandoned_test.go diff --git a/changelog.d/added-contributor-abandoned-status.md b/changelog.d/added-contributor-abandoned-status.md new file mode 100644 index 0000000000..c330a64a88 --- /dev/null +++ b/changelog.d/added-contributor-abandoned-status.md @@ -0,0 +1 @@ +- Show abandoned PR counts and recent-adoption tooltips on Contributors cards, and expose historical totals and per-login counts in `/api/status.contributorPool`. diff --git a/dashboard/openapi.json b/dashboard/openapi.json index c7a0757390..6e45967174 100644 --- a/dashboard/openapi.json +++ b/dashboard/openapi.json @@ -1323,6 +1323,30 @@ "hiveId": { "type": "string" }, + "contributorPool": { + "type": "object", + "description": "Registered contributor pool; historical counts include offline and revoked profiles.", + "properties": { + "active": { "type": "integer" }, + "online": { "type": "integer" }, + "registered": { "type": "integer" }, + "presence_window": { "type": "string" }, + "by_role": { + "type": "object", + "additionalProperties": { "type": "integer" } + }, + "abandoned": { + "type": "integer", + "description": "Sum of persisted per-profile abandoned PR counters, deduped per PR by the adoption recorder." + }, + "abandoned_by_login": { + "type": "object", + "description": "Abandoned counts keyed by lowercase GitHub login, including zero counts; empty object for an empty registry.", + "additionalProperties": { "type": "integer" } + } + }, + "required": ["active", "online", "registered", "presence_window", "abandoned", "abandoned_by_login"] + }, "governor": { "type": "object", "description": "dashboard.FrontendGovernor (src/pkg/dashboard/server.go), built by buildGovernor (status_builder.go).", diff --git a/src/docs/api-reference/health-status-events.md b/src/docs/api-reference/health-status-events.md index 81330e9160..a3bc5e453f 100644 --- a/src/docs/api-reference/health-status-events.md +++ b/src/docs/api-reference/health-status-events.md @@ -1,5 +1,21 @@ # Dashboard REST API reference — Health, status, events +## Contributor pool counters + +`GET /api/status` includes `contributorPool.abandoned`, the sum of persisted +abandoned-PR counters across all registered profiles, and +`contributorPool.abandoned_by_login`, an object keyed by lowercase GitHub login. +Offline and revoked contributors remain included; zero-count logins are present. +An empty registry returns `abandoned: 0` and `abandoned_by_login: {}`. These are +historical adoption counts, not failed tasks or disconnected task runs. +`GET /api/contributors` provides each profile's `abandoned` and `abandoned_prs` +records (`repo`, `pr`, `adopted_into_pr`, `reason`, `at`). The Contributors tile +shows a nonzero count with the five most recent records in its tooltip. +See [Abandoned contributor PRs](../operator-reference.md#abandoned-contributor-prs) +for counting semantics. + +## Endpoints + Part of the [Dashboard REST API reference](../api-reference.md); see that page for how auth levels and `pkg/:` source citations are read and checked. Edit this file for routes in this area and run `src/scripts/check-api-reference-citations.sh --fix` to resync citations. diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index f915f32641..5b374d431b 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -18,6 +18,29 @@ read or mutate live `/data` state and have killed agent sessions. Human operators can debug inside the pod by setting `HIVE_ALLOW_LOCAL_GO_TEST=1`; all other Go subcommands pass through unchanged. +## Abandoned contributor PRs + +An abandoned PR is a contributor PR the hive adopts to finish, either **in +place** on the contributor's branch or by **supersession** into a hive PR. +Operator **Adopt now** / `adoption/supersede` takeovers count with reason +`operator_takeover`; automatic adoptions carry `offline` or `unresponsive`. +A relay disconnect or failed task alone is not a PR adoption. + +The adoption recorder deduplicates by repository and original PR: adopting the +same PR again does not increment the count. If an in-place adoption is later +superseded, its existing record gains `adopted_into_pr` rather than counting +again. A zero `adopted_into_pr` means adoption in place. Records also carry the +original `repo`, `pr`, `reason`, and timestamp `at`. + +The dashboard **Contributors** tile shows **Abandoned N** in muted red only for +nonzero counts. Hover for the five most recent adopted PRs, newest first, with +the superseding PR (or “in-place”), reason, and timestamp. +`/api/status.contributorPool` exposes the historical `abandoned` total and +`abandoned_by_login` counts (lowercase login keys), including offline and +revoked profiles. `/api/contributors` exposes the underlying per-profile +`abandoned` and `abandoned_prs` data. These counters are independent of +Completed/Failed task counts and do not change contributor trust tiers. + ## Minimum required configuration Most of `hive.yaml.example` is optional. The smallest config the hive will start diff --git a/src/pkg/dashboard/api_contribute.go b/src/pkg/dashboard/api_contribute.go index 21b6db2e17..454b2bd011 100644 --- a/src/pkg/dashboard/api_contribute.go +++ b/src/pkg/dashboard/api_contribute.go @@ -97,6 +97,10 @@ type ContributorPoolStatus struct { // PresenceWindow is the window Online was judged against ("15m"). PresenceWindow string `json:"presence_window"` ByRole map[string]int `json:"by_role,omitempty"` + // Abandoned totals adopted PRs across all registered profiles, including + // offline and revoked contributors. Login keys are canonical lowercase. + Abandoned int `json:"abandoned"` + AbandonedByLogin map[string]int `json:"abandoned_by_login"` } func (s *Server) BuildContributorPoolStatus() *ContributorPoolStatus { @@ -110,15 +114,33 @@ func (s *Server) BuildContributorPoolStatus() *ContributorPoolStatus { window = s.contributeHub.presenceWindow() online = countOnlineContributors(profiles, s.contributeHub.LastHeartbeats(), window, time.Now()) } + abandoned, abandonedByLogin := contributorAbandonedCounts(profiles) return &ContributorPoolStatus{ - Active: active, - Online: online, - Registered: len(profiles), - PresenceWindow: stageTrackerShortDuration(window), - ByRole: byRole, + Abandoned: abandoned, + AbandonedByLogin: abandonedByLogin, + Active: active, + Online: online, + Registered: len(profiles), + PresenceWindow: stageTrackerShortDuration(window), + ByRole: byRole, } } +// contributorAbandonedCounts reads the persisted counters, not the size of +// the recent-PR tooltip. Presence and trust tier do not filter historical cost. +func contributorAbandonedCounts(profiles []ContributorProfile) (int, map[string]int) { + total := 0 + byLogin := make(map[string]int) + for _, p := range profiles { + total += p.Abandoned + login := strings.ToLower(strings.TrimSpace(p.GitHubUsername)) + if login != "" { + byLogin[login] += p.Abandoned + } + } + return total, byLogin +} + // countOnlineContributors counts the registered profiles whose freshest // relay heartbeat is within window of now — the tracker's presence // predicate (liveConnectionsFor) applied across the registry, so the diff --git a/src/pkg/dashboard/contributor_abandoned_badge_test.go b/src/pkg/dashboard/contributor_abandoned_badge_test.go new file mode 100644 index 0000000000..d45ffec2be --- /dev/null +++ b/src/pkg/dashboard/contributor_abandoned_badge_test.go @@ -0,0 +1,44 @@ +package dashboard + +import ( + "os/exec" + "strings" + "testing" +) + +func TestContributorAbandonedBadge(t *testing.T) { + html := indexHTML(t) + render := jsFunctionBody(t, html, "function renderContributors(contributors)") + if !strings.Contains(render, "${contributorAbandonedBadge(c)}") { + t.Fatal("contributor cards do not render the abandoned badge") + } + node, err := exec.LookPath("node") + if err != nil { + t.Skip("node not on PATH — abandoned badge rendering was NOT executed") + } + js := jsFunctionBody(t, html, "function esc(s)") + "\n" + jsFunctionBody(t, html, "function contributorAbandonedBadge(c)") + ` +function assert(ok, message) { if (!ok) throw new Error(message); } +for (const c of [{}, {abandoned: 0}, {abandoned: -1}]) { + assert(contributorAbandonedBadge(c) === '', 'zero/legacy counters should be hidden'); +} +const records = Array.from({length: 7}, (_, i) => ({repo: 'org/repo', pr: i + 1, + adopted_into_pr: i === 6 ? 90 : 0, reason: 'offline', at: '2026-10-0' + (i + 1) + 'T12:00:00Z'})); +records[6].reason = 'operator_takeover'; +const before = JSON.stringify(records); +const badge = contributorAbandonedBadge({abandoned: 7, abandoned_prs: records}); +assert(badge.includes('Abandoned 7'), badge); +assert(badge.includes('color-mix(in srgb, var(--red) 70%, var(--muted))'), 'muted red missing'); +assert(badge.includes('org/repo#7 → #90 · operator_takeover · 2026-10-07T12:00:00Z'), badge); +assert(badge.includes('org/repo#6 → in-place · offline'), badge); +assert(badge.indexOf('org/repo#7') < badge.indexOf('org/repo#6'), 'not newest first'); +assert(!badge.includes('org/repo#2') && badge.includes('org/repo#3'), 'tooltip must cap at five recent PRs'); +assert(JSON.stringify(records) === before, 'render mutated source records'); +const unsafe = contributorAbandonedBadge({abandoned: 1, abandoned_prs: [{repo: '\"', pr: 2, + reason: '\" onmouseover=\"evil', at: '