From 0c7f5b688cb831071135578f0a7c4165f3ebfd29 Mon Sep 17 00:00:00 2001 From: Danathar <6772335+Danathar@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:59:55 -0500 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20Governor=20PRs=20by=20model:=20?= =?UTF-8?q?what=20each=20model's=20PRs=20cost=20the=20hive=20to=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each /api/governor/pr-models bucket gains hive_cost (usd, launches, prs_with_cost, usd_per_merged_pr), summed from the PR refs' share_usd in the cached launch-cost snapshot, plus a top-level hive_cost_coverage with the snapshot window, unattributed / backend-unsupported spend and the estimate disclaimer. usd is null, not 0, when nothing was attributed; hive_cost is omitted while the snapshot is not ready. The join uses effectivePRRepo/effectivePRKey and also matches refs recorded with a short repo name. Only the cached snapshot is read. The Governor card shows the figure in each row's tooltip and a coverage note under the header. Refs #18717 Signed-off-by: Danathar <6772335+Danathar@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WcWm7qFmFJp26r9LPdmi3t --- .../added-18717-pr-models-hive-cost.md | 1 + .../governor-pr-models-hive-cost-ui.test.js | 89 +++++++ src/docs/api-reference/agents-and-controls.md | 2 +- src/docs/dashboard.md | 6 + src/docs/token-tracking.md | 2 +- src/pkg/dashboard/api_governor_pr_models.go | 29 ++- .../api_governor_pr_models_hive_cost.go | 222 ++++++++++++++++++ .../api_governor_pr_models_hive_cost_test.go | 190 +++++++++++++++ .../dashboard/static-src/js/governor-view.js | 29 ++- src/pkg/dashboard/static/index.html | 29 ++- 10 files changed, 588 insertions(+), 11 deletions(-) create mode 100644 changelog.d/added-18717-pr-models-hive-cost.md create mode 100644 dashboard/test/governor-pr-models-hive-cost-ui.test.js create mode 100644 src/pkg/dashboard/api_governor_pr_models_hive_cost.go create mode 100644 src/pkg/dashboard/api_governor_pr_models_hive_cost_test.go diff --git a/changelog.d/added-18717-pr-models-hive-cost.md b/changelog.d/added-18717-pr-models-hive-cost.md new file mode 100644 index 0000000000..ebb36223f4 --- /dev/null +++ b/changelog.d/added-18717-pr-models-hive-cost.md @@ -0,0 +1 @@ +- **Governor PRs by model: what each model's PRs cost the hive to review (#18717).** Each model bucket in `GET /api/governor/pr-models` now carries `hive_cost` (`usd`, `launches`, `prs_with_cost`, `usd_per_merged_pr`): the hive's own estimated spend on reviewing, adjudicating and fixing that model's PRs, summed from the PR refs' `share_usd` in the cached launch-cost snapshot (#12128). `usd` is `null`, not `0`, when none of the model's PRs had attributed usage, and `hive_cost` is omitted while the snapshot is not ready. A top-level `hive_cost_coverage` reports the launch-cost window, the unattributed and backend-unsupported spend, and the estimate disclaimer. The card shows the figure in each row's tooltip with a coverage note under the header. It reads only the cached snapshot: no new token scanning or GitHub calls, and existing fields are unchanged. diff --git a/dashboard/test/governor-pr-models-hive-cost-ui.test.js b/dashboard/test/governor-pr-models-hive-cost-ui.test.js new file mode 100644 index 0000000000..15308f3e8b --- /dev/null +++ b/dashboard/test/governor-pr-models-hive-cost-ui.test.js @@ -0,0 +1,89 @@ +'use strict'; + +// Governor PRs by model: hive review cost per model (#18717). + +const { test } = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); + +const indexHtml = fs.readFileSync(path.join(__dirname, '..', '..', 'src', 'pkg', 'dashboard', 'static', 'index.html'), 'utf8'); + +function extractFunction(name) { + const start = indexHtml.indexOf('function ' + name + '('); + assert.notEqual(start, -1, `${name} function exists`); + const brace = indexHtml.indexOf('{', start); + let depth = 0; + for (let i = brace; i < indexHtml.length; i++) { + const ch = indexHtml[i]; + if (ch === '{') depth++; + if (ch === '}') depth--; + if (depth === 0) return indexHtml.slice(start, i + 1); + } + throw new Error(`unterminated ${name}`); +} + +function load() { + const context = { exports: {} }; + vm.runInNewContext([ + "function fmtUSD(n) { return n == null ? '—' : '$' + Number(n).toFixed(2); }", + "function escapeHtml(s) { return String(s).replace(/&/g, '&').replace(/ { + const { tip } = load(); + const out = tip({ hive_cost: { usd: 2, launches: 3, prs_with_cost: 2, usd_per_merged_pr: 1 } }, data); + assert.match(out, /Hive review cost: \$2\.00 est\. over 2 PRs with launch records, 3 launches · \$1\.00 per merged PR/); + assert.match(out, /launch-cost window: last 14d/); + assert.ok(out.includes(disclaimer), 'disclaimer travels with the figure'); + assert.ok(!out.includes('not $0'), 'no null note for a measured figure'); +}); + +test('null usd renders as a dash, never $0', () => { + const { tip } = load(); + const out = tip({ hive_cost: { usd: null, launches: 1, prs_with_cost: 1, usd_per_merged_pr: null } }, data); + assert.match(out, /Hive review cost: — est\./); + assert.ok(out.includes('no attributed usage, not $0')); + assert.ok(!out.includes('per merged PR')); + assert.ok(!out.includes('$0.00')); +}); + +test('nothing renders when the snapshot is not ready or hive_cost is absent', () => { + const { tip, note } = load(); + assert.equal(tip({}, data), ''); + assert.equal(tip({ hive_cost: { usd: 1 } }, { total: 1, hive_cost_coverage: { ready: false } }), ''); + assert.equal(note({ total: 1, hive_cost_coverage: { ready: false, disclaimer } }), ''); + assert.equal(note({ total: 1 }), ''); +}); + +test('coverage note names the window, the unattributed spend and the disclaimer', () => { + const { note } = load(); + const out = note(data); + assert.match(out, /estimate over the last 14d of launch records/); + assert.match(out, /not tied to any PR: \$7\.25 unattributed/); + assert.ok(!out.includes('backends without a usage timeline'), 'null bucket is not shown as $0'); + assert.ok(out.includes(disclaimer)); +}); + +test('the tile wires the hive cost into the row tooltip and the coverage notes', () => { + for (const expected of [ + '${governorPRModelHiveCostTip(b, data)}', + 'const hiveCostNote = governorPRModelsHiveCostNote(data);', + '${hiveCostNote}', + ]) { + assert.ok(indexHtml.includes(expected), `index.html missing ${expected}`); + } +}); diff --git a/src/docs/api-reference/agents-and-controls.md b/src/docs/api-reference/agents-and-controls.md index fa1b6297f9..1d090c45b9 100644 --- a/src/docs/api-reference/agents-and-controls.md +++ b/src/docs/api-reference/agents-and-controls.md @@ -21,7 +21,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `POST` | `/api/unpin/{agent}/{dimension}` | Owner only | Unpin | `pkg/dashboard/api.go:135` | | `POST` | `/api/restart/{agent}` | Owner only | Restart | `pkg/dashboard/api.go:139` | | `GET` | `/api/model-advisor` | Dashboard auth/session | Model Advisor | `pkg/dashboard/api.go:156` | -| `GET` | `/api/governor/pr-models` | Dashboard auth/session | Agent-authored PR distribution by normalized attribution model/backend for `window=7d`, `30d`, or `all`, including per-model rework stats, Wilson 95% `*_ci` intervals on the rates (omitted when the denominator is 0), a `coverage` block (closed-PR lookback and run-log partiality, as on `/api/contribute/effective-models`), `earliest_pr_created_at`, and the top 10 most-reworked PRs | `pkg/dashboard/api.go:157` | +| `GET` | `/api/governor/pr-models` | Dashboard auth/session | Agent-authored PR distribution by normalized attribution model/backend for `window=7d`, `30d`, or `all`, including per-model rework stats, Wilson 95% `*_ci` intervals on the rates (omitted when the denominator is 0), a `coverage` block (closed-PR lookback and run-log partiality, as on `/api/contribute/effective-models`), `earliest_pr_created_at`, the top 10 most-reworked PRs, and per-bucket `hive_cost` (`usd`, `launches`, `prs_with_cost`, `usd_per_merged_pr`: the hive's estimated review/fix spend on that model's PRs from the cached `/api/launch-cost` snapshot; `usd` is `null`, not `0`, when nothing was attributed; omitted while the snapshot is not ready) with a top-level `hive_cost_coverage` (`ready`, `window_hours`, `unattributed_usd`, `backend_unsupported_usd`, `disclaimer`) | `pkg/dashboard/api.go:157` | | `GET` | `/api/reviewer/accuracy` | Dashboard auth/session | Reviewer verdict calibration for the configured window: false-approve/false-block rates and confidence buckets per perspective and reviewer model | `pkg/dashboard/api.go:220` | | `GET` | `/api/review/queue` | Dashboard auth/session | PR review queue: every open PR (agent and contributor, actionable and held) ranked by triage class, confidence band, CI state and age, with per-PR `reasons`; unreviewed items carry `pending_since` and `redispatch_count` from the review dispatch state; each entry carries `stage` `{stage, entered_at, last_activity_at, quiet_for, stalled, waiting_on_hive, past_dwell, history[]}` from the stage-label store (`stalled`/`past_dwell` follow `governor.labels.stage.dwell` and `stalled.require_quiet`; `history[]` is `{from, to, at, reason, regressed}`, newest last, capped at 8) and the top-level `hive_held` counts PRs past their stage dwell while waiting on the hive (`waiting_on_hive` and `past_dwell` both true); paged with `limit` (1-200, default 50) and `offset` | `pkg/dashboard/api.go:502` | | `POST` | `/api/review/queue/{owner}/{repo}/{number}/superseded/close` | Owner only | Close a superseded PR now (grace window or not): posts the close comment, adds `hive/superseded`, closes it | `pkg/dashboard/api.go:505` | diff --git a/src/docs/dashboard.md b/src/docs/dashboard.md index 174dcdef4d..2998fbef30 100644 --- a/src/docs/dashboard.md +++ b/src/docs/dashboard.md @@ -174,6 +174,12 @@ posture, and cadence controls for the hive. Its collapsible **PRs by model** nes sub-section reads `GET /api/governor/pr-models` with the selected `7d`, `30d`, or `all` window. The nested header keeps the window/sort toggles visible and its collapsed summary shows the current top-ranked model plus model count. +Each model row's tooltip also shows **Hive review cost**: what the hive's own +agents (reviewers, adjudicator, fixers) are estimated to have spent on that +model's PRs, joined from the cached launch-cost snapshot (see +[Launch attribution](token-tracking.md#launch-attribution)). A note under the +header names the launch-cost window and the spend that could not be tied to any +PR. "—" means no attributed usage, not $0. The Governor **actionable issues** and **actionable PRs** tiles use the shared server-side actionable partition described in [Repository card legend, issue diff --git a/src/docs/token-tracking.md b/src/docs/token-tracking.md index 01a9dc3b62..8e5da576d4 100644 --- a/src/docs/token-tracking.md +++ b/src/docs/token-tracking.md @@ -102,7 +102,7 @@ The kick path records a `LaunchRecord` (`pkg/tokens/launch.go`) each time the go - USD is `null` when nothing was attributed — never `$0.00`. - `?ref=owner/repo#N` narrows `by_ref` and `by_launch` to one work item; totals stay whole-window. -The dashboard Cost panel renders the top rows as "cost by work item". Manual `send-kick` and startup prompts do not record launches, so their spend stays unattributed. This is visibility only: nothing here gates or budgets a kick, and the governor window budget remains the single enforced budget. +The dashboard Cost panel renders the top rows as "cost by work item". The Governor **PRs by model** card (`GET /api/governor/pr-models`) sums the PR refs' `share_usd` per authoring model as `hive_cost` (#18717): refs with `kind: "pr"` only, joined on the canonical `owner/repo#N` (a short configured repo name joins on the repo name), never `launch_usd`, and `null` when no matched ref carried usage. `hive_cost_coverage` copies the snapshot's `window_hours`, `unattributed` and `backend_unsupported` USD and the disclaimer; on backends without a usage timeline most models show `null`. Manual `send-kick` and startup prompts do not record launches, so their spend stays unattributed. This is visibility only: nothing here gates or budgets a kick, and the governor window budget remains the single enforced budget. ## Metering diagnostics and zero-token health diff --git a/src/pkg/dashboard/api_governor_pr_models.go b/src/pkg/dashboard/api_governor_pr_models.go index 15c5af130c..016579b4fc 100644 --- a/src/pkg/dashboard/api_governor_pr_models.go +++ b/src/pkg/dashboard/api_governor_pr_models.go @@ -35,6 +35,10 @@ type governorPRModelsResponse struct { // created_at among the PRs counted, omitted when there are none. Coverage contributeEffectiveModelsCoverage `json:"coverage"` EarliestPRCreatedAt string `json:"earliest_pr_created_at,omitempty"` + // HiveCostCoverage describes the launch-cost snapshot behind each + // bucket's hive_cost (#18717). Always present; Ready=false means no + // bucket carries hive_cost. + HiveCostCoverage governorPRModelsHiveCostCoverage `json:"hive_cost_coverage"` } // governorPRModelBucket is one canonical model (modelfamily.Canonical folds @@ -57,6 +61,9 @@ type governorPRModelBucket struct { // Efforts splits the bucket by the trailer's effort= value ("unknown" // when absent), sorted by PRs descending (hivecommons/hive#18715). Efforts []governorPRModelEffort `json:"efforts,omitempty"` + // HiveCost is what this model's PRs cost the hive to review and repair + // (#18717); omitted when the launch-cost snapshot is not ready. + HiveCost *governorPRModelHiveCost `json:"hive_cost,omitempty"` } // governorPRModelSource is one raw attribution spelling folded into a bucket. @@ -186,6 +193,8 @@ func (s *Server) handleGovernorPRModels(w http.ResponseWriter, r *http.Request) resp.Coverage = effectiveModelsCoverage(governorPRModelsWindowDuration(window), ghpkg.AttributedClosedPRLookback(), runs, rotated, now) effective := aggregateEffectiveModelsFromPRAggregation(resp, aggregateEffectiveRunStats(runs, effectiveModelsFilterAll), effectiveModelsFilterAll, minMergedPRs) applyGovernorPRModelEffectiveness(&resp, effective, minMergedPRs) + launchCost, launchCostReady := s.launchCostSnapshotForPRModels() + applyGovernorPRModelHiveCost(&resp, actionable.PRs.Attributed, launchCost, launchCostReady, now) w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(resp) } @@ -213,13 +222,7 @@ func normalizeGovernorPRModelsWindow(window string) string { func aggregateGovernorPRModels(prs []ghpkg.PullRequest, window string, now time.Time) governorPRModelsResponse { window = normalizeGovernorPRModelsWindow(window) - cutoff := time.Time{} - switch window { - case governorPRModelsWindow7d: - cutoff = now.AddDate(0, 0, -governorPRModelsDays7) - case governorPRModelsWindow30d: - cutoff = now.AddDate(0, 0, -governorPRModelsDays30) - } + cutoff := governorPRModelsCutoff(window, now) type bucketState struct { governorPRModelBucket @@ -398,6 +401,18 @@ func finishGovernorPRModelEfforts(m map[string]*governorPRModelSliceState) []gov return out } +// governorPRModelsCutoff is the earliest PR created_at a window counts; zero +// for "all". +func governorPRModelsCutoff(window string, now time.Time) time.Time { + switch normalizeGovernorPRModelsWindow(window) { + case governorPRModelsWindow7d: + return now.AddDate(0, 0, -governorPRModelsDays7) + case governorPRModelsWindow30d: + return now.AddDate(0, 0, -governorPRModelsDays30) + } + return time.Time{} +} + // joinedBackends returns the sorted distinct backends and their comma-joined // display form ("codex, pi"). func joinedBackends(set map[string]bool) ([]string, string) { diff --git a/src/pkg/dashboard/api_governor_pr_models_hive_cost.go b/src/pkg/dashboard/api_governor_pr_models_hive_cost.go new file mode 100644 index 0000000000..302d94ca63 --- /dev/null +++ b/src/pkg/dashboard/api_governor_pr_models_hive_cost.go @@ -0,0 +1,222 @@ +package dashboard + +// Hive review cost per authoring model (#18717): joins the cached launch-cost +// snapshot's PR refs (#12128) to the PRs on the Governor "PRs by model" card, +// so each model's row shows what its PRs cost the hive's own agents (review, +// adjudication, fixes). Read-only over the cached snapshot: no token scanning +// and no GitHub calls. + +import ( + "strings" + "time" + + "github.com/hivecommons/hive/pkg/dashboard/collect" + ghpkg "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/modelfamily" + "github.com/hivecommons/hive/pkg/tokens" +) + +// governorPRModelHiveCost is one bucket's share of the hive's spend on its PRs. +type governorPRModelHiveCost struct { + // USD sums share_usd over the bucket's PRs that had a PR ref; nil when + // none had attributed usage (nil ≠ 0, as on /api/launch-cost). + USD *float64 `json:"usd"` + // Launches sums the matched refs' launch counts. + Launches int `json:"launches"` + // PRsWithCost counts the bucket's PRs that had a PR ref entry. + PRsWithCost int `json:"prs_with_cost"` + // USDPerMergedPR is USD / merged when both are > 0, else nil. + USDPerMergedPR *float64 `json:"usd_per_merged_pr"` +} + +// governorPRModelsHiveCostCoverage describes the snapshot the join read. +type governorPRModelsHiveCostCoverage struct { + Ready bool `json:"ready"` + WindowHours int `json:"window_hours"` + // UnattributedUSD and BackendUnsupportedUSD are copied from the snapshot: + // spend that could not be tied to any PR. nil when nothing landed there. + UnattributedUSD *float64 `json:"unattributed_usd"` + BackendUnsupportedUSD *float64 `json:"backend_unsupported_usd"` + Disclaimer string `json:"disclaimer"` +} + +// launchCostSnapshotForPRModels reads the cached launch-cost snapshot only. +// Unlike handleLaunchCost there is no inline fallback: without a collector +// the card reports ready=false rather than scanning tokens per request. +func (s *Server) launchCostSnapshotForPRModels() (collect.LaunchCostResponse, bool) { + if s == nil || s.deps == nil || s.deps.LaunchCost == nil { + return collect.LaunchCostResponse{}, false + } + return s.deps.LaunchCost.Snapshot() +} + +// applyGovernorPRModelHiveCost fills hive_cost_coverage and, when the +// snapshot is ready, each bucket's hive_cost. It re-walks the same PRs +// aggregateGovernorPRModels counted (attributed, inside resp.Window) and +// leaves every existing field untouched. +func applyGovernorPRModelHiveCost(resp *governorPRModelsResponse, prs []ghpkg.PullRequest, snap collect.LaunchCostResponse, ready bool, now time.Time) { + if resp == nil { + return + } + resp.HiveCostCoverage = governorPRModelsHiveCostCoverage{Ready: ready, Disclaimer: collect.CostEstimateDisclaimer} + if !ready { + return + } + resp.HiveCostCoverage.WindowHours = snap.WindowHours + resp.HiveCostCoverage.UnattributedUSD = snap.Unattributed.USD + resp.HiveCostCoverage.BackendUnsupportedUSD = snap.BackendUnsupported.USD + if snap.Disclaimer != "" { + resp.HiveCostCoverage.Disclaimer = snap.Disclaimer + } + + idx := newPRRefCostIndex(snap.ByRef) + type acc struct { + usd float64 + hasUSD bool + launches int + prs int + } + accs := map[string]*acc{} + cutoff := governorPRModelsCutoff(resp.Window, now) + for _, pr := range prs { + if !pr.HiveAttributed { + continue + } + if !cutoff.IsZero() && pr.CreatedAt.Before(cutoff) { + continue + } + entries := idx.lookup(pr) + if len(entries) == 0 { + continue + } + model := modelfamily.Canonical(pr.HiveModel) + a := accs[model] + if a == nil { + a = &acc{} + accs[model] = a + } + a.prs++ + for _, e := range entries { + a.launches += e.Launches + if e.ShareUSD != nil { + a.usd += *e.ShareUSD + a.hasUSD = true + } + } + } + for i := range resp.Buckets { + b := &resp.Buckets[i] + hc := &governorPRModelHiveCost{} + if a := accs[b.Model]; a != nil { + hc.Launches = a.launches + hc.PRsWithCost = a.prs + if a.hasUSD { + usd := a.usd + hc.USD = &usd + if usd > 0 && b.Merged > 0 { + per := usd / float64(b.Merged) + hc.USDPerMergedPR = &per + } + } + } + b.HiveCost = hc + } +} + +// prRefCostIndex finds launch-cost PR refs for a PR record. Refs are keyed +// with effectivePRKey; a PR is looked up by its canonical owner/repo +// (effectivePRRepo, the #10687 normalisation). Refs recorded with a short +// repo name ("repo#N") match on the repo's last path segment; a short PR +// repo matches a full ref only when exactly one owner has that repo#N. +type prRefCostIndex struct { + entries []collect.RefCostEntry + full map[string][]int // "owner/repo#n" → entry indexes + short map[string][]int // "repo#n" for refs recorded without an owner + tail map[string][]int // "repo#n" for refs recorded with an owner +} + +func newPRRefCostIndex(refs []collect.RefCostEntry) prRefCostIndex { + idx := prRefCostIndex{full: map[string][]int{}, short: map[string][]int{}, tail: map[string][]int{}} + for _, e := range refs { + if e.Kind != tokens.LaunchRefKindPR { + continue + } + repo, number := strings.TrimSpace(e.Repo), e.Number + if repo == "" || number <= 0 { + parsed, ok := tokens.ParseLaunchRef(e.Ref) + if !ok || parsed.Number <= 0 { + continue + } + repo, number = parsed.Repo, parsed.Number + } + i := len(idx.entries) + idx.entries = append(idx.entries, e) + if strings.Contains(repo, "/") { + idx.full[effectivePRKey(repo, number)] = append(idx.full[effectivePRKey(repo, number)], i) + tk := effectivePRKey(repoTail(repo), number) + idx.tail[tk] = append(idx.tail[tk], i) + } else { + idx.short[effectivePRKey(repo, number)] = append(idx.short[effectivePRKey(repo, number)], i) + } + } + return idx +} + +// lookup returns the distinct ref entries for pr. +func (idx prRefCostIndex) lookup(pr ghpkg.PullRequest) []collect.RefCostEntry { + if len(idx.entries) == 0 || pr.Number <= 0 { + return nil + } + seen := map[int]bool{} + var out []collect.RefCostEntry + add := func(is []int) { + for _, i := range is { + if !seen[i] { + seen[i] = true + out = append(out, idx.entries[i]) + } + } + } + repo := strings.TrimSpace(effectivePRRepo(pr)) + if repo == "" { + return nil + } + tk := effectivePRKey(repoTail(repo), pr.Number) + if strings.Contains(repo, "/") { + add(idx.full[effectivePRKey(repo, pr.Number)]) + add(idx.short[tk]) + return out + } + add(idx.short[tk]) + if full := idx.tail[tk]; len(full) > 0 && singleOwner(idx.entries, full) { + add(full) + } + return out +} + +func repoTail(repo string) string { + repo = strings.TrimSpace(repo) + if i := strings.LastIndex(repo, "/"); i >= 0 { + return repo[i+1:] + } + return repo +} + +// singleOwner reports whether every indexed entry names the same owner/repo. +func singleOwner(entries []collect.RefCostEntry, is []int) bool { + first := "" + for _, i := range is { + r := strings.ToLower(strings.TrimSpace(entries[i].Repo)) + if r == "" { + if p, ok := tokens.ParseLaunchRef(entries[i].Ref); ok { + r = strings.ToLower(p.Repo) + } + } + if first == "" { + first = r + } else if r != first { + return false + } + } + return true +} diff --git a/src/pkg/dashboard/api_governor_pr_models_hive_cost_test.go b/src/pkg/dashboard/api_governor_pr_models_hive_cost_test.go new file mode 100644 index 0000000000..affc6e1baa --- /dev/null +++ b/src/pkg/dashboard/api_governor_pr_models_hive_cost_test.go @@ -0,0 +1,190 @@ +package dashboard + +import ( + "encoding/json" + "math" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/dashboard/collect" + ghpkg "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/modelfamily" + "github.com/hivecommons/hive/pkg/tokens" +) + +func hiveCostUSD(v float64) *float64 { return &v } + +func hiveCostBucket(t *testing.T, resp governorPRModelsResponse, rawModel string) governorPRModelBucket { + t.Helper() + model := modelfamily.Canonical(rawModel) + for _, b := range resp.Buckets { + if b.Model == model { + return b + } + } + t.Fatalf("no bucket for %q (canonical %q) in %+v", rawModel, model, resp.Buckets) + return governorPRModelBucket{} +} + +func hiveCostApprox(a, b float64) bool { return math.Abs(a-b) < 1e-9 } + +func TestGovernorPRModelsHiveCostJoin(t *testing.T) { + now := time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) + recent := now.AddDate(0, 0, -2) + prs := []ghpkg.PullRequest{ + // opus: a short configured repo name with a full URL, a full repo + // name with no URL, an open PR with no ref, and one PR outside 30d. + {Repo: "repo", Number: 1, URL: "https://github.com/org/repo/pull/1", HiveAttributed: true, HiveModel: "opus", HiveBackend: "claude", CreatedAt: recent, MergedAt: now}, + {Repo: "org/repo", Number: 2, HiveAttributed: true, HiveModel: "opus", HiveBackend: "claude", CreatedAt: recent, MergedAt: now}, + {Repo: "org/repo", Number: 3, HiveAttributed: true, HiveModel: "opus", HiveBackend: "claude", CreatedAt: recent, State: "open"}, + {Repo: "org/repo", Number: 9, HiveAttributed: true, HiveModel: "opus", HiveBackend: "claude", CreatedAt: now.AddDate(0, 0, -40), MergedAt: now}, + // sonnet: its ref was recorded with a short repo name. + {Repo: "org/other", Number: 5, HiveAttributed: true, HiveModel: "sonnet", HiveBackend: "copilot", CreatedAt: recent, MergedAt: now}, + // gpt-6.1-sol: a ref exists but carried no usage → usd null. + {Repo: "org/repo", Number: 8, HiveAttributed: true, HiveModel: "gpt-6.1-sol", HiveBackend: "codex", CreatedAt: recent, MergedAt: now}, + // haiku: no refs at all. + {Repo: "org/repo", Number: 11, HiveAttributed: true, HiveModel: "haiku", HiveBackend: "claude", CreatedAt: recent, MergedAt: now}, + } + snap := collect.LaunchCostResponse{ + Ready: true, + WindowHours: 336, + Disclaimer: collect.CostEstimateDisclaimer, + ByRef: []collect.RefCostEntry{ + {Ref: "Org/Repo#1", Kind: tokens.LaunchRefKindPR, Repo: "Org/Repo", Number: 1, Launches: 2, ShareUSD: hiveCostUSD(1.5), LaunchUSD: hiveCostUSD(9)}, + {Ref: "org/repo#2", Kind: tokens.LaunchRefKindPR, Repo: "org/repo", Number: 2, Launches: 1, ShareUSD: hiveCostUSD(0.5), LaunchUSD: hiveCostUSD(0.5)}, + {Ref: "org/repo#3", Kind: tokens.LaunchRefKindIssue, Repo: "org/repo", Number: 3, Launches: 4, ShareUSD: hiveCostUSD(4)}, + {Ref: "org/repo#9", Kind: tokens.LaunchRefKindPR, Repo: "org/repo", Number: 9, Launches: 5, ShareUSD: hiveCostUSD(10)}, + {Ref: "other#5", Kind: tokens.LaunchRefKindPR, Repo: "other", Number: 5, Launches: 3, ShareUSD: hiveCostUSD(2)}, + {Ref: "org/repo#8", Kind: tokens.LaunchRefKindPR, Repo: "org/repo", Number: 8, Launches: 1}, + }, + Unattributed: collect.RepoCostEntry{Repo: collect.RepoCostBucketUnattributed, USD: hiveCostUSD(7.25)}, + BackendUnsupported: collect.RepoCostEntry{Repo: collect.RepoCostBucketBackendUnsupported}, + } + + resp := aggregateGovernorPRModels(prs, governorPRModelsWindow30d, now) + applyGovernorPRModelHiveCost(&resp, prs, snap, true, now) + + cov := resp.HiveCostCoverage + if !cov.Ready || cov.WindowHours != 336 || cov.Disclaimer != collect.CostEstimateDisclaimer { + t.Fatalf("hive_cost_coverage = %+v", cov) + } + if cov.UnattributedUSD == nil || *cov.UnattributedUSD != 7.25 || cov.BackendUnsupportedUSD != nil { + t.Fatalf("coverage buckets = unattributed %v backend_unsupported %v", cov.UnattributedUSD, cov.BackendUnsupportedUSD) + } + + tests := []struct { + model string + usd *float64 + launches int + prsWithCost int + perMerged *float64 + }{ + // #1 (1.5, short repo + URL) + #2 (0.5); #3 is an issue ref, #9 is outside the window. + {model: "opus", usd: hiveCostUSD(2), launches: 3, prsWithCost: 2, perMerged: hiveCostUSD(1)}, + {model: "sonnet", usd: hiveCostUSD(2), launches: 3, prsWithCost: 1, perMerged: hiveCostUSD(2)}, + {model: "gpt-6.1-sol", usd: nil, launches: 1, prsWithCost: 1, perMerged: nil}, + {model: "haiku", usd: nil, launches: 0, prsWithCost: 0, perMerged: nil}, + } + for _, tc := range tests { + t.Run(tc.model, func(t *testing.T) { + hc := hiveCostBucket(t, resp, tc.model).HiveCost + if hc == nil { + t.Fatalf("hive_cost missing") + } + if (hc.USD == nil) != (tc.usd == nil) || (hc.USD != nil && !hiveCostApprox(*hc.USD, *tc.usd)) { + t.Fatalf("usd = %v, want %v", hc.USD, tc.usd) + } + if (hc.USDPerMergedPR == nil) != (tc.perMerged == nil) || (hc.USDPerMergedPR != nil && !hiveCostApprox(*hc.USDPerMergedPR, *tc.perMerged)) { + t.Fatalf("usd_per_merged_pr = %v, want %v", hc.USDPerMergedPR, tc.perMerged) + } + if hc.Launches != tc.launches || hc.PRsWithCost != tc.prsWithCost { + t.Fatalf("launches/prs_with_cost = %d/%d, want %d/%d", hc.Launches, hc.PRsWithCost, tc.launches, tc.prsWithCost) + } + }) + } + + // Null is not zero on the wire. + raw, err := json.Marshal(hiveCostBucket(t, resp, "haiku")) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(raw), `"hive_cost":{"usd":null,`) { + t.Fatalf("haiku bucket JSON = %s, want usd null", raw) + } + + // The all window counts #9 too. + all := aggregateGovernorPRModels(prs, governorPRModelsWindowAll, now) + applyGovernorPRModelHiveCost(&all, prs, snap, true, now) + if hc := hiveCostBucket(t, all, "opus").HiveCost; hc == nil || hc.USD == nil || !hiveCostApprox(*hc.USD, 12) || hc.PRsWithCost != 3 { + t.Fatalf("all-window opus hive_cost = %+v", hc) + } +} + +func TestGovernorPRModelsHiveCostShortPRRepo(t *testing.T) { + now := time.Now().UTC() + prs := []ghpkg.PullRequest{ + {Repo: "repo", Number: 4, HiveAttributed: true, HiveModel: "opus", CreatedAt: now, MergedAt: now}, + {Repo: "dup", Number: 6, HiveAttributed: true, HiveModel: "sonnet", CreatedAt: now, MergedAt: now}, + } + snap := collect.LaunchCostResponse{Ready: true, ByRef: []collect.RefCostEntry{ + {Ref: "org/repo#4", Kind: tokens.LaunchRefKindPR, Repo: "org/repo", Number: 4, Launches: 1, ShareUSD: hiveCostUSD(3)}, + // Two owners have dup#6: ambiguous, so neither is joined. + {Ref: "a/dup#6", Kind: tokens.LaunchRefKindPR, Repo: "a/dup", Number: 6, Launches: 1, ShareUSD: hiveCostUSD(1)}, + {Ref: "b/dup#6", Kind: tokens.LaunchRefKindPR, Repo: "b/dup", Number: 6, Launches: 1, ShareUSD: hiveCostUSD(1)}, + }} + resp := aggregateGovernorPRModels(prs, governorPRModelsWindowAll, now) + applyGovernorPRModelHiveCost(&resp, prs, snap, true, now) + if hc := hiveCostBucket(t, resp, "opus").HiveCost; hc == nil || hc.USD == nil || *hc.USD != 3 || hc.PRsWithCost != 1 { + t.Fatalf("short PR repo vs full ref: hive_cost = %+v", hc) + } + if hc := hiveCostBucket(t, resp, "sonnet").HiveCost; hc == nil || hc.USD != nil || hc.PRsWithCost != 0 { + t.Fatalf("ambiguous owner: hive_cost = %+v, want no match", hc) + } +} + +func TestGovernorPRModelsHiveCostNotReady(t *testing.T) { + now := time.Now().UTC() + prs := []ghpkg.PullRequest{{Repo: "org/repo", Number: 1, HiveAttributed: true, HiveModel: "opus", CreatedAt: now, MergedAt: now}} + resp := aggregateGovernorPRModels(prs, governorPRModelsWindow7d, now) + snap := collect.LaunchCostResponse{ByRef: []collect.RefCostEntry{{Ref: "org/repo#1", Kind: tokens.LaunchRefKindPR, Repo: "org/repo", Number: 1, Launches: 1, ShareUSD: hiveCostUSD(1)}}} + applyGovernorPRModelHiveCost(&resp, prs, snap, false, now) + if resp.HiveCostCoverage.Ready || resp.HiveCostCoverage.Disclaimer == "" { + t.Fatalf("coverage = %+v, want ready=false with disclaimer", resp.HiveCostCoverage) + } + for _, b := range resp.Buckets { + if b.HiveCost != nil { + t.Fatalf("bucket %s has hive_cost %+v while snapshot not ready", b.Model, b.HiveCost) + } + } + + // Through the handler: no collector, then a collector that has not + // collected yet. Both answer 200 without hive_cost on any bucket. + for _, name := range []string{"no collector", "not ready"} { + t.Run(name, func(t *testing.T) { + s := covApiServer(t) + s.deps.Scheduler = metricsSchedulerStub{actionable: &ghpkg.ActionableResult{PRs: ghpkg.PRResult{Attributed: prs}}} + if name == "not ready" { + s.deps.LaunchCost = collect.NewLaunchCostCollector(&fakeLaunchTokens{summary: &tokens.AggregateSummary{}}, nil) + } + rec := httptest.NewRecorder() + s.handleGovernorPRModels(rec, httptest.NewRequest(http.MethodGet, "/api/governor/pr-models?window=7d", nil)) + if rec.Code != http.StatusOK { + t.Fatalf("status = %d, want 200", rec.Code) + } + body := rec.Body.String() + if strings.Contains(body, `"hive_cost":`) { + t.Fatalf("hive_cost present while not ready: %s", body) + } + var got governorPRModelsResponse + if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil { + t.Fatal(err) + } + if got.HiveCostCoverage.Ready || len(got.Buckets) != 1 || got.Buckets[0].PRs != 1 { + t.Fatalf("response = %+v", got) + } + }) + } +} diff --git a/src/pkg/dashboard/static-src/js/governor-view.js b/src/pkg/dashboard/static-src/js/governor-view.js index f275439581..aa0eb39120 100644 --- a/src/pkg/dashboard/static-src/js/governor-view.js +++ b/src/pkg/dashboard/static-src/js/governor-view.js @@ -125,6 +125,31 @@ `; } + // Hive review cost per authoring model (#18717): what the hive's own + // agents spent reviewing / fixing this model's PRs, from the cached + // launch-cost join. "—" means no attributed usage, not $0. + function governorPRModelHiveCostTip(b, data) { + const hc = b && b.hive_cost; + const cov = data && data.hive_cost_coverage; + if (!hc || !cov || !cov.ready) return ''; + const prs = Number(hc.prs_with_cost) || 0; + const usd = hc.usd == null ? '—' : fmtUSD(hc.usd); + const per = hc.usd_per_merged_pr == null ? '' : ` · ${fmtUSD(hc.usd_per_merged_pr)} per merged PR`; + const hours = Number(cov.window_hours) || 0; + const windowLabel = hours ? ` (launch-cost window: last ${hours % 24 ? hours + 'h' : (hours / 24) + 'd'})` : ''; + const noUsage = hc.usd == null ? '\n— = no attributed usage, not $0' : ''; + return `\n\nHive review cost: ${usd} est. over ${prs} PR${prs === 1 ? '' : 's'} with launch records, ${Number(hc.launches) || 0} launch${hc.launches === 1 ? '' : 'es'}${per}${windowLabel}${noUsage}\n${cov.disclaimer || ''}`; + } + function governorPRModelsHiveCostNote(data) { + const cov = data && data.hive_cost_coverage; + if (!cov || !cov.ready || !(data.total > 0)) return ''; + const hours = Number(cov.window_hours) || 0; + const span = hours ? `last ${hours % 24 ? hours + 'h' : (hours / 24) + 'd'}` : 'launch-cost window'; + const gaps = []; + if (cov.unattributed_usd != null) gaps.push(`${fmtUSD(cov.unattributed_usd)} unattributed`); + if (cov.backend_unsupported_usd != null) gaps.push(`${fmtUSD(cov.backend_unsupported_usd)} from backends without a usage timeline`); + return `
Hive review cost (hover a row) is an estimate over the ${escapeHtml(span)} of launch records${gaps.length ? '; not tied to any PR: ' + gaps.join(', ') : ''}. ${escapeHtml(cov.disclaimer || '')}
`; + } function renderGovernorPRModelsTile() { const data = govPRModelsData && govPRModelsData.window === govPRModelsWindow ? govPRModelsData : null; const total = data?.total || 0; @@ -170,7 +195,7 @@ const agentBreakdown = (b.agents || []).map(a => `${a.agent || 'unknown'} / ${a.backend || b.backend || 'unknown'}: ${a.prs} PRs (${a.merged || 0} merged, ${a.open || 0} open, ${a.closed_unmerged || 0} closed-unmerged)`).join('\n'); const scoreFormula = measured ? ' × (1 − fail) × (1 − no ship)' : ' (first-pass bound only: no runs recorded, so the run factors were skipped)'; const scoreLine = eff.rank ? `\nRank #${eff.rank} · score ${(Number(eff.score) || 0).toFixed(3)} = Wilson lower bound(${eff.first_pass_merged ?? '?'}/${eff.merged_prs ?? b.merged ?? 0} first pass)${scoreFormula}` : (unattributed ? '\nUnattributed: no model recorded, listed but not ranked' : `\nUnranked: fewer than ${data.min_merged_prs || 5} merged PRs`); - const tip = `${b.model || 'unknown'} via ${backends.join(', ')}${scoreLine}\n${prs} PRs (${share.toFixed(1)}%)\n${b.merged || 0} merged · ${b.open || 0} open · ${b.closed_unmerged || 0} closed-unmerged\nFirst-pass ${values.first_pass}${ci(eff.first_pass_merge_rate_ci || rw.first_pass_merge_rate_ci)} · PR run rate ${values.pr_runs}${measured ? ci(eff.verified_pr_run_rate_ci) : ''} · failure ${values.fail}${measured ? ci(eff.failure_rate_ci) : ''} · nothing-to-ship ${values.no_ship}${measured ? ci(eff.nothing_to_ship_rate_ci) : ''}${measured ? '' : '\n— = no runs recorded, not a measured 0%'}\nAvg rounds ${(rw.avg_review_rounds || 0).toFixed(1)} · avg fix attempts ${(rw.avg_fix_attempts || 0).toFixed(1)}${sources ? '\n\nRaw model ids folded into this row:\n' + sources : ''}${agentBreakdown ? '\n\n' + agentBreakdown : ''}${effortBreakdown ? '\n\nBy effort:\n' + effortBreakdown : ''}`; + const tip = `${b.model || 'unknown'} via ${backends.join(', ')}${scoreLine}\n${prs} PRs (${share.toFixed(1)}%)\n${b.merged || 0} merged · ${b.open || 0} open · ${b.closed_unmerged || 0} closed-unmerged\nFirst-pass ${values.first_pass}${ci(eff.first_pass_merge_rate_ci || rw.first_pass_merge_rate_ci)} · PR run rate ${values.pr_runs}${measured ? ci(eff.verified_pr_run_rate_ci) : ''} · failure ${values.fail}${measured ? ci(eff.failure_rate_ci) : ''} · nothing-to-ship ${values.no_ship}${measured ? ci(eff.nothing_to_ship_rate_ci) : ''}${measured ? '' : '\n— = no runs recorded, not a measured 0%'}\nAvg rounds ${(rw.avg_review_rounds || 0).toFixed(1)} · avg fix attempts ${(rw.avg_fix_attempts || 0).toFixed(1)}${sources ? '\n\nRaw model ids folded into this row:\n' + sources : ''}${agentBreakdown ? '\n\n' + agentBreakdown : ''}${effortBreakdown ? '\n\nBy effort:\n' + effortBreakdown : ''}${governorPRModelHiveCostTip(b, data)}`; return `
${rank}${escapeHtml(b.model || 'unknown')}
${backendChips}
@@ -211,6 +236,7 @@ if (cov && cov.closed_prs_partial) covParts.push(`closed PRs: last ${cov.closed_pr_lookback_days || 0} days scanned${data.earliest_pr_created_at ? ` (earliest counted ${escapeHtml(String(data.earliest_pr_created_at).slice(0, 10))})` : ''}`); if (cov && cov.runs_partial) covParts.push(`runs: ${cov.runs_since ? 'since ' + escapeHtml(String(cov.runs_since).slice(0, 10)) : 'none retained'} (older runs rotated out)`); const coverageNote = covParts.length ? `
Partial history: ${covParts.join(' · ')}. Run columns come from the task-run log; — means no runs recorded, not a measured 0%.
` : ''; + const hiveCostNote = governorPRModelsHiveCostNote(data); const header = data && total > 0 ? `
Model
Outcome
@@ -226,6 +252,7 @@
${coverageNote} + ${hiveCostNote} ${header} ${rows} ${reworkTable} diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 82750035a6..a037e284f2 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -33797,6 +33797,31 @@

All labels

`; } + // Hive review cost per authoring model (#18717): what the hive's own + // agents spent reviewing / fixing this model's PRs, from the cached + // launch-cost join. "—" means no attributed usage, not $0. + function governorPRModelHiveCostTip(b, data) { + const hc = b && b.hive_cost; + const cov = data && data.hive_cost_coverage; + if (!hc || !cov || !cov.ready) return ''; + const prs = Number(hc.prs_with_cost) || 0; + const usd = hc.usd == null ? '—' : fmtUSD(hc.usd); + const per = hc.usd_per_merged_pr == null ? '' : ` · ${fmtUSD(hc.usd_per_merged_pr)} per merged PR`; + const hours = Number(cov.window_hours) || 0; + const windowLabel = hours ? ` (launch-cost window: last ${hours % 24 ? hours + 'h' : (hours / 24) + 'd'})` : ''; + const noUsage = hc.usd == null ? '\n— = no attributed usage, not $0' : ''; + return `\n\nHive review cost: ${usd} est. over ${prs} PR${prs === 1 ? '' : 's'} with launch records, ${Number(hc.launches) || 0} launch${hc.launches === 1 ? '' : 'es'}${per}${windowLabel}${noUsage}\n${cov.disclaimer || ''}`; + } + function governorPRModelsHiveCostNote(data) { + const cov = data && data.hive_cost_coverage; + if (!cov || !cov.ready || !(data.total > 0)) return ''; + const hours = Number(cov.window_hours) || 0; + const span = hours ? `last ${hours % 24 ? hours + 'h' : (hours / 24) + 'd'}` : 'launch-cost window'; + const gaps = []; + if (cov.unattributed_usd != null) gaps.push(`${fmtUSD(cov.unattributed_usd)} unattributed`); + if (cov.backend_unsupported_usd != null) gaps.push(`${fmtUSD(cov.backend_unsupported_usd)} from backends without a usage timeline`); + return `
Hive review cost (hover a row) is an estimate over the ${escapeHtml(span)} of launch records${gaps.length ? '; not tied to any PR: ' + gaps.join(', ') : ''}. ${escapeHtml(cov.disclaimer || '')}
`; + } function renderGovernorPRModelsTile() { const data = govPRModelsData && govPRModelsData.window === govPRModelsWindow ? govPRModelsData : null; const total = data?.total || 0; @@ -33842,7 +33867,7 @@

All labels

const agentBreakdown = (b.agents || []).map(a => `${a.agent || 'unknown'} / ${a.backend || b.backend || 'unknown'}: ${a.prs} PRs (${a.merged || 0} merged, ${a.open || 0} open, ${a.closed_unmerged || 0} closed-unmerged)`).join('\n'); const scoreFormula = measured ? ' × (1 − fail) × (1 − no ship)' : ' (first-pass bound only: no runs recorded, so the run factors were skipped)'; const scoreLine = eff.rank ? `\nRank #${eff.rank} · score ${(Number(eff.score) || 0).toFixed(3)} = Wilson lower bound(${eff.first_pass_merged ?? '?'}/${eff.merged_prs ?? b.merged ?? 0} first pass)${scoreFormula}` : (unattributed ? '\nUnattributed: no model recorded, listed but not ranked' : `\nUnranked: fewer than ${data.min_merged_prs || 5} merged PRs`); - const tip = `${b.model || 'unknown'} via ${backends.join(', ')}${scoreLine}\n${prs} PRs (${share.toFixed(1)}%)\n${b.merged || 0} merged · ${b.open || 0} open · ${b.closed_unmerged || 0} closed-unmerged\nFirst-pass ${values.first_pass}${ci(eff.first_pass_merge_rate_ci || rw.first_pass_merge_rate_ci)} · PR run rate ${values.pr_runs}${measured ? ci(eff.verified_pr_run_rate_ci) : ''} · failure ${values.fail}${measured ? ci(eff.failure_rate_ci) : ''} · nothing-to-ship ${values.no_ship}${measured ? ci(eff.nothing_to_ship_rate_ci) : ''}${measured ? '' : '\n— = no runs recorded, not a measured 0%'}\nAvg rounds ${(rw.avg_review_rounds || 0).toFixed(1)} · avg fix attempts ${(rw.avg_fix_attempts || 0).toFixed(1)}${sources ? '\n\nRaw model ids folded into this row:\n' + sources : ''}${agentBreakdown ? '\n\n' + agentBreakdown : ''}${effortBreakdown ? '\n\nBy effort:\n' + effortBreakdown : ''}`; + const tip = `${b.model || 'unknown'} via ${backends.join(', ')}${scoreLine}\n${prs} PRs (${share.toFixed(1)}%)\n${b.merged || 0} merged · ${b.open || 0} open · ${b.closed_unmerged || 0} closed-unmerged\nFirst-pass ${values.first_pass}${ci(eff.first_pass_merge_rate_ci || rw.first_pass_merge_rate_ci)} · PR run rate ${values.pr_runs}${measured ? ci(eff.verified_pr_run_rate_ci) : ''} · failure ${values.fail}${measured ? ci(eff.failure_rate_ci) : ''} · nothing-to-ship ${values.no_ship}${measured ? ci(eff.nothing_to_ship_rate_ci) : ''}${measured ? '' : '\n— = no runs recorded, not a measured 0%'}\nAvg rounds ${(rw.avg_review_rounds || 0).toFixed(1)} · avg fix attempts ${(rw.avg_fix_attempts || 0).toFixed(1)}${sources ? '\n\nRaw model ids folded into this row:\n' + sources : ''}${agentBreakdown ? '\n\n' + agentBreakdown : ''}${effortBreakdown ? '\n\nBy effort:\n' + effortBreakdown : ''}${governorPRModelHiveCostTip(b, data)}`; return `
${rank}${escapeHtml(b.model || 'unknown')}
${backendChips}
@@ -33883,6 +33908,7 @@

