Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/changed-pills-until-merge-gate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Hive activity monitor: `sentinel`, `needs human`, `needs human decision` and merge-time `unauthorized` pills are held back (payload `deferred_modifiers`) until the pull request reaches the merge gate (stage/080+), and do not count under *Needs attention* before then; `hold`, `draft`, `stalled`, `regressed` and an `unauthorized` on held workflow runs always show.
23 changes: 19 additions & 4 deletions src/docs/dashboard-sections.md

Large diffs are not rendered by default.

114 changes: 104 additions & 10 deletions src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,20 @@ type StageTrackerItem struct {
Reason string `json:"reason,omitempty"`
Caption string `json:"caption"`
Actor string `json:"actor,omitempty"`
// Modifiers are the health and control markers in effect: stalled,
// regressed, hold, needs-human, needs-decision (stage/045 on an issue or
// stage/085 on a PR carried as a park signal), needs-rebase, blocked,
// draft.
// Modifiers are the health and control markers in effect and drawn as
// pills: stalled, regressed, hold, needs-human, needs-decision
// (stage/045 on an issue or stage/085 on a PR carried as a park
// signal), needs-rebase, blocked, draft, unauthorized. A merge-gate
// marker on a PR that has not reached the gate band is not listed
// here; it waits in DeferredModifiers.
Modifiers []string `json:"modifiers"`
// DeferredModifiers are the merge-gate markers held back while the PR
// is still in motion before the gate (needs-human, needs-decision,
// sentinel, a merge-time unauthorized step): nothing a person does now
// moves the row, so the tracker draws no pill and "Needs attention"
// does not count them until the PR reaches stage/080 or later. The
// labels themselves are untouched; this is presentation only.
DeferredModifiers []string `json:"deferred_modifiers,omitempty"`
// RegressedFrom / RegressedTo / RegressedAt / RegressedReason narrate
// the unresolved regression behind the `regressed` modifier: the
// high-water stage the item fell from, the stage that fall landed on
Expand Down Expand Up @@ -399,6 +408,9 @@ type StageTrackerLinkedPR struct {
StageSince *time.Time `json:"stage_since,omitempty"`
Caption string `json:"caption,omitempty"`
Modifiers []string `json:"modifiers,omitempty"`
// DeferredModifiers mirrors the nested PR's own row field: the
// merge-gate pills it is not yet drawing.
DeferredModifiers []string `json:"deferred_modifiers,omitempty"`
// SentinelAlert / SentinelReason mirror the nested PR's own row fields
// so a sub-row under an issue names the alert too.
SentinelAlert bool `json:"sentinel_alert,omitempty"`
Expand Down Expand Up @@ -461,6 +473,9 @@ const (
// hive's GitHub App lacks the permission for its next step and a
// person must take it (hivecommons/hive#14589).
modUnauthorized = "unauthorized"
// modSentinel names the sentinel chip in DeferredModifiers; the chip
// itself is drawn from SentinelAlert, never from Modifiers.
modSentinel = "sentinel"
)

// Lane names.
Expand Down Expand Up @@ -684,7 +699,48 @@ func (s *Server) stageTrackerSentinel(verifier *github.ReviewEvidenceVerifier, r
// stageTrackerModifierOrder is the modifier precedence the payload carries.
var stageTrackerModifierOrder = []string{modStalled, modRegressed, modHold, modUnauthorized, modNeedsHuman, modNeedsDecision, modNeedsTriage, modPossibleDupe, modNeedsRebase, modBlocked, modDraft}

func stageTrackerModifiers(labels []string, hiveID string, rec stagelabels.Record, hasRec bool, overrides map[string]time.Duration, now time.Time, draft bool) []string {
// stageTrackerModifier is one health or control marker with its class.
type stageTrackerModifier struct {
Name string
// ActionableNow: a person must do something right now for the row to
// move, whatever its stage (hold, draft, stalled, regressed, a step
// the App may not take that blocks the current stage). False marks a
// merge-gate marker — needs-human, needs-decision, a merge-time
// unauthorized step — that only becomes actionable once the PR reaches
// the gate band; before that the tracker holds it back.
ActionableNow bool
}

// stageTrackerPillsDeferred reports whether a row's merge-gate markers are
// held back: a PR (or an issue riding its covering PR's stage) that has
// not reached the merge-gate band yet. The band starts at stage/080 —
// stagelabels.AwaitingMergeAdmission, the same boundary adoption yields
// at — and runs through 085/090/095/100. Issues on their own stages keep
// every pill: a needs-human on an unclaimed issue is a park the person
// owes now, not a merge-time notice.
func stageTrackerPillsDeferred(kind string, stageNumber int, mirrored bool) bool {
if kind != "pr" && !mirrored {
return false
}
return stageNumber < stagelabels.AwaitingMergeAdmission.Number()
}

// stageTrackerUnauthorizedActionableNow reports whether the step the App
// may not take blocks the row where it stands, so a person must act now:
// held workflow runs mean CI cannot even start, and waiting for the merge
// gate would waste the whole CI / review cycle. Any other refused step
// (merge, branch update, …), or a label whose reason no longer names the
// step, is a merge-time step and waits for the gate.
func stageTrackerUnauthorizedActionableNow(reason string) bool {
base, _ := stagelabels.HumanApprovedReason(strings.TrimSpace(reason))
rest, ok := strings.CutPrefix(base, stageengineprstage.StageReasonUnauthorizedPrefix)
return ok && strings.TrimSpace(rest) == stageengineprstage.UnauthorizedStepApproveWorkflowRuns
}

// stageTrackerClassifyModifiers derives the row's markers from its labels,
// store record and draft flag, each with its class; reason is the lane's
// stage reason, read for the unauthorized step. Order is the pill priority.
func stageTrackerClassifyModifiers(labels []string, hiveID string, rec stagelabels.Record, hasRec bool, overrides map[string]time.Duration, now time.Time, draft bool, reason string) []stageTrackerModifier {
set := map[string]bool{}
for _, l := range labels {
switch lower := strings.ToLower(strings.TrimSpace(l)); lower {
Expand Down Expand Up @@ -727,11 +783,19 @@ func stageTrackerModifiers(labels []string, hiveID string, rec stagelabels.Recor
if draft {
set[modDraft] = true
}
out := make([]string, 0, len(set))
out := make([]stageTrackerModifier, 0, len(set))
for _, m := range stageTrackerModifierOrder {
if set[m] {
out = append(out, m)
if !set[m] {
continue
}
actionable := true
switch m {
case modNeedsHuman, modNeedsDecision:
actionable = false
case modUnauthorized:
actionable = stageTrackerUnauthorizedActionableNow(reason)
}
out = append(out, stageTrackerModifier{Name: m, ActionableNow: actionable})
}
return out
}
Expand Down Expand Up @@ -774,6 +838,26 @@ func stageTrackerBlockerList(repo string, blockers []string) string {
return strings.Join(parts, ", ")
}

// stageTrackerModifiers splits a row's markers into the pills it draws
// (shown) and the merge-gate pills it holds back (deferred) until the PR
// reaches the gate band. Everything actionable now is always shown; a
// merge-gate marker is shown once stageTrackerPillsDeferred says the row
// is at or past the gate, or the row is an issue on its own stage.
func stageTrackerModifiers(labels []string, hiveID string, rec stagelabels.Record, hasRec bool, overrides map[string]time.Duration, now time.Time, draft bool, reason string, kind string, stage stagelabels.Stage, mirrored bool) (shown, deferred []string) {
held := stageTrackerPillsDeferred(kind, stage.Number(), mirrored)
for _, m := range stageTrackerClassifyModifiers(labels, hiveID, rec, hasRec, overrides, now, draft, reason) {
if m.ActionableNow || !held {
shown = append(shown, m.Name)
} else {
deferred = append(deferred, m.Name)
}
}
if shown == nil {
shown = []string{}
}
return shown, deferred
}

// noVerdictClause is the bare no-verdict clause; stageTrackerCaption swaps
// in "awaiting review of head <sha7>" when the item's head is known.
const noVerdictClause = "no review verdict yet"
Expand Down Expand Up @@ -1276,7 +1360,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
// An issue wearing a PR stage (050+) is riding its covering PR; its
// own parking bay 045 is not a mirror.
it.Mirrored = it.Kind == "issue" && stage != stagelabels.None && !stage.Applies(stagelabels.IssueItem)
it.Modifiers = stageTrackerModifiers(labels, status.HiveID, rec, hasRec, overrides, now, draft)
it.Modifiers, it.DeferredModifiers = stageTrackerModifiers(labels, status.HiveID, rec, hasRec, overrides, now, draft, it.Reason, it.Kind, stage, it.Mirrored)
// 045/085 have their own chevron word ("Needs human decision"); the
// chip only adds information when needs-decision modifies another
// stage.
Expand All @@ -1301,7 +1385,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
if stage == stagelabels.ReadyForHumanMerge {
it.HumanMergeReason, _, it.HumanMergeReasonText = stageTrackerHumanMergeReason(it.Reason)
}
if slices.Contains(it.Modifiers, modUnauthorized) {
if slices.Contains(it.Modifiers, modUnauthorized) || slices.Contains(it.DeferredModifiers, modUnauthorized) {
it.UnauthorizedStep, it.Unauthorized = stageTrackerUnauthorized(it.Reason)
}
it.History = stageTrackerHistory(rec)
Expand Down Expand Up @@ -1404,6 +1488,13 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
}
finish(&it, pr.Labels, labelStage(pr.Labels), rec, ok, pr.Draft)
it.SentinelAlert, it.SentinelFindings, it.SentinelReason = s.stageTrackerSentinel(evidenceVerifier, repoName, pr.Number, pr.HeadSHA, pr.Labels)
// The sentinel chip is a merge-gate pill too (the trusted-author
// notice and the real alert alike): sentinel_alert stays truthful
// for the gate word and the Decide… preface, but before the gate
// the chip is held with the other deferred pills.
if it.SentinelAlert && stageTrackerPillsDeferred(it.Kind, it.Stage, it.Mirrored) {
it.DeferredModifiers = append([]string{modSentinel}, it.DeferredModifiers...)
}
it.LinkedIssues = stageTrackerPRLinkedIssues(pr, repoName, status.GitHubBaseURL)
add(it)
}
Expand Down Expand Up @@ -2106,6 +2197,9 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem) {
if len(pr.Modifiers) > 0 {
lp.Modifiers = append([]string(nil), pr.Modifiers...)
}
if len(pr.DeferredModifiers) > 0 {
lp.DeferredModifiers = append([]string(nil), pr.DeferredModifiers...)
}
if lp.URL == "" {
lp.URL = pr.URL
}
Expand Down
Loading
Loading