diff --git a/changelog.d/fixed-tracker-human-reason.md b/changelog.d/fixed-tracker-human-reason.md new file mode 100644 index 0000000000..515b4b1a9f --- /dev/null +++ b/changelog.d/fixed-tracker-human-reason.md @@ -0,0 +1 @@ +- Explain exact-head human requirements separately from optional delegation and neutral ownership without inferring human presence, preserve covering-PR reasons and genuine current actions, reconcile old-head push requests and observed same-head CI retries, and keep pending head validation and requested review changes in CI/Review rather than implying approval or preparation admits a ready merge-queue seat. diff --git a/src/docs/dashboard-sections/activity-monitor.md b/src/docs/dashboard-sections/activity-monitor.md index 6af87d38a1..5a13f8eac1 100644 --- a/src/docs/dashboard-sections/activity-monitor.md +++ b/src/docs/dashboard-sections/activity-monitor.md @@ -6,10 +6,48 @@ Part of [Dashboard sections explained](../dashboard-sections.md); see that page A progress strip per open issue and pull request showing which step of the pipeline it is on and who must act next. +Human requirements have visible **Needs human: …** text inside the corresponding +row, with the actual PR number, requester and next mover when known. This is +separate from its pipeline stage: a covered issue can still read **PR in +progress** while a specific linked PR asks a person to act. Multiple-PR trees +identify the asking PR rather than placing its siblings on hold; a PR drawn +under another issue names that host. A missing reason explicitly says **Human +decision required; reason unavailable** and links to the item. + +The person glyph is reserved for an exact-current requirement. Claim ownership +and ordinary author work instead have explicit **Claimed by** / **Next move** +context; **Let hive decide** can be an optional delegation action, not a status +indicator. These lines do not change stages, sorting, reference-versus-closing +links, preparation train styling, native queues, or live notes' tuck/reopen +controls. Cleared decisions and mismatching PR heads lose the requirement. +An operator's recorded approval is not a review verdict: current-head review +changes requested remain the visible blocker and keep the author/rework stage. +The tracker records the approval separately rather than claiming that the merge +queue will take the PR. Approval on an earlier head is historical, not permission +or current review proof for a new head. +When the PR's new head satisfies a recorded old-head author-push request, the +backend reconciles push/rework observations before building the row: its pill, +actor and caption return to pending CI/re-review instead of still asking for a +push. An independently evaluated author action on the new head remains visible. +If the head is known but its push time is not, no push age is invented. +When the current-head snapshot observes real checks running again without any +failing checks, an old CI-only push request becomes **checks pending Β· no new push +requested**. This is not a push or merge-readiness proof; independent review, +conflict and sign-off requirements still stand. +Adoption ownership policy is not a PR rejection: the chip distinguishes +**author-owned**, **maintainer-owned** and **contributor-managed** from an actual +**adoption blocked** capability. No adoption observation means no adoption chip. +Operator admission never promises that outstanding review/CI findings are clear. +Human availability is unknown: agent heartbeats do not prove that a person is +online or offline. Observed push/comment and waiting timestamps remain action +history, not presence evidence or an implied relinquishment of ownership. +Explicit adoption actions/provenance remain visible; a returning human does not +silently revoke an adoption. + ### First use: find the next action 1. Find an item by repository, number or title. Every open issue and PR in the watched repositories is represented, including held, draft, filtered, exempt and reporter-triage work. Being visible does not make it actionable. -2. Read the lit step and its words, then the reason on the item's `#N` link or lit chevron. The word says where the work is; the actor icon says whose move it is. +2. Read the lit step and the visible human/actor context beneath it. The word says where the work is; **Needs human** names the actual requirement, while **Next move** and **Claimed by** distinguish ordinary actor/claim ownership. Links and chevrons retain further detail. 3. Use **πŸ™‹ Needs human** for work waiting on a person's action. Use **⏸ On hold** separately for work a maintainer deliberately paused. Neither filter grants permission to act. 4. Open **β‹―** (or right-click / Shift+F10) for the actions allowed in that state. Read the confirmation and the result toast; a queued decision is not proof the PR merged. @@ -276,13 +314,13 @@ A copy that then fails (closed unmerged, or red at two heads) reopens the origin #### 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 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 contributor agent is registered here, "@zoe: no clanker registered β€” waiting for a human reply" with the pill reading `waiting on @zoe (human Β· no clanker)`. +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}` ([hivecommons/hive#15051](https://github.com/hivecommons/hive/issues/15051)). For a contributor agent, presence comes from the contributor hub's profile/relay heartbeat and uses the same adoption clock: a filled **dot** (`--cue-decision`, a soft breathe; none under `prefers-reduced-motion`) for an online clanker, a filled **square** (`--status-error`) for an offline clanker, and a **hollow ring** when that clanker is not registered here. These are agent states, never human availability. A human author carries only the person glyph and `unknown`: "Waiting on @zoe (human) β€” human availability is unknown; waiting for a human reply". No agent heartbeat, elapsed response time or GitHub activity becomes a human online/offline indicator or an implied ownership transfer. 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. -**An offline clanker's PR that has not been returned.** A clanker-authored PR the engine has not classified yet (the chevron reads `PR in progress Β· @odttlnt's clanker`) carries the same `presence` for its author, with `next: wait` and no `adopt_at` β€” the adoption clock runs only at 072. When the clanker is offline (or not registered here) the chevron's holder gains a muted suffix with the state square: `PR in progress Β· @odttlnt's clanker Β· β–  offline 3h`, and the caption states the next automatic step: "@odttlnt's clanker is offline 3h; a green PR is reviewed and merged without its author β€” hive adopts it only once it is returned (red CI, conflicts or review asks) and nothing is pushed for 15m" (`governor.labels.stage.adoption.after_offline`). A green PR does not need its author online: review and merge admission run on the contributor lane regardless; adoption is the exit for a PR that is red, conflicting or asked to change while its clanker is away, never for a green one, and never for a human's PR. +**An offline clanker's PR that has not been returned.** A clanker-authored PR the engine has not classified yet (the chevron reads `PR in progress Β· @odttlnt's clanker`) carries the same agent `presence`, with `next: wait` and no `adopt_at` β€” the automatic clock runs only at 072. When the clanker is offline (or not registered here) the chevron's holder gains a muted suffix with the state square: `PR in progress Β· @odttlnt's clanker Β· β–  offline 3h`, and the caption states the next automatic step: "@odttlnt's clanker is offline 3h; a green PR is reviewed and merged without its author β€” hive adopts it only once it is returned (red CI, conflicts or review asks) and nothing is pushed for 15m" (`governor.labels.stage.adoption.after_offline`). This automatic clanker projection does not infer a human's availability or an adoption request. Explicit adoption actions and provenance are separate; a returning human's activity does not silently undo an adoption. A contributor PR whose `stage/*` labels the write-back gate kept off GitHub (no opt-in label, see [What hive writes to GitHub, and when](../operator-reference.md#what-hive-writes-to-github-and-when)) is tracked from the engine's record alone: the record carries `labels_suppressed` and the tracker trusts its stage (085 reads *Needs human decision*, not *PR in progress*) even though the item's labels say nothing. Until this fix the tracker read the missing park label as a lifted park and dropped the record, so a dozen fork PRs parked at 085 for a human's decision sat under "PR in progress Β· @x's clanker" for hours while their clankers were offline. @@ -511,9 +549,9 @@ Every PR at the gate now carries `merge_gate: {state, reason, sweep_running, las | 100 merge queue | **Merging** | β€” | ⟳ (static) β€” *Admitted and soaked; hive is merging it now (GitHub merge queue / merge window).* | | any stage while hive's merge call is in flight (`merge_gate.merging_since`, `merge_path`) | **Merging** | *merge call in flight*, then *merge landed* while the SPA holds the row | ⟳ (static) β€” *hive is merging it now (automerge sweep) β€” the merge call has been in flight since 3s ago.* | | any stage after GitHub refused hive's merge call (`merge_gate.state: merge-failed`, `merge_failed`, `merge_failed_kind`, `merge_failed_text`, `merge_failed_at`) | **Merge failed** | the refusal translated to a short phrase β€” *branch protection*, *needs rebase*, *not allowed*, *review required*, or *retrying* while the sweep is on it; never GitHub's raw text | πŸ•“ clock β€” *hive tried to merge this (maintainer merge from the dashboard) 9s ago and GitHub refused β€” branch protection blocks it. The lane re-evaluates it on its next pass. Details: 405 Pull Request is not mergeable* | -| any stage after the merge call drew *N of M required status checks are expected* (`merge_failed_kind: checks-pending`, `merge_failed_checks`) | **Waiting for CI** | *4 checks* | ⟳ while the sweep is on it, else πŸ•“ β€” *hive tried to merge this (automerge sweep) 1m ago before its required checks had reported β€” 4 required checks haven't finished. It merges once they pass.* | +| a queue/gate stage after the merge call drew *N of M required status checks are expected* (`merge_failed_kind: checks-pending`, `merge_failed_checks`) | **Waiting for CI** | *4 checks* | ⟳ while the sweep is on it, else πŸ•“ β€” *hive tried to merge this (automerge sweep) 1m ago before its required checks had reported β€” 4 required checks haven't finished. It merges once they pass.* | -A merge outcome (**Merging**, **Merge failed**, **Waiting for CI**) lights the **Merge queue** column, whatever numeric stage the lane fell back to (hivecommons/docs#512 drew "Merge failed" in CI / Review because the PR sat at 060) β€” unless the PR is under repair. The chevron column follows the **current** state, never the highest stage the row once reached: a PR at 070 fixing, 071 needs-author, 072 returned-to-contributor, 074 adopted-by-hive or with a red required check lights **CI / Review** even while a stale `merge_gate` (`merge-failed` from the attempt that found the conflict) or a planner-ordered `merge_train` still rides on the record (hive's own #15574 read *Fixing Β· conflicting* under Merge queue with the caption *fell back to Fixing β€” … β€” conflicting*; the maintainer: "why is this in merge queue if it is being fixed?"). The "fell back to …" caption keeps the history; the column follows the fallback. One predicate decides both β€” `stageTrackerTrainUnderRepair` (Go, `stageTrackerItemColumn`) and `stageTrackerUnderRepair` (SPA, `stageTrackerAnchor`) β€” so train membership and column can never disagree; the 085 decision park is the one exception that rides no train yet stays at the gate, where the person decides. +A live merge call or actual queue-stage refusal lights the **Merge queue** column. A premature merge call refused for pending PR-head checks does **not** admit a PR still at 050/060: it remains **CI / Review**, and the earlier refusal is retained as history rather than current CI proof. A preparation ticket does not change that placement; forge-owned queue entries and synthetic candidate validation remain separate observations. The chevron column follows the **current** state, never the highest stage the row once reached: a PR at 070 fixing, 071 needs-author, 072 returned-to-contributor, 074 adopted-by-hive or with a red required check lights **CI / Review** even while a stale `merge_gate` (`merge-failed` from the attempt that found the conflict) or a planner-ordered `merge_train` still rides on the record (hive's own #15574 read *Fixing Β· conflicting* under Merge queue with the caption *fell back to Fixing β€” … β€” conflicting*; the maintainer: "why is this in merge queue if it is being fixed?"). The "fell back to …" caption keeps the history; the column follows the fallback. Go's `stageTrackerItemColumn` and the SPA's `stageTrackerAnchor` apply the same precedence; the 085 decision park is the exception that rides no train yet stays at the gate, where the person decides. A refusal is scoped to the head it failed on. Once the PR head moves (merge-from-base, a new push) or the record falls back below 080 to wait on CI (`required-check-pending:*`) after the refusal, the chevron reads the live stage word (**CI running Β· build-and-test**, **Review pending**) and the refusal survives only in the hover β€” *merge attempt on previous head 92d4cef failed: branch protection* (`merge_gate.prior_head_merge_failed`, `prior_head_merge_failed_kind`, `prior_head_merge_failed_text`, `prior_head_merge_failed_at`, `prior_head_merge_failed_head`). The chevron and the caption never disagree about whether a merge is failing now ([#15611](https://github.com/hivecommons/hive/issues/15611); hive#15574 read "Merge failed Β· branch protection" over a caption waiting on CI for the new head). | 110 | **Merged** (the βœ“ cap) | β€” | β€” | diff --git a/src/pkg/dashboard/api_repo_item_takeover_test.go b/src/pkg/dashboard/api_repo_item_takeover_test.go index 495f26d1c5..088ef448c9 100644 --- a/src/pkg/dashboard/api_repo_item_takeover_test.go +++ b/src/pkg/dashboard/api_repo_item_takeover_test.go @@ -338,7 +338,7 @@ func TestStageTrackerTakeoverQueuedAfterAdoptNow(t *testing.T) { store.NoteAdmission(key, "feed", stagelabels.OperatorApprovalAdmission("andan02"), now.Add(-10*time.Minute)) store.NoteAdoptionBlocked(key, "feed", stagelabels.AdoptBlockedOperatorAdmission, now.Add(-9*time.Minute)) it := trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14524) - if it.Adoption == nil || it.Adoption.BlockedBy != stagelabels.AdoptBlockedOperatorAdmission || !strings.Contains(it.Adoption.Text, "a maintainer approved this head") || it.Takeover == nil || !it.Takeover.AdoptNow { + if it.Adoption == nil || it.Adoption.BlockedBy != stagelabels.AdoptBlockedOperatorAdmission || !strings.Contains(it.Adoption.Text, "operator approval recorded for this head; existing review/CI requirements still apply") || it.Takeover == nil || !it.Takeover.AdoptNow { t.Fatalf("precondition (approved, blocked, Adopt now offered): adoption=%+v takeover=%+v", it.Adoption, it.Takeover) } @@ -354,8 +354,8 @@ func TestStageTrackerTakeoverQueuedAfterAdoptNow(t *testing.T) { if it.DecisionNeeded != nil { t.Fatalf("queued adoption still asks a person: %+v", it.DecisionNeeded) } - if strings.Contains(it.Caption, "not adopted") { - t.Fatalf("caption still says not adopted: %q", it.Caption) + if strings.Contains(it.Caption, "not adopted") || strings.Contains(it.Caption, "contributor-managed") { + t.Fatalf("explicit queued adoption still shows the prior ownership-only state: %q", it.Caption) } for _, o := range takeoverDecisionOptions(tk, false) { if o.Action == decisionActionAdoptNow { diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 53f7136df3..acbd9d9239 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -362,6 +362,9 @@ type StageTrackerItem struct { // stalled, a handled regression, blocked-on-pr, 040 covered or a PR // ready for auto-merge β€” the hive advances those (hivecommons/hive#15008). NeedsHuman bool `json:"needs_human,omitempty"` + // HumanAttention is the current item's actionable human requirement, + // separate from an actor/claimant icon or optional delegation action. + HumanAttention *StageTrackerHumanAttention `json:"human_attention,omitempty"` // OnHold is true when the item wears a hold pill: paused on purpose, // waiting on nobody. OnHold bool `json:"on_hold,omitempty"` @@ -413,6 +416,9 @@ type StageTrackerItem struct { // says β€” a header read "8 PRs" over seven seats because a red 090 // row was counted. ciRed bool + // ciChecking is a real check observed running on this snapshot's head + // with no failing checks, not a pending reviewer or meta check. + ciChecking bool // SentinelAlert is true on a PR the suspicious-activity sentinel flagged: // it wears the configured alert label (sentinel.label, default // sentinel-alert) or the review evidence bundle for its current head @@ -667,16 +673,17 @@ type StageTrackerLinkedIssue struct { // StageTrackerLinkedPR is one covering PR nested under an issue row. type StageTrackerLinkedPR struct { - Preparation *StageTrackerPreparation `json:"preparation,omitempty"` - BaseRef string `json:"base_ref,omitempty"` - Number int `json:"number"` - Title string `json:"title,omitempty"` - URL string `json:"url,omitempty"` - Author string `json:"author,omitempty"` - AuthorKind string `json:"author_kind,omitempty"` - Stage int `json:"stage,omitempty"` - StageSince *time.Time `json:"stage_since,omitempty"` - Caption string `json:"caption,omitempty"` + HumanAttention *StageTrackerHumanAttention `json:"human_attention,omitempty"` + Preparation *StageTrackerPreparation `json:"preparation,omitempty"` + BaseRef string `json:"base_ref,omitempty"` + Number int `json:"number"` + Title string `json:"title,omitempty"` + URL string `json:"url,omitempty"` + Author string `json:"author,omitempty"` + AuthorKind string `json:"author_kind,omitempty"` + Stage int `json:"stage,omitempty"` + StageSince *time.Time `json:"stage_since,omitempty"` + Caption string `json:"caption,omitempty"` // NoteChangedAt mirrors the PR row's: when the caption last changed // meaning. NoteChangedAt *time.Time `json:"note_changed_at,omitempty"` diff --git a/src/pkg/dashboard/stage_tracker_actor.go b/src/pkg/dashboard/stage_tracker_actor.go index 0cd1237a96..7b0c5fce72 100644 --- a/src/pkg/dashboard/stage_tracker_actor.go +++ b/src/pkg/dashboard/stage_tracker_actor.go @@ -204,7 +204,7 @@ func stageTrackerStageActorOf(it StageTrackerItem, workers map[string]stageTrack // The author's push landed and CI / the re-review for it still // run: the ball is back with the hive, the person glyph goes // (hivecommons/hive#15784). - if it.Push != nil && it.Push.State == pushStatePushed { + if it.Push != nil && (it.Push.State == pushStatePushed || it.Push.State == pushStateChecking) { return set(StageActorHive, "", stageTrackerPushWhy(it.Push)) } return stageTrackerAuthorStageActor(a, it, stage, workers, now) @@ -322,6 +322,9 @@ func stageTrackerDecisionWhy(it StageTrackerItem) string { // unknown author is StageActorNone. func stageTrackerAuthorStageActor(a *StageTrackerActor, it StageTrackerItem, stage stagelabels.Stage, workers map[string]stageTrackerWorker, now time.Time) *StageTrackerActor { kind := stageTrackerAuthorActorKind(it.Author, it.AuthorKind) + if it.Adoption != nil && it.Adoption.BlockedBy == stagelabels.AdoptBlockedAuthorPerson { + kind = StageActorHuman + } a.Kind, a.Login = kind, it.Author switch kind { case StageActorHive: @@ -459,10 +462,13 @@ func stageTrackerResolveActors(items []StageTrackerItem) { cp := *lead.StageActor // The issue's chevron names the PR the person is wanted on. if cp.Kind == StageActorHuman { - ask := "needs a person" - if pr := prs[it.Repo+"#"+strconv.Itoa(lead.Number)]; pr != nil { + ask := cp.HumanReason + if pr := prs[it.Repo+"#"+strconv.Itoa(lead.Number)]; ask == "" && pr != nil { ask = stageTrackerHumanAsk(stageByNumber(pr.Stage)) } + if ask == "" { + ask = "needs a person" + } cp.HumanReason = stageTrackerClipReason("#" + strconv.Itoa(lead.Number) + " " + ask) } it.StageActor = &cp diff --git a/src/pkg/dashboard/stage_tracker_adopt_queued.test.js b/src/pkg/dashboard/stage_tracker_adopt_queued.test.js index 0eae9cdc3d..63adf990ed 100644 --- a/src/pkg/dashboard/stage_tracker_adopt_queued.test.js +++ b/src/pkg/dashboard/stage_tracker_adopt_queued.test.js @@ -48,7 +48,7 @@ function row(over) { test('before Adopt now: the approved-head blocker shows and Adopt now is offered', () => { const it = row(); assert.equal(api.queued(it), false); - assert.equal(api.chipText(it), 'not adopted'); + assert.equal(api.chipText(it), 'contributor-managed'); const adopt = api.actions(it, ctx).find(a => a.id === 'decide:adopt-now'); assert.ok(adopt && adopt.enabled, 'Adopt now offered'); }); diff --git a/src/pkg/dashboard/stage_tracker_adoption.go b/src/pkg/dashboard/stage_tracker_adoption.go index e3ead89f17..f9049a7890 100644 --- a/src/pkg/dashboard/stage_tracker_adoption.go +++ b/src/pkg/dashboard/stage_tracker_adoption.go @@ -188,7 +188,7 @@ func stageTrackerAdoptionText(author string, a StageTrackerAdoption, now time.Ti who = "@" + author } if a.BlockedBy == stagelabels.AdoptBlockedAuthorPerson { - return who + " pushed this PR themselves β€” not adopted: the hive asks them, not adopts" + return "author-owned β€” " + who + " remains the owner; human availability is unknown" } if a.QueuedBy != "" { return "Adopting… (queued by @" + a.QueuedBy + "; the hive opens its copy on the next stage pass)" @@ -210,11 +210,11 @@ func stageTrackerAdoptionText(author string, a StageTrackerAdoption, now time.Ti case a.BlockedBy == stagelabels.AdoptBlockedAuthorMaintainer && a.Policy == config.AdoptionMaintainerPolicyAsk: text += " β€” adopt?" case a.BlockedBy == stagelabels.AdoptBlockedAuthorMaintainer: - text += " β€” not adopted: maintainer_policy is never" + text += " β€” maintainer-owned: automatic adoption is disabled by maintainer_policy=never" case a.BlockedBy == stagelabels.AdoptBlockedOperatorAdmission: - text += " β€” not adopted: a maintainer approved this head; the hive merges it as-is" + text += " β€” contributor-managed: operator approval recorded for this head; existing review/CI requirements still apply" case a.BlockedBy != "": - text += " β€” not adopted: " + a.BlockedBy + text += " β€” adoption blocked: " + a.BlockedBy case a.AutoDue: text += " β€” hive adopts it on the next sweep" + stageTrackerAdoptionNeverHedge(a, " unless") case a.AutoAdoptAt != nil && a.AutoAdoptAt.After(now): diff --git a/src/pkg/dashboard/stage_tracker_adoption_test.go b/src/pkg/dashboard/stage_tracker_adoption_test.go index b364b3a5e8..4f0fdc3a7f 100644 --- a/src/pkg/dashboard/stage_tracker_adoption_test.go +++ b/src/pkg/dashboard/stage_tracker_adoption_test.go @@ -102,7 +102,7 @@ func TestStageTrackerAdoptionNeverSaysSo(t *testing.T) { s, store, status := adoptionFixture(t, now, config.AdoptionMaintainerPolicyNever, offlinePresence(time.Time{})) store.NoteAdoptionBlocked(stagelabels.Key("hivecommons/hive", 14524), "feed", stagelabels.AdoptBlockedAuthorMaintainer, now.Add(-25*time.Hour)) it := trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14524) - if a := it.Adoption; a == nil || a.Action != "" || a.Text != "waiting on @hanthor (maintainer, offline 26h) β€” not adopted: maintainer_policy is never" { + if a := it.Adoption; a == nil || a.Action != "" || a.Text != "waiting on @hanthor (maintainer, offline 26h) β€” maintainer-owned: automatic adoption is disabled by maintainer_policy=never" { t.Fatalf("adoption = %+v", a) } if it.DecisionNeeded != nil { @@ -443,10 +443,10 @@ func TestStageTrackerAdoptionPersonAuthoredSaysNotAdopted(t *testing.T) { if a == nil || !a.Due || a.BlockedBy != stagelabels.AdoptBlockedAuthorPerson || a.Action != "" { t.Fatalf("adoption = %+v", a) } - if a.Text != "@clubanderson pushed this PR themselves β€” not adopted: the hive asks them, not adopts" { + if a.Text != "author-owned β€” @clubanderson remains the owner; human availability is unknown" { t.Fatalf("text = %q", a.Text) } - if !strings.Contains(it.Caption, "not adopted") { + if !strings.Contains(it.Caption, "author-owned") { t.Fatalf("caption = %q", it.Caption) } if d := it.DecisionNeeded; d != nil { diff --git a/src/pkg/dashboard/stage_tracker_author_head_payload_test.go b/src/pkg/dashboard/stage_tracker_author_head_payload_test.go new file mode 100644 index 0000000000..3c240004ce --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_author_head_payload_test.go @@ -0,0 +1,61 @@ +package dashboard + +import ( + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +func TestStageTrackerHeadReconciliationReachesCoveredRows(t *testing.T) { + const oldHead = "dfaadfae26fd0fabef7cb704d31feb6975bcfcc5" + const newHead = "78c30d99fc5567ba809871db8c77dac5cb6dd052" + now := time.Date(2026, 10, 31, 12, 0, 0, 0, time.UTC) + clock := now.Add(-time.Hour) + s := newTestServer() + store := stagelabels.NewStore("", func() time.Time { return clock }) + s.stageStore = store + key := stagelabels.Key("hivecommons/hive", 16012) + store.Observe(key, stagelabels.NeedsAuthor, "contributor-lane:changes-requested") + store.NoteActivity(key, stagelabels.Activity{Head: oldHead, Comments: -1, Reviews: -1}) + store.MarkNudged(key, oldHead, 1, false, clock) + status := minimalPayload() + status.HiveID = "hive" + status.Repos = []FrontendRepo{{Name: "hive", Full: "hivecommons/hive", + ActionableIssues: []any{github.Issue{Number: 16010, Title: "Covered work", State: "open", Labels: []string{"stage/040-covered-by-pr"}, + LinkedPRs: []github.IssueLinkedPR{{Number: 16012, State: "open", Closing: true}}}}, + OpenPrs: []any{FrontendPR{PullRequest: github.PullRequest{Number: 16012, Title: "Fix", Author: "clubanderson", HeadSHA: newHead, + URL: "https://github.com/hivecommons/hive/pull/16012", Labels: []string{"stage/071-needs-author", "author/human"}, + LinkedIssues: []github.PRLinkedIssue{{Number: 16010, State: "open"}}}}}}} + s.UpdateStatus(status) + clock = now + tr := s.buildStageTracker(s.status, store, now) + it := trackerItem(t, tr, "pr", 16012) + if it.Stage != stagelabels.NeedsAuthor.Number() || it.Push == nil || it.Push.State != pushStatePushed || + it.Presence != nil || it.Rework != nil || it.Adoption != nil || it.HumanAttention != nil || it.NeedsHuman { + t.Fatalf("new-head payload mixes satisfied author wait with pending review: %+v", it) + } + + if it.Caption != "new head observed β†’ re-review pending" || it.NoteChangedAt != nil || it.StageActor == nil || it.StageActor.Kind != StageActorHive { + t.Fatalf("caption/actor disagree with push: %+v", it) + } + issue := trackerItem(t, tr, "issue", 16010) + if len(issue.LinkedPRs) != 1 || issue.LinkedPRs[0].Push == nil || issue.LinkedPRs[0].Push.State != pushStatePushed || + issue.LinkedPRs[0].Presence != nil || issue.LinkedPRs[0].HumanAttention != nil || issue.StageActor == nil || issue.StageActor.Kind != StageActorHive { + t.Fatalf("covered-row projection retained old author work: %+v", issue) + } + // No webhook is needed. A real fresh evaluation that still needs a + // push must restore the author state on this head, not an old event. + store.NoteActivity(key, stagelabels.Activity{Head: newHead, Comments: -1, Reviews: -1, WaitingOnHive: false}) + tr = s.buildStageTracker(s.status, store, now) + it = trackerItem(t, tr, "pr", 16012) + if it.Push == nil || it.Push.State != pushStateWaiting || it.Rework == nil || it.Rework.State == reworkStatePushed || + it.StageActor == nil || it.StageActor.Kind != StageActorHuman || it.HumanAttention == nil || !it.NeedsHuman { + t.Fatalf("fresh current-head author action was hidden: %+v", it) + } + if strings.Contains(it.Caption, "new head observed") { + t.Fatalf("fresh author action still claims only re-review is pending: %q", it.Caption) + } +} diff --git a/src/pkg/dashboard/stage_tracker_author_head_test.go b/src/pkg/dashboard/stage_tracker_author_head_test.go new file mode 100644 index 0000000000..5ea133d279 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_author_head_test.go @@ -0,0 +1,63 @@ +package dashboard + +import ( + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +func TestStageTrackerNewHeadSynchronizesAuthorWaitAndReview(t *testing.T) { + now := time.Date(2026, 10, 31, 12, 0, 0, 0, time.UTC) + requested := now.Add(-time.Hour) + for _, stage := range []stagelabels.Stage{stagelabels.NeedsAuthor, stagelabels.ReturnedToContributor} { + t.Run(stage.String(), func(t *testing.T) { + rec := stagelabels.Record{Stage: stage, EnteredAt: requested, NudgeHead: "old-head", + FirstNudgeAt: requested, LastNudgeAt: requested, WaitingPushSince: requested, + ActivityHead: "old-head", Reason: "contributor-lane:changes-requested"} + it := StageTrackerItem{Kind: "pr", Repo: "o/r", Number: 16012, Head: "new-head", Stage: stage.Number(), + Author: "clubanderson", AuthorKind: authorKindHuman, Reason: rec.Reason, URL: "https://github.com/o/r/pull/16012"} + it.Push = stageTrackerPushFor(it, stage, rec, true, time.Hour, now) + if it.Push == nil || it.Push.State != pushStatePushed || it.Push.Sha != it.Head || it.Push.Next != pushNextReReview || it.Push.Since != nil { + t.Fatalf("new head must satisfy the old request without inventing a push time: %+v", it.Push) + } + + it.StageActor = stageTrackerStageActor(it, nil, now) + if it.StageActor.Kind != StageActorHive || !strings.Contains(it.StageActor.Why, "re-review") { + t.Fatalf("new head still waits on its author: %+v", it.StageActor) + } + if stageTrackerNeedsHuman(it) || stageTrackerHumanAttention(it) != nil || stageTrackerApprovalReviewBlocker(it) != "" { + t.Fatalf("old-head author/review blocker survived the push: %+v", it) + } + if caption := stageTrackerPushCaption(it.Push, now); caption != "new head observed β†’ re-review pending" { + t.Fatalf("caption contradicts pending re-review: %q", caption) + } + rework := stageTrackerReworkFor(it, it.Author, stage, rec, true, nil, now) + if rework == nil || rework.State != reworkStatePushed || rework.Head != it.Head { + t.Fatalf("event path disagrees with the canonical push: %+v", rework) + } + // A sweep evaluated this head and returned it to the author for + // another action. Its fresh wait outranks the old nudge. + rec.ActivityHead, rec.WaitingPushSince = it.Head, now.Add(-time.Minute) + it.Push = stageTrackerPushFor(it, stage, rec, true, time.Hour, now) + if it.Push == nil || it.Push.State != pushStateWaiting || !it.Push.Since.Equal(rec.WaitingPushSince) { + t.Fatalf("current-head author request was hidden: %+v", it.Push) + } + rework = stageTrackerReworkFor(it, it.Author, stage, rec, true, nil, now) + if rework == nil || rework.State == reworkStatePushed { + t.Fatalf("current-head wait falsely emits a pushed event: %+v", rework) + } + it.StageActor = stageTrackerStageActor(it, nil, now) + if it.StageActor.Kind != StageActorHuman || !stageTrackerNeedsHuman(it) || stageTrackerHumanAttention(it) == nil { + t.Fatalf("independent current-head author work was lost: %+v", it) + } + // A pending exact-head review is not an author hold. + rec.WaitingOnHive = true + it.Push = stageTrackerPushFor(it, stage, rec, true, time.Hour, now) + if it.Push == nil || it.Push.State != pushStatePushed { + t.Fatalf("hive-side review still claims to wait on author: %+v", it.Push) + } + }) + } +} diff --git a/src/pkg/dashboard/stage_tracker_build.go b/src/pkg/dashboard/stage_tracker_build.go index e78c15160d..9ca5c66d37 100644 --- a/src/pkg/dashboard/stage_tracker_build.go +++ b/src/pkg/dashboard/stage_tracker_build.go @@ -194,10 +194,9 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto if hasAttempt && (attempt.InFlight() || attempt.Merged) { it.Caption, it.Actor = stageTrackerMergingCaption(attempt), StageActorHive } - // Adoption is clanker-only (a human's PR is never adopted), so a - // human-authored 072 row keeps its plain caption. The one exception - // is a person's PR the engine was asked to adopt and refused - // (hivecommons/hive#15202): that row says "not adopted" wherever it sits. + // Do not infer a human takeover request from an author wait. A + // recorded author-person ownership policy gets neutral ownership + // wording; explicit adoption actions and provenance stay separate. personRefused := hasRec && it.Kind == "pr" && rec.AdoptionBlocked(it.Head) == stagelabels.AdoptBlockedAuthorPerson if personRefused || (stage == stagelabels.ReturnedToContributor && it.Kind == "pr" && it.AuthorKind != authorKindHuman) { if it.Adoption = stageTrackerAdoption(*it, rec, hasRec, presence, maintainerPolicy, adoptionClock, now); it.Adoption != nil { @@ -205,12 +204,15 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto } } it.Push = stageTrackerPushFor(*it, stage, rec, hasRec, pushStaleAfter, now) - pushed := it.Push != nil && it.Push.State == pushStatePushed + pushed := it.Push != nil && (it.Push.State == pushStatePushed || it.Push.State == pushStateChecking) if pushed { // The ball is back with the hive: the row says what the push // queued, and its note ages from the push (a new hive line). it.Caption = stageTrackerPushCaption(it.Push, now) - if it.NoteChangedAt == nil || it.Push.Since.After(*it.NoteChangedAt) { + if it.Push.Since == nil { + it.NoteChangedAt = nil + } + if it.Push.Since != nil && (it.NoteChangedAt == nil || it.Push.Since.After(*it.NoteChangedAt)) { at := *it.Push.Since it.NoteChangedAt = &at } @@ -374,6 +376,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto URL: overviewItemURL(pr.URL, pr.Repo, pr.Number, "pr", status.GitHubBaseURL)} it.BaseRef = pr.BaseRef it.ciRed = strings.EqualFold(pr.CIStatus, "failure") || len(pr.FailingChecks) > 0 + it.ciChecking = it.Head != "" && !it.ciRed && strings.EqualFold(pr.CIStatus, "pending") && pr.CIChecksRunning it.AuthorKind, it.AuthorKindSource = stageTrackerAuthorKind(pr.Labels, pr.Author, pr.AppAuthored, pr.HiveAttributed) it.AuthorKind, it.AuthorKindSource = stageTrackerRegistryAuthorKind(it.AuthorKind, it.AuthorKindSource, it.Author, isClankerOwner) if it.AuthorKindSource == authorKindSrcLabel { @@ -516,6 +519,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto stageTrackerResolveLinkedPRs(resp.Items, prOpen) stageTrackerMarkClosedBy(resp.Items, s.mergedLedger().ClosedBy) stageTrackerResolveActors(resp.Items) + stageTrackerResolveHumanAttention(resp.Items) sort.SliceStable(resp.Items, stageTrackerLess(resp.Items)) return resp } @@ -572,9 +576,8 @@ func stageTrackerNeedsHuman(it StageTrackerItem) bool { if slices.Contains(stageTrackerNeedsHumanStages, it.Stage) { return true } - // The author pushed and the hive has not evaluated the new head yet: - // the ball is with the hive, not a person (hivecommons/hive#16021). - return slices.Contains(stageTrackerNeedsHumanAuthorStages, it.Stage) && it.AuthorKind == authorKindHuman && !stageTrackerPushPending(it) + humanOwner := it.AuthorKind == authorKindHuman || (it.Adoption != nil && it.Adoption.BlockedBy == stagelabels.AdoptBlockedAuthorPerson) + return slices.Contains(stageTrackerNeedsHumanAuthorStages, it.Stage) && humanOwner && !stageTrackerPushPending(it) } // stageTrackerOnHold mirrors the dashboard's stageTrackerItemOnHold: the diff --git a/src/pkg/dashboard/stage_tracker_ci_retry_test.go b/src/pkg/dashboard/stage_tracker_ci_retry_test.go new file mode 100644 index 0000000000..b0787b1c23 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_ci_retry_test.go @@ -0,0 +1,85 @@ +package dashboard + +import ( + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +func TestStageTrackerSameHeadCIRetryDoesNotDemandAnUnrelatedPush(t *testing.T) { + now := time.Date(2026, 10, 31, 12, 0, 0, 0, time.UTC) + stage := stagelabels.NeedsAuthor + rec := stagelabels.Record{Stage: stage, Reason: "check-failing:docker (contributor)", + ActivityHead: "current", NudgeHead: "current", WaitingPushSince: now.Add(-time.Hour)} + it := StageTrackerItem{Kind: "pr", Number: 16016, Head: "current", Stage: stage.Number(), + Author: "clubanderson", AuthorKind: authorKindHuman, Reason: rec.Reason, ciChecking: true} + it.Push = stageTrackerPushFor(it, stage, rec, true, time.Hour, now) + if it.Push == nil || it.Push.State != pushStateChecking || it.Push.Sha != it.Head || it.Push.Since != nil || it.Push.Login != "" { + t.Fatalf("same-head CI retry must not fabricate a push or its time: %+v", it.Push) + } + it.StageActor = stageTrackerStageActor(it, nil, now) + if it.StageActor.Kind != StageActorHive || stageTrackerNeedsHuman(it) || stageTrackerHumanAttention(it) != nil || + !strings.Contains(stageTrackerPushCaption(it.Push, now), "no new push requested") { + t.Fatalf("observed retry still demands author work: %+v", it) + } + for _, reason := range []string{"contributor-lane:changes-requested", "conflicting", "dco-missing-signoff"} { + rec.Reason = reason + if p := stageTrackerPushFor(it, stage, rec, true, time.Hour, now); p == nil || p.State != pushStateWaiting { + t.Fatalf("CI retry hid an independent author action %q: %+v", reason, p) + } + } + rec.Reason = it.Reason + for _, mod := range []string{modNeedsRebase, modNeedsHuman, modNeedsDecision, modUnauthorized, modHold, modBlocked, modDraft} { + it.Modifiers = []string{mod} + if p := stageTrackerPushFor(it, stage, rec, true, time.Hour, now); p == nil || p.State != pushStateWaiting { + t.Fatalf("CI retry hid an independent requirement %q: %+v", mod, p) + } + } + it.Modifiers = nil + it.ciChecking = false + if p := stageTrackerPushFor(it, stage, rec, true, time.Hour, now); p == nil || p.State != pushStateWaiting { + t.Fatalf("settled current-head failure was hidden: %+v", p) + } + it.ciChecking, rec.ActivityHead = true, "another-head" + if p := stageTrackerPushFor(it, stage, rec, true, time.Hour, now); p == nil || p.State != pushStateWaiting { + t.Fatalf("another head's checks released the author: %+v", p) + } + rec.ActivityHead, it.ciRed = it.Head, true + if p := stageTrackerPushFor(it, stage, rec, true, time.Hour, now); p == nil || p.State != pushStateWaiting { + t.Fatalf("a failed check with other jobs running was hidden: %+v", p) + } +} + +func TestStageTrackerSameHeadCIRetryReachesRootAndCoveredRows(t *testing.T) { + now := time.Date(2026, 10, 31, 12, 0, 0, 0, time.UTC) + s := newTestServer() + store := stagelabels.NewStore("", func() time.Time { return now }) + s.stageStore = store + key := stagelabels.Key("hivecommons/hive", 16016) + store.Observe(key, stagelabels.NeedsAuthor, "check-failing:docker (contributor)") + store.NoteActivity(key, stagelabels.Activity{Head: "94ed43c7a5262972b79a7c811c0d6bca01f6ebcb", Comments: -1, Reviews: -1}) + status := minimalPayload() + status.HiveID = "hive" + status.Repos = []FrontendRepo{{Name: "hive", Full: "hivecommons/hive", + ActionableIssues: []any{github.Issue{Number: 16015, State: "open", Labels: []string{"stage/040-covered-by-pr"}, + LinkedPRs: []github.IssueLinkedPR{{Number: 16016, State: "open", Closing: true}}}}, + OpenPrs: []any{FrontendPR{PullRequest: github.PullRequest{Number: 16016, Author: "clubanderson", + HeadSHA: "94ed43c7a5262972b79a7c811c0d6bca01f6ebcb", CIStatus: "pending", CIChecksRunning: true, + Labels: []string{"stage/071-needs-author", "author/human"}, + LinkedIssues: []github.PRLinkedIssue{{Number: 16015, State: "open"}}}}}}} + s.UpdateStatus(status) + tr := s.buildStageTracker(s.status, store, now) + it := trackerItem(t, tr, "pr", 16016) + if it.Push == nil || it.Push.State != pushStateChecking || it.Presence != nil || it.Rework != nil || + it.HumanAttention != nil || it.NeedsHuman || it.StageActor == nil || it.StageActor.Kind != StageActorHive { + t.Fatalf("same-head observed CI retry still asks for another push: %+v", it) + } + issue := trackerItem(t, tr, "issue", 16015) + if len(issue.LinkedPRs) != 1 || issue.LinkedPRs[0].Push == nil || issue.LinkedPRs[0].Push.State != pushStateChecking || + issue.LinkedPRs[0].Presence != nil || issue.LinkedPRs[0].HumanAttention != nil || issue.StageActor == nil || issue.StageActor.Kind != StageActorHive { + t.Fatalf("covering row disagrees about same-head retry: %+v", issue) + } +} diff --git a/src/pkg/dashboard/stage_tracker_decide_plan_cache_test.go b/src/pkg/dashboard/stage_tracker_decide_plan_cache_test.go index 97ed6dfc55..aedc2a075a 100644 --- a/src/pkg/dashboard/stage_tracker_decide_plan_cache_test.go +++ b/src/pkg/dashboard/stage_tracker_decide_plan_cache_test.go @@ -179,7 +179,7 @@ func TestStageTrackerNoHumanMarkerWithoutReason(t *testing.T) { issue.StageActor = &StageTrackerActor{Kind: StageActorHive, Why: "an agent has a PR under way; not yet opened"} items := []StageTrackerItem{pr, issue} stageTrackerResolveActors(items) - if a := items[1].StageActor; a.Kind != StageActorHuman || a.HumanReason != "#15759 needs a decision" || a.Why != pr.StageActor.Why { + if a := items[1].StageActor; a.Kind != StageActorHuman || a.HumanReason != stageTrackerClipReason("#15759 "+pr.StageActor.HumanReason) || a.Why != pr.StageActor.Why { t.Errorf("riding issue actor = %+v", a) } check("riding issue", items[1].StageActor) diff --git a/src/pkg/dashboard/stage_tracker_decided.go b/src/pkg/dashboard/stage_tracker_decided.go index d8e21d4e29..efed608cde 100644 --- a/src/pkg/dashboard/stage_tracker_decided.go +++ b/src/pkg/dashboard/stage_tracker_decided.go @@ -4,10 +4,12 @@ import ( "regexp" "slices" "strconv" + "strings" "time" "github.com/hivecommons/hive/pkg/delegatedecision" "github.com/hivecommons/hive/pkg/github/automerge" + stageengineprstage "github.com/hivecommons/hive/pkg/stageengine/prstage" "github.com/hivecommons/hive/pkg/stagelabels" ) @@ -39,6 +41,10 @@ import ( // StageTrackerDecided is the `decided` field of a row with a recorded // decision. type StageTrackerDecided struct { + // CurrentBlocker is a finished-snapshot blocker that outranks a recorded + // operator approval. Head binds that explanation to the displayed PR. + CurrentBlocker string `json:"current_blocker,omitempty"` + Head string `json:"head,omitempty"` // Action is the ledger action (let-hive-decide, approve, queue-merge, // merge-now); Verdict the delegate's verdict for let-hive-decide // (adopt-supersede, approve, …), else the action's own verb. @@ -165,6 +171,23 @@ func stageTrackerDecided(it StageTrackerItem, sweep automerge.SweepState, now ti return d } d.Word, d.Text, d.Acting = verb.Word, verb.Text, verb.Acting + approval := verdict == string(delegatedecision.VerdictApprove) || verdict == operatorActionQueueMerge || verdict == operatorActionMergeNow + if approval && a.HeadSHA != "" && a.HeadSHA != it.Head { + d.Effect, d.Word, d.Acting = decidedEffectNone, "Earlier approval recorded", "" + d.Text = "Operator approval recorded on a previous head; current checks and reviews still apply" + if it.Head == "" { + d.Text = "Operator approval recorded; current head unavailable, so current approval cannot be established" + } + d.Title = d.Text + return d + } + if blocker := stageTrackerApprovalReviewBlocker(it); approval && blocker != "" { + d.Effect, d.Word, d.Acting = decidedEffectNone, "Review changes requested", "" + d.CurrentBlocker, d.Head = blocker, it.Head + d.Text = d.CurrentBlocker + " Β· operator approval recorded separately, not review approval or merge readiness" + d.Title = d.Text + return d + } moved := a.StageAt != 0 && it.Stage != a.StageAt switch { case it.AdoptedBy > 0 && verdict == string(delegatedecision.VerdictAdoptSupersede): @@ -205,6 +228,37 @@ func stageTrackerDecided(it StageTrackerItem, sweep automerge.SweepState, now ti return d } +func stageTrackerApprovalReviewBlocker(it StageTrackerItem) string { + stage := stageByNumber(it.Stage) + if it.Kind != "pr" || (stage != stagelabels.Fixing && stage != stagelabels.NeedsAuthor && stage != stagelabels.ReturnedToContributor && + stage != stagelabels.NeedsDecision && stage != stagelabels.ReadyForHumanMerge) { + return "" + } + if it.Push != nil && it.Push.State == pushStatePushed { + return "" + } + if !strings.Contains(it.Reason, stageengineprstage.ContributorLaneReasonChangesRequested) && + !strings.Contains(it.Reason, stagelabels.LaneReasonChangesRequested) { + return "" + } + why := "Review changes requested on the current head" + if it.Head == "" { + why = "Review changes requested; evaluated head unavailable" + } + actor := it.Author + if it.Rework != nil && it.Rework.Actor != "" { + actor = it.Rework.Actor + } + if actor != "" { + why += " Β· waiting on @" + actor + if it.AuthorKind == authorKindClanker { + why += "'s contributor agent" + } + why += " to address the review" + } + return why +} + // stageTrackerDecidedTitle is the badge tooltip: "Hive decided 17:51 β€” // adopted (supersede); next: adoption pass in 4m" (you Β· Let hive decide Β· // hive chose adopt-supersede). diff --git a/src/pkg/dashboard/stage_tracker_human_attention.go b/src/pkg/dashboard/stage_tracker_human_attention.go new file mode 100644 index 0000000000..67b4b97ea5 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_human_attention.go @@ -0,0 +1,83 @@ +package dashboard + +import ( + "slices" + "strconv" + "strings" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// StageTrackerHumanAttention is a finished-snapshot requirement on this exact +// item, not an available decision action or the kind of its claim holder. +type StageTrackerHumanAttention struct { + Number int `json:"number"` + Kind string `json:"kind"` + Head string `json:"head,omitempty"` + Reason string `json:"reason"` + AskedBy string `json:"asked_by,omitempty"` + Owner string `json:"owner,omitempty"` +} + +func stageTrackerHumanAttention(it StageTrackerItem) *StageTrackerHumanAttention { + if !stageTrackerNeedsHuman(it) || it.Stage >= stagelabels.MergeQueue.Number() || + slices.Contains(it.Modifiers, modDraft) || slices.Contains(it.Modifiers, "merged") { + return nil + } + // Mirrored issues carry their PR's observation on the link, never an + // issue-wide requirement inherited from a parent RFC or a sibling PR. + if it.Kind == "issue" && it.Mirrored { + return nil + } + a := &StageTrackerHumanAttention{Number: it.Number, Kind: it.Kind, Head: it.Head} + if d := it.DecisionNeeded; d != nil { + a.Reason = strings.TrimSpace(nonEmpty(d.Question, d.Blocker)) + a.AskedBy = strings.TrimSpace(d.AskedBy) + } + if a.Reason == "" { + a.Reason = strings.TrimSpace(it.HumanMergeReasonText) + } + if a.Reason == "" { + a.Reason = stageTrackerDecisionWhy(it) + } + if actor := it.StageActor; actor != nil && actor.Kind == StageActorHuman { + a.Owner = actor.Login + if a.Reason == "" { + switch stageByNumber(it.Stage) { + case stagelabels.TriageNeeded, stagelabels.PossiblyExisting, stagelabels.Fixing, stagelabels.NeedsAuthor, stagelabels.ReturnedToContributor: + a.Reason = strings.TrimSpace(actor.Why) + } + } + } + if a.Reason == "" { + a.Reason = "Human decision required; reason unavailable" + } + return a +} + +// Resolve only after operator/decision projections, current PR link hydration +// and actor resolution, so cleared decisions and new heads cannot retain a +// previous link's requirement. No traversal of issue/RFC ancestry is involved. +func stageTrackerResolveHumanAttention(items []StageTrackerItem) { + prs := map[string]*StageTrackerItem{} + for i := range items { + it := &items[i] + it.HumanAttention = stageTrackerHumanAttention(*it) + if it.Kind == "pr" { + prs[it.Repo+"#"+strconv.Itoa(it.Number)] = it + } + } + for i := range items { + it := &items[i] + for j := range it.LinkedPRs { + lp := &it.LinkedPRs[j] + lp.HumanAttention = nil + pr := prs[it.Repo+"#"+strconv.Itoa(lp.Number)] + if pr == nil || pr.Head != lp.Head || lp.State == "closed" || + lp.SupersededBy > 0 || lp.AdoptedBy > 0 { + continue + } + lp.HumanAttention = pr.HumanAttention + } + } +} diff --git a/src/pkg/dashboard/stage_tracker_human_attention.test.js b/src/pkg/dashboard/stage_tracker_human_attention.test.js new file mode 100644 index 0000000000..5979a5a76a --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_human_attention.test.js @@ -0,0 +1,216 @@ +// CI-only behavioral tests of the shipped human context and actual row adapters. +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); +const source = name => fs.readFileSync(path.join(__dirname, 'static-src/js', name + '.js'), 'utf8'); +const fn = (file, name) => { + const text = source(file); + const match = text.match(new RegExp('function ' + name + '\\([^\\n]*\\) \\{[^\\n]*\\}\\s*(?:\\n|$)')) + || text.match(new RegExp('function ' + name + '\\([^\\n]*\\) \\{[\\s\\S]*?\\n \\}')); + assert.ok(match, name); + return match[0]; +}; +const esc = value => String(value).replace(/[&<>"']/g, ch => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[ch])); +const plain = value => JSON.parse(JSON.stringify(value)); +function load() { + const c = vm.createContext({ Date, esc, + STAGE_TRACKER_TERMINAL: 100, STAGE_TRACKER_PR_COLUMN: 40, + STAGE_TRACKER_LINKED_GLYPH: '↳', STAGE_TRACKER_SOFT_LINK_TIP: 'refs', + stageTrackerAnchor: n => Number(n) || 0, + stageTrackerAttentionTier: () => 1, + stageTrackerLeadStage: lp => lp.stage || 40, + stageTrackerIcon: (kind, cls) => ``, + stageTrackerPRRef: (n, url, kind, author, title) => `#${n} ${esc(title || '')}`, + stageTrackerPRPillsHtml: ref => ref, + stageTrackerTitleHtml: text => `${esc(text)}`, + stageTrackerTooltip: it => it.caption || '', + stageTrackerLinkedTip: () => '', + stageTrackerActedBadgeHtml: () => '', stageTrackerRowToolsHtml: () => '', + stageTrackerChipsHtml: () => '', stageTrackerMoveAttrs: () => '', stageTrackerSinceHtml: () => '', + stageTrackerStripItems: it => `
  • `, + stageTrackerCurrentStageHtml: it => `${it.stage}`, + stageTrackerEventHtml: (key, ctx) => `

    ${esc(ctx && ctx.note || 'live note')}

    `, + stageTrackerActionCtx: () => ({ user: 'viewer' }), + stageTrackerLeadActionOnRow: item => item.optionalAction ? { id: 'decide:delegate', label: 'Let hive decide' } : null, + }); + for (const name of ['stageTrackerLinkedSuperseder', 'stageTrackerLinkedSupersededGone', 'stageTrackerLinkedSupersededText', 'stageTrackerLinkedSupersededTip']) vm.runInContext(fn('tracker-words-gate', name), c); + for (const name of ['stageTrackerItemKey', 'stageTrackerPRKey', 'stageTrackerRowPRKeys']) vm.runInContext(fn('tracker-merged', name), c); + for (const name of ['stageTrackerLinkedPRItem', 'stageTrackerLinkedPROpen', 'stageTrackerLinkedDrawnHere', 'stageTrackerLinkedSorted', 'stageTrackerHeadColsHtml', 'stageTrackerRowHtml', 'stageTrackerSubRowHtml']) vm.runInContext(fn('tracker-row-layout', name), c); + vm.runInContext(fn('tracker-filter', 'stageTrackerPRIssueSlot'), c); + vm.runInContext(source('tracker-human-attention'), c); + return c; +} +function pr(number = 15985) { + return { kind: 'pr', repo: 'hivecommons/hive', number, stage: 85, state: 'open', head: 'current-' + number, + title: 'PR ' + number, url: 'https://github.com/hivecommons/hive/pull/' + number, base_ref: 'v5', + human_attention: { kind: 'pr', number, head: 'current-' + number, reason: 'Confirm the compatibility policy', + asked_by: 'a reviewer', owner: 'maintainer' }, + stage_actor: { kind: 'human', login: 'maintainer', why: 'Confirm the compatibility policy' } }; +} +function issue(linked) { + return { kind: 'issue', repo: 'hivecommons/hive', number: 15937, stage: 40, linked_pr: linked[0].number, + title: 'Matrix overlay', linked_prs: linked, url: 'https://github.com/hivecommons/hive/issues/15937', + stage_actor: linked[0].stage_actor }; +} + +test('covered issue shows the exact PR requirement/requester in visible prose without overriding its actual stage', () => { + const c = load(), child = pr(), item = issue([child]), before = plain(item); + const html = c.stageTrackerRowHtml(item, [], { nowMs: 1, note: 'review comment' }); + assert.match(html, /data-ham-kind="issue".*data-ham-stage="40"/); + assert.match(html, /data-stage="85"/); + assert.match(html, /PR #15985 β€” Needs human: Confirm the compatibility policy Β· next move: @maintainer Β· requested by a reviewer/); + assert.match(html, />View PR #15985<\/a>/); + assert.match(html, /cue-event-tuckable.*data-cue-key=.*review comment.*Reopen/); + assert.doesNotMatch(html, /Needs you|ham-preparation-head|
    { + const c = load(), child = { ...pr(), drawn_under: 15862 }, item = issue([child]); + const html = c.stageTrackerRowHtml(item, [], { nowMs: 1 }); + assert.match(html, /PR #15985 β€” Needs human:.*shown under issue #15862/); + assert.doesNotMatch(html, /data-ham-sub-key=/); + assert.equal(item.stage, 40); + assert.equal(item.human_attention, undefined); +}); + +test('mixed multiple PR trees render only the asking child and preserve child order/stages', () => { + const c = load(), asking = pr(), ordinary = { ...pr(15998), stage: 50, human_attention: null, stage_actor: { kind: 'hive', why: 'CI pending' } }; + const item = issue([ordinary, asking]), before = plain(item); + const html = c.stageTrackerRowHtml(item, [], { nowMs: 1 }); + assert.equal((html.match(/Needs human:/g) || []).length, 1); + assert.match(html, /data-ham-stage="85" data-ham-sub-key="hivecommons\/hive\/pr#15985"/); + assert.match(html, /data-ham-stage="50" data-ham-sub-key="hivecommons\/hive\/pr#15998"/); + assert.ok(html.indexOf('data-ham-sub-key="hivecommons/hive/pr#15985"') < html.indexOf('Needs human:')); + assert.ok(html.indexOf('Needs human:') < html.indexOf('data-ham-sub-key="hivecommons/hive/pr#15998"')); + assert.deepEqual(plain(item), before); +}); + +test('optional Let hive decide is explicitly an optional action, never evidence of a human gate', () => { + const c = load(), item = { ...pr(), human_attention: null, optionalAction: true, stage: 50, stage_actor: { kind: 'hive' } }; + const html = c.stageTrackerHumanContextHtml(item, [], 1); + assert.match(html, /Optional delegation: Let hive decide is available/); + assert.doesNotMatch(html, /Needs human:|Needs you/); +}); + +test('claim owner and human next mover are explained separately from a required decision', () => { + const c = load(), item = { ...pr(), human_attention: null, stage: 40, stage_actor: { kind: 'none' }, claimant: { kind: 'person', login: 'author' } }; + assert.match(c.stageTrackerHumanContextHtml(item, [], 1), /Claimed by @author Β· claim ownership, not a human decision request/); + item.stage_actor = { kind: 'human', login: 'author', why: '@author must push a fix; the hive does not edit a person’s PR' }; + const html = c.stageTrackerHumanContextHtml(item, [], 1); + assert.match(html, /Next move: @author β€” @author must push a fix/); + assert.doesNotMatch(html, /Needs human:|Needs you/); +}); + +test('changed head/identity, closed/draft/held/superseded and answered observations cannot retain a requirement', () => { + for (const mutate of [ + it => { it.head = 'new-head'; }, it => { it.number++; }, it => { it.kind = 'issue'; }, + it => { it.state = 'closed'; }, it => { it.modifiers = ['draft']; }, it => { it.modifiers = ['hold']; }, + it => { it.hold = { by: 'owner' }; }, it => { it.superseded_by = 16000; }, + it => { it.human_attention = null; it.stage_actor = { kind: 'hive' }; }, + ]) { + const c = load(), item = pr(); mutate(item); + assert.equal(c.stageTrackerHumanAttentionOf(item), null); + assert.doesNotMatch(c.stageTrackerHumanContextHtml(item, [], 1), /Needs human:/); + } +}); + +test('unknown reason is explicit with a detail route; data is escaped and no owner is invented', () => { + const c = load(), item = pr(); + item.human_attention.reason = ''; delete item.human_attention.owner; delete item.human_attention.asked_by; + let html = c.stageTrackerHumanContextHtml(item, [], 1); + assert.match(html, /Needs human: Human decision required; reason unavailable/); + assert.match(html, />View PR #15985/); + assert.doesNotMatch(html, /next move: @|requested by|Needs you/); + item.human_attention.reason = ''; + html = c.stageTrackerHumanContextHtml(item, [], 1); + assert.match(html, /<script>/); + assert.doesNotMatch(html, /