diff --git a/changelog.d/added-rework-pickup-signal.md b/changelog.d/added-rework-pickup-signal.md new file mode 100644 index 0000000000..65dae07cc8 --- /dev/null +++ b/changelog.d/added-rework-pickup-signal.md @@ -0,0 +1 @@ +- Stage tracker: a PR row returned to its author (071 needs-author / 072 returned-to-contributor) now carries a `rework` pickup signal — requested / queued / acknowledged / working / re-review pending — on the waiting-on pill, its tooltip and the row event line, derived from the stage record, the PR list and the contributor fix queue with no extra GitHub calls. diff --git a/src/docs/api-reference.md b/src/docs/api-reference.md index ade562be9b..47f9354407 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:43` | | `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:44` | | `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:65` | -| `GET` | `/api/health` | Public | Basic health probe | `pkg/dashboard/server.go:1585` | -| `GET` | `/api/health/deep` | Public | Deep health probe | `pkg/dashboard/server.go:1586` | -| `GET` | `/api/livez` | Public | Kubernetes liveness probe | `pkg/dashboard/server.go:1587` | -| `GET` | `/metrics` | Registered only when `HIVE_METRICS_ENABLED`; requires `Authorization: ****** (403 if the token is unset) | Prometheus metrics | `pkg/dashboard/server.go:1593` | -| `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:1598` | -| `GET` | `/api/status/summary` | Dashboard auth/session | Compact agent/governor/budget status summary for pollers; honors `Accept-Encoding: gzip` | `pkg/dashboard/server.go:1599` | -| `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:1600` | -| `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:1601` | -| `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:1602` | -| `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:1603` | -| `GET` | `/api/events` | Dashboard auth/session | Server-sent event stream | `pkg/dashboard/server.go:1604` | +| `GET` | `/api/health` | Public | Basic health probe | `pkg/dashboard/server.go:1588` | +| `GET` | `/api/health/deep` | Public | Deep health probe | `pkg/dashboard/server.go:1589` | +| `GET` | `/api/livez` | Public | Kubernetes liveness probe | `pkg/dashboard/server.go:1590` | +| `GET` | `/metrics` | Registered only when `HIVE_METRICS_ENABLED`; requires `Authorization: ****** (403 if the token is unset) | Prometheus metrics | `pkg/dashboard/server.go:1596` | +| `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:1601` | +| `GET` | `/api/status/summary` | Dashboard auth/session | Compact agent/governor/budget status summary for pollers; honors `Accept-Encoding: gzip` | `pkg/dashboard/server.go:1602` | +| `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:1603` | +| `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:1604` | +| `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:1605` | +| `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:1606` | +| `GET` | `/api/events` | Dashboard auth/session | Server-sent event stream | `pkg/dashboard/server.go:1607` | | `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:45` | -| `GET` | `/branding/custom.css` | Dashboard auth/session | Operator branding stylesheet override, read per request (see [branding](branding.md)) | `pkg/dashboard/server.go:1665` | +| `GET` | `/branding/custom.css` | Dashboard auth/session | Operator branding stylesheet override, read per request (see [branding](branding.md)) | `pkg/dashboard/server.go:1668` | | `GET` | `/api/snapshot/frame-ancestors` | Public | Snapshot framing allowlist | `pkg/dashboard/api.go:78` | | `GET` | `/api/snapshot` | Public | Snapshot data | `pkg/dashboard/api.go:79` | | `GET` | `/snapshot` | Public | Public read-only snapshot page | `pkg/dashboard/api.go:80` | @@ -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:1605` | -| `POST` | `/api/github-app/install-clicked` | Dashboard auth/session | GitHub App Install Clicked | `pkg/dashboard/server.go:1606` | -| `GET` | `/gh-setup` | Public | GitHub App Setup Callback | `pkg/dashboard/server.go:1607` | +| `POST` | `/api/github-app/recheck` | Dashboard auth/session | GitHub App Recheck | `pkg/dashboard/server.go:1608` | +| `POST` | `/api/github-app/install-clicked` | Dashboard auth/session | GitHub App Install Clicked | `pkg/dashboard/server.go:1609` | +| `GET` | `/gh-setup` | Public | GitHub App Setup Callback | `pkg/dashboard/server.go:1610` | ## 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:1612` | +| `GET` | `/sso` | Public | SSO | `pkg/dashboard/server.go:1615` | ## Hub SaaS diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index 289254664a..9bc85e9edc 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -688,6 +688,8 @@ Fed by `GET /api/stage-tracker`. Every issue and pull request follows the same p **Presence indicator on the waiting-on pill.** Every PR row that waits on a named person — `stage/071-needs-author`, `stage/072-returned-to-contributor` (before and after the nudge), `stage/017-possibly-existing` on a PR — carries `presence{login, state: online|offline|unknown, kind: clanker|human, since, last_seen, next: wait|adopt, adopt_at}`, read from the contributor hub's live presence (registered profile + relay heartbeat: the same lookup adoption consults, so the indicator and the adoption text never disagree) and projected through adoption's own clock ([hivecommons/hive#15051](https://github.com/hivecommons/hive/issues/15051)). The pill draws it just before the `@login`: a filled **dot** (`--cue-decision`, a soft breathe; none under `prefers-reduced-motion`) when the person's clanker — their connected contributor agent — is online, tooltip "@Danathar's clanker: online, last seen 2 min ago — hive is waiting for them"; a filled **square** (`--status-error`) when it is offline, "@hanthor's clanker: offline 26h — hive will adopt at 15:10 (in 38m)" (or "— hive is waiting for them" when `ask`/`never`/adoption-off holds the clock); a **hollow ring** when no clanker is registered here, "@zoe: no clanker registered — waiting for a human reply" with the pill reading `waiting on @zoe (human · no clanker)`. Shape, not colour alone, carries the state; the indicator has its own `aria-label` ("@hanthor: clanker offline — hive will adopt at …"). A row with presence but no adoption line (071, a 072 not yet nudged, a human's PR) gets a muted `waiting on @login` pill carrying the indicator; a nudged 072 row keeps its single amber adoption pill with the indicator inside it. The Needs-human popover shows the same line under the question when the waiting person is named, a per-PR sub-row under an issue mirrors it, and the row tooltip adds a `Presence:` line. It refreshes with the tracker like every other pill. +**Rework pickup on the waiting-on pill.** The same 071 / 072 rows also carry `rework{state: requested|acknowledged|in_progress|pushed, actor, requested_at, since, evidence: queued|claim|activity|commit, mode, ahead, head}` — whether the person the row waits on has picked up the rework the hive (or a human reviewer) asked for ([hivecommons/hive#15280](https://github.com/hivecommons/hive/issues/15280): "waiting on @x" said who, never whether anything had happened since). It is derived from data the tracker already holds, no extra GitHub calls: `requested_at` is the first nudge the contributor engine recorded on the current head (`stage/072`) or, before any nudge, when the row entered the stage (`stage/071` after a human's changes-requested review); **pushed** when the PR's head is no longer the head the request named (`evidence: commit` — the stage engine routes the row back to `050` on its next sweep, the pill says `re-review pending` meanwhile); **in_progress** when the author's clanker relay — or, after a Reroute, the target's — has taken the `fix-pr` task from the contributor fix queue (`evidence: claim`, `mode` spawn/preempt/boundary, `since` the dispatch); **acknowledged** when the PR's `updated_at` moved after the request and after the hive's own nudge comment (`evidence: activity` — a reply, a review-thread answer, an edit; reactions do not bump it, so an 👀 alone is not seen); otherwise **requested**, with `evidence: queued` and `ahead` when the fix is enqueued on the clanker's hub queue but not yet dispatched. The pill appends the state after the login — `waiting on @x · no response`, `· queued`, `· acknowledged`, `· working`, `· re-review pending` — and its tooltip (and the row tooltip's `Rework:` line) says since when: "rework requested 1 hour ago (13:32 UTC) · no response from @x yet", "@x acknowledged · activity on the PR 20 min ago", "@x's clanker picked up the rework 5 min ago (spawn)", "@x pushed a new head 1 min ago · re-review pending". A state change at an unchanged stage writes the row's event line ("@x acknowledged the rework request", "@x's clanker picked up the rework", "@x pushed a new head — re-review pending"). The presence indicator stays; a nested per-PR row under an issue mirrors the field. + **Adopt now / Reroute (072, 071).** Every `author/clanker` pull request waiting on its author's hive — `stage/072-returned-to-contributor` or `stage/071-needs-author`, not yet adopted — also carries `takeover{author, author_online, adopt_now, adopt_now_reason, reroute, reroute_reason, clankers[], rerouted, forced_by, forced_at, fallback_at, grace_elapsed}`, and the ⋯ row menu (and the nested per-PR row under an issue) gains two operator actions beyond Hold / Re-evaluate / Mark needs-human / Open / Copy ([hivecommons/hive#15038](https://github.com/hivecommons/hive/pull/15038): "Returned to contributor · waiting on @Danathar" offered nothing to end the wait). **Adopt now — hive takes it over** (`decide:adopt-now`) carries the consequence line *closes the contributor's PR after hive opens its copy; their commits + sign-off are preserved* under the label, asks an in-app confirm (don't-ask-again supported, keyed `hive.tracker.confirm.decide:adopt-now`; the confirm adds "its hive is online right now" when it is) and POSTs `{"decision":"adopt","force":true}`: the hive posts an attributed `` note, sets `adoption/supersede`, marks the stage record forced and nudges the sweep, which runs the existing supersede adoption at once — presence, the grace windows and `maintainer_policy` are all bypassed (`hold` still stops it; the menu says *release the hold first*). The persistent result toast reads `Adopted → #N (hive's copy), contributor PR will close when #N merges` when the sweep lands inside the handler's wait, else `Adoption forced: hive opens its copy on the pass now running`; the audit entry is `repo_item_decision_adopt_now` with `action=adopt-now`. **Reroute to another clanker** (`decide:reroute`) opens a submenu of the currently-online registered contributor clankers from the contributor fleet (`@login · hive · online 12m ago · 1 in hand` / `idle`, via `clankers[]` — the same facts as `/api/contribute/fleet`) plus *any available (N online)*; in the Needs-human popover it is a required choice list. The pick (after a confirm keyed `hive.tracker.confirm.decide:reroute`) POSTs `{"decision":"reroute","to":"|any"}`: the hive enqueues the PR's follow-up work (the stage record's return reason — the failing check or the reviewer's requested changes — plus the operator's comment) on the target's contributor fix queue and dispatches it as a `fix-pr` `task_assign` interrupt, the same path the 072 nudge takes to the author's own relay; the task's instruction says whose PR it is and that the target either pushes the fix (if the branch allows) or opens a replacement PR carrying the author's commits and sign-off. The author is told by ``, the row shows a `rerouted → @X` pill with a presence dot (green while the target's relay is on the hub), and the toast reads `Rerouted → @X (dispatched now, preempt)` / `(queued; N ahead)`. If the target's relay has not taken the task within `governor.reroute.pickup_timeout` (default 30m) the hive falls back to Adopt now by itself: the queued item is withdrawn, the record marks the forced adoption, a `lapsed=true` note goes on the PR, a warning system alert and a `repo_item_reroute_fallback` audit entry are raised, and the sweep is nudged. With no clanker online the item is disabled with the reason *no clankers online — use Adopt now*. Both actions appear in the Needs-human popover's options when the blocker is a waiting-on-contributor condition — once the nudge grace has elapsed and the engine is not adopting on its own, the row carries `decision_needed` (`blocker_reason: adoption:`, options Adopt now, Reroute, Hold) — and **Let hive decide** picks Adopt now (`grace-elapsed-adopt-now`) when the grace has already run out. Write access required. **Blocked pill.** An issue wearing `blocked` because the hive parked it on a pull request — its body carries `` (the review backlog's spin-off issues, `hive-open-issue comment --blocked-on-pr`) — names that PR: the payload carries `blocked_on_pr: {repo, number, url, state}`, the pill reads `blocked on #N` and links to the PR, its tooltip says `Blocked on PR owner/repo#N (open) — lifts when it merges; re-triage if closed unmerged`, the caption reads `Blocked on PR #N — lifts when it merges` instead of `No stage recorded yet`, and the row's title and chevron tooltip carry the blocker too ([#14952](https://github.com/hivecommons/hive/issues/14952): #14863 showed a bare grey pill and "blocked · since 7h" with nothing to say what it waited on). The state (`open`, `merged`, `closed`, or absent when nothing knows) comes only from what the hive already holds — the status snapshot's open PRs, the ForgeState cache, the recent-merge ring — never a GitHub call from the tracker build; a merged or closed-unmerged blocker says so (`merged; the blocked sweep lifts the label next` / `closed unmerged; the blocked sweep re-triages it next`). The server reads the marker from the issue body when it has one, else from the enumeration's `blocked on owner/repo#N` reason, so sidelined rows (which carry only the reason) name it too. A `blocked` issue with neither (a human-applied label) keeps the bare pill. This is distinct from `blocked_on`, the open GitHub "blocked by" dependencies of a sequenced sub-issue ([#14765](https://github.com/hivecommons/hive/issues/14765)); when a row has both, the chevron tooltip lists them together. diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index b0b5beaba1..84a0f8ab6f 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -741,7 +741,14 @@ audit entry; with no clanker online the Reroute item is disabled ("no clankers online — use Adopt now"). Both are also options in the Needs-human popover once the nudge grace has elapsed, and "Let hive decide" picks Adopt now then (hivecommons/hive#15038; -[dashboard-sections.md](dashboard-sections.md#hive-activity-monitor)). When the +[dashboard-sections.md](dashboard-sections.md#hive-activity-monitor)). While +the row waits at 071 / 072 its waiting-on pill also says whether the rework +has been picked up — `· no response`, `· queued` (on the clanker's fix queue, +N ahead), `· acknowledged` (activity on the PR after the request), +`· working` (the clanker relay took the `fix-pr` task), `· re-review pending` +(a new head, routed back to 050 on the next sweep) — from the stage record, +the PR list and the fix queue the tracker already holds, with no extra +GitHub calls (hivecommons/hive#15280). When the PR allows maintainer edits (`adoption.in_place`, default on) the hive adopts it in place: `stage/074-adopted-by-hive`, the PR's own branch filed in `ci-failing.json` as the hive's (`adopted: true`) for the scanner's red-PR diff --git a/src/pkg/dashboard/contribute_fixqueue.go b/src/pkg/dashboard/contribute_fixqueue.go index 3490139746..787f819da1 100644 --- a/src/pkg/dashboard/contribute_fixqueue.go +++ b/src/pkg/dashboard/contribute_fixqueue.go @@ -659,6 +659,34 @@ func (h *ContributeWSHub) FixQueueItems(username string) []fixqueue.Item { return h.fixQueue().Queued(username) } +// FixWorkFor reports where the fix work for repo#number stands in +// username's fix queue: waiting behind other fixes (Queued, with how many +// are ahead) or handed to their relay as a fix-pr task (InFlight, with when +// and in which mode). The stage tracker reads it as the rework-pickup +// signal on a waiting-on row (hivecommons/hive#15280). ok is false when the +// PR is in neither. +func (h *ContributeWSHub) FixWorkFor(username, repo string, number int) (StageTrackerFixWork, bool) { + username = strings.TrimSpace(username) + if h == nil || username == "" || repo == "" || number <= 0 { + return StageTrackerFixWork{}, false + } + key := fixqueue.Key(repo, number) + sched := h.fixQueue() + for _, d := range sched.InFlight(username) { + for _, it := range d.Items { + if it.Key() == key { + return StageTrackerFixWork{InFlight: true, DispatchedAt: d.At, Mode: string(d.Mode)}, true + } + } + } + for i, it := range sched.Queued(username) { + if it.Key() == key { + return StageTrackerFixWork{Queued: true, QueuedAt: it.EnqueuedAt, Ahead: i}, true + } + } + return StageTrackerFixWork{}, false +} + // ContributorFixQueue is the profile-API view of a contributor's fix budget. type ContributorFixQueue struct { fixqueue.Status diff --git a/src/pkg/dashboard/server.go b/src/pkg/dashboard/server.go index f268ac97cc..a030161790 100644 --- a/src/pkg/dashboard/server.go +++ b/src/pkg/dashboard/server.go @@ -124,6 +124,9 @@ type Server struct { // presenceLookup overrides the contribute hub as the tracker's author // presence source for 072 rows (stage_tracker_adoption.go); tests only. presenceLookup func(login string) (automerge.ContributorPresence, bool) + // fixWorkLookup overrides the contribute hub as the tracker's fix-queue + // source for the rework-pickup signal (stage_tracker_rework.go); tests only. + fixWorkLookup func(login, repo string, number int) (StageTrackerFixWork, bool) // sweepState overrides the automerge lanes' live sweep state for the // tracker's merge-gate rows (stage_tracker_merge_gate.go); tests only. sweepState func() automerge.SweepState diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index e0fdf711b7..e7137d2a5d 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -456,6 +456,11 @@ type StageTrackerItem struct { // hive's likely next move (wait or adopt, with the adopt-at time), so // the waiting-on pill can carry an indicator (hivecommons/hive#15051). Presence *StageTrackerPresence `json:"presence,omitempty"` + // Rework is, on a PR row returned to its author (071 / 072), whether + // the rework request has been picked up: requested, acknowledged, + // in_progress or pushed, with the evidence (hivecommons/hive#15280, + // stage_tracker_rework.go). + Rework *StageTrackerRework `json:"rework,omitempty"` // Takeover is, on a 072 / 071 clanker PR, the operator's Adopt now / // Reroute offer and any pending reroute or forced adoption // (hivecommons/hive#15038, stage_tracker_takeover.go). @@ -600,6 +605,8 @@ type StageTrackerLinkedPR struct { DrawnUnder int `json:"drawn_under,omitempty"` // Presence mirrors the nested PR's own row field (hivecommons/hive#15051). Presence *StageTrackerPresence `json:"presence,omitempty"` + // Rework mirrors the nested PR's own row field (hivecommons/hive#15280). + Rework *StageTrackerRework `json:"rework,omitempty"` // Takeover mirrors the nested PR's own row field (hivecommons/hive#15038). Takeover *StageTrackerTakeover `json:"takeover,omitempty"` // Supersedes mirrors the nested PR's own row field. @@ -1844,6 +1851,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto return store.Get(stagelabels.Key(repo, number)) } presence, maintainerPolicy := s.stageTrackerPresence(), s.stageTrackerMaintainerPolicy() + fixWork := s.stageTrackerFixWorkLookup() sweep := s.stageTrackerSweepState() soakWindow := s.stageTrackerSoakWindow() attempts := s.stageTrackerMergeAttempts() @@ -1943,6 +1951,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto } if login := stageTrackerWaitingOn(*it, stage); login != "" { it.Presence = stageTrackerPresenceFor(*it, login, stage, rec, hasRec, presence, adoptionClock, now) + it.Rework = stageTrackerReworkFor(*it, login, stage, rec, hasRec, fixWork, now) } if it.Takeover = stageTrackerTakeover(*it, rec, hasRec, presence, rerouteCandidates, adoptionEnabled, takeoverGrace, now); it.Takeover != nil { it.Caption = stageTrackerTakeoverCaption(it.Caption, it.Takeover) @@ -2895,6 +2904,7 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem, open func(repo strin lp.SentinelAlert, lp.SentinelReason, lp.Head = pr.SentinelAlert, pr.SentinelReason, pr.Head lp.Adoption = pr.Adoption lp.Presence = pr.Presence + lp.Rework = pr.Rework lp.Takeover = pr.Takeover lp.Supersedes = pr.Supersedes lp.HumanApprover, lp.ManualMerge = pr.HumanApprover, pr.ManualMerge diff --git a/src/pkg/dashboard/stage_tracker_rework.go b/src/pkg/dashboard/stage_tracker_rework.go new file mode 100644 index 0000000000..6cf2195761 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_rework.go @@ -0,0 +1,185 @@ +package dashboard + +import ( + "strings" + "time" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// Rework pickup on a waiting-on row (hivecommons/hive#15280): when a PR is +// returned to its author (071 Needs author for a human, 072 Returned to +// contributor for a clanker PR), the waiting-on pill said who the hive +// waits on and whether their clanker was online — nothing about whether +// anyone had picked the request up. The operator's question: "how can I +// know when the clanker or the author has started the rework?" The row's +// `rework` field answers from data the tracker already holds, never a +// fresh GitHub call: the stage record (when the request went out and for +// which head), the hub's fix queue (the clanker's relay was handed the fix +// task, or it waits in their queue), the PR list payload (updated_at, +// head) — in that order of confidence. + +// Rework states and evidence on the wire. +const ( + reworkStateRequested = "requested" + reworkStateAcknowledged = "acknowledged" + reworkStateInProgress = "in_progress" + reworkStatePushed = "pushed" + + // reworkEvidenceQueued: the fix waits in the clanker's hub queue behind + // other fixes (still "requested": nobody has it in hand yet). + reworkEvidenceQueued = "queued" + // reworkEvidenceClaim: the clanker's relay took the fix-pr task. + reworkEvidenceClaim = "claim" + // reworkEvidenceActivity: the PR's updated_at moved after the request + // and after the hive's own last word — a comment or an edit by someone + // (the list payload cannot say who). + reworkEvidenceActivity = "activity" + // reworkEvidenceCommit: the PR head is no longer the one the request + // named. + reworkEvidenceCommit = "commit" + + // reworkActivitySlack is how far past the request (or the hive's own + // nudge comment) updated_at must move before it counts as somebody + // else's activity: the hive's label writes and nudge comment bump + // updated_at themselves, within seconds of the record's timestamps. + reworkActivitySlack = 2 * time.Minute +) + +// StageTrackerRework is the `rework` field of a row returned to its author. +type StageTrackerRework struct { + // State is requested (sent, nobody has acted), acknowledged (activity on + // the PR since), in_progress (the clanker's relay holds the fix task) + // or pushed (a new head is up; re-review pending). + State string `json:"state"` + // Actor is who the signal is about: the author, or the clanker an + // operator rerouted the fix to. + Actor string `json:"actor"` + // RequestedAt is when the request went out: the first nudge / 071 note + // when one was posted, else when the row entered the stage. + RequestedAt *time.Time `json:"requested_at,omitempty"` + // Since is when the current state began (absent when unknown). + Since *time.Time `json:"since,omitempty"` + // Evidence names what the state rests on: queued, claim, activity, commit. + Evidence string `json:"evidence,omitempty"` + // Mode is the fix dispatch mode on a claim (spawn / preempt / boundary). + Mode string `json:"mode,omitempty"` + // Ahead is how many fixes wait before this one in the clanker's queue. + Ahead int `json:"ahead,omitempty"` + // Head is the new head on a pushed state. + Head string `json:"head,omitempty"` +} + +// StageTrackerFixWork is the hub's fix-queue standing for one PR and one +// contributor (ContributeWSHub.FixWorkFor). +type StageTrackerFixWork struct { + Queued bool + QueuedAt time.Time + Ahead int + InFlight bool + DispatchedAt time.Time + Mode string +} + +// stageTrackerFixWorkLookup is the live fix-queue lookup the tracker uses: +// the contribute hub when the server has one. Tests inject fixWorkLookup. +func (s *Server) stageTrackerFixWorkLookup() func(login, repo string, number int) (StageTrackerFixWork, bool) { + if s == nil { + return nil + } + if s.fixWorkLookup != nil { + return s.fixWorkLookup + } + if s.contributeHub == nil { + return nil + } + hub := s.contributeHub + return hub.FixWorkFor +} + +// stageTrackerReworkFor derives the `rework` field for a PR row waiting on +// login at stage (071 / 072 only). rec is the row's stage record; fixWork +// is the hub's fix-queue lookup (nil when the server has none). +func stageTrackerReworkFor(it StageTrackerItem, login string, stage stagelabels.Stage, rec stagelabels.Record, hasRec bool, fixWork func(login, repo string, number int) (StageTrackerFixWork, bool), now time.Time) *StageTrackerRework { + if login == "" || it.Kind != "pr" || !hasRec { + return nil + } + if stage != stagelabels.NeedsAuthor && stage != stagelabels.ReturnedToContributor { + return nil + } + requested := rec.NudgeStart() + if requested.IsZero() { + requested = rec.EnteredAt + } + if requested.IsZero() { + return nil + } + out := &StageTrackerRework{State: reworkStateRequested, Actor: login} + t := requested + out.RequestedAt = &t + // A rerouted fix is another clanker's to pick up while the reroute + // stands on this head. + actors := []string{login} + if to := strings.TrimSpace(rec.RerouteTo); to != "" && !strings.EqualFold(to, login) && (rec.RerouteHead == "" || rec.RerouteHead == it.Head) { + actors = append(actors, to) + } + // Pushed: the head the request named is gone. The stage engine routes + // the row back to 050 on its next sweep; until then the row says so. + if rec.NudgeHead != "" && it.Head != "" && it.Head != rec.NudgeHead { + out.State, out.Evidence, out.Head = reworkStatePushed, reworkEvidenceCommit, it.Head + if it.UpdatedAt != nil && it.UpdatedAt.After(requested) { + u := *it.UpdatedAt + out.Since = &u + } + return out + } + if fixWork != nil { + var queued *StageTrackerFixWork + var queuedActor string + for _, actor := range actors { + w, ok := fixWork(actor, it.Repo, it.Number) + if !ok { + continue + } + if w.InFlight { + out.State, out.Evidence, out.Actor, out.Mode = reworkStateInProgress, reworkEvidenceClaim, actor, w.Mode + if !w.DispatchedAt.IsZero() { + d := w.DispatchedAt + out.Since = &d + } + return out + } + if w.Queued && queued == nil { + wc := w + queued, queuedActor = &wc, actor + } + } + if queued != nil { + out.Evidence, out.Actor, out.Ahead = reworkEvidenceQueued, queuedActor, queued.Ahead + if !queued.QueuedAt.IsZero() { + q := queued.QueuedAt + out.Since = &q + } + } + } + // Acknowledged: the PR moved after the request and after the hive's own + // last comment on it — somebody replied or edited. + if it.UpdatedAt != nil { + floor := requested + if rec.LastNudgeAt.After(floor) { + floor = rec.LastNudgeAt + } + if rec.EnteredAt.After(floor) { + floor = rec.EnteredAt + } + if u := *it.UpdatedAt; u.After(floor.Add(reworkActivitySlack)) && !u.After(now.Add(reworkActivitySlack)) { + out.State, out.Evidence, out.Mode, out.Ahead = reworkStateAcknowledged, reworkEvidenceActivity, "", 0 + out.Since = &u + return out + } + } + if out.Since == nil { + out.Since = out.RequestedAt + } + return out +} diff --git a/src/pkg/dashboard/stage_tracker_rework_test.go b/src/pkg/dashboard/stage_tracker_rework_test.go new file mode 100644 index 0000000000..d4f60930cc --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_rework_test.go @@ -0,0 +1,249 @@ +package dashboard + +import ( + "encoding/json" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/github/automerge" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// hivecommons/hive#15280: a PR row returned to its author (071 / 072) +// carries `rework` — whether the request has been picked up: requested, +// acknowledged (activity on the PR after the request), in_progress (the +// clanker's relay claimed the fix) or pushed (the head moved; 050 next +// sweep) — from the stage record, the PR list and the hub fix queue the +// tracker already has. No extra GitHub calls. + +func TestStageTrackerReworkFor(t *testing.T) { + now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC) + requested := now.Add(-time.Hour) + tp := func(d time.Duration) *time.Time { v := now.Add(d); return &v } + pr := func(head string, updated *time.Time) StageTrackerItem { + return StageTrackerItem{Kind: "pr", Repo: "hivecommons/hive", Number: 42, Head: head, UpdatedAt: updated} + } + nudged := stagelabels.Record{Stage: stagelabels.ReturnedToContributor, EnteredAt: requested.Add(-time.Minute), NudgeHead: "aaa", FirstNudgeAt: requested, LastNudgeAt: requested, NudgeCount: 1} + none := func(string, string, int) (StageTrackerFixWork, bool) { return StageTrackerFixWork{}, false } + inflight := func(login, repo string, n int) (StageTrackerFixWork, bool) { + if login != "zoe" || repo != "hivecommons/hive" || n != 42 { + return StageTrackerFixWork{}, false + } + return StageTrackerFixWork{InFlight: true, DispatchedAt: now.Add(-5 * time.Minute), Mode: "spawn"}, true + } + queued := func(login, repo string, n int) (StageTrackerFixWork, bool) { + return StageTrackerFixWork{Queued: true, QueuedAt: now.Add(-10 * time.Minute), Ahead: 2}, login == "zoe" + } + rerouted := func(login, repo string, n int) (StageTrackerFixWork, bool) { + return StageTrackerFixWork{InFlight: true, DispatchedAt: now.Add(-2 * time.Minute), Mode: "preempt"}, login == "kai" + } + + cases := []struct { + name string + it StageTrackerItem + login string + stage stagelabels.Stage + rec stagelabels.Record + hasRec bool + fixWork func(string, string, int) (StageTrackerFixWork, bool) + wantNil bool + state string + evidence string + actor string + since time.Time + ahead int + mode string + head string + reqAtFrom time.Time + }{ + {name: "not a returned stage", it: pr("aaa", nil), login: "zoe", stage: stagelabels.ReviewPending, rec: nudged, hasRec: true, fixWork: none, wantNil: true}, + {name: "nobody waited on", it: pr("aaa", nil), login: "", stage: stagelabels.NeedsAuthor, rec: nudged, hasRec: true, fixWork: none, wantNil: true}, + {name: "issue row", it: StageTrackerItem{Kind: "issue", Repo: "hivecommons/hive", Number: 42}, login: "zoe", stage: stagelabels.NeedsAuthor, rec: nudged, hasRec: true, fixWork: none, wantNil: true}, + {name: "no record", it: pr("aaa", nil), login: "zoe", stage: stagelabels.NeedsAuthor, hasRec: false, fixWork: none, wantNil: true}, + {name: "requested, nothing moved", it: pr("aaa", tp(-90*time.Minute)), login: "zoe", stage: stagelabels.ReturnedToContributor, rec: nudged, hasRec: true, fixWork: none, + state: "requested", actor: "zoe", since: requested, reqAtFrom: requested}, + {name: "hive's own nudge comment is not an ack", it: pr("aaa", tp(-59*time.Minute)), login: "zoe", stage: stagelabels.ReturnedToContributor, rec: nudged, hasRec: true, fixWork: none, + state: "requested", actor: "zoe", since: requested, reqAtFrom: requested}, + {name: "071 without a nudge dates from stage entry", it: pr("aaa", nil), login: "zoe", stage: stagelabels.NeedsAuthor, + rec: stagelabels.Record{Stage: stagelabels.NeedsAuthor, EnteredAt: now.Add(-20 * time.Minute)}, hasRec: true, fixWork: nil, + state: "requested", actor: "zoe", since: now.Add(-20 * time.Minute), reqAtFrom: now.Add(-20 * time.Minute)}, + {name: "activity after the request acknowledges", it: pr("aaa", tp(-30*time.Minute)), login: "zoe", stage: stagelabels.ReturnedToContributor, rec: nudged, hasRec: true, fixWork: none, + state: "acknowledged", evidence: "activity", actor: "zoe", since: now.Add(-30 * time.Minute), reqAtFrom: requested}, + {name: "activity after a later re-nudge still counts from the re-nudge", it: pr("aaa", tp(-30*time.Minute)), login: "zoe", stage: stagelabels.ReturnedToContributor, + rec: stagelabels.Record{Stage: stagelabels.ReturnedToContributor, EnteredAt: requested, NudgeHead: "aaa", FirstNudgeAt: requested, LastNudgeAt: now.Add(-29 * time.Minute), NudgeCount: 2}, hasRec: true, fixWork: none, + state: "requested", actor: "zoe", since: requested, reqAtFrom: requested}, + {name: "future updated_at is clock skew, not an ack", it: pr("aaa", tp(10*time.Minute)), login: "zoe", stage: stagelabels.ReturnedToContributor, rec: nudged, hasRec: true, fixWork: none, + state: "requested", actor: "zoe", since: requested, reqAtFrom: requested}, + {name: "queued in the clanker's hub queue", it: pr("aaa", nil), login: "zoe", stage: stagelabels.ReturnedToContributor, rec: nudged, hasRec: true, fixWork: queued, + state: "requested", evidence: "queued", actor: "zoe", since: now.Add(-10 * time.Minute), ahead: 2, reqAtFrom: requested}, + {name: "clanker claimed the fix", it: pr("aaa", tp(-30*time.Minute)), login: "zoe", stage: stagelabels.ReturnedToContributor, rec: nudged, hasRec: true, fixWork: inflight, + state: "in_progress", evidence: "claim", actor: "zoe", since: now.Add(-5 * time.Minute), mode: "spawn", reqAtFrom: requested}, + {name: "rerouted fix claimed by the other clanker", it: pr("aaa", nil), login: "zoe", stage: stagelabels.ReturnedToContributor, + rec: stagelabels.Record{Stage: stagelabels.ReturnedToContributor, EnteredAt: requested, NudgeHead: "aaa", FirstNudgeAt: requested, LastNudgeAt: requested, NudgeCount: 1, RerouteTo: "kai", RerouteHead: "aaa"}, hasRec: true, fixWork: rerouted, + state: "in_progress", evidence: "claim", actor: "kai", since: now.Add(-2 * time.Minute), mode: "preempt", reqAtFrom: requested}, + {name: "stale reroute on an older head is ignored", it: pr("aaa", nil), login: "zoe", stage: stagelabels.ReturnedToContributor, + rec: stagelabels.Record{Stage: stagelabels.ReturnedToContributor, EnteredAt: requested, NudgeHead: "aaa", FirstNudgeAt: requested, LastNudgeAt: requested, NudgeCount: 1, RerouteTo: "kai", RerouteHead: "000"}, hasRec: true, fixWork: rerouted, + state: "requested", actor: "zoe", since: requested, reqAtFrom: requested}, + {name: "new head pushed", it: pr("bbb", tp(-3*time.Minute)), login: "zoe", stage: stagelabels.ReturnedToContributor, rec: nudged, hasRec: true, fixWork: inflight, + state: "pushed", evidence: "commit", actor: "zoe", since: now.Add(-3 * time.Minute), head: "bbb", reqAtFrom: requested}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + got := stageTrackerReworkFor(tc.it, tc.login, tc.stage, tc.rec, tc.hasRec, tc.fixWork, now) + if tc.wantNil { + if got != nil { + t.Fatalf("rework = %+v, want nil", got) + } + return + } + if got == nil { + t.Fatal("rework = nil") + } + if got.State != tc.state || got.Evidence != tc.evidence || got.Actor != tc.actor || got.Ahead != tc.ahead || got.Mode != tc.mode || got.Head != tc.head { + t.Fatalf("rework = %+v", got) + } + if got.RequestedAt == nil || !got.RequestedAt.Equal(tc.reqAtFrom) { + t.Fatalf("requested_at = %v, want %v", got.RequestedAt, tc.reqAtFrom) + } + if got.Since == nil || !got.Since.Equal(tc.since) { + t.Fatalf("since = %v, want %v", got.Since, tc.since) + } + }) + } +} + +// Through the tracker: the field rides on the PR row, dated from the nudge +// the contributor engine recorded. +func TestStageTrackerReworkPayload(t *testing.T) { + now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC) + s := newTestServer() + clock := now + store := stagelabels.NewStore("", func() time.Time { return clock }) + s.stageStore = store + s.presenceLookup = func(string) (automerge.ContributorPresence, bool) { + return automerge.ContributorPresence{Registered: true, Online: true, LastSeen: now}, true + } + s.deps = &Dependencies{Config: &config.Config{}} + s.fixWorkLookup = func(login, repo string, n int) (StageTrackerFixWork, bool) { + if login == "zoe" && n == 14991 { + return StageTrackerFixWork{InFlight: true, DispatchedAt: now.Add(-4 * time.Minute), Mode: "spawn"}, true + } + return StageTrackerFixWork{}, false + } + clock = now.Add(-3 * time.Hour) + store.Observe(stagelabels.Key("hivecommons/hive", 14990), stagelabels.NeedsAuthor, "changes-requested") + store.Observe(stagelabels.Key("hivecommons/hive", 14991), stagelabels.ReturnedToContributor, "check-failing:ci") + store.MarkNudged(stagelabels.Key("hivecommons/hive", 14991), "bbb", 1, true, now.Add(-2*time.Hour)) + clock = now + upd := now.Add(-90 * time.Minute) + status := minimalPayload() + status.HiveID = "hive" + status.Repos = []FrontendRepo{{ + Name: "hive", Full: "hivecommons/hive", + OpenPrs: []any{ + FrontendPR{PullRequest: github.PullRequest{Number: 14990, Title: "Docs", Author: "zoe", HeadSHA: "aaa", UpdatedAt: now.Add(-4 * time.Hour), Labels: []string{"stage/071-needs-author", "author/human"}}}, + FrontendPR{PullRequest: github.PullRequest{Number: 14991, Title: "Fix", Author: "zoe", HeadSHA: "bbb", UpdatedAt: upd, Labels: []string{"stage/072-returned-to-contributor"}}}, + FrontendPR{PullRequest: github.PullRequest{Number: 14992, Title: "Other", Author: "zoe", HeadSHA: "ccc", Labels: []string{"stage/050-review-pending"}}}, + }, + }} + s.UpdateStatus(status) + tr := s.buildStageTracker(status, store, now) + if r := trackerItem(t, tr, "pr", 14990).Rework; r == nil || r.State != "requested" || r.Actor != "zoe" || r.RequestedAt == nil || !r.RequestedAt.Equal(now.Add(-3*time.Hour)) { + t.Fatalf("071 rework = %+v", r) + } + it := trackerItem(t, tr, "pr", 14991) + if r := it.Rework; r == nil || r.State != "in_progress" || r.Evidence != "claim" || r.Mode != "spawn" || r.RequestedAt == nil || !r.RequestedAt.Equal(now.Add(-2*time.Hour)) { + t.Fatalf("072 rework = %+v", r) + } + if r := trackerItem(t, tr, "pr", 14992).Rework; r != nil { + t.Fatalf("050 row carries rework: %+v", r) + } + raw, _ := json.Marshal(it) + for _, want := range []string{`"rework":{`, `"state":"in_progress"`, `"evidence":"claim"`, `"mode":"spawn"`, `"requested_at":"2026-10-28T14:00:00Z"`, `"since":"2026-10-28T15:56:00Z"`} { + if !strings.Contains(string(raw), want) { + t.Errorf("payload lacks %s: %s", want, raw) + } + } +} + +func TestStageTrackerReworkJS(t *testing.T) { + html := indexHTML(t) + script := strings.Join([]string{ + stageTrackerRowActionsPreamble(t, html), + jsFunc(t, html, "stageTrackerAdoptionTip"), + jsFunc(t, html, "stageTrackerAdoptOffered"), + jsFunc(t, html, "stageTrackerAdoptionChipText"), + jsFunc(t, html, "stageTrackerAdoptionChipHtml"), + jsFunc(t, html, "stageTrackerDecisionOf"), + jsFunc(t, html, "stageTrackerDecisionTriggerHtml"), + jsFunc(t, html, "stageTrackerDecisionPopHtml"), + stageTrackerPresenceJS(t, html), + jsConstLine(t, html, "STAGE_TRACKER_REWORK_WORDS"), + jsFunc(t, html, "stageTrackerReworkOf"), + jsFunc(t, html, "stageTrackerReworkWord"), + jsFunc(t, html, "stageTrackerReworkSuffix"), + jsFunc(t, html, "stageTrackerReworkTip"), + jsFunc(t, html, "stageTrackerReworkJoinTip"), + jsConstBlock(t, html, "STAGE_TRACKER_EVENT_MOD_WORDS"), + jsFunc(t, html, "stageTrackerStateMap"), + jsFunc(t, html, "stageTrackerStageFell"), + jsFunc(t, html, "stageTrackerEventText"), + jsConstLine(t, html, "STAGE_TRACKER_REWORK_EVENT_WORDS"), + jsFunc(t, html, "stageTrackerReworkEventText"), + ` +const NOW = Date.parse('2026-10-28T14:32:00Z'); +Date.now = () => NOW; +const iso = ms => new Date(ms).toISOString(); +const MIN = 60000, HOUR = 60 * MIN; +const base = { kind: 'pr', repo: 'hivecommons/hive', number: 14989, stage: 71, author: 'Danathar', author_kind: 'clanker', + presence: { login: 'Danathar', state: 'online', kind: 'clanker', since: iso(NOW - 3 * HOUR), last_seen: iso(NOW - 2 * MIN), next: 'wait' } }; +const w = (rework) => Object.assign({}, base, { rework }); +const requested = w({ state: 'requested', actor: 'Danathar', requested_at: iso(NOW - HOUR), since: iso(NOW - HOUR) }); +const queued = w({ state: 'requested', actor: 'Danathar', requested_at: iso(NOW - HOUR), since: iso(NOW - 10 * MIN), evidence: 'queued', ahead: 2 }); +const acked = w({ state: 'acknowledged', actor: 'Danathar', requested_at: iso(NOW - HOUR), since: iso(NOW - 20 * MIN), evidence: 'activity' }); +const working = w({ state: 'in_progress', actor: 'Danathar', requested_at: iso(NOW - HOUR), since: iso(NOW - 5 * MIN), evidence: 'claim', mode: 'spawn' }); +const pushed = w({ state: 'pushed', actor: 'Danathar', requested_at: iso(NOW - HOUR), since: iso(NOW - 1 * MIN), evidence: 'commit', head: 'bbb' }); + +// Without the field the pill is exactly what it was (hivecommons/hive#15051 tests). +assert.strictEqual(stageTrackerPresenceChipText(base), 'waiting on @Danathar'); +assert.strictEqual(stageTrackerReworkTip(base, NOW), ''); +assert.strictEqual(stageTrackerReworkJoinTip('x', base, NOW), 'x'); +// The state word rides on the pill text after the login; the title says since when. +assert.strictEqual(stageTrackerPresenceChipText(requested), 'waiting on @Danathar · no response'); +assert.strictEqual(stageTrackerPresenceChipText(queued), 'waiting on @Danathar · queued'); +assert.strictEqual(stageTrackerPresenceChipText(acked), 'waiting on @Danathar · acknowledged'); +assert.strictEqual(stageTrackerPresenceChipText(working), 'waiting on @Danathar · working'); +assert.strictEqual(stageTrackerPresenceChipText(pushed), 'waiting on @Danathar · re-review pending'); +assert.match(stageTrackerReworkTip(requested, NOW), /^rework requested 1 hour ago \(\S+ .*\) · no response from @Danathar yet$/); +assert.match(stageTrackerReworkTip(queued, NOW), /^rework queued for @Danathar's clanker · 2 ahead · queued 10 min ago \(/); +assert.match(stageTrackerReworkTip(acked, NOW), /^@Danathar acknowledged · activity on the PR 20 min ago \(/); +assert.match(stageTrackerReworkTip(working, NOW), /^@Danathar's clanker picked up the rework 5 min ago \(.*\) \(spawn\)$/); +assert.match(stageTrackerReworkTip(pushed, NOW), /^@Danathar pushed a new head 1 min ago \(.*\) · re-review pending$/); +// The pill keeps its class, dot and login; title and aria carry the rework line after the presence line. +const chip = stageTrackerPresenceChipHtml(acked); +assert.ok(/^waiting on ]*>[\s\S]*<\/span>@Danathar · acknowledged<\/span>$/.test(chip), chip); +// Same on the 072 adoption pill. +const adopt = Object.assign({}, working, { stage: 72, adoption: { author: 'Danathar', due: false, nudges: 1, author_online: true, author_registered: true, policy: 'adopt', text: 'waiting on @Danathar (online, 1 nudge)' } }); +const achip = stageTrackerAdoptionChipHtml(adopt); +assert.ok(/@Danathar · working<\/span>$/.test(achip), achip); +assert.ok(achip.includes("picked up the rework 5 min ago"), achip); +assert.strictEqual(stageTrackerAdoptionChipText(Object.assign({}, adopt, { adoption: Object.assign({}, adopt.adoption, { blocked_by: 'x' }) })), 'not adopted', 'a blocked adoption keeps its own word'); +// Event line: the stage does not change, the pickup does. +const states = (items) => stageTrackerStateMap(items); +const before = states([requested]), after = states([acked]); +const key = Object.keys(after)[0]; +assert.strictEqual(stageTrackerEventText(before[key], after[key], []), '@Danathar acknowledged the rework request'); +assert.strictEqual(stageTrackerEventText(states([acked])[key], states([working])[key], []), "@Danathar's clanker picked up the rework"); +assert.strictEqual(stageTrackerEventText(states([working])[key], states([pushed])[key], []), '@Danathar pushed a new head — re-review pending'); +assert.strictEqual(stageTrackerEventText(states([acked])[key], states([acked])[key], []), '', 'no change, no line'); +assert.strictEqual(stageTrackerEventText(states([base])[key], states([requested])[key], []), '', 'the request itself is the stage move, already said'); +// Nested linked PRs carry it too. +const issue = { kind: 'issue', repo: 'hivecommons/hive', number: 7, stage: 72, linked_prs: [{ number: 14989, stage: 72, rework: acked.rework }] }; +const lk = Object.keys(states([issue])).find(k => k.endsWith('#14989')); +assert.strictEqual(states([issue])[lk].rework, 'acknowledged'); +`}, "\n") + runStageTrackerRowActionsScript(t, script) +} diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 7681431e45..1e4e029c7a 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -14786,7 +14786,10 @@

Where to get help

const a = item && item.adoption; if (!a) return ''; if (stageTrackerAdoptOffered(item)) return 'adopt?'; - return a.blocked_by ? 'not adopted' : ('waiting on ' + (a.author ? '@' + a.author : 'author')); + if (a.blocked_by) return 'not adopted'; + // Guarded: the test harnesses load helpers by name. + const text = 'waiting on ' + (a.author ? '@' + a.author : 'author'); + return typeof stageTrackerReworkSuffix === 'function' ? stageTrackerReworkSuffix(text, item) : text; } function stageTrackerAdoptionChipHtml(item) { const tip = stageTrackerAdoptionTip(item); @@ -14797,7 +14800,8 @@

Where to get help

// (hivecommons/hive#15051); its line joins the tooltip. const ptip = stageTrackerPresenceTip(item, Date.now()); const inner = stageTrackerPresenceInPillHtml(item, stageTrackerAdoptionChipText(item)); - const full = ptip ? tip + ' · ' + ptip : tip; + const joined = ptip ? tip + ' · ' + ptip : tip; + const full = typeof stageTrackerReworkJoinTip === 'function' ? stageTrackerReworkJoinTip(joined, item, Date.now()) : joined; // "adopt?" opens the Needs-human popover (its decision_needed carries // the Adopt option) when the popover helpers are present. const decision = offered && typeof stageTrackerDecisionOf === 'function' && item.decision_needed ? stageTrackerDecisionOf(item) : null; @@ -14897,14 +14901,73 @@

Where to get help

function stageTrackerPresenceChipText(item) { const p = stageTrackerPresenceOf(item); if (!p) return ''; - return 'waiting on @' + p.login; + const text = 'waiting on @' + p.login; + // Guarded: the test harnesses load helpers by name. + return typeof stageTrackerReworkSuffix === 'function' ? stageTrackerReworkSuffix(text, item) : text; } function stageTrackerPresenceChipHtml(item) { const p = stageTrackerPresenceOf(item); if (!p || stageTrackerAdoptionTip(item)) return ''; - const tip = stageTrackerPresenceTip(item, Date.now()); + const ptip = stageTrackerPresenceTip(item, Date.now()); + const tip = typeof stageTrackerReworkJoinTip === 'function' ? stageTrackerReworkJoinTip(ptip, item, Date.now()) : ptip; return `${stageTrackerPresenceInPillHtml(item, stageTrackerPresenceChipText(item))}`; } + + // Rework pickup on a returned PR (`rework`: {state, actor, requested_at, + // since, evidence, mode, ahead, head} — hivecommons/hive#15280). The + // waiting-on pill says who, this says whether they have picked it up: + // requested — the request went out; nothing has moved on the PR + // since (evidence "queued": the fix sits in the clanker's + // hub queue, `ahead` fixes before it). + // acknowledged — the PR saw activity after the request (a comment or + // a push the sweep has not routed yet). + // in_progress — the clanker's relay took the fix task (claim). + // pushed — the head moved since the request; 050 on the next sweep. + const STAGE_TRACKER_REWORK_WORDS = { requested: 'no response', acknowledged: 'acknowledged', in_progress: 'working', pushed: 're-review pending' }; + function stageTrackerReworkOf(item) { + const r = item && item.rework; + if (!r || !STAGE_TRACKER_REWORK_WORDS[r.state]) return null; + return r; + } + function stageTrackerReworkWord(item) { + const r = stageTrackerReworkOf(item); + if (!r) return ''; + if (r.state === 'requested' && r.evidence === 'queued') return 'queued'; + return STAGE_TRACKER_REWORK_WORDS[r.state]; + } + // "waiting on @x · acknowledged" — the pill text with the pickup word. + function stageTrackerReworkSuffix(text, item) { + const w = stageTrackerReworkWord(item); + return w ? text + ' · ' + w : text; + } + function stageTrackerReworkTip(item, nowMs) { + const r = stageTrackerReworkOf(item); + if (!r) return ''; + const now = Number(nowMs) || Date.now(); + const who = r.actor ? '@' + r.actor : 'the author'; + const when = (iso) => { + const ms = Date.parse(iso || ''); + return Number.isFinite(ms) ? agentNowAgo(now - ms) + ' (' + agentNowClockTime(ms, now) + ')' : ''; + }; + const req = when(r.requested_at); + const since = when(r.since); + switch (r.state) { + case 'pushed': + return who + ' pushed a new head' + (since ? ' ' + since : '') + ' · re-review pending'; + case 'in_progress': + return who + "'s clanker picked up the rework" + (since ? ' ' + since : '') + (r.mode ? ' (' + r.mode + ')' : ''); + case 'acknowledged': + return who + ' acknowledged · activity on the PR' + (since ? ' ' + since : ''); + default: + if (r.evidence === 'queued') return 'rework queued for ' + who + "'s clanker" + (r.ahead ? ' · ' + r.ahead + ' ahead' : '') + (since ? ' · queued ' + since : ''); + return 'rework requested' + (req ? ' ' + req : '') + ' · no response from ' + who + ' yet'; + } + } + function stageTrackerReworkJoinTip(tip, item, nowMs) { + const rt = stageTrackerReworkTip(item, nowMs); + if (!rt) return tip || ''; + return tip ? tip + ' · ' + rt : rt; + } /* Takeover (hivecommons/hive#15038): a PR waiting on a contributor's clanker (072 returned-to-contributor / 071 needs-author) carries `takeover` {author, author_online, adopt_now, adopt_now_reason, @@ -15400,6 +15463,8 @@

Where to get help

if (adoption) lines.push('Adoption: ' + adoption + (typeof stageTrackerAdoptOffered === 'function' && stageTrackerAdoptOffered(item) ? ' (row menu → Adopt)' : '')); const presence = typeof stageTrackerPresenceTip === 'function' ? stageTrackerPresenceTip(item, nowMs) : ''; if (presence) lines.push('Presence: ' + presence); + const rework = typeof stageTrackerReworkTip === 'function' ? stageTrackerReworkTip(item, nowMs) : ''; + if (rework) lines.push('Rework: ' + rework); if (mods.length) lines.push('Flags: ' + mods.map(m => STAGE_TRACKER_MOD_TEXT[m] || m).join(', ')); const stale = stageTrackerStaleLabelsText(item); if (stale) lines.push(stale); @@ -15768,7 +15833,7 @@

Where to get help

stage: lp.stage || 0, stage_since: lp.stage_since || '', stage_slug: lp.stage_slug || '', modifiers: lp.modifiers || [], deferred_modifiers: lp.deferred_modifiers || [], caption: lp.caption || '', reason: lp.reason || '', human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', base_ref: lp.base_ref || '', decision_needed: lp.decision_needed || null, adoption: lp.adoption || null, takeover: lp.takeover || null, superseded: !!lp.superseded, supersedes: lp.supersedes || null, parent: Number(issue.number) || 0, siblings: open.map(x => Number(x.number) || 0), - last_operator_action: lp.last_operator_action || null, operator_action_count: lp.operator_action_count || 0, hold: lp.hold || null, stage_actor: lp.stage_actor || null, presence: lp.presence || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null }; + last_operator_action: lp.last_operator_action || null, operator_action_count: lp.operator_action_count || 0, hold: lp.hold || null, stage_actor: lp.stage_actor || null, presence: lp.presence || null, rework: lp.rework || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null }; } // Pure: whether a linked PR is still open (not merged / closed / superseded). function stageTrackerLinkedPROpen(lp) { @@ -16000,7 +16065,7 @@

Where to get help

const who = (lp.author_kind || 'hive') + (lp.author ? ' · @' + lp.author : ''); prRefs = [STAGE_TRACKER_LINKED_GLYPH + stageTrackerPRRef(lp.number, lp.url, lp.author_kind || '', lp.author, lp.title, (lp.title ? lp.title + '\n' : '') + 'Author: ' + who + ' · ' + stageTrackerLinkedTip(item, lp.number, ctx)) + (lp.base_ref ? ` ${esc(lp.base_ref)}` : '')]; shown = Object.assign({}, item, { via_pr: true, stage: lp.stage || 40, stage_since: lp.stage_since || item.stage_since, modifiers: lp.modifiers || item.modifiers, deferred_modifiers: lp.deferred_modifiers || item.deferred_modifiers || [], caption: lp.caption || item.caption, reason: lp.reason || item.reason, - human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', decision_needed: lp.decision_needed || null, hold: lp.hold || null, adoption: lp.adoption || null, stage_actor: lp.stage_actor || item.stage_actor || null, presence: lp.presence || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null }); + human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', decision_needed: lp.decision_needed || null, hold: lp.hold || null, adoption: lp.adoption || null, stage_actor: lp.stage_actor || item.stage_actor || null, presence: lp.presence || null, rework: lp.rework || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null }); } else if (linked.length) { // Several covering PRs: the issue strip ends at Claimed, all passed // and nothing lit; one sub-row per PR carries the live chevron. @@ -16143,7 +16208,7 @@

Where to get help

// Pure: key → the fields the event line watches. function stageTrackerStateMap(items) { const out = {}; - const put = (key, it) => { out[key] = { stage: Number(it.stage) || 0, label: it.stage_label || '', caption: it.caption || '', mods: (Array.isArray(it.modifiers) ? it.modifiers : []).slice().sort() }; }; + const put = (key, it) => { out[key] = { stage: Number(it.stage) || 0, label: it.stage_label || '', caption: it.caption || '', mods: (Array.isArray(it.modifiers) ? it.modifiers : []).slice().sort(), rework: it.rework && it.rework.state ? String(it.rework.state) : '', reworkActor: it.rework && it.rework.actor ? String(it.rework.actor) : '' }; }; for (const it of (Array.isArray(items) ? items : [])) { if (!it || !it.kind || !(Number(it.number) > 0)) continue; put(stageTrackerItemKey(it), it); @@ -16177,9 +16242,23 @@

Where to get help

} for (const m of next.mods) if (prev.mods.indexOf(m) < 0 && STAGE_TRACKER_EVENT_MOD_WORDS[m]) return STAGE_TRACKER_EVENT_MOD_WORDS[m][0]; for (const m of prev.mods) if (next.mods.indexOf(m) < 0 && STAGE_TRACKER_EVENT_MOD_WORDS[m]) return STAGE_TRACKER_EVENT_MOD_WORDS[m][1]; + // Guarded: the test harnesses load helpers by name. + const rework = typeof stageTrackerReworkEventText === 'function' ? stageTrackerReworkEventText(prev, next) : ''; + if (rework) return rework; if (next.caption && next.caption !== prev.caption) return next.caption; return ''; } + // Rework pickup on a returned PR (hivecommons/hive#15280): the row stays + // at 071 / 072, so the stage diff is silent — say who moved instead. + const STAGE_TRACKER_REWORK_EVENT_WORDS = { acknowledged: 'acknowledged the rework request', in_progress: "'s clanker picked up the rework", pushed: 'pushed a new head — re-review pending' }; + function stageTrackerReworkEventText(prev, next) { + const to = next && next.rework ? String(next.rework) : ''; + if (!to || to === (prev && prev.rework ? String(prev.rework) : '')) return ''; + const w = STAGE_TRACKER_REWORK_EVENT_WORDS[to]; + if (!w) return ''; + const who = next.reworkActor ? '@' + next.reworkActor : 'the author'; + return w.charAt(0) === "'" ? who + w : who + ' ' + w; + } let _stageTrackerStates = null; let _stageTrackerEvents = {}; // Pure: the events map after payload d at nowMs — new lines for what diff --git a/src/pkg/fixqueue/fixqueue.go b/src/pkg/fixqueue/fixqueue.go index 6fc00bbc22..d0078def6d 100644 --- a/src/pkg/fixqueue/fixqueue.go +++ b/src/pkg/fixqueue/fixqueue.go @@ -139,6 +139,9 @@ type Dispatch struct { ID string Mode Mode Items []Item + // At is when the dispatch was handed out (the contributor's relay took + // the fix task); the stage tracker reads it as when the rework began. + At time.Time } // Status is the per-contributor view exposed on the profile API. @@ -168,6 +171,7 @@ type dispatch struct { id string mode Mode items map[string]Item + at time.Time } type contributor struct { @@ -426,7 +430,7 @@ func (s *Scheduler) DispatchAtBoundary(user string, cap Capacity) *Dispatch { // pop takes the queue head plus every queued item sharing its cause. func (s *Scheduler) pop(user string, c *contributor, mode Mode) *Dispatch { head := c.queue[0] - d := &dispatch{mode: mode, items: map[string]Item{head.Key(): head}} + d := &dispatch{mode: mode, items: map[string]Item{head.Key(): head}, at: s.opts.Now()} rest := c.queue[:0:0] for _, q := range c.queue[1:] { // A rerouted PR (another author's) never shares a task with the @@ -455,7 +459,7 @@ func (d *dispatch) public() Dispatch { items = append(items, it) } sortQueue(items) - return Dispatch{ID: d.id, Mode: d.mode, Items: items} + return Dispatch{ID: d.id, Mode: d.mode, Items: items, At: d.at} } // Overflow removes and returns user's queued items that have waited longer diff --git a/src/pkg/fixqueue/fixqueue_test.go b/src/pkg/fixqueue/fixqueue_test.go index 6bd34cb1ef..94c3c5f7b6 100644 --- a/src/pkg/fixqueue/fixqueue_test.go +++ b/src/pkg/fixqueue/fixqueue_test.go @@ -401,3 +401,20 @@ func TestCapacityHelpers(t *testing.T) { t.Fatal("item key") } } + +// A dispatch remembers when it left the queue (hivecommons/hive#15280: the +// stage tracker says "clanker picked up the rework 5 min ago" from it). +func TestDispatchAt(t *testing.T) { + c := newClock() + s := newSched(c) + s.Enqueue("ida", red(1, time.Hour, c)) + c.advance(7 * time.Minute) + d := s.Dispatch("ida", Capacity{Max: 1}) + if d == nil || !d.At.Equal(c.at) { + t.Fatalf("dispatch=%+v, want At=%v", d, c.at) + } + c.advance(time.Minute) + if got := s.InFlight("ida"); len(got) != 1 || !got[0].At.Equal(c.at.Add(-time.Minute)) { + t.Fatalf("inflight=%+v", got) + } +}