diff --git a/changelog.d/fixed-overview-restart-refresh-banner.md b/changelog.d/fixed-overview-restart-refresh-banner.md new file mode 100644 index 0000000000..4933733928 --- /dev/null +++ b/changelog.d/fixed-overview-restart-refresh-banner.md @@ -0,0 +1 @@ +- Dashboard Overview: after a restart the stale badge reads "⟳ refreshing after restart (m ago) · N/M repos scanned · showing snapshot from " while the governor still serves the snapshot restored from disk, instead of "⚠ stale since (1h ago) · serving last-good". `/api/status` carries `restartRefresh` (restore time, snapshot read time, scan tally); it clears with the first completed enumeration. diff --git a/src/cmd/hive/main.go b/src/cmd/hive/main.go index 19fb645fe5..9a876130e2 100644 --- a/src/cmd/hive/main.go +++ b/src/cmd/hive/main.go @@ -3203,6 +3203,7 @@ func (b *boot) bootCollectorsWith(deps bootCollectorsDeps) { // so the Overview never shows pre-restart totals as current // (hivecommons/hive#13373); the first enumeration replaces it. cached.MarkAllStale() + cached.RestoredAt = time.Now().UTC() b.lastActionable.Store(&cached) if b.sched != nil { b.sched.SetLastActionable(&cached) diff --git a/src/docs/api-reference.md b/src/docs/api-reference.md index e9f02180a2..efe9457260 100644 --- a/src/docs/api-reference.md +++ b/src/docs/api-reference.md @@ -13,17 +13,17 @@ History point limits, timestamp cutoffs, incremental cost reads and ETag/304 beh | `GET` | `/api/version` | Dashboard auth/session | Build/version metadata; includes `upgradeMarker` (`target`, `current`, `attempts`, `maxAttempts`, `failed`, `requestedAt`, `lastError`) while a self-upgrade is in flight or has failed ([#6765](https://github.com/hivecommons/hive/issues/6765)), the hub-delivered `upgradePolicy` (`hub_managed`, `spoke_managed`, `schedule`, `schedule_hour`, `schedule_timezone`, `schedule_weekday`, `paused`, `branch`, `channel`, `target_sha`, `target_resolved`, `armed_target`, and `next_update_at` — the hub's RFC3339 ETA for the next promotion into the `stable` channel, omitted when unknown ([#10256](https://github.com/hivecommons/hive/issues/10256))) when available, and an `autoUpdate` object (`enabled`, `state` — one of `disabled`/`up_to_date`/`behind`/`retrying`/`failed`/`unknown` — `healthy`, `period`, `targetBranch`, `targetCommit`, `currentCommit`, `commitsBehind`, `lastAttemptAt`, `lastError`, `detail`, and `nextUpdateAt` — the hub's RFC3339 ETA for the next update, omitted when unknown, disabled or paused ([#10257](https://github.com/hivecommons/hive/issues/10257))) that never reports a failed or unknown update as healthy ([#6962](https://github.com/hivecommons/hive/issues/6962), [#6963](https://github.com/hivecommons/hive/issues/6963)) | `pkg/dashboard/api.go:42` | | `GET` | `/api/version/release-notes` | Dashboard auth/session | Changelog gap between two revisions: `?from=&to=` returns `{from:{sha,version?}, to:{sha,ref,version?}, sections:[{version,date,categories:{added,changed,fixed,security,deprecated}}], unreleased?, truncated, source, error?}` — the `CHANGELOG.md` release sections present at `to` and absent at `from`, newest first, plus (when `to` is not a release tag) the `changelog.d/` fragments new at `to` under an `Unreleased (in this build)` section. Fetch failures return `source: "unavailable"` with `error` rather than an error status; results are cached per (from, to) for an hour ([#11065](https://github.com/hivecommons/hive/issues/11065)) | `pkg/dashboard/api.go:43` | | `POST` | `/api/release-channel` | Owner only | Hosted spoke self-service release-channel selector; relays `stable`/`candidate`/`edge` to the hub's existing switch-branch endpoint with the spoke dashboard-token proof, and reports the requested channel as pending until the Deployment image lands | `pkg/dashboard/api.go:64` | -| `GET` | `/api/health` | Public | Basic health probe | `pkg/dashboard/server.go:1533` | -| `GET` | `/api/health/deep` | Public | Deep health probe | `pkg/dashboard/server.go:1534` | -| `GET` | `/api/livez` | Public | Kubernetes liveness probe | `pkg/dashboard/server.go:1535` | -| `GET` | `/metrics` | Registered only when `HIVE_METRICS_ENABLED`; requires `Authorization: ****** (403 if the token is unset) | Prometheus metrics | `pkg/dashboard/server.go:1541` | -| `GET` | `/api/status` | Dashboard auth/session | Dashboard aggregate status; `labelPresets[]` (`{key,label,description,labels[],states[]}`) lists the built-in label-filter presets for the Projects cards, led by `needs-human` whose `labels[]` are the effective hard-suppress labels plus `needs-signal`, the hold labels, `stage/071-needs-author` and the reporter-trust awaiting label (#12172); accepts `?fields=a,b` for top-level selection and `?omit=repos` to drop heavy sections, and honors `Accept-Encoding: gzip`; `agents[]` includes busy-pane visibility fields (`kicksUndeliverable`, `busySince`, `lastTranscriptActivity`, `condition`, `conditionMessage`) when a Working pane cannot accept kicks; a working agent also carries `agents[].run` — the live per-run line (#14576): `{since, elapsedS, costUSD, tokens, priced, tests, filesChanged}`, the estimated spend/tokens since the kick was delivered (`lastKickAt`, falling back to `busySince`) (delta of the token collector's per-agent cumulative figure; `priced:false` when the agent has none yet), the last visible test-runner result (`pass`/`fail`/empty) and the last `N files changed` git summary (`-1` when none) parsed from the captured pane; top-level `fleetRun` `{running, hourUSD, hourPriced}` is the governor strip's `running N · $X this hour` figure; `sla` (fleet) and `repos[].sla` (per repo) carry the Delivery SLA block derived from the lifecycle timeline with no extra GitHub calls: `windows.{7d,30d}.{open_to_triage,triage_to_start,start_to_pr,pr_to_merge,open_to_merge}` as `{p50_h,p95_h,n}` (hours, nearest-rank), `history[]` of up to 30 daily buckets `{day,start_to_pr_p50,pr_to_merge_p50,open_to_merge_p50,n_started,n_pr,n_merged}` persisted under `/data/sla-history.json`, `stale_in_progress[]` (`{number,repo,started_at,age_h,agent}` — issues carrying `hive/in-progress` longer than the agent claim TTL with no linked PR), `stale_count`, `merged_7d`, `claim_ttl_s` and, on the fleet block, the effective `targets` (`start_to_pr_h`, `pr_to_merge_h`, `open_to_merge_h`); `staleSince` and `repos[].countsStale` / `countsStaleSince` mark totals served from last-good figures — the previous enumeration (#13382) or the ForgeState cache's last-good counts (#13376) | `pkg/dashboard/server.go:1546` | -| `GET` | `/api/status/summary` | Dashboard auth/session | Compact agent/governor/budget status summary for pollers; honors `Accept-Encoding: gzip` | `pkg/dashboard/server.go:1547` | -| `GET` | `/api/overview/issues.csv` | Dashboard auth/session | Cached Overview issue-band export as browser-compatible CSV; filters `band`, `repo`/`repos`, `stale`, and `held` are ANDed. | `pkg/dashboard/server.go:1548` | -| `GET` | `/api/overview/issues.json` | Dashboard auth/session | Cached Overview issue-band export as typed JSON with `bands[]` metadata and row fields matching the CSV columns. | `pkg/dashboard/server.go:1549` | -| `GET` | `/api/overview/prs.csv` | Dashboard auth/session | Cached Overview PR-band export as browser-compatible CSV; filters `band`, `repo`/`repos`, `stale`, and `held` are ANDed. | `pkg/dashboard/server.go:1550` | -| `GET` | `/api/overview/prs.json` | Dashboard auth/session | Cached Overview PR-band export as typed JSON with `bands[]` metadata and row fields matching the CSV columns. | `pkg/dashboard/server.go:1551` | -| `GET` | `/api/events` | Dashboard auth/session | Server-sent event stream | `pkg/dashboard/server.go:1552` | +| `GET` | `/api/health` | Public | Basic health probe | `pkg/dashboard/server.go:1553` | +| `GET` | `/api/health/deep` | Public | Deep health probe | `pkg/dashboard/server.go:1554` | +| `GET` | `/api/livez` | Public | Kubernetes liveness probe | `pkg/dashboard/server.go:1555` | +| `GET` | `/metrics` | Registered only when `HIVE_METRICS_ENABLED`; requires `Authorization: ****** (403 if the token is unset) | Prometheus metrics | `pkg/dashboard/server.go:1561` | +| `GET` | `/api/status` | Dashboard auth/session | Dashboard aggregate status; `labelPresets[]` (`{key,label,description,labels[],states[]}`) lists the built-in label-filter presets for the Projects cards, led by `needs-human` whose `labels[]` are the effective hard-suppress labels plus `needs-signal`, the hold labels, `stage/071-needs-author` and the reporter-trust awaiting label (#12172); accepts `?fields=a,b` for top-level selection and `?omit=repos` to drop heavy sections, and honors `Accept-Encoding: gzip`; `agents[]` includes busy-pane visibility fields (`kicksUndeliverable`, `busySince`, `lastTranscriptActivity`, `condition`, `conditionMessage`) when a Working pane cannot accept kicks; a working agent also carries `agents[].run` — the live per-run line (#14576): `{since, elapsedS, costUSD, tokens, priced, tests, filesChanged}`, the estimated spend/tokens since the kick was delivered (`lastKickAt`, falling back to `busySince`) (delta of the token collector's per-agent cumulative figure; `priced:false` when the agent has none yet), the last visible test-runner result (`pass`/`fail`/empty) and the last `N files changed` git summary (`-1` when none) parsed from the captured pane; top-level `fleetRun` `{running, hourUSD, hourPriced}` is the governor strip's `running N · $X this hour` figure; `sla` (fleet) and `repos[].sla` (per repo) carry the Delivery SLA block derived from the lifecycle timeline with no extra GitHub calls: `windows.{7d,30d}.{open_to_triage,triage_to_start,start_to_pr,pr_to_merge,open_to_merge}` as `{p50_h,p95_h,n}` (hours, nearest-rank), `history[]` of up to 30 daily buckets `{day,start_to_pr_p50,pr_to_merge_p50,open_to_merge_p50,n_started,n_pr,n_merged}` persisted under `/data/sla-history.json`, `stale_in_progress[]` (`{number,repo,started_at,age_h,agent}` — issues carrying `hive/in-progress` longer than the agent claim TTL with no linked PR), `stale_count`, `merged_7d`, `claim_ttl_s` and, on the fleet block, the effective `targets` (`start_to_pr_h`, `pr_to_merge_h`, `open_to_merge_h`); `staleSince` and `repos[].countsStale` / `countsStaleSince` mark totals served from last-good figures — the previous enumeration (#13382) or the ForgeState cache's last-good counts (#13376) | `pkg/dashboard/server.go:1566` | +| `GET` | `/api/status/summary` | Dashboard auth/session | Compact agent/governor/budget status summary for pollers; honors `Accept-Encoding: gzip` | `pkg/dashboard/server.go:1567` | +| `GET` | `/api/overview/issues.csv` | Dashboard auth/session | Cached Overview issue-band export as browser-compatible CSV; filters `band`, `repo`/`repos`, `stale`, and `held` are ANDed. | `pkg/dashboard/server.go:1568` | +| `GET` | `/api/overview/issues.json` | Dashboard auth/session | Cached Overview issue-band export as typed JSON with `bands[]` metadata and row fields matching the CSV columns. | `pkg/dashboard/server.go:1569` | +| `GET` | `/api/overview/prs.csv` | Dashboard auth/session | Cached Overview PR-band export as browser-compatible CSV; filters `band`, `repo`/`repos`, `stale`, and `held` are ANDed. | `pkg/dashboard/server.go:1570` | +| `GET` | `/api/overview/prs.json` | Dashboard auth/session | Cached Overview PR-band export as typed JSON with `bands[]` metadata and row fields matching the CSV columns. | `pkg/dashboard/server.go:1571` | +| `GET` | `/api/events` | Dashboard auth/session | Server-sent event stream | `pkg/dashboard/server.go:1572` | | `GET` | `/api/swarm` | Dashboard auth/session | Current swarm status: display name, duration, active repo, expiry, persisted prep metrics when available, and idle-unlock fields. | `pkg/dashboard/swarm.go:310` | | `POST` | `/api/swarm` | Owner only | Start a 24h repo swarm for a configured repo, returning 409 when another swarm is active and 423 when a previous swarm keeps the next swarm locked until enough agents are idle unless body `{"repo":"owner/name","force":true}` is used; saves the active record before repo prep, persists prep metrics, and announces the start to Discord when configured. | `pkg/dashboard/swarm.go:311` | | `DELETE` | `/api/swarm` | Owner only | End the active swarm, score issues closed and PRs merged in the window, append it to history, and announce the result to Discord when configured. | `pkg/dashboard/swarm.go:312` | @@ -66,7 +66,7 @@ History point limits, timestamp cutoffs, incremental cost reads and ETag/304 beh | Method | Path | Auth | Purpose | Source | |---|---|---|---|---| | `GET` | `/api/style` | Public | Sanitized custom dashboard CSS | `pkg/dashboard/api.go:44` | -| `GET` | `/branding/custom.css` | Dashboard auth/session | Operator branding stylesheet override, read per request (see [branding](branding.md)) | `pkg/dashboard/server.go:1613` | +| `GET` | `/branding/custom.css` | Dashboard auth/session | Operator branding stylesheet override, read per request (see [branding](branding.md)) | `pkg/dashboard/server.go:1633` | | `GET` | `/api/snapshot/frame-ancestors` | Public | Snapshot framing allowlist | `pkg/dashboard/api.go:77` | | `GET` | `/api/snapshot` | Public | Snapshot data | `pkg/dashboard/api.go:78` | | `GET` | `/snapshot` | Public | Public read-only snapshot page | `pkg/dashboard/api.go:79` | @@ -94,9 +94,9 @@ History point limits, timestamp cutoffs, incremental cost reads and ETag/304 beh | `GET` | `/api/openrouter/models` | Dashboard auth/session | Open Router Models | `pkg/dashboard/openrouter.go:47` | | `GET` | `/api/openrouter/credit` | Dashboard auth/session | Open Router Credit | `pkg/dashboard/openrouter.go:48` | | `GET` | `/openrouter/callback` | Public | Open Router Callback | `pkg/dashboard/openrouter.go:49` | -| `POST` | `/api/github-app/recheck` | Dashboard auth/session | GitHub App Recheck | `pkg/dashboard/server.go:1553` | -| `POST` | `/api/github-app/install-clicked` | Dashboard auth/session | GitHub App Install Clicked | `pkg/dashboard/server.go:1554` | -| `GET` | `/gh-setup` | Public | GitHub App Setup Callback | `pkg/dashboard/server.go:1555` | +| `POST` | `/api/github-app/recheck` | Dashboard auth/session | GitHub App Recheck | `pkg/dashboard/server.go:1573` | +| `POST` | `/api/github-app/install-clicked` | Dashboard auth/session | GitHub App Install Clicked | `pkg/dashboard/server.go:1574` | +| `GET` | `/gh-setup` | Public | GitHub App Setup Callback | `pkg/dashboard/server.go:1575` | ## Configuration @@ -595,7 +595,7 @@ always resolved server-side from the validated token. | `POST` | `/api/hives/{id}/heartbeat` | Dashboard auth/session | Hives Heartbeat | `pkg/dashboard/api_contribute.go:275` | | `DELETE` | `/api/hives/{id}` | Owner only | Hives Delete | `pkg/dashboard/api_contribute.go:276` | | `POST` | `/api/hives/onboard` | Dashboard auth/session | Hives Onboard | `pkg/dashboard/api_contribute.go:277` | -| `GET` | `/sso` | Public | SSO | `pkg/dashboard/server.go:1560` | +| `GET` | `/sso` | Public | SSO | `pkg/dashboard/server.go:1580` | ## Hub SaaS diff --git a/src/docs/scale-envelope.md b/src/docs/scale-envelope.md index a93f7cad7f..23eea36d1d 100644 --- a/src/docs/scale-envelope.md +++ b/src/docs/scale-envelope.md @@ -34,7 +34,7 @@ ones to: 2. **Truncation must preserve the prioritization signal, not cut an arbitrary slice.** This holds today and is easy to assume backwards: - Issues are sorted by actionable rank tier, then **oldest first** within each tier before any cap is applied - (`RankActionableIssues`, `src/pkg/github/client.go:4780-4790`, descending `AgeMinutes` within each tier). + (`RankActionableIssues`, `src/pkg/github/client.go:4786-4796`, descending `AgeMinutes` within each tier). - PRs are sorted by **review class then oldest-first within class** (`SortPullRequestsForReview`, `src/pkg/github/review_priority.go:334`; fixes → refactors/docs → tests). diff --git a/src/pkg/dashboard/overview_kpi_values_10139_test.go b/src/pkg/dashboard/overview_kpi_values_10139_test.go index b550ab7e61..da175a96a1 100644 --- a/src/pkg/dashboard/overview_kpi_values_10139_test.go +++ b/src/pkg/dashboard/overview_kpi_values_10139_test.go @@ -65,6 +65,8 @@ const OVERVIEW_PR_BREAKDOWN_LABELS = { hold: 'held', draft: 'draft', filtered: ' ` + jsFunc(t, html, "overviewOutsideBreakdownText") + ` ` + jsFunc(t, html, "overviewStaleSince") + ` ` + jsFunc(t, html, "fmtOverviewStaleSince") + ` +` + jsFunc(t, html, "overviewRestartRefresh") + ` +` + jsFunc(t, html, "overviewStaleBadgeText") + ` ` + jsFunc(t, html, "relativeTimeShort") + ` ` + jsFunc(t, html, "renderOverviewTotalPartitionSubline") + ` ` + jsFunc(t, html, "renderOverviewSplitSubline") + ` diff --git a/src/pkg/dashboard/overview_restart_refresh_test.go b/src/pkg/dashboard/overview_restart_refresh_test.go new file mode 100644 index 0000000000..679901663b --- /dev/null +++ b/src/pkg/dashboard/overview_restart_refresh_test.go @@ -0,0 +1,156 @@ +package dashboard + +import ( + "os/exec" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/governor" +) + +// After a restart the governor serves the snapshot it restored from disk, +// marked stale, until its first enumeration completes. The status must say +// that is a restart window (restartRefresh with this process's clock and +// the scan tally), not merely "stale since ", and +// the marker must clear the moment a fresh enumeration publishes. +func TestRestartRefreshInfo_StaleToFreshAcrossRestart(t *testing.T) { + cfg := &config.Config{ + Project: config.ProjectConfig{Org: "myorg", Repos: []string{"repo1", "repo2", "repo3"}}, + } + previousRead := time.Date(2026, 10, 28, 21, 15, 0, 0, time.UTC) + restartedAt := time.Date(2026, 10, 28, 22, 56, 33, 0, time.UTC) + + // 1. Boot: the restored snapshot is a previous process's read. + restored := &github.ActionableResult{ + GeneratedAt: previousRead, + TotalByRepo: map[string]github.RepoCounts{ + "repo1": {Issues: 16, PRs: 20}, + "repo2": {Issues: 1}, + "repo3": {PRs: 2}, + }, + } + restored.MarkAllStale() + restored.RestoredAt = restartedAt + repos := buildRepos(cfg, restored, governor.State{}) + rr := restartRefreshInfo(restored, repos) + if rr == nil { + t.Fatal("restored snapshot must report the restart window") + } + if rr.RestoredAt != "2026-10-28T22:56:33Z" { + t.Fatalf("RestoredAt = %q, want this process's restore time", rr.RestoredAt) + } + if rr.SnapshotAt != "2026-10-28T21:15:00Z" { + t.Fatalf("SnapshotAt = %q, want the previous read time", rr.SnapshotAt) + } + if rr.ReposScanned != 0 || rr.ReposTotal != 3 { + t.Fatalf("scan tally = %d/%d, want 0/3 before the first enumeration", rr.ReposScanned, rr.ReposTotal) + } + if got := staleSinceRFC3339(restored); got != "2026-10-28T21:15:00Z" { + t.Fatalf("staleSinceRFC3339 = %q, want the previous read time kept as the raw marker", got) + } + + // 2. A whole-pass failure on the restored snapshot keeps the window: + // still the restored copy, still no fresh repo. + kept := restored.Clone() + kept.MarkAllStale() + if rr := restartRefreshInfo(kept, buildRepos(cfg, kept, governor.State{})); rr == nil || rr.RestoredAt != "2026-10-28T22:56:33Z" { + t.Fatalf("a re-marked restored snapshot must keep the restart window, got %+v", rr) + } + + // 3. The first enumeration publishes a fresh result (no RestoredAt): + // the window closes with the stale marker. + fresh := &github.ActionableResult{ + GeneratedAt: restartedAt.Add(10 * time.Minute), + TotalByRepo: map[string]github.RepoCounts{ + "repo1": {Issues: 23, PRs: 19}, + "repo2": {Issues: 1}, + "repo3": {PRs: 2}, + }, + } + freshRepos := buildRepos(cfg, fresh, governor.State{}) + if rr := restartRefreshInfo(fresh, freshRepos); rr != nil { + t.Fatalf("fresh enumeration must clear the restart window, got %+v", rr) + } + if staleSinceRFC3339(fresh) != "" || overviewStaleSince(freshRepos) != "" { + t.Fatal("fresh enumeration must carry no stale marker") + } + + // 4. A later refusal on the fresh process is an ordinary stale window, + // not a restart one: RestoredAt is gone with the restored snapshot. + refused := fresh.Clone() + refused.MarkAllStale() + if rr := restartRefreshInfo(refused, buildRepos(cfg, refused, governor.State{})); rr != nil { + t.Fatalf("post-restart refusal must not claim a restart window, got %+v", rr) + } + + // 5. Partial progress: a restored snapshot with some repos already + // re-read counts them as scanned. + partial := restored.Clone() + partial.StaleRepos = []string{"repo2"} + if rr := restartRefreshInfo(partial, buildRepos(cfg, partial, governor.State{})); rr == nil || rr.ReposScanned != 2 || rr.ReposTotal != 3 { + t.Fatalf("partial scan tally = %+v, want 2/3", rr) + } +} + +// The Overview badge reads "refreshing after restart () · N/M repos +// scanned · showing snapshot from " in the restart window, and falls +// back to "stale since · serving last-good" for an ordinary refusal. +func TestOverviewStaleBadgeWordsRestartWindow(t *testing.T) { + node, err := exec.LookPath("node") + if err != nil { + t.Skip("node unavailable: Overview restart badge rule was not executed") + } + html := indexHTML(t) + script := overviewKPIRenderPrelude(t, html) + ` +const pillEl = () => document.getElementById('overview-sidebar-badge'); +const state = { showKPIs: true }; +const issueSlices = [], prSlices = []; +const repos = [{ name: 'hivecommons/hive', issues: 16, prs: 20 }]; +_overviewLastRepos = repos; +const snapshotAt = new Date(Date.now() - 100 * 60e3).toISOString(); +const restoredAt = new Date(Date.now() - 12 * 60e3).toISOString(); +window._lastStatus = { + repos, + overviewTotals: { issues: { forge: 16 }, prs: { forge: 20 } }, + staleSince: snapshotAt, + restartRefresh: { restoredAt, snapshotAt, reposScanned: 5, reposTotal: 10 }, +}; +let out = renderOverviewKPIs(repos, issueSlices, prSlices, state); +const badge = (out.match(/]*>([^<]*)<\/span>/) || [])[1] || ''; +assert.match(badge, /^⟳ refreshing after restart \(12m ago\) · 5\/10 repos scanned · showing snapshot from /, badge); +assert.doesNotMatch(badge, /stale since/, 'restart window must not read as stale since the previous pod'); +assert.doesNotMatch(badge, /1h ago/, 'the relative time is the restart, not the previous read'); +assert.match(out, /title="Hive restarted 12m ago and its first full scan/); +assert.match(pillEl().title, /\(refreshing after restart \(12m ago\) · 5\/10 repos scanned · showing snapshot from .+\)$/, pillEl().title); + +// The window closes: the server drops restartRefresh with staleSince. +delete window._lastStatus.restartRefresh; +delete window._lastStatus.staleSince; +out = renderOverviewKPIs(repos, issueSlices, prSlices, state); +assert.doesNotMatch(out, /overview-kpi-stale/); +assert.doesNotMatch(pillEl().title, /refreshing|stale/); + +// An ordinary refusal later keeps the old wording. +window._lastStatus.staleSince = snapshotAt; +out = renderOverviewKPIs(repos, issueSlices, prSlices, state); +assert.match(out, /⚠ stale since .+ \(1h ago\) · serving last-good" instead of showing zeros. Empty when fresh. StaleSince string `json:"staleSince,omitempty"` - Timestamp string `json:"timestamp"` - TimeZone string `json:"timeZone,omitempty"` + // RestartRefresh is set while StaleSince points at the snapshot this + // process restored from disk at startup, before its first enumeration + // completed. The Overview then says "refreshing after restart · N/M + // repos scanned · showing snapshot from " instead of "stale since + // ". Nil once a fresh enumeration publishes. + RestartRefresh *FrontendRestartRefresh `json:"restartRefresh,omitempty"` + Timestamp string `json:"timestamp"` + TimeZone string `json:"timeZone,omitempty"` // StatusSeq is a monotonic publish sequence (#4348): the frontend drops // any status payload whose seq is older than the last one it rendered, // so a stale in-flight poll/SSE response can never repaint over a newer @@ -1080,6 +1086,20 @@ type FrontendSession struct { Estimated bool `json:"estimated,omitempty"` } +// FrontendRestartRefresh describes the post-restart window in which the +// Overview serves the snapshot restored from disk (FrontendStatus.RestartRefresh). +type FrontendRestartRefresh struct { + // RestoredAt (RFC 3339) is when this process read the snapshot back. + RestoredAt string `json:"restoredAt"` + // SnapshotAt (RFC 3339) is when the restored snapshot was last read + // from GitHub by the previous process. + SnapshotAt string `json:"snapshotAt,omitempty"` + // ReposScanned is how many unpaused configured repos already have a + // fresh read this process; ReposTotal is the unpaused configured count. + ReposScanned int `json:"reposScanned"` + ReposTotal int `json:"reposTotal"` +} + type FrontendRepo struct { Name string `json:"name"` Full string `json:"full"` diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index ab3bbf7d7c..177247fec6 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -24199,6 +24199,35 @@

All labels

}); return earliest; } + /* Pure: the post-restart window the server reports while it still + serves the snapshot restored from disk (status.restartRefresh, + status_builder.go restartRefreshInfo). Null outside that window. */ + function overviewRestartRefresh() { + if (_overviewKPILocalScope !== 'all') return null; + const rr = window._lastStatus?.restartRefresh; + return rr && rr.restoredAt ? rr : null; + } + /* Pure: the stale badge's text and tooltip. During the post-restart + window the figures are not "stale since " — this + process restarted and its first full scan is still running — so the + badge says so with the process's own clock and the scan progress. */ + function overviewStaleBadgeText(staleSince, rr) { + if (rr) { + const ago = relativeTimeShort(rr.restoredAt); + const total = Number(rr.reposTotal || 0); + const scanned = Math.min(Number(rr.reposScanned || 0), total); + const snapAt = rr.snapshotAt || staleSince; + const text = `refreshing after restart${ago ? ` (${ago})` : ''}${total > 0 ? ` · ${scanned}/${total} repos scanned` : ''}${snapAt ? ` · showing snapshot from ${fmtOverviewStaleSince(snapAt)}` : ''}`; + const title = `Hive restarted${ago ? ` ${ago}` : ''} and its first full scan of every repo has not finished yet${total > 0 ? ` (${scanned} of ${total} repos read so far)` : ''}. Until it does, these figures are the snapshot the previous process saved${snapAt ? ` at ${fmtOverviewStaleSince(snapAt)}` : ''} plus webhook updates since; the scan clears this.`; + return { icon: '⟳', text, title }; + } + const ago = relativeTimeShort(staleSince); + return { + icon: '⚠', + text: `stale since ${fmtOverviewStaleSince(staleSince)}${ago ? ` (${ago})` : ''} · serving last-good`, + title: `GitHub refused the latest enumeration or count reconcile (rate limit or outage). These figures are the last successful read plus webhook updates since, as of ${fmtOverviewStaleSince(staleSince)}; the next enumeration or hourly reconcile clears this.` + }; + } function fmtOverviewStaleSince(ts) { if (typeof formatDashboardDateTime === 'function') return formatDashboardDateTime(ts, undefined, String(ts || '')); const t = new Date(ts || '').getTime(); @@ -24362,7 +24391,8 @@

All labels

} if (!state.showKPIs) return ''; if (snapshotComplete) overviewKPIRecordLocal(overviewKPICurrentSample(coverageCard ? cards.concat([coverageCard]) : cards)); - const staleBadge = staleSince ? `⚠ stale since ${esc(fmtOverviewStaleSince(staleSince))}${(() => { const ago = relativeTimeShort(staleSince); return ago ? ` (${esc(ago)})` : ''; })()} · serving last-good` : ''; + const staleText = staleSince ? overviewStaleBadgeText(staleSince, overviewRestartRefresh()) : null; + const staleBadge = staleText ? `${esc(staleText.icon)} ${esc(staleText.text)}` : ''; const unlistedBadge = unlisted.issues + unlisted.prs > 0 ? `+${unlisted.issues + unlisted.prs} not yet listed` : ''; // A repo listing open PRs but no issues while its issue side is // stale or unlisted (repos[].issuesSyncing) is a pending issue fetch, @@ -24388,7 +24418,7 @@

All labels

const issues = Number(openIssues) || 0; const prs = Number(openPRs) || 0; let title = equationLabel || `${issues} total open issues + ${prs} total open PRs`; - if (staleSince) title += ` (stale since ${fmtOverviewStaleSince(staleSince)} · serving last-good)`; + if (staleSince) title += ` (${overviewStaleBadgeText(staleSince, overviewRestartRefresh()).text})`; const syncing = overviewSyncingNote(unlisted); if (syncing) title += ` · ${syncing}`; const note = overviewUnlistedNote(unlisted); diff --git a/src/pkg/dashboard/status_builder.go b/src/pkg/dashboard/status_builder.go index d23422cc5b..fc509023a9 100644 --- a/src/pkg/dashboard/status_builder.go +++ b/src/pkg/dashboard/status_builder.go @@ -406,6 +406,7 @@ func BuildFrontendStatus( Repos: repos, OverviewKPIIncomplete: overviewKPIIncomplete(cfg, actionable) || overviewStaleSince(repos) != "", StaleSince: earliestRFC3339(staleSinceRFC3339(actionable), overviewStaleSince(repos)), + RestartRefresh: restartRefreshInfo(actionable, repos), Beads: BuildBeadsFromConfig(beadStores, cfg), Planning: BuildPlanning(beadStores, architectPausedFromStatuses(agentStatuses), detectACMMLevel(cfg)), Health: health, @@ -2249,6 +2250,34 @@ type forgeOpenCounter interface { OpenItems(repo string) (forgestate.Snapshot, bool) } +// restartRefreshInfo reports the post-restart window: the published +// snapshot is the one this process restored from disk (RestoredAt set, +// cmd/hive bootCollectors) and is still marked stale because no +// enumeration has replaced it. Nil otherwise, including once the first +// enumeration publishes a fresh result (which carries no RestoredAt), so +// the Overview's "refreshing after restart" wording clears with the stale +// badge. The repo tally counts unpaused configured repos whose counts are +// not stale, so the banner can say "N/M repos scanned". +func restartRefreshInfo(actionable *github.ActionableResult, repos []FrontendRepo) *FrontendRestartRefresh { + if actionable == nil || !actionable.Stale() || actionable.RestoredAt.IsZero() { + return nil + } + out := &FrontendRestartRefresh{RestoredAt: actionable.RestoredAt.UTC().Format(time.RFC3339)} + if !actionable.GeneratedAt.IsZero() { + out.SnapshotAt = actionable.GeneratedAt.UTC().Format(time.RFC3339) + } + for _, r := range repos { + if r.Paused { + continue + } + out.ReposTotal++ + if !r.CountsStale { + out.ReposScanned++ + } + } + return out +} + // overviewStaleSince is the earliest countsStaleSince over repos, or "" when // no repo is serving last-good counts. The Overview shows it as "stale since // " instead of zeros, and KPI history skips the snapshot. diff --git a/src/pkg/github/client.go b/src/pkg/github/client.go index ffd79f14d7..70dcb488a1 100644 --- a/src/pkg/github/client.go +++ b/src/pkg/github/client.go @@ -1136,6 +1136,12 @@ type ActionableResult struct { // StaleSince is the time the stale share of the result was last fetched // for real: the data is current as of then. Zero when nothing is stale. StaleSince time.Time `json:"stale_since,omitzero"` + // RestoredAt is when this process read the snapshot back from disk at + // startup (cmd/hive bootCollectors). Set only on that restored copy, so + // the dashboard can say "refreshing after restart" with the process's + // own clock instead of "stale since "; the first + // enumeration replaces the snapshot and the marker with it. + RestoredAt time.Time `json:"restored_at,omitzero"` // ItemPatches records, per item, when its copy was last read from GitHub // and (for a webhook-driven upsert) from which delivery, so an // irreversible action can bound its staleness and an operator can audit