All labels

if (cov && cov.closed_prs_partial) covParts.push(`closed PRs: last ${cov.closed_pr_lookback_days || 0} days scanned${data.earliest_pr_created_at ? ` (earliest counted ${escapeHtml(String(data.earliest_pr_created_at).slice(0, 10))})` : ''}`); if (cov && cov.runs_partial) covParts.push(`runs: ${cov.runs_since ? 'since ' + escapeHtml(String(cov.runs_since).slice(0, 10)) : 'none retained'} (older runs rotated out)`); const coverageNote = covParts.length ? `
Partial history: ${covParts.join(' · ')}. Run columns come from the task-run log; — means no runs recorded, not a measured 0%.
` : ''; + const hiveCostNote = governorPRModelsHiveCostNote(data); const header = data && total > 0 ? `
Model
Outcome
@@ -33898,6 +33924,7 @@

All labels

${coverageNote} + ${hiveCostNote} ${header} ${rows} ${reworkTable} From 28e6b42110302c4589ee01316cba98754a013e1e Mon Sep 17 00:00:00 2001 From: Danathar <6772335+Danathar@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:50:50 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=8C=B1=20pr=5Fmodels=5Fheader=5Fonce?= =?UTF-8?q?=20test:=20lift=20the=20hive-cost=20helpers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test lifts renderGovernorPRModelsTile out of index.html by name, so it needs governorPRModelHiveCostTip, governorPRModelsHiveCostNote and a fmtUSD stub alongside it. Adds an assertion that the hive review cost shows in the row tooltip, "—" for null, and the coverage note. Refs #18717 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WcWm7qFmFJp26r9LPdmi3t Signed-off-by: Danathar <6772335+Danathar@users.noreply.github.com> --- src/pkg/dashboard/pr_models_header_once.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/pkg/dashboard/pr_models_header_once.test.js b/src/pkg/dashboard/pr_models_header_once.test.js index e8c14f0bf5..d96563d0aa 100644 --- a/src/pkg/dashboard/pr_models_header_once.test.js +++ b/src/pkg/dashboard/pr_models_header_once.test.js @@ -22,6 +22,9 @@ const src = [ 'const escapeHtml = s => String(s).replace(/[&<>"\']/g, c => ({"&":"&","<":"<",">":">",\'"\':""","\'":"'"}[c]));', 'const dashboardSectionHelpMark = () => "";', 'const formatFixTime = () => "";', + 'const fmtUSD = n => n == null ? "—" : "$" + Number(n).toFixed(2);', + pick(/function governorPRModelHiveCostTip\(b, data\) \{[\s\S]*?\n \}\n/, 'governorPRModelHiveCostTip'), + pick(/function governorPRModelsHiveCostNote\(data\) \{[\s\S]*?\n \}\n/, 'governorPRModelsHiveCostNote'), pick(/function governorPRModelUnattributed\(b\) \{[\s\S]*?\n \}\n/, 'governorPRModelUnattributed'), pick(/const GOV_PR_MODEL_COLUMNS = \[[\s\S]*?\n \];\n/, 'GOV_PR_MODEL_COLUMNS'), pick(/function governorPRModelRows\(data\) \{[\s\S]*?\n \}\n/, 'governorPRModelRows'), @@ -82,3 +85,16 @@ test('raw model ids and backends surface in the row tooltip and chips', () => { assert.ok(out.includes('copilot'), 'each backend a chip'); assert.ok(out.includes('Wilson lower bound'), 'tooltip states the rank formula'); }); + +test('hive review cost surfaces in the row tooltip and a coverage note (#18717)', () => { + const withCost = { + ...data, + hive_cost_coverage: { ready: true, window_hours: 336, unattributed_usd: 4, backend_unsupported_usd: null, disclaimer: 'Not a bill.' }, + buckets: data.buckets.map((b, i) => ({ ...b, hive_cost: i === 0 ? { usd: null, launches: 0, prs_with_cost: 0, usd_per_merged_pr: null } : { usd: 6, launches: 3, prs_with_cost: 2, usd_per_merged_pr: 1.5 } })), + }; + const out = lifted.render(withCost); + assert.ok(out.includes('Hive review cost: $6.00 est. over 2 PRs with launch records, 3 launches · $1.50 per merged PR'), 'cost in the row tooltip'); + assert.ok(out.includes('Hive review cost: — est.'), 'null cost renders as a dash'); + assert.ok(out.includes('class="gov-pr-model-sub gov-pr-model-sub-spaced gov-pr-models-hive-cost"'), 'coverage note rendered'); + assert.ok(!lifted.render(data).includes('Hive review cost'), 'nothing without hive_cost_coverage'); +}); From be6bcbc3f6aaac3332f3c406f7794c55ea51fae8 Mon Sep 17 00:00:00 2001 From: Danathar <6772335+Danathar@users.noreply.github.com> Date: Tue, 17 Nov 2026 21:02:27 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8C=B1=20ci:=20retrigger=20docker=20b?= =?UTF-8?q?uild=20after=20transient=20npm=20ETARGET?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The docker (contributor/hive) jobs failed installing cline@3.0.74 because its transitive dep ai@7.0.176 was not yet resolvable on the npm registry (publish race; v5 push build failed the same way at the same time). The version now resolves; no code change needed. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Danathar <6772335+Danathar@users.noreply.github.com>