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/fixed-14578-sentinel-gate-live-label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The activity-monitor merge gate now follows the live `sentinel-alert` label instead of the head's append-only sentinel evidence, so removing the label clears the "Sentinel alert Β· needs human" pill on the next tick; linked issues resolve their title and URL when the configured repo is a short name; and a trusted merger's approving review on a manual-merge lane (workflow path, tests removed, human-merge path) now routes the PR to `stage/090-ready-for-human-merge` with an "Awaiting human merge β€” approved by @login; click Merge" caption and comment instead of re-posting an open-ended needs-decision ([#14578](https://github.com/hivecommons/hive/issues/14578)).
2 changes: 1 addition & 1 deletion src/pkg/dashboard/delegated_pr_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func delegatedCompetingNumbers(items []StageTrackerItem, repo string, pr *gh.Pul
// The requested head may be newer than the enumeration's link evidence.
refs := github.PRReferencedIssues(pr.GetTitle(), pr.GetBody(), repo, pr.GetNumber())
livePR := github.PullRequest{Repo: repo, Number: pr.GetNumber(), ReferencedIssues: refs}
live := StageTrackerItem{Repo: repo, Kind: "pr", Number: pr.GetNumber(), LinkedIssues: stageTrackerPRLinkedIssues(livePR, "")}
live := StageTrackerItem{Repo: repo, Kind: "pr", Number: pr.GetNumber(), LinkedIssues: stageTrackerPRLinkedIssues(livePR, repo, "")}
found := false
for i := range items {
if items[i].Repo == repo && items[i].Kind == "pr" && items[i].Number == live.Number {
Expand Down
133 changes: 112 additions & 21 deletions src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dashboard

import (
Expand All @@ -18,6 +18,7 @@
"github.com/hivecommons/hive/pkg/dashboard/webstatic"
"github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/stageengine"
stageengineprstage "github.com/hivecommons/hive/pkg/stageengine/prstage"
"github.com/hivecommons/hive/pkg/stagelabels"
)

Expand Down Expand Up @@ -287,12 +288,22 @@
// SentinelReason is the first finding's summary, so the lane text can
// name why a person must look (hivecommons/hive: "Sentinel alert Β·
// needs human").
SentinelAlert bool `json:"sentinel_alert,omitempty"`
SentinelFindings int `json:"sentinel_findings,omitempty"`
SentinelReason string `json:"sentinel_reason,omitempty"`
NudgeCount int `json:"nudge_count,omitempty"`
LastNudgeAt *time.Time `json:"last_nudge_at,omitempty"`
AdoptedBy int `json:"adopted_by,omitempty"`
SentinelAlert bool `json:"sentinel_alert,omitempty"`
SentinelFindings int `json:"sentinel_findings,omitempty"`
SentinelReason string `json:"sentinel_reason,omitempty"`
// HumanApprover is the trusted merger whose GitHub Approve review on
// the current head settled a requires_human verdict or a manual-merge
// lane rule (the `:human-approved@login` suffix on the stage reason).
// ManualMerge is true when the stage reason is a lane rule the hive
// never merges unattended (CI workflow / action edits, removed tests,
// a human-merge path): at 090 the merge gate then reads "Awaiting
// human merge" and names the approver, since the only step left is
// the maintainer's merge click.
HumanApprover string `json:"human_approver,omitempty"`
ManualMerge bool `json:"manual_merge,omitempty"`
NudgeCount int `json:"nudge_count,omitempty"`
LastNudgeAt *time.Time `json:"last_nudge_at,omitempty"`
AdoptedBy int `json:"adopted_by,omitempty"`
// ClaimantKind is the author kind of whoever holds the live claim on a
// claimed issue (human / clanker / hive), from the worker-claim ledger.
ClaimantKind string `json:"claimant_kind,omitempty"`
Expand Down Expand Up @@ -573,16 +584,19 @@
// named in SentinelReason.
const stageTrackerSentinelMoreFormat = " (+%d more)"

// stageTrackerSentinel reports whether the sentinel flagged repo#number at
// head: the PR wears the configured alert label (the sweep's blocking
// signal, read from the live labels so a webhook label patch flips it at
// once) or the verified review evidence bundle for head records sentinel
// findings (how a trusted author's notice-only finding is seen, since those
// carry a comment rather than the label). The findings count and the first
// finding's summary come from the bundle; both are empty when only the
// label says so. One file read per PR with a known head, ENOENT when the
// sentinel never wrote one; the tracker payload is memoised so this runs
// once per snapshot, not per request.
// stageTrackerSentinel reports whether the sentinel alert on repo#number
// at head still stands. The live labels decide: the sweep announces a
// blocking finding through the configured alert label, and a maintainer
// removing that label is the sweep's own clearance signal
// (sentinelClearedByMaintainer), so a webhook label patch flips the gate at
// once. The verified review evidence bundle for head supplies the findings
// count and the first finding's summary, and promotes the alert on its own
// only for a notice-only finding (a trusted author's PR: comment, never the
// label), since no label ever carried that one. A blocking finding whose
// label is gone is reported as cleared β€” findings and reason still fill
// the tooltip, alert does not. One file read per PR with a known head,
// ENOENT when the sentinel never wrote one; the tracker payload is memoised
// so this runs once per snapshot, not per request.
func (s *Server) stageTrackerSentinel(verifier *github.ReviewEvidenceVerifier, repo string, number int, head string, labels []string) (alert bool, findings int, reason string) {
label := s.sentinelLabel()
for _, l := range labels {
Expand All @@ -606,7 +620,13 @@
if findings > 1 {
reason += fmt.Sprintf(stageTrackerSentinelMoreFormat, findings-1)
}
return true, findings, reason
for _, f := range b.Sentinel {
if f.Notice {
alert = true
break
}
}
return alert, findings, reason
}
func stageTrackerModifiers(labels []string, hiveID string, rec stagelabels.Record, hasRec bool, overrides map[string]time.Duration, now time.Time, draft bool) []string {
set := map[string]bool{}
Expand Down Expand Up @@ -681,6 +701,13 @@
if r == "" {
return ""
}
if base, approver := stagelabels.HumanApprovedReason(r); approver != "" {
clause := humanizeStageReason(base)
if clause == "" {
return "approved by @" + approver
}
return clause + " β€” approved by @" + approver
}
lower := strings.ToLower(r)
switch lower {
case "actionable", "live agent claim", "live issue claim", "open pr covers it":
Expand Down Expand Up @@ -754,12 +781,31 @@
if strings.HasPrefix(lower, "status-") || strings.HasPrefix(lower, "check-") {
return "CI is red (" + r + ")"
}
switch lower {
case stageengineprstage.ContributorLaneReasonWorkflowPath:
return "workflow path"
case stageengineprstage.ContributorLaneReasonTestsRemoved:
return "tests removed"
case stageengineprstage.AutoMergeReasonHumanMergePath:
return "human-merge path"
}
if rest, ok := strings.CutPrefix(lower, "contributor-lane:"); ok {
return strings.ReplaceAll(strings.ReplaceAll(rest, "-", " "), "_", " ")
}
return strings.NewReplacer("-", " ", "_", " ", ":", ": ").Replace(r)
}

// stageTrackerManualMergeReason reports whether a bare stage reason is a
// lane rule the hive never merges unattended, so a 090 under it is waiting
// on a maintainer's merge click rather than on /lgtm /approve.
func stageTrackerManualMergeReason(reason string) bool {
switch strings.ToLower(strings.TrimSpace(reason)) {
case stageengineprstage.ContributorLaneReasonWorkflowPath, stageengineprstage.ContributorLaneReasonTestsRemoved, stageengineprstage.AutoMergeReasonHumanMergePath:
return true
}
return false
}

// trackerSoakRemainingRE pulls the time left out of the lane's
// `contributor-lane:soaking(remaining=12m0s)` reason.
var trackerSoakRemainingRE = regexp.MustCompile(`remaining=([0-9hms.]+)`)
Expand Down Expand Up @@ -884,6 +930,13 @@
case stagelabels.NeedsDecision, stagelabels.IssueNeedsDecision:
return joinClause("A human decision is owed", clause), "maintainer"
case stagelabels.ReadyForHumanMerge:
if base, approver := stagelabels.HumanApprovedReason(reason); stageTrackerManualMergeReason(base) {
c := "Awaiting human merge (" + humanizeStageReason(base) + ")"
if approver != "" {
c += " β€” approved by @" + approver
}
return c + "; the hive never merges this itself: click Merge (or /lgtm + /approve for tide)", "maintainer"
}
return joinClause("Ready for a maintainer's /lgtm /approve; the hive cannot merge it itself", clause), "maintainer"
case stagelabels.PreMergeSoak:
return joinClause("Admitted by the automerge lane; the pre-merge soak window is running", clause), "automerge lane"
Expand Down Expand Up @@ -1072,6 +1125,9 @@
it.Modifiers = slices.DeleteFunc(it.Modifiers, func(m string) bool { return m == modNeedsTriage })
}
it.Caption, it.Actor = stageTrackerCaption(stage, it.Reason, it.Author, it.Kind, it.Mirrored, rec, hasRec, it.LinkedPR, it.Head)
base, approver := stagelabels.HumanApprovedReason(it.Reason)
it.HumanApprover = approver
it.ManualMerge = stageTrackerManualMergeReason(base)
it.History = stageTrackerHistory(rec)
}
seen := map[string]bool{}
Expand Down Expand Up @@ -1171,7 +1227,7 @@
}
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)
it.LinkedIssues = stageTrackerPRLinkedIssues(pr, status.GitHubBaseURL)
it.LinkedIssues = stageTrackerPRLinkedIssues(pr, repoName, status.GitHubBaseURL)
add(it)
}
for _, repo := range status.Repos {
Expand Down Expand Up @@ -1418,20 +1474,30 @@
// and carries no Via; the softer tiers keep theirs so the UI can mark them.
// Mention-tier entries are provisional: stageTrackerResolveLinkedPRs drops
// them unless the number is an issue listed in the response.
func stageTrackerPRLinkedIssues(pr github.PullRequest, baseURL string) []StageTrackerLinkedIssue {
//
// repoName is the PR's repository as owner/name. pr.Repo may be the config's
// short name ("hive") while GitHub's closing references carry the full one
// ("hivecommons/hive"): the two name the same repository, so a titled
// closing link is kept β€” not dropped for the untitled text reference that
// rendered "(title unavailable)" β€” and the fallback URL is built from the
// full name, never from the short one.
func stageTrackerPRLinkedIssues(pr github.PullRequest, repoName, baseURL string) []StageTrackerLinkedIssue {
var out []StageTrackerLinkedIssue
seen := map[int]bool{}
full := nonEmpty(strings.TrimSpace(repoName), pr.Repo)
add := func(li github.PRLinkedIssue, via string) {
if li.Number <= 0 || li.Number == pr.Number || seen[li.Number] {
return
}
if li.Repo != "" && !strings.EqualFold(li.Repo, pr.Repo) {
// Compare against the fully-qualified name when one is known so a
// same-named repository under another owner is still foreign.
if li.Repo != "" && !stageTrackerSameRepo(li.Repo, full) {
return
}
seen[li.Number] = true
out = append(out, StageTrackerLinkedIssue{
Number: li.Number, Title: li.Title, State: strings.ToLower(strings.TrimSpace(li.State)),
URL: overviewItemURL(li.URL, pr.Repo, li.Number, "issue", baseURL), Via: via,
URL: overviewItemURL(li.URL, full, li.Number, "issue", baseURL), Via: via,
})
}
for _, li := range pr.LinkedIssues {
Expand All @@ -1447,6 +1513,31 @@
return out
}

// stageTrackerSameRepo reports whether two repository names denote the
// same repository: equal ignoring case, or one is the bare name of the
// other's owner/name form.
func stageTrackerSameRepo(a, b string) bool {
a, b = strings.TrimSpace(a), strings.TrimSpace(b)
if a == "" || b == "" {
return false
}
if strings.EqualFold(a, b) {
return true
}
shortA, shortB := a, b
if i := strings.LastIndex(a, "/"); i >= 0 {
shortA = a[i+1:]
}
if i := strings.LastIndex(b, "/"); i >= 0 {
shortB = b[i+1:]
}
// Both fully qualified but different owners: different repositories.
if strings.Contains(a, "/") && strings.Contains(b, "/") {
return false
}
return strings.EqualFold(shortA, shortB)
}

// stageTrackerLinkSoft reports whether a linked issue is a reference link
// rather than a closing one.
func stageTrackerLinkSoft(li StageTrackerLinkedIssue) bool {
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/dashboard/stage_tracker_motion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func TestStageTrackerMotionDetector(t *testing.T) {
jsConstLine(t, html, "STAGE_TRACKER_PR_COLUMN"),
jsConstLine(t, html, "STAGE_TRACKER_MERGE_COLUMN"),
jsConstLine(t, html, "STAGE_TRACKER_NEEDS_DECISION"),
stageTrackerManualMergeJS(t, html),
jsConstLine(t, html, "STAGE_TRACKER_ISSUE_NEEDS_DECISION"),
jsConstLine(t, html, "STAGE_TRACKER_ISSUE_DECISION_COLUMN"),
jsConstLine(t, html, "STAGE_TRACKER_TRIAGE_NEEDED"),
Expand Down Expand Up @@ -380,6 +381,7 @@ func TestStageTrackerMotionRowStamp(t *testing.T) {
jsConstLine(t, html, "STAGE_TRACKER_PR_COLUMN"),
jsConstLine(t, html, "STAGE_TRACKER_MERGE_COLUMN"),
jsConstLine(t, html, "STAGE_TRACKER_NEEDS_DECISION"),
stageTrackerManualMergeJS(t, html),
jsConstLine(t, html, "STAGE_TRACKER_ISSUE_NEEDS_DECISION"),
jsConstLine(t, html, "STAGE_TRACKER_ISSUE_DECISION_COLUMN"),
jsConstLine(t, html, "STAGE_TRACKER_TRIAGE_NEEDED"),
Expand Down Expand Up @@ -478,6 +480,7 @@ func TestStageTrackerMotionPreviewSample(t *testing.T) {
jsConstLine(t, html, "STAGE_TRACKER_PR_COLUMN"),
jsConstLine(t, html, "STAGE_TRACKER_MERGE_COLUMN"),
jsConstLine(t, html, "STAGE_TRACKER_NEEDS_DECISION"),
stageTrackerManualMergeJS(t, html),
jsConstLine(t, html, "STAGE_TRACKER_ISSUE_NEEDS_DECISION"),
jsConstLine(t, html, "STAGE_TRACKER_TRIAGE_NEEDED"),
jsConstLine(t, html, "STAGE_TRACKER_POSSIBLY_EXISTS"),
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/dashboard/stage_tracker_reference_links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestStageTrackerPRLinkedIssuesOrdersClosingFirst(t *testing.T) {
pr := github.PullRequest{Repo: "acme/console", Number: 50,
LinkedIssues: []github.PRLinkedIssue{{Number: 9, Title: "Nine", State: "OPEN"}},
ReferencedIssues: []github.PRLinkedIssue{{Number: 11, Repo: "acme/console", Via: github.PRLinkViaTitle}, {Number: 9, Repo: "acme/console", Via: github.PRLinkViaRefs}, {Number: 50, Repo: "acme/console", Via: github.PRLinkViaRefs}, {Number: 12, Repo: "acme/console", Via: github.PRLinkViaFixes}}}
got := stageTrackerPRLinkedIssues(pr, "https://github.com")
got := stageTrackerPRLinkedIssues(pr, "", "https://github.com")
if len(got) != 3 || got[0].Number != 9 || got[0].Via != "" || got[0].State != "open" || got[1].Number != 11 || got[1].Via != github.PRLinkViaTitle || got[2].Number != 12 || got[2].Via != "" {
t.Fatalf("got %+v", got)
}
Expand Down
1 change: 1 addition & 0 deletions src/pkg/dashboard/stage_tracker_regressed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func TestStageTrackerRegressedPillExplainsItself(t *testing.T) {
jsConstLine(t, html, "STAGE_TRACKER_MOD_TEXT"),
jsFunc(t, html, "stageTrackerStageWord"),
jsConstLine(t, html, "STAGE_TRACKER_NEEDS_DECISION"),
stageTrackerManualMergeJS(t, html),
stageTrackerSentinelJS(t, html),
jsFunc(t, html, "stageTrackerRegressionText"),
jsFunc(t, html, "stageTrackerChipsHtml"),
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/dashboard/stage_tracker_repo_grouping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func stageTrackerRepoGroupingHarness(t *testing.T, html string) string {
jsConstLine(t, html, "STAGE_TRACKER_PR_COLUMN"),
jsConstLine(t, html, "STAGE_TRACKER_MERGE_COLUMN"),
jsConstLine(t, html, "STAGE_TRACKER_NEEDS_DECISION"),
stageTrackerManualMergeJS(t, html),
jsConstLine(t, html, "STAGE_TRACKER_ISSUE_NEEDS_DECISION"),
jsConstLine(t, html, "STAGE_TRACKER_CLOSED_ISSUE_TITLE"),
jsConstLine(t, html, "STAGE_TRACKER_UNTITLED_ISSUE"),
Expand Down Expand Up @@ -198,6 +199,7 @@ const stages = [
{ number: 50, label: 'Review pending', short: 'CI / Review' }, { number: 60, label: 'Reviewed', short: 'Reviewed' },
{ number: 70, label: 'Fixing', short: 'Fixing', branch_from: 50 }, { number: 71, label: 'Needs author', short: 'Needs author', branch_from: 50 },
{ number: 80, label: 'Awaiting merge admission', short: 'Merge gate' }, { number: 85, label: 'Needs human decision', short: 'Needs human decision', branch_from: 80 },
{ number: 90, label: 'Ready for human merge', short: 'Ready for human merge', branch_from: 80 },
{ number: 100, label: 'Merge queue', short: 'Merge queue' }, { number: 110, label: 'Merged', short: 'Merged' },
];
const P = (repo, n, stage, extra) => Object.assign({ kind: 'pr', repo, number: n, stage, title: 'PR ' + n, url: 'https://x/' + n, author: 'ann', author_kind: 'human', stage_since: '2026-01-01T11:00:00Z', created_at: '2026-01-01T10:00:00Z', modifiers: [] }, extra || {});
Expand Down
Loading
Loading