From 10bb90df29ad02a47cecbbc587132432f305ef9f Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 23:07:00 -0400 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20review:=20contributor=20deci?= =?UTF-8?q?sion=20questions=20park=20at=20085=20only=20on=20a=20finding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Owner rule: no decisions by a human while a PR is in CI/Review unless the review found something. The aggregate honoured a reviewer decision marker blindly on non-hive-authored PRs; it now parks only when the question is backed (duplicate, risk class, high-risk marker, finding at threshold, risk-escalation term) and records the finding as decision_finding, which the 085 comment, verdict-route log and tracker print. Unbacked questions are advisory and the PR moves on to the merge gate's human-merge rule. Fixes #15640 Signed-off-by: Andrew Anderson --- ...ixed-contributor-decision-needs-finding.md | 1 + src/cmd/hive/merge_eligibility.go | 1 + src/docs/hive-merge.md | 13 ++ src/docs/review-swarm.md | 28 ++++ src/pkg/dashboard/stage_tracker_decision.go | 3 + .../github/automerge/automerge_stage_human.go | 1 + .../automerge/automerge_stage_labels.go | 2 +- src/pkg/review/review.go | 132 ++++++++++++++++++ src/pkg/review/review_test.go | 93 +++++++++++- .../derive_pr_no_decision_in_ci_test.go | 67 +++++++++ src/pkg/stageengine/prstage/types.go | 6 + src/pkg/stagelabels/human.go | 7 + src/pkg/stagelabels/human_test.go | 5 + 13 files changed, 355 insertions(+), 4 deletions(-) create mode 100644 src/changelog.d/fixed-contributor-decision-needs-finding.md create mode 100644 src/pkg/stageengine/derive_pr_no_decision_in_ci_test.go diff --git a/src/changelog.d/fixed-contributor-decision-needs-finding.md b/src/changelog.d/fixed-contributor-decision-needs-finding.md new file mode 100644 index 0000000000..1bf97af394 --- /dev/null +++ b/src/changelog.d/fixed-contributor-decision-needs-finding.md @@ -0,0 +1 @@ +- Contributor-lane PRs no longer park at `stage/085-needs-decision` on a reviewer decision marker alone while they are in CI/Review. The review aggregate honours a `decision_requested` verdict on a non-hive-authored PR only when the review found something — a duplicate, a trust-surface / risk-class question, the reviewer's high-risk marker, or a finding at the human threshold — and records it as `decision_finding`, which the 085 comment and the tracker print as `the review found: …`. An unbacked question is advisory: the PR keeps moving and a contributor the lane cannot vouch for waits at `stage/090-ready-for-human-merge` under the human-merge rule instead. diff --git a/src/cmd/hive/merge_eligibility.go b/src/cmd/hive/merge_eligibility.go index 02bcd281a1..2a69441805 100644 --- a/src/cmd/hive/merge_eligibility.go +++ b/src/cmd/hive/merge_eligibility.go @@ -234,6 +234,7 @@ func contributorLaneVerdictFromArtifact(artifact review.Artifact, repo string, n Verdict: string(match.Verdict), DecisionRequested: match.DecisionRequested, DecisionQuestion: match.DecisionQuestion, + DecisionFinding: match.DecisionFinding, RedundantOf: match.RedundantOf, HumanSummaries: append([]string(nil), match.HumanSummaries...), HiveAuthoredKnown: match.HiveAuthoredKnown, diff --git a/src/docs/hive-merge.md b/src/docs/hive-merge.md index b3f1f3446f..e78dd3a0fe 100644 --- a/src/docs/hive-merge.md +++ b/src/docs/hive-merge.md @@ -614,6 +614,19 @@ unattended (for example `mrbobbytables`): A claim keeps the tier the contributor held when it was taken, so grant the tier before the issue is leased. +**No decision during CI/Review.** A contributor PR is not parked at +`stage/085-needs-decision` on a reviewer decision marker alone. While it is +in CI/Review the hive runs CI and the review swarm to completion; the +aggregate honours a `decision_requested` verdict only when the review +*found* something (duplicate, trust-surface / risk-class question, high-risk +marker, finding at the human threshold) and records that finding as +`decision_finding`, which the 085 comment prints as `the review found: …`. +A question with nothing behind it is advisory and the PR keeps moving; a +contributor whose tier the lane cannot vouch for then waits at +`stage/090-ready-for-human-merge` under the human-merge rule — a merge-gate +state, not a review decision. See +[review-swarm.md](review-swarm.md) ("Contributor and human-authored PRs: no decision in CI/Review"). + ### Issue-author credit at merge time Every merge the hive performs — the self-authored, trusted-author, diff --git a/src/docs/review-swarm.md b/src/docs/review-swarm.md index e82232fef7..2683a056d5 100644 --- a/src/docs/review-swarm.md +++ b/src/docs/review-swarm.md @@ -322,6 +322,34 @@ decision marker parks the PR for a person. The reviewer template issue/spec and PR body before asking, and to cite the answer (`per #: …`) instead of raising a question the issue already settled. +**Contributor and human-authored PRs: no decision in CI/Review unless the +review found something.** The owner rule (2026-10-29) is that while a PR +is in CI/Review the hive runs CI and the review swarm to completion on its +own; a person is only asked when the review *found* something concrete. +A decision-requested verdict on a non-hive-authored PR therefore parks at +`stage/085-needs-decision` only when it is **backed** by one of: + +- a duplicate (``, or the question says the + change already landed / is byte-identical / is a no-op); +- the reviewer's `` marker; +- a question in one of the risk classes above (trust surface: workflows, + CODEOWNERS, permissions, …); +- an in-scope finding at or above the `requires_human` severity threshold; +- a risk-escalation term in the summary or findings (sentinel alert, + credential, secret, …). + +The aggregate then records **what** was found as `decision_finding`, and the +085 comment and tracker popover print it as `the review found: …` next to +the reviewer's question. A question with nothing behind it is advisory: +the aggregate is `approve` (or `changes_requested`, handed to the fixer, +when a sibling perspective asked for changes), recorded as +`decision question not backed by a finding — the PR keeps moving; a person meets it at the merge gate; recorded as advisory: `, and the PR keeps moving to the +merge gate. A contributor- or human-authored PR that needs a person's merge +click waits there, at `stage/090-ready-for-human-merge` under the +human-merge rule — a merge-queue state, never an 085 decision raised during +review. The same `self_authored_decision_policy: escalate` switch restores +the old park-on-every-marker behavior for these PRs too. + Two decision questions never reach the swarm or a person at all, because the hive already owns the answer: diff --git a/src/pkg/dashboard/stage_tracker_decision.go b/src/pkg/dashboard/stage_tracker_decision.go index 910f3dad30..bfb1a26234 100644 --- a/src/pkg/dashboard/stage_tracker_decision.go +++ b/src/pkg/dashboard/stage_tracker_decision.go @@ -835,6 +835,9 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel d.Blocker = "Neither the author nor the hive can make CI run for this fork PR." case reviewerDeferred: d.Blocker = "The hive will not merge until a person decides." + if verdict != nil && strings.TrimSpace(verdict.DecisionFinding) != "" { + d.Blocker = "The review found: " + strings.TrimSpace(verdict.DecisionFinding) + ". " + d.Blocker + } } if held && selfHold == nil { if d.Blocker != "" { diff --git a/src/pkg/github/automerge/automerge_stage_human.go b/src/pkg/github/automerge/automerge_stage_human.go index fe98b62b6c..0568c9f483 100644 --- a/src/pkg/github/automerge/automerge_stage_human.go +++ b/src/pkg/github/automerge/automerge_stage_human.go @@ -221,6 +221,7 @@ func (c *Engine) humanEvidence(ctx context.Context, tracker *StageTracker, key s Cause: cause, CauseReason: decisionCauseFor(obs.Reason, workflowManual), DecisionQuestion: strings.TrimSpace(contributorVerdict.DecisionQuestion), + DecisionFinding: strings.TrimSpace(contributorVerdict.DecisionFinding), HumanSummaries: append([]string(nil), contributorVerdict.HumanSummaries...), SelfAuthored: obs.Lane == stageLaneSelf, AuthorKind: obs.AuthorKind, diff --git a/src/pkg/github/automerge/automerge_stage_labels.go b/src/pkg/github/automerge/automerge_stage_labels.go index 73acfa5582..5c5abcf01d 100644 --- a/src/pkg/github/automerge/automerge_stage_labels.go +++ b/src/pkg/github/automerge/automerge_stage_labels.go @@ -1149,7 +1149,7 @@ func (c *Engine) ApplyStageLabels(ctx context.Context) (StageLabelResult, error) if obs.Detail.VerdictKnown { rawVerdict := obs.Detail.Verdict normalizedVerdict := normalizeContributorLaneVerdict(rawVerdict) - c.info("stage labels: reviewer verdict route", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "lane", obs.Lane, "raw_verdict", rawVerdict.Verdict, "normalized_verdict", normalizedVerdict.Verdict, "decision_requested", normalizedVerdict.DecisionRequested, "decision_answered", normalizedVerdict.DecisionAnswered && normalizedVerdict.DecisionAnsweredHead == obs.HeadSHA, "decision_by", normalizedVerdict.DecisionAnsweredBy, "decision_directive", normalizedVerdict.DecisionDirective, "stage", verdict.Stage.String(), "reason", obs.Reason) + c.info("stage labels: reviewer verdict route", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "lane", obs.Lane, "raw_verdict", rawVerdict.Verdict, "normalized_verdict", normalizedVerdict.Verdict, "decision_requested", normalizedVerdict.DecisionRequested, "decision_answered", normalizedVerdict.DecisionAnswered && normalizedVerdict.DecisionAnsweredHead == obs.HeadSHA, "decision_by", normalizedVerdict.DecisionAnsweredBy, "decision_directive", normalizedVerdict.DecisionDirective, "decision_finding", normalizedVerdict.DecisionFinding, "stage", verdict.Stage.String(), "reason", obs.Reason) } add, remove := stagelabels.Plan(obs.Labels, want) if len(add)+len(remove) > 0 { diff --git a/src/pkg/review/review.go b/src/pkg/review/review.go index 2ce6921412..906def5604 100644 --- a/src/pkg/review/review.go +++ b/src/pkg/review/review.go @@ -238,6 +238,14 @@ type Aggregate struct { CloseRecommended bool `json:"close_recommended"` DecisionRequested bool `json:"decision_requested,omitempty"` DecisionQuestion string `json:"decision_question,omitempty"` + // DecisionFinding names what the review found that makes the decision + // question a person's to answer — a duplicate, a finding at or above + // the human threshold, a risk-class question (workflow, security, …) + // or the reviewer's explicit high-risk marker. A question with no + // finding behind it never parks a PR in CI/Review (owner rule, see + // contributorDecisionBacking); the text is what the tracker and the + // 085 comment print as "the review found". + DecisionFinding string `json:"decision_finding,omitempty"` // RedundantOf is the PR a reviewer named as already carrying this // change, carried from the first report that set one. RedundantOf int `json:"redundant_of,omitempty"` @@ -478,6 +486,41 @@ func aggregateReports(reports []PerspectiveReport, opts AggregateOptions) Aggreg sort.Strings(agg.HumanSummaries) if decisionRequested { + if finding, backed := decisionQuestionsBacked(reports, threshold); !backed && !agg.HiveAuthored && !strings.EqualFold(strings.TrimSpace(opts.SelfAuthoredDecisionPolicy), "escalate") { + // Owner rule (hivecommons/hive, 2026-10-29): no human decision + // while a PR is in CI/Review unless the review found something. + // A contributor-lane question with no finding behind it — no + // duplicate, no finding at the human threshold, no risk-class + // wording, no high-risk marker — is advisory: the PR keeps + // moving and a person meets it at the merge gate, where the + // human-merge rule for contributor PRs applies. Twelve of + // hive's own PRs sat 3–21h on such questions. + if hasChanges { + if opts.FixAttempts >= maxFix { + agg.Verdict = VerdictRequiresHuman + agg.RequiresHuman = true + agg.DecisionFinding = fmt.Sprintf("fix cycle cap reached (%d/%d)", opts.FixAttempts, maxFix) + agg.Reasons = []string{agg.DecisionFinding} + return agg + } + agg.Verdict = VerdictChangesRequested + agg.FixCycle = true + markRequiresHumanPerspectivesAsChangesRequested(&agg) + } else { + agg.Verdict = VerdictApprove + agg.MergeEligible = true + markRequiresHumanPerspectivesAsApprove(&agg) + agg.Reasons = nil + } + agg.RequiresHuman = false + agg.DecisionRequested = false + agg.DecisionQuestion = "" + agg.Reasons = append(append([]string{}, agg.Reasons...), contributorDecisionAdvisory(decisionQuestions)) + sortReasons(agg.Reasons) + return agg + } else if backed { + agg.DecisionFinding = finding + } if resolveSelfAuthoredDecisionQuestions(reports, opts, decisionQuestions, hasReject || riskEscalation || unresolvedRequiresHuman) { if hasChanges || selfAuthoredHumanWithConcreteRemediation { if opts.FixAttempts >= maxFix { @@ -636,6 +679,79 @@ func markRequiresHumanPerspectivesAsChangesRequested(a *Aggregate) { } } +// markRequiresHumanPerspectivesAsApprove is the approve counterpart: the +// relay stamps every perspective of a decision-requested review +// requires_human, so once the question is resolved as advisory the +// perspectives read as the approvals they were. +func markRequiresHumanPerspectivesAsApprove(a *Aggregate) { + if a == nil || len(a.Perspectives) == 0 { + return + } + for p, v := range a.Perspectives { + if v == VerdictRequiresHuman { + a.Perspectives[p] = VerdictApprove + } + } +} + +// decisionQuestionsBacked reports whether any report's decision question +// stands on something the review actually found, and names it. The +// backing, first match wins per report: a redundant-of marker (the answer +// is a close), the reviewer's explicit high-risk marker, a question whose +// wording lands in a DecisionRiskClass (workflow, security, permissions, +// duplicate, …), an in-scope finding at or above the human threshold, or +// risk-escalation wording in the review text. +func decisionQuestionsBacked(reports []PerspectiveReport, threshold outputschema.Severity) (string, bool) { + for _, r := range reports { + if !r.DecisionRequested { + continue + } + if finding := decisionQuestionBacking(r, threshold); finding != "" { + return finding, true + } + } + return "", false +} + +// duplicateQuestionPattern is the text form of the `hive-redundant-of` +// marker: the review found the change already on the base or in another +// open PR, so the answer is a close — which only a person gives on a +// contributor's PR. +var duplicateQuestionPattern = regexp.MustCompile(`(?i)\b(duplicates?|dup|redundant)\b|in favou?r of #\d+|already (landed|merged|fixed|on (the )?base|contains)|byte-identical|strict superset|as (a )?no-op`) + +func duplicateQuestionText(question string) bool { + return duplicateQuestionPattern.MatchString(strings.TrimSpace(question)) +} + +func decisionQuestionBacking(r PerspectiveReport, threshold outputschema.Severity) string { + if r.RedundantOf > 0 { + return fmt.Sprintf("duplicate: #%d already carries this change", r.RedundantOf) + } + if duplicateQuestionText(r.DecisionQuestion) { + return "duplicate: the review found this change already landed or open elsewhere" + } + if r.DecisionRiskHigh { + return "reviewer marked the question high-risk" + } + if class, risk := DecisionQuestionRiskClassFor(r.DecisionQuestion, r.PermissionsTighteningOnly); risk { + return class + " question" + } + for _, f := range r.Findings { + if InScopeFinding(f) && severityAtLeast(f.Severity, threshold) { + return fmt.Sprintf("%s finding %q is %s", r.Perspective, strings.TrimSpace(f.Title), f.Severity) + } + } + if containsRiskEscalationTermFor(r.Summary, r.PermissionsTighteningOnly) { + return "risk escalation in the " + string(r.Perspective) + " review" + } + for _, f := range r.Findings { + if containsRiskEscalationTermFor(f.Title, r.PermissionsTighteningOnly) || containsRiskEscalationTermFor(f.Summary, r.PermissionsTighteningOnly) { + return fmt.Sprintf("risk escalation in %s finding %q", r.Perspective, strings.TrimSpace(f.Title)) + } + } + return "" +} + // FixCycleCapReached reports whether an aggregate is held because the review // repair loop exhausted its configured retry budget. func FixCycleCapReached(a Aggregate) bool { @@ -1027,6 +1143,22 @@ func selfAuthoredDecisionAdvisory(questions []string) string { return "decision resolved by policy: " + strings.Join(names, ", ") + " — not a risk question; recorded as advisory: " + strings.Join(cleaned, " | ") } +// contributorDecisionAdvisory is the audit reason for a contributor-lane +// decision question the review did not back with a finding. +func contributorDecisionAdvisory(questions []string) string { + var cleaned []string + for _, q := range questions { + if q = strings.TrimSpace(q); q != "" { + cleaned = append(cleaned, q) + } + } + sort.Strings(cleaned) + if len(cleaned) == 0 { + return "decision question not backed by a finding — the PR keeps moving; a person meets it at the merge gate" + } + return "decision question not backed by a finding — the PR keeps moving; a person meets it at the merge gate; recorded as advisory: " + strings.Join(cleaned, " | ") +} + func decisionReason(question string) string { question = strings.TrimSpace(question) if question == "" { diff --git a/src/pkg/review/review_test.go b/src/pkg/review/review_test.go index 0499cd4d16..094fe80fa2 100644 --- a/src/pkg/review/review_test.go +++ b/src/pkg/review/review_test.go @@ -58,12 +58,18 @@ func TestAggregateReportsMatrix(t *testing.T) { {name: "changes requested enters fix cycle", reps: append(allApprove()[:1], baseReport(PerspectiveSecurity, VerdictChangesRequested)), want: VerdictChangesRequested, fix: true}, {name: "severity threshold requires human", reps: []PerspectiveReport{baseReport(PerspectiveSecurity, VerdictApprove, highFinding)}, want: VerdictRequiresHuman, human: true}, {name: "explicit requires human wins", reps: []PerspectiveReport{baseReport(PerspectiveCorrectness, VerdictApprove), baseReport(PerspectiveSecurity, VerdictRequiresHuman)}, want: VerdictRequiresHuman, human: true}, - {name: "decision request marker wins", reps: []PerspectiveReport{func() PerspectiveReport { + {name: "decision request marker wins when backed by a finding", reps: []PerspectiveReport{func() PerspectiveReport { r := baseReport(PerspectiveCorrectness, VerdictApprove) r.DecisionRequested = true - r.DecisionQuestion = "@clubanderson should decide whether this groundwork lands before its consumer." + r.DecisionQuestion = "@clubanderson should decide whether this workflow trigger change is acceptable." return r }()}, want: VerdictRequiresHuman, human: true}, + {name: "unbacked decision request on a contributor PR is advisory", reps: []PerspectiveReport{func() PerspectiveReport { + r := baseReport(PerspectiveCorrectness, VerdictApprove) + r.DecisionRequested = true + r.DecisionQuestion = "@clubanderson should decide whether this groundwork lands before its consumer." + return r + }()}, want: VerdictApprove, merge: true}, {name: "reject recommends close", reps: []PerspectiveReport{baseReport(PerspectiveCorrectness, VerdictReject)}, want: VerdictReject, close: true}, {name: "fix cap requires human", reps: []PerspectiveReport{baseReport(PerspectiveCorrectness, VerdictChangesRequested)}, opts: AggregateOptions{FixAttempts: DefaultFixCycleCap}, want: VerdictRequiresHuman, human: true}, {name: "missing perspectives is incomplete, not a human hold", reps: []PerspectiveReport{baseReport(PerspectiveCorrectness, VerdictApprove)}, want: VerdictIncomplete}, @@ -82,7 +88,7 @@ func TestAggregateReportsMatrix(t *testing.T) { func TestAggregateReportsCarriesDecisionQuestion(t *testing.T) { r := baseReport(PerspectiveCorrectness, VerdictApprove) r.DecisionRequested = true - r.DecisionQuestion = "@clubanderson should decide whether this groundwork lands before its consumer." + r.DecisionQuestion = "@clubanderson should decide whether this CODEOWNERS-protected workflow change is acceptable." got := AggregateReports([]PerspectiveReport{r}, AggregateOptions{}) @@ -690,3 +696,84 @@ func TestAggregateReportsKeepsRedundantOfDecisionOnHiveAuthoredPR(t *testing.T) t.Fatalf("aggregate = %+v, want requires_human with redundant_of 15427", got) } } + +// Owner rule (2026-10-29): no human decision while a contributor PR is in +// CI/Review unless the review found something. hive's own #15312 (duplicate +// of #15309), #15410 (workflow pin) and friends sat 3–21h on +// decision-requested verdicts; the duplicate and trust-surface questions +// stay a person's, a bare "should this land?" does not. +func TestAggregateReportsContributorDecisionNeedsBacking(t *testing.T) { + ask := func(q string, findings ...outputschema.Finding) PerspectiveReport { + r := baseReport(PerspectiveIntentAlignment, VerdictRequiresHuman, findings...) + r.DecisionRequested = true + r.DecisionQuestion = q + return r + } + tests := []struct { + name string + rep PerspectiveReport + parked bool + finding string + }{ + {name: "bare product question keeps moving", rep: ask("@clubanderson should decide whether this groundwork lands before its consumer."), parked: false}, + {name: "duplicate of another PR is a finding", rep: ask("@clubanderson should decide whether #15312 is closed in favour of #15309, which clears the same ledger row."), parked: true, finding: "duplicate"}, + {name: "already landed is a finding", rep: ask("@clubanderson should confirm #15324 can be closed as a no-op — #15301 already landed this exact fix."), parked: true, finding: "duplicate"}, + {name: "workflow question is a risk class", rep: ask("@clubanderson should decide whether to accept this workflow-trigger change."), parked: true, finding: "sensitive-paths question"}, + {name: "redundant-of marker is a finding", rep: func() PerspectiveReport { + r := ask("close as superseded?") + r.RedundantOf = 15309 + return r + }(), parked: true, finding: "duplicate: #15309"}, + {name: "high-risk marker is a finding", rep: func() PerspectiveReport { + r := ask("should this land?") + r.DecisionRiskHigh = true + return r + }(), parked: true, finding: "high-risk"}, + {name: "finding at the human threshold is a finding", rep: ask("should this land?", outputschema.Finding{Title: "Clears the wrong ledger key", Severity: outputschema.SeverityHigh, ReviewScope: "in-scope"}), parked: true, finding: `finding "Clears the wrong ledger key" is high`}, + {name: "finding below the human threshold is not", rep: ask("should this land?", outputschema.Finding{Title: "Get-before-Clear is redundant", Severity: outputschema.SeverityLow, ReviewScope: "in-scope"}), parked: false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := AggregateReports([]PerspectiveReport{tt.rep}, AggregateOptions{}) + if tt.parked { + if got.Verdict != VerdictRequiresHuman || !got.DecisionRequested || got.DecisionQuestion != tt.rep.DecisionQuestion { + t.Fatalf("aggregate = %+v, want decision request kept", got) + } + if !strings.Contains(got.DecisionFinding, tt.finding) { + t.Fatalf("DecisionFinding = %q, want it to name %q", got.DecisionFinding, tt.finding) + } + return + } + if got.Verdict != VerdictApprove || !got.MergeEligible || got.RequiresHuman || got.DecisionRequested || got.DecisionQuestion != "" || got.DecisionFinding != "" { + t.Fatalf("aggregate = %+v, want advisory approve", got) + } + if got.Perspectives[PerspectiveIntentAlignment] != VerdictApprove { + t.Fatalf("perspectives = %v, want the forced requires_human read as approve", got.Perspectives) + } + if len(got.Reasons) != 1 || !strings.Contains(got.Reasons[0], "not backed by a finding") || !strings.Contains(got.Reasons[0], tt.rep.DecisionQuestion) { + t.Fatalf("Reasons = %v, want one advisory carrying the question", got.Reasons) + } + }) + } +} + +func TestAggregateReportsContributorDecisionEscalatePolicyKeepsQuestion(t *testing.T) { + r := baseReport(PerspectiveCorrectness, VerdictRequiresHuman) + r.DecisionRequested = true + r.DecisionQuestion = "@clubanderson should decide whether this groundwork lands before its consumer." + got := AggregateReports([]PerspectiveReport{r}, AggregateOptions{SelfAuthoredDecisionPolicy: "escalate"}) + if got.Verdict != VerdictRequiresHuman || !got.DecisionRequested { + t.Fatalf("aggregate = %+v, want escalate policy to keep every decision question", got) + } +} + +func TestAggregateReportsContributorUnbackedDecisionWithChangesRoutesToFixer(t *testing.T) { + ask := baseReport(PerspectiveIntentAlignment, VerdictRequiresHuman) + ask.DecisionRequested = true + ask.DecisionQuestion = "@clubanderson should decide whether this groundwork lands before its consumer." + changes := baseReport(PerspectiveCorrectness, VerdictChangesRequested, outputschema.Finding{Title: "nil deref", Severity: outputschema.SeverityMedium, ReviewScope: "in-scope"}) + got := AggregateReports([]PerspectiveReport{ask, changes}, AggregateOptions{}) + if got.Verdict != VerdictChangesRequested || !got.FixCycle || got.DecisionRequested || got.RequiresHuman { + t.Fatalf("aggregate = %+v, want the sibling change request to route to the fixer, question advisory", got) + } +} diff --git a/src/pkg/stageengine/derive_pr_no_decision_in_ci_test.go b/src/pkg/stageengine/derive_pr_no_decision_in_ci_test.go new file mode 100644 index 0000000000..0d39457653 --- /dev/null +++ b/src/pkg/stageengine/derive_pr_no_decision_in_ci_test.go @@ -0,0 +1,67 @@ +package stageengine + +import ( + "testing" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// Owner rule (2026-10-29): "there should be no decisions by a human while +// these are in ci/review — unless the review found something." Twelve of +// hive's own contributor-lane PRs (#15312, #15324, #15410, …) sat 3–21h as +// 085 records the tracker read as "PR in progress". The aggregate now +// resolves a decision question with nothing behind it as advisory, so the +// stage engine only ever sees a decision-requested verdict that names its +// finding; this pins the three shapes the lane must produce. +func TestClassifyStageContributorLaneNoDecisionDuringCIReview(t *testing.T) { + cases := []struct { + name string + reason string + detail stageDetail + wantStage stagelabels.Stage + wantReason string + }{ + { + // (a) no verdict yet: the head waits for the swarm, nobody is asked. + name: "no verdict → review pending, not 085", + reason: contributorLaneReasonNoVerdict, + detail: stageDetail{}, + wantStage: stagelabels.ReviewPending, + }, + { + name: "no verdict with CI pending → review pending, not 085", + reason: "check-pending", + detail: stageDetail{}, + wantStage: stagelabels.ReviewPending, + }, + { + // (b) the review found something: 085 with the finding carried. + name: "decision backed by a finding → 085 with the decision-requested reason", + reason: "check-pending", + detail: stageDetail{VerdictKnown: true, Verdict: ContributorLaneVerdict{Configured: true, Verdict: "requires_human", DecisionRequested: true, DecisionQuestion: "close #15312 in favour of #15309?", DecisionFinding: "duplicate: the review found this change already landed or open elsewhere"}}, + wantStage: stagelabels.NeedsDecision, + wantReason: StageReasonDecisionRequested, + }, + { + // (c) green and approved: the merge gate's human-merge state. + name: "green + approved, author below the lane's trust → 090 ready for human merge, not 085", + reason: contributorLaneReasonClaimTier, + detail: stageDetail{VerdictKnown: true, Verdict: ContributorLaneVerdict{Configured: true, Approved: true, Verdict: "approve"}}, + wantStage: stagelabels.ReadyForHumanMerge, + }, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + v := ClassifyStage(stageObservation{Lane: stageLaneContributor, Reason: tc.reason, HeadSHA: goldenHead, Detail: tc.detail}) + if v.Stage != tc.wantStage { + t.Fatalf("classified as %+v, want stage %s", v, tc.wantStage) + } + if tc.wantReason != "" && v.Reason != tc.wantReason { + t.Fatalf("reason = %q, want %q", v.Reason, tc.wantReason) + } + if tc.wantStage != stagelabels.NeedsDecision && v.Stage == stagelabels.NeedsDecision { + t.Fatalf("classified as %+v, want not needs-decision", v) + } + }) + } +} diff --git a/src/pkg/stageengine/prstage/types.go b/src/pkg/stageengine/prstage/types.go index 4c4e2fd698..426f002258 100644 --- a/src/pkg/stageengine/prstage/types.go +++ b/src/pkg/stageengine/prstage/types.go @@ -184,6 +184,12 @@ type ReviewVerdict struct { Verdict string DecisionRequested bool DecisionQuestion string + // DecisionFinding names what the review found that makes the decision + // a person's (duplicate, risk-class question, finding at the human + // threshold, reviewer high-risk marker). A decision-requested verdict + // without one never reaches the stage engine: the aggregate resolves + // it as advisory (review.AggregateReports, owner rule 2026-10-29). + DecisionFinding string // RedundantOf is the PR the reviewer named as already carrying this // change (``): the decision is a close, // and for the hive's own PR the lane performs it (hivecommons/hive#15499). diff --git a/src/pkg/stagelabels/human.go b/src/pkg/stagelabels/human.go index 2abe2e5474..588c03bfdb 100644 --- a/src/pkg/stagelabels/human.go +++ b/src/pkg/stagelabels/human.go @@ -122,6 +122,10 @@ type Evidence struct { // DecisionQuestion is the maintainer-facing question from the reviewer // verdict/comment, when the swarm explicitly deferred a product call. DecisionQuestion string + // DecisionFinding is what the review found that makes the question a + // person's — printed so the comment and tracker say WHY, not just that + // a decision is owed (hivecommons/hive, owner rule 2026-10-29). + DecisionFinding string // HumanSummaries are reviewer summaries for requires_human verdicts that // did not carry a structured decision question. HumanSummaries []string @@ -352,6 +356,9 @@ func RouteHuman(e Evidence) Route { break } decide = append(decide, "the reviewer swarm returned `requires_human` @"+ShortSHA(e.Head)) + if f := strings.TrimSpace(e.DecisionFinding); f != "" { + decide = append(decide, "the review found: "+f) + } if q := strings.TrimSpace(e.DecisionQuestion); q != "" { if decisionQuestionPlaceholderMention(q) { q += " _(the reviewer named no specific person; repository approvers/owners, this is yours)_" diff --git a/src/pkg/stagelabels/human_test.go b/src/pkg/stagelabels/human_test.go index 5696c12b79..39ca1399e6 100644 --- a/src/pkg/stagelabels/human_test.go +++ b/src/pkg/stagelabels/human_test.go @@ -149,6 +149,11 @@ func TestRouteHumanDecision(t *testing.T) { e.Verdict = VerdictRequiresHuman e.DecisionQuestion = "@clubanderson should decide whether to land this now." }, "reviewer question: @clubanderson should decide whether to land this now."}, + {"requires_human finding", func(e *Evidence) { + e.Verdict = VerdictRequiresHuman + e.DecisionQuestion = "close in favour of #15309?" + e.DecisionFinding = "duplicate: the review found this change already landed or open elsewhere" + }, "the review found: duplicate: the review found this change already landed or open elsewhere"}, {"requires_human summary", func(e *Evidence) { e.Verdict = VerdictRequiresHuman e.HumanSummaries = []string{"security requires human: relay owner should confirm before merge"} From ef1aa230982589327116ea27b88a67a81979469c Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 23:27:41 -0400 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20review:=20only=20a=20securit?= =?UTF-8?q?y=20finding=20parks=20an=20untrusted=20PR=20during=20CI/Review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Owner refinements (#15640): the only early exit from hands-free CI/Review for a contributor PR is something fishy or insecure — one predicate, review.IsSecuritySensitiveFinding (reviewer high-risk marker, security perspective hold, security-class question, finding on a sentinel or security.sensitive_paths path, insecure behaviour flagged). Duplicates, nits, ordinary findings go back to the clanker or are advisory. The operator has the last word on untrusted merges: a green, approved, soaked untrusted PR parks at 090, never auto-merges (test). Sweep tests assert no CI/Review stage is human-owned and every tracker CI/Review row names its mover. Signed-off-by: Andrew Anderson --- ...ixed-contributor-decision-needs-finding.md | 2 +- src/cmd/hive/main.go | 1 + src/docs/hive-merge.md | 27 ++- src/docs/review-swarm.md | 71 ++++-- src/pkg/config/config.go | 3 + src/pkg/config/security.go | 17 ++ .../config/testdata/agent_runtime_golden.json | 1 + .../dashboard/settings_parity_allowlist.txt | 1 + .../stage_tracker_ci_review_mover_test.go | 27 +++ .../automerge_contributor_lane_test.go | 30 +++ src/pkg/review/plan_match_test.go | 5 + src/pkg/review/review.go | 130 ++--------- src/pkg/review/review_test.go | 86 ++++--- src/pkg/review/security_finding.go | 218 ++++++++++++++++++ .../derive_pr_no_decision_in_ci_test.go | 72 ++++++ 15 files changed, 522 insertions(+), 169 deletions(-) create mode 100644 src/pkg/config/security.go create mode 100644 src/pkg/dashboard/stage_tracker_ci_review_mover_test.go create mode 100644 src/pkg/review/security_finding.go diff --git a/src/changelog.d/fixed-contributor-decision-needs-finding.md b/src/changelog.d/fixed-contributor-decision-needs-finding.md index 1bf97af394..82fd75f172 100644 --- a/src/changelog.d/fixed-contributor-decision-needs-finding.md +++ b/src/changelog.d/fixed-contributor-decision-needs-finding.md @@ -1 +1 @@ -- Contributor-lane PRs no longer park at `stage/085-needs-decision` on a reviewer decision marker alone while they are in CI/Review. The review aggregate honours a `decision_requested` verdict on a non-hive-authored PR only when the review found something — a duplicate, a trust-surface / risk-class question, the reviewer's high-risk marker, or a finding at the human threshold — and records it as `decision_finding`, which the 085 comment and the tracker print as `the review found: …`. An unbacked question is advisory: the PR keeps moving and a contributor the lane cannot vouch for waits at `stage/090-ready-for-human-merge` under the human-merge rule instead. +- Contributor-lane PRs no longer park at `stage/085-needs-decision` on a reviewer decision marker or bare `requires_human` while they are in CI/Review. The only early exit is a concrete security / trust finding (`review.IsSecuritySensitiveFinding`: reviewer high-risk marker, security perspective hold, security-class question, finding on a sensitive path — `sentinel.sensitive_paths` plus the new `security.sensitive_paths` — or insecure behaviour flagged), recorded as `decision_finding` and printed by the 085 comment and tracker as `the review found: …`. Everything else goes back to the clanker or is advisory and the PR moves on to the merge gate, where an untrusted author's PR parks at `stage/090-ready-for-human-merge` for the operator's merge — never auto-merged (#15640). diff --git a/src/cmd/hive/main.go b/src/cmd/hive/main.go index 56a4cd6243..b601143429 100644 --- a/src/cmd/hive/main.go +++ b/src/cmd/hive/main.go @@ -11180,6 +11180,7 @@ func refreshReviewVerdicts(cfg *config.Config, logger *slog.Logger) { MaxPerspectivesPerPR: cfg.Review.MaxPerspectivesPerPR, Perspectives: reviewPerspectiveSet(cfg, logger), SelfAuthoredDecisionPolicy: cfg.Review.EffectiveSelfAuthoredDecisionPolicy(), + SensitivePaths: cfg.Security.SensitivePaths, ModelStamps: reviewModelStamps(logger), ExpectedHeads: cfg.ExpectedReviewHeads(), MissingHeads: reviewMissingHeads(), diff --git a/src/docs/hive-merge.md b/src/docs/hive-merge.md index e78dd3a0fe..e914f28dab 100644 --- a/src/docs/hive-merge.md +++ b/src/docs/hive-merge.md @@ -614,18 +614,23 @@ unattended (for example `mrbobbytables`): A claim keeps the tier the contributor held when it was taken, so grant the tier before the issue is leased. -**No decision during CI/Review.** A contributor PR is not parked at +**No decision during CI/Review; the operator has the last word on +untrusted merges.** A contributor PR is not parked at `stage/085-needs-decision` on a reviewer decision marker alone. While it is -in CI/Review the hive runs CI and the review swarm to completion; the -aggregate honours a `decision_requested` verdict only when the review -*found* something (duplicate, trust-surface / risk-class question, high-risk -marker, finding at the human threshold) and records that finding as -`decision_finding`, which the 085 comment prints as `the review found: …`. -A question with nothing behind it is advisory and the PR keeps moving; a -contributor whose tier the lane cannot vouch for then waits at -`stage/090-ready-for-human-merge` under the human-merge rule — a merge-gate -state, not a review decision. See -[review-swarm.md](review-swarm.md) ("Contributor and human-authored PRs: no decision in CI/Review"). +in CI/Review the hive runs CI and the review swarm to completion and the +row always names its mover; the only early exit is a concrete security / +trust finding (`review.IsSecuritySensitiveFinding`: high-risk marker, +security perspective hold, security-class question, finding on a sensitive +path — `sentinel.sensitive_paths` plus `security.sensitive_paths` — or +insecure behaviour flagged), recorded as `decision_finding` and printed as +`the review found: …`. Anything else goes back to the clanker or is +advisory and the PR keeps moving. At the merge gate a contributor the lane +cannot vouch for parks at `stage/090-ready-for-human-merge` +(`contributor-lane:claim-tier-untrusted`, `untrusted-author-role`, the +human-merge rule) and waits for the operator's merge — the hive never +auto-merges an untrusted author's PR, however green, approved and soaked. +See [review-swarm.md](review-swarm.md) ("Contributor and human-authored +PRs: no decision in CI/Review"). ### Issue-author credit at merge time diff --git a/src/docs/review-swarm.md b/src/docs/review-swarm.md index 2683a056d5..5f143f5ad0 100644 --- a/src/docs/review-swarm.md +++ b/src/docs/review-swarm.md @@ -323,30 +323,55 @@ issue/spec and PR body before asking, and to cite the answer (`per #: …`) instead of raising a question the issue already settled. **Contributor and human-authored PRs: no decision in CI/Review unless the -review found something.** The owner rule (2026-10-29) is that while a PR -is in CI/Review the hive runs CI and the review swarm to completion on its -own; a person is only asked when the review *found* something concrete. -A decision-requested verdict on a non-hive-authored PR therefore parks at -`stage/085-needs-decision` only when it is **backed** by one of: - -- a duplicate (``, or the question says the - change already landed / is byte-identical / is a no-op); +review found something fishy or insecure.** The owner's rules +([#15640](https://github.com/hivecommons/hive/issues/15640)), verbatim: + +> there should be no decisions by a human while these are in ci/review — +> unless the review found something. +> unless you find something fishy and insecure happening at the pr in +> progress level, then we can let things go and then decide in merge +> queue, if needed. +> we dont want to create a log jam during pr in progress. +> i always have the last word when it comes to merge of untrusted. + +So while a PR the hive did not author is in CI/Review, the hive runs CI and +the review swarm to completion on its own, and the stage always has an +active mover (CI, the swarm, the clanker fixing, the hive adopting). The +**only** early exit to `stage/085-needs-decision` is a concrete security / +trust finding — one predicate, `review.IsSecuritySensitiveFinding` +(`src/pkg/review/security_finding.go`): + - the reviewer's `` marker; -- a question in one of the risk classes above (trust surface: workflows, - CODEOWNERS, permissions, …); -- an in-scope finding at or above the `requires_human` severity threshold; -- a risk-escalation term in the summary or findings (sentinel alert, - credential, secret, …). - -The aggregate then records **what** was found as `decision_finding`, and the -085 comment and tracker popover print it as `the review found: …` next to -the reviewer's question. A question with nothing behind it is advisory: -the aggregate is `approve` (or `changes_requested`, handed to the fixer, -when a sibling perspective asked for changes), recorded as -`decision question not backed by a finding — the PR keeps moving; a person meets it at the merge gate; recorded as advisory: `, and the PR keeps moving to the -merge gate. A contributor- or human-authored PR that needs a person's merge -click waits there, at `stage/090-ready-for-human-merge` under the -human-merge rule — a merge-queue state, never an 085 decision raised during +- the security perspective withholding approval (`requires_human`); +- a decision question in a security-class risk class — `security`, + `permissions-credentials`, `sensitive-paths` (workflows, CODEOWNERS, + branch protection, deploy, Dockerfiles, dependency manifests, …); +- an in-scope finding on a sensitive path: `sentinel.DefaultSensitivePaths` + plus the operator's extra globs in `security.sensitive_paths`; +- an in-scope finding, or the review summary, flagging insecure or + suspicious behaviour (injection, exfiltration, secrets, unpinned actions, + supply chain, …). + +A sentinel alert (`contributor-lane:sentinel-blocked`), a workflow-path or +tests-removed lane rule and a reporter-trust hold are the lane-side +equivalents and park the PR the same way. The finding is recorded as +`decision_finding` and the 085 comment and tracker popover print it as +`the review found: …` next to the reviewer's question, so the operator is +told WHAT was found. + +Everything else the review raises — ordinary nits and findings, a duplicate, +naming, scope, sequencing, licensing, a failing optional check, a conflict +— never asks a person during CI/Review: a finding goes back to the +clanker / adoption path as `changes_requested`; a bare question is +advisory, the aggregate is `approve`, recorded as +`no security finding — the PR keeps moving; a person has the last word at the merge gate; recorded as advisory: `, +and the PR moves on. At the merge gate the untrusted-author invariant +holds: a contributor the lane cannot vouch for parks at +`stage/090-ready-for-human-merge` (`contributor-lane:claim-tier-untrusted`, +`untrusted-author-role`, the human-merge rule) and waits for the operator's +merge-now / queue-merge — the hive never auto-merges an untrusted author's +PR, green, approved and soaked or not. `self_authored_decision_policy: +escalate` restores the old park-on-every-marker behavior for these PRs too. review. The same `self_authored_decision_policy: escalate` switch restores the old park-on-every-marker behavior for these PRs too. diff --git a/src/pkg/config/config.go b/src/pkg/config/config.go index 026fe86b08..c85997c7da 100644 --- a/src/pkg/config/config.go +++ b/src/pkg/config/config.go @@ -126,6 +126,9 @@ type Config struct { // escalation or codebase damage, from any author. Default on; see // SentinelConfig. Sentinel SentinelConfig `yaml:"sentinel,omitempty" json:"sentinel,omitempty"` + // Security holds the hive-wide security knobs that are not one agent's + // or one sweep's; see SecurityConfig. + Security SecurityConfig `yaml:"security,omitempty" json:"security,omitempty"` // Evidence controls the review evidence bundles the review relay writes // (hivecommons/hive#11060). Default on, unsigned; see EvidenceConfig. Evidence EvidenceConfig `yaml:"evidence,omitempty" json:"evidence,omitempty"` diff --git a/src/pkg/config/security.go b/src/pkg/config/security.go new file mode 100644 index 0000000000..734c78870d --- /dev/null +++ b/src/pkg/config/security.go @@ -0,0 +1,17 @@ +package config + +// SecurityConfig is the hive-wide `security:` block. +// +// Owner rule (hivecommons/hive#15640): a contributor's PR runs CI and the +// review swarm hands-free; the only thing that may park it for a person +// during CI/Review is a concrete security / trust finding +// (review.IsSecuritySensitiveFinding). The finding predicate treats a +// review finding on a sensitive path as such a finding; the path set is +// sentinel.DefaultSensitivePaths plus the globs here. +type SecurityConfig struct { + // SensitivePaths are extra glob patterns (same syntax as + // sentinel.sensitive_paths: `deploy/**`, `internal/auth/**`, + // `**/Dockerfile`) that an untrusted author touching, with a review + // finding on them, parks the PR for a person during CI/Review. + SensitivePaths []string `yaml:"sensitive_paths,omitempty" json:"sensitive_paths,omitempty"` +} diff --git a/src/pkg/config/testdata/agent_runtime_golden.json b/src/pkg/config/testdata/agent_runtime_golden.json index b464060d78..d417b2075f 100644 --- a/src/pkg/config/testdata/agent_runtime_golden.json +++ b/src/pkg/config/testdata/agent_runtime_golden.json @@ -671,6 +671,7 @@ "quality": {}, "intent": {}, "sentinel": {}, + "security": {}, "evidence": { "complexity": {} }, diff --git a/src/pkg/dashboard/settings_parity_allowlist.txt b/src/pkg/dashboard/settings_parity_allowlist.txt index 2750c503f4..d443261c5c 100644 --- a/src/pkg/dashboard/settings_parity_allowlist.txt +++ b/src/pkg/dashboard/settings_parity_allowlist.txt @@ -470,6 +470,7 @@ forgestate.freshness_bound_s # yaml-only until readers migrate (#13373) forgestate.reconcile_interval_s # yaml-only until readers migrate (#13373) forgestate.search_budget # yaml-only until readers migrate (#13373) scanner.skip_issues_with_open_pr # open-PR dispatch guard (#14799); yaml-only +security.sensitive_paths[] # TODO #15640 self_experiments.scheduler.enabled # TODO #11854 self_experiments.scheduler.interval_s # TODO #11854 self_experiments.scheduler.mode # TODO #11854 diff --git a/src/pkg/dashboard/stage_tracker_ci_review_mover_test.go b/src/pkg/dashboard/stage_tracker_ci_review_mover_test.go new file mode 100644 index 0000000000..9661e6e206 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_ci_review_mover_test.go @@ -0,0 +1,27 @@ +package dashboard + +import ( + "testing" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// Owner rule (hivecommons/hive#15640): "we dont want to create a log jam +// during pr in progress". Every CI/Review row names who is moving it — CI, +// the review swarm, the hive, or the author — never a maintainer and never +// nobody, whatever lane reason the record carries. +func TestStageTrackerCIReviewCaptionAlwaysNamesAMover(t *testing.T) { + stages := []stagelabels.Stage{stagelabels.ReviewPending, stagelabels.Reviewed, stagelabels.Fixing, stagelabels.NeedsAuthor, stagelabels.ReturnedToContributor, stagelabels.AdoptedByHive} + reasons := []string{"", "contributor-lane:no-verdict", "contributor-lane:claim-tier-untrusted", "check-pending", "check-failing:unit", "conflicting", "contributor-lane:changes-requested", "something-unmapped"} + for _, stage := range stages { + for _, reason := range reasons { + caption, actor := stageTrackerCaption(stage, reason, "odttlnt", "pr", false, stagelabels.Record{}, false, 0, "036bff04036bff04036bff04036bff04036bff04") + if caption == "" || actor == "" { + t.Errorf("%v %q: caption=%q actor=%q — a CI/Review row with no mover", stage, reason, caption, actor) + } + if actor == "maintainer" { + t.Errorf("%v %q: actor is the maintainer during CI/Review (%q)", stage, reason, caption) + } + } + } +} diff --git a/src/pkg/github/automerge/automerge_contributor_lane_test.go b/src/pkg/github/automerge/automerge_contributor_lane_test.go index d9636a1b40..db17b8a562 100644 --- a/src/pkg/github/automerge/automerge_contributor_lane_test.go +++ b/src/pkg/github/automerge/automerge_contributor_lane_test.go @@ -24,6 +24,8 @@ import ( "github.com/hivecommons/hive/pkg/intent" "github.com/hivecommons/hive/pkg/review" hreview "github.com/hivecommons/hive/pkg/review" + "github.com/hivecommons/hive/pkg/stageengine" + "github.com/hivecommons/hive/pkg/stageengine/prstage" "github.com/hivecommons/hive/pkg/stagelabels" ) @@ -2022,3 +2024,31 @@ func storedChangeRequest(t *testing.T, head string) *hreview.HumanChangeRequests } return store } + +// Owner invariant (hivecommons/hive#15640), verbatim: "i always have the +// last word when it comes to merge of untrusted". A green, approved, +// soaked PR from a contributor the lane cannot vouch for (self-registered +// newcomer, untrusted tier) is never auto-merged: the lane refuses with +// claim-tier-untrusted and the stage engine parks it at 090 +// ready-for-human-merge — the merge gate, not an 085 decision in review. +func TestContributorLaneUntrustedGreenApprovedParksForHumanMerge(t *testing.T) { + fx := validContributorFixture() + fx.issueComments[0]["body"] = contributorClaimMarkerTier(contributorLaneTestAuthor, "contributor", contributorLaneTestHive, " tier=newcomer verified=false") + api := newContributorLaneAPI(t, &fx) + defer api.Close() + policy := defaultContributorLanePolicy() + clock := &contributorLaneClock{at: time.Date(2026, 10, 15, 13, 0, 0, 0, time.UTC)} + engine := newContributorLaneEngine(api.URL, policy, clock, Options{ContributorSoak: soakedTracker(clock)}) + + _, reason, err := engine.trySweepContributorLanePR(context.Background(), "widget", "acme", "widget", 7, policy) + if err != nil || reason != contributorLaneReasonClaimTier { + t.Fatalf("reason = %q err = %v, want %q", reason, err, contributorLaneReasonClaimTier) + } + if fx.merges != 0 { + t.Fatalf("untrusted author auto-merged (%d merges)", fx.merges) + } + v := stageengine.ClassifyStage(prstage.Observation{Lane: stageLaneContributor, Reason: reason, HeadSHA: "sha7", Detail: prstage.Detail{VerdictKnown: true, Verdict: approvedVerdict("acme/widget", 7, "sha7")}}) + if v.Stage != stagelabels.ReadyForHumanMerge || !v.Human { + t.Fatalf("stage = %+v, want 090 ready-for-human-merge awaiting the operator", v) + } +} diff --git a/src/pkg/review/plan_match_test.go b/src/pkg/review/plan_match_test.go index 33bdf93708..eb8e29f49e 100644 --- a/src/pkg/review/plan_match_test.go +++ b/src/pkg/review/plan_match_test.go @@ -161,6 +161,11 @@ func TestPlanMatchScopeFindingHoldsForHuman(t *testing.T) { set := (PerspectiveSet{}).WithPlanMatch() scope := outputschema.Finding{Title: "scope exceeds plan", Severity: outputschema.SeverityHigh, Summary: "adds pkg/billing/invoice.go, which no planned item covers", File: "pkg/billing/invoice.go", Line: 1} reps := append(allApprove(), planMatchReport(VerdictRequiresHuman, scope)) + // Plans are the hive's own; a contributor's out-of-plan file is a fixer + // round, not a human hold (hivecommons/hive#15640). + for i := range reps { + reps[i].HiveAuthored = true + } agg := AggregateReports(reps, AggregateOptions{Perspectives: set}) if agg.Verdict != VerdictRequiresHuman || !agg.RequiresHuman { t.Fatalf("scope finding aggregate = %s", agg.Verdict) diff --git a/src/pkg/review/review.go b/src/pkg/review/review.go index 906def5604..f9b29541c5 100644 --- a/src/pkg/review/review.go +++ b/src/pkg/review/review.go @@ -195,6 +195,11 @@ type AggregateOptions struct { // a decision question that matches no DecisionRiskClass and carries no // `hive-decision-risk: high` marker. SelfAuthoredDecisionPolicy string + // SensitivePaths are the operator's extra `security.sensitive_paths` + // globs; a contributor-PR finding on one of them (or on a + // sentinel.DefaultSensitivePaths path) is a security finding that may + // park the PR for a person during CI/Review (IsSecuritySensitiveFinding). + SensitivePaths []string // MaxPerspectivesPerPR mirrors DispatchOptions.MaxPerspectivesPerPR. A // perspective the dispatcher never hands out cannot approve, so unanimity // must be judged against what the PR was eligible to receive. Zero means @@ -379,6 +384,7 @@ func aggregatePlainReports(reports []PerspectiveReport, opts AggregateOptions) A func aggregateReports(reports []PerspectiveReport, opts AggregateOptions) Aggregate { threshold := opts.HumanThreshold + sensitivePaths := SecuritySensitivePaths(opts.SensitivePaths) if threshold == "" { threshold = DefaultHumanThreshold } @@ -486,38 +492,15 @@ func aggregateReports(reports []PerspectiveReport, opts AggregateOptions) Aggreg sort.Strings(agg.HumanSummaries) if decisionRequested { - if finding, backed := decisionQuestionsBacked(reports, threshold); !backed && !agg.HiveAuthored && !strings.EqualFold(strings.TrimSpace(opts.SelfAuthoredDecisionPolicy), "escalate") { - // Owner rule (hivecommons/hive, 2026-10-29): no human decision - // while a PR is in CI/Review unless the review found something. - // A contributor-lane question with no finding behind it — no - // duplicate, no finding at the human threshold, no risk-class - // wording, no high-risk marker — is advisory: the PR keeps - // moving and a person meets it at the merge gate, where the - // human-merge rule for contributor PRs applies. Twelve of - // hive's own PRs sat 3–21h on such questions. - if hasChanges { - if opts.FixAttempts >= maxFix { - agg.Verdict = VerdictRequiresHuman - agg.RequiresHuman = true - agg.DecisionFinding = fmt.Sprintf("fix cycle cap reached (%d/%d)", opts.FixAttempts, maxFix) - agg.Reasons = []string{agg.DecisionFinding} - return agg - } - agg.Verdict = VerdictChangesRequested - agg.FixCycle = true - markRequiresHumanPerspectivesAsChangesRequested(&agg) - } else { - agg.Verdict = VerdictApprove - agg.MergeEligible = true - markRequiresHumanPerspectivesAsApprove(&agg) - agg.Reasons = nil - } - agg.RequiresHuman = false - agg.DecisionRequested = false - agg.DecisionQuestion = "" - agg.Reasons = append(append([]string{}, agg.Reasons...), contributorDecisionAdvisory(decisionQuestions)) - sortReasons(agg.Reasons) - return agg + if finding, backed := securityFindingAcross(reports, sensitivePaths); !backed && contributorHandsFree(agg, opts) { + // Owner rule (hivecommons/hive#15640): no human decision while + // a contributor's PR is in CI/Review unless the review found + // something fishy or insecure. A question with no security + // finding behind it is advisory: the PR keeps moving and the + // person has the last word at the merge gate (090), where the + // untrusted-author merge is theirs. Twelve of hive's own PRs + // sat 3–21h on such questions. + return contributorHandsFreeAggregate(agg, opts, hasChanges || reportsHaveInScopeFinding(reports), maxFix, decisionQuestions) } else if backed { agg.DecisionFinding = finding } @@ -573,6 +556,15 @@ func aggregateReports(reports []PerspectiveReport, opts AggregateOptions) Aggreg return agg } if len(agg.Reasons) > 0 || seenVerdicts[VerdictRequiresHuman] { + if seenVerdicts[VerdictRequiresHuman] && contributorHandsFree(agg, opts) { + // Same rule for a bare requires_human on a contributor's PR + // (hivecommons/hive#15640): only a security finding parks it. + if finding, backed := securityFindingAcross(reports, sensitivePaths); backed { + agg.DecisionFinding = finding + } else { + return contributorHandsFreeAggregate(agg, opts, hasChanges || reportsHaveInScopeFinding(reports), maxFix, agg.HumanSummaries) + } + } if !riskEscalation && selfAuthoredHumanWithConcreteRemediation { if opts.FixAttempts >= maxFix { agg.Verdict = VerdictRequiresHuman @@ -694,64 +686,6 @@ func markRequiresHumanPerspectivesAsApprove(a *Aggregate) { } } -// decisionQuestionsBacked reports whether any report's decision question -// stands on something the review actually found, and names it. The -// backing, first match wins per report: a redundant-of marker (the answer -// is a close), the reviewer's explicit high-risk marker, a question whose -// wording lands in a DecisionRiskClass (workflow, security, permissions, -// duplicate, …), an in-scope finding at or above the human threshold, or -// risk-escalation wording in the review text. -func decisionQuestionsBacked(reports []PerspectiveReport, threshold outputschema.Severity) (string, bool) { - for _, r := range reports { - if !r.DecisionRequested { - continue - } - if finding := decisionQuestionBacking(r, threshold); finding != "" { - return finding, true - } - } - return "", false -} - -// duplicateQuestionPattern is the text form of the `hive-redundant-of` -// marker: the review found the change already on the base or in another -// open PR, so the answer is a close — which only a person gives on a -// contributor's PR. -var duplicateQuestionPattern = regexp.MustCompile(`(?i)\b(duplicates?|dup|redundant)\b|in favou?r of #\d+|already (landed|merged|fixed|on (the )?base|contains)|byte-identical|strict superset|as (a )?no-op`) - -func duplicateQuestionText(question string) bool { - return duplicateQuestionPattern.MatchString(strings.TrimSpace(question)) -} - -func decisionQuestionBacking(r PerspectiveReport, threshold outputschema.Severity) string { - if r.RedundantOf > 0 { - return fmt.Sprintf("duplicate: #%d already carries this change", r.RedundantOf) - } - if duplicateQuestionText(r.DecisionQuestion) { - return "duplicate: the review found this change already landed or open elsewhere" - } - if r.DecisionRiskHigh { - return "reviewer marked the question high-risk" - } - if class, risk := DecisionQuestionRiskClassFor(r.DecisionQuestion, r.PermissionsTighteningOnly); risk { - return class + " question" - } - for _, f := range r.Findings { - if InScopeFinding(f) && severityAtLeast(f.Severity, threshold) { - return fmt.Sprintf("%s finding %q is %s", r.Perspective, strings.TrimSpace(f.Title), f.Severity) - } - } - if containsRiskEscalationTermFor(r.Summary, r.PermissionsTighteningOnly) { - return "risk escalation in the " + string(r.Perspective) + " review" - } - for _, f := range r.Findings { - if containsRiskEscalationTermFor(f.Title, r.PermissionsTighteningOnly) || containsRiskEscalationTermFor(f.Summary, r.PermissionsTighteningOnly) { - return fmt.Sprintf("risk escalation in %s finding %q", r.Perspective, strings.TrimSpace(f.Title)) - } - } - return "" -} - // FixCycleCapReached reports whether an aggregate is held because the review // repair loop exhausted its configured retry budget. func FixCycleCapReached(a Aggregate) bool { @@ -1143,22 +1077,6 @@ func selfAuthoredDecisionAdvisory(questions []string) string { return "decision resolved by policy: " + strings.Join(names, ", ") + " — not a risk question; recorded as advisory: " + strings.Join(cleaned, " | ") } -// contributorDecisionAdvisory is the audit reason for a contributor-lane -// decision question the review did not back with a finding. -func contributorDecisionAdvisory(questions []string) string { - var cleaned []string - for _, q := range questions { - if q = strings.TrimSpace(q); q != "" { - cleaned = append(cleaned, q) - } - } - sort.Strings(cleaned) - if len(cleaned) == 0 { - return "decision question not backed by a finding — the PR keeps moving; a person meets it at the merge gate" - } - return "decision question not backed by a finding — the PR keeps moving; a person meets it at the merge gate; recorded as advisory: " + strings.Join(cleaned, " | ") -} - func decisionReason(question string) string { question = strings.TrimSpace(question) if question == "" { diff --git a/src/pkg/review/review_test.go b/src/pkg/review/review_test.go index 094fe80fa2..414d90b666 100644 --- a/src/pkg/review/review_test.go +++ b/src/pkg/review/review_test.go @@ -697,11 +697,11 @@ func TestAggregateReportsKeepsRedundantOfDecisionOnHiveAuthoredPR(t *testing.T) } } -// Owner rule (2026-10-29): no human decision while a contributor PR is in -// CI/Review unless the review found something. hive's own #15312 (duplicate -// of #15309), #15410 (workflow pin) and friends sat 3–21h on -// decision-requested verdicts; the duplicate and trust-surface questions -// stay a person's, a bare "should this land?" does not. +// Owner rule (hivecommons/hive#15640): no human decision while a +// contributor PR is in CI/Review unless the review found something fishy +// or insecure; everything else keeps moving and the person has the last +// word at the merge gate. hive's own #15312 (duplicate of #15309), #15410 +// (workflow pin) and friends sat 3–21h on decision-requested verdicts. func TestAggregateReportsContributorDecisionNeedsBacking(t *testing.T) { ask := func(q string, findings ...outputschema.Finding) PerspectiveReport { r := baseReport(PerspectiveIntentAlignment, VerdictRequiresHuman, findings...) @@ -712,51 +712,81 @@ func TestAggregateReportsContributorDecisionNeedsBacking(t *testing.T) { tests := []struct { name string rep PerspectiveReport - parked bool + opts AggregateOptions + want Verdict finding string }{ - {name: "bare product question keeps moving", rep: ask("@clubanderson should decide whether this groundwork lands before its consumer."), parked: false}, - {name: "duplicate of another PR is a finding", rep: ask("@clubanderson should decide whether #15312 is closed in favour of #15309, which clears the same ledger row."), parked: true, finding: "duplicate"}, - {name: "already landed is a finding", rep: ask("@clubanderson should confirm #15324 can be closed as a no-op — #15301 already landed this exact fix."), parked: true, finding: "duplicate"}, - {name: "workflow question is a risk class", rep: ask("@clubanderson should decide whether to accept this workflow-trigger change."), parked: true, finding: "sensitive-paths question"}, - {name: "redundant-of marker is a finding", rep: func() PerspectiveReport { + {name: "bare product question keeps moving", rep: ask("@clubanderson should decide whether this groundwork lands before its consumer."), want: VerdictApprove}, + {name: "duplicate question is a merge-gate call, not a CI/Review one", rep: ask("@clubanderson should decide whether #15312 is closed in favour of #15309, which clears the same ledger row."), want: VerdictApprove}, + {name: "redundant-of marker likewise", rep: func() PerspectiveReport { r := ask("close as superseded?") r.RedundantOf = 15309 return r - }(), parked: true, finding: "duplicate: #15309"}, + }(), want: VerdictApprove}, + {name: "workflow question is a sensitive-paths finding", rep: ask("@clubanderson should decide whether to accept this workflow-trigger change."), want: VerdictRequiresHuman, finding: "sensitive-paths question"}, + {name: "credential question is a security finding", rep: ask("should the relay token be read from the environment here?"), want: VerdictRequiresHuman, finding: "permissions-credentials question"}, + {name: "licensing question is not", rep: ask("@clubanderson is the copyright header acceptable?"), want: VerdictApprove}, {name: "high-risk marker is a finding", rep: func() PerspectiveReport { r := ask("should this land?") r.DecisionRiskHigh = true return r - }(), parked: true, finding: "high-risk"}, - {name: "finding at the human threshold is a finding", rep: ask("should this land?", outputschema.Finding{Title: "Clears the wrong ledger key", Severity: outputschema.SeverityHigh, ReviewScope: "in-scope"}), parked: true, finding: `finding "Clears the wrong ledger key" is high`}, - {name: "finding below the human threshold is not", rep: ask("should this land?", outputschema.Finding{Title: "Get-before-Clear is redundant", Severity: outputschema.SeverityLow, ReviewScope: "in-scope"}), parked: false}, + }(), want: VerdictRequiresHuman, finding: "high-risk"}, + {name: "finding on a default sensitive path is a finding", rep: ask("should this land?", outputschema.Finding{Title: "new job runs on pull_request_target", Severity: outputschema.SeverityMedium, ReviewScope: "in-scope", File: ".github/workflows/ci.yml"}), want: VerdictRequiresHuman, finding: "sensitive path .github/workflows/ci.yml"}, + {name: "finding on an operator sensitive path is a finding", rep: ask("should this land?", outputschema.Finding{Title: "changes the proxy allowlist", Severity: outputschema.SeverityLow, ReviewScope: "in-scope", File: "internal/proxy/allow.go"}), opts: AggregateOptions{SensitivePaths: []string{"internal/proxy/**"}}, want: VerdictRequiresHuman, finding: "sensitive path internal/proxy/allow.go"}, + {name: "finding flagging insecure behaviour is a finding", rep: ask("should this land?", outputschema.Finding{Title: "Shells out with user input", Severity: outputschema.SeverityMedium, Summary: "command injection via the branch name", ReviewScope: "in-scope"}), want: VerdictRequiresHuman, finding: "flags insecure behaviour"}, + {name: "ordinary high finding goes back to the clanker", rep: ask("should this land?", outputschema.Finding{Title: "Clears the wrong ledger key", Severity: outputschema.SeverityHigh, ReviewScope: "in-scope"}), want: VerdictChangesRequested}, + {name: "ordinary low finding goes back to the clanker", rep: ask("should this land?", outputschema.Finding{Title: "Get-before-Clear is redundant", Severity: outputschema.SeverityLow, ReviewScope: "in-scope"}), want: VerdictChangesRequested}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := AggregateReports([]PerspectiveReport{tt.rep}, AggregateOptions{}) - if tt.parked { - if got.Verdict != VerdictRequiresHuman || !got.DecisionRequested || got.DecisionQuestion != tt.rep.DecisionQuestion { + got := AggregateReports([]PerspectiveReport{tt.rep}, tt.opts) + if got.Verdict != tt.want { + t.Fatalf("aggregate = %+v, want %s", got, tt.want) + } + switch tt.want { + case VerdictRequiresHuman: + if !got.DecisionRequested || got.DecisionQuestion != tt.rep.DecisionQuestion { t.Fatalf("aggregate = %+v, want decision request kept", got) } if !strings.Contains(got.DecisionFinding, tt.finding) { t.Fatalf("DecisionFinding = %q, want it to name %q", got.DecisionFinding, tt.finding) } - return - } - if got.Verdict != VerdictApprove || !got.MergeEligible || got.RequiresHuman || got.DecisionRequested || got.DecisionQuestion != "" || got.DecisionFinding != "" { - t.Fatalf("aggregate = %+v, want advisory approve", got) - } - if got.Perspectives[PerspectiveIntentAlignment] != VerdictApprove { - t.Fatalf("perspectives = %v, want the forced requires_human read as approve", got.Perspectives) - } - if len(got.Reasons) != 1 || !strings.Contains(got.Reasons[0], "not backed by a finding") || !strings.Contains(got.Reasons[0], tt.rep.DecisionQuestion) { - t.Fatalf("Reasons = %v, want one advisory carrying the question", got.Reasons) + case VerdictApprove: + if !got.MergeEligible || got.RequiresHuman || got.DecisionRequested || got.DecisionQuestion != "" || got.DecisionFinding != "" { + t.Fatalf("aggregate = %+v, want advisory approve", got) + } + if got.Perspectives[PerspectiveIntentAlignment] != VerdictApprove { + t.Fatalf("perspectives = %v, want the forced requires_human read as approve", got.Perspectives) + } + if len(got.Reasons) != 1 || !strings.Contains(got.Reasons[0], "no security finding") || !strings.Contains(got.Reasons[0], tt.rep.DecisionQuestion) { + t.Fatalf("Reasons = %v, want one advisory carrying the question", got.Reasons) + } + case VerdictChangesRequested: + if !got.FixCycle || got.RequiresHuman || got.DecisionRequested || got.DecisionFinding != "" { + t.Fatalf("aggregate = %+v, want the fixer lane", got) + } } }) } } +// A bare requires_human (no decision marker) on a contributor PR follows +// the same rule: only a security finding parks it. +func TestAggregateReportsContributorRequiresHumanNeedsSecurityFinding(t *testing.T) { + plain := baseReport(PerspectiveIntentAlignment, VerdictRequiresHuman) + plain.Summary = "Unclear whether the groundwork should land before its consumer." + got := AggregateReports([]PerspectiveReport{plain}, AggregateOptions{}) + if got.Verdict != VerdictApprove || got.RequiresHuman || !got.MergeEligible { + t.Fatalf("aggregate = %+v, want advisory approve", got) + } + sec := baseReport(PerspectiveSecurity, VerdictRequiresHuman) + sec.Summary = "Trust-surface file by location; a relay owner should confirm before merge." + got = AggregateReports([]PerspectiveReport{sec}, AggregateOptions{}) + if got.Verdict != VerdictRequiresHuman || !got.RequiresHuman || !strings.Contains(got.DecisionFinding, "security review withheld approval") { + t.Fatalf("aggregate = %+v, want the security perspective's hold kept with its finding", got) + } +} + func TestAggregateReportsContributorDecisionEscalatePolicyKeepsQuestion(t *testing.T) { r := baseReport(PerspectiveCorrectness, VerdictRequiresHuman) r.DecisionRequested = true diff --git a/src/pkg/review/security_finding.go b/src/pkg/review/security_finding.go new file mode 100644 index 0000000000..45a6b7fa7b --- /dev/null +++ b/src/pkg/review/security_finding.go @@ -0,0 +1,218 @@ +package review + +import ( + "fmt" + "sort" + "strings" + + "github.com/hivecommons/hive/pkg/intent" + "github.com/hivecommons/hive/pkg/sentinel" +) + +// Owner rule (hivecommons/hive, 2026-10-29), verbatim: "there should be no +// decisions by a human while these are in ci/review — unless the review +// found something", refined to "unless you find something fishy and +// insecure happening at the pr in progress level, then we can let things +// go and then decide in merge queue, if needed", and "i always have the +// last word when it comes to merge of untrusted". +// +// So for a PR the hive did not author, the ONLY thing that may take it out +// of hands-free CI/Review and park it for a person is a concrete +// security / trust finding — the predicate below. Everything else the +// review raises (nits, duplicates, naming, scope, sequencing, a failing +// optional check, a conflict) goes back to the clanker / adoption path or +// is recorded as advisory, and the person meets the PR at the merge gate +// (090 ready-for-human-merge), where the untrusted-author merge is theirs. + +// securitySensitiveClasses are the DecisionRiskClass names that count as +// "fishy and insecure". The other classes (licensing, external side +// effects, data loss, unverifiable, merge policy) are merge-gate +// decisions, not CI/Review ones, for a contributor's PR. +var securitySensitiveClasses = map[string]bool{ + "security": true, + "permissions-credentials": true, + "sensitive-paths": true, +} + +// securityFindingTerms is the wording in a finding or summary that flags +// insecure or suspicious behaviour. Deliberately narrower than +// reviewtext.RiskEscalationTerms: "breaking", "cost", "license" and the +// like are not security. +var securityFindingTerms = []string{ + "security", "vulnerab", "insecure", "secret", "credential", "token leak", "leaks", "exfiltrat", + "authentication", "authorization", "permission", "privilege", "injection", "malicious", + "suspicious", "backdoor", "obfuscat", "supply chain", "supply-chain", "typosquat", + "remote code", "arbitrary code", "shell out", "curl | sh", "unpinned action", "high-risk", +} + +// SecuritySensitivePaths resolves the operator's extra globs +// (`security.sensitive_paths`) on top of sentinel.DefaultSensitivePaths. +func SecuritySensitivePaths(extra []string) []string { + out := append([]string{}, sentinel.DefaultSensitivePaths...) + for _, g := range extra { + if g = strings.TrimSpace(g); g != "" { + out = append(out, g) + } + } + return out +} + +// IsSecuritySensitiveFinding is the single early-exit predicate for a +// non-hive-authored PR in CI/Review. It reports what the review found that +// is fishy or insecure, in the words the 085 comment and the tracker print +// after "the review found:"; an empty string means nothing security- +// relevant was found and the PR must keep moving. +// +// Triggers, in order: +// - the reviewer's explicit `` marker; +// - a decision question in a security-class risk class (security, +// permissions-credentials, sensitive-paths — workflows, CODEOWNERS, +// deploy, Dockerfiles, dependency manifests, …); +// - an in-scope finding on a sensitive path (defaults plus +// `security.sensitive_paths`); +// - an in-scope finding, or the review summary, flagging insecure or +// suspicious behaviour (securityFindingTerms). +func IsSecuritySensitiveFinding(r PerspectiveReport, sensitivePaths []string) (string, bool) { + if r.DecisionRiskHigh { + return "the reviewer marked this change high-risk", true + } + if r.Perspective == PerspectiveSecurity && r.Verdict == VerdictRequiresHuman { + // The security perspective withholding approval is itself the + // reviewer flagging the change, whatever words it used. + if summary := strings.TrimSpace(r.Summary); summary != "" { + return "the security review withheld approval: " + summary, true + } + return "the security review withheld approval", true + } + if class, risk := DecisionQuestionRiskClassFor(r.DecisionQuestion, r.PermissionsTighteningOnly); risk && securitySensitiveClasses[class] { + return class + " question from the " + string(r.Perspective) + " review", true + } + paths := sensitivePaths + if paths == nil { + paths = SecuritySensitivePaths(nil) + } + for _, f := range r.Findings { + if !InScopeFinding(f) { + continue + } + if file := strings.TrimSpace(f.File); file != "" && intent.PathMatchesAny(file, paths) { + return fmt.Sprintf("sensitive path %s: %s finding %q", file, r.Perspective, strings.TrimSpace(f.Title)), true + } + } + for _, f := range r.Findings { + if !InScopeFinding(f) { + continue + } + if securityTermIn(f.Title, r.PermissionsTighteningOnly) || securityTermIn(f.Summary, r.PermissionsTighteningOnly) { + return fmt.Sprintf("%s finding %q flags insecure behaviour", r.Perspective, strings.TrimSpace(f.Title)), true + } + } + if securityTermIn(r.Summary, r.PermissionsTighteningOnly) { + return "the " + string(r.Perspective) + " review flags insecure behaviour", true + } + return "", false +} + +func securityTermIn(text string, permissionsTighteningOnly bool) bool { + q := strings.ToLower(strings.TrimSpace(text)) + if q == "" { + return false + } + for _, term := range securityFindingTerms { + if permissionsTighteningOnly && permissionsTighteningSuppressedTerms[term] { + continue + } + if strings.Contains(q, term) { + return true + } + } + return false +} + +// securityFindingAcross runs IsSecuritySensitiveFinding over the reports +// that would hold the PR for a person (a decision marker or a +// requires_human verdict) and returns the first finding. +func securityFindingAcross(reports []PerspectiveReport, sensitivePaths []string) (string, bool) { + for _, r := range reports { + if !r.DecisionRequested && r.Verdict != VerdictRequiresHuman { + continue + } + if finding, ok := IsSecuritySensitiveFinding(r, sensitivePaths); ok { + return finding, true + } + } + return "", false +} + +// contributorHandsFree reports whether the contributor rule applies to the +// aggregate: a PR the hive did not author, with the global +// `self_authored_decision_policy: escalate` opt-out not set. +func contributorHandsFree(agg Aggregate, opts AggregateOptions) bool { + return !agg.HiveAuthored && !strings.EqualFold(strings.TrimSpace(opts.SelfAuthoredDecisionPolicy), "escalate") +} + +// reportsHaveInScopeFinding says the review left the author something to +// fix, so the hands-free resolution is the fixer lane, not approve. +func reportsHaveInScopeFinding(reports []PerspectiveReport) bool { + for _, r := range reports { + for _, f := range r.Findings { + if InScopeFinding(f) { + return true + } + } + } + return false +} + +// contributorDecisionAdvisory is the audit reason for a contributor-lane +// review hold (decision question or requires_human) with no security +// finding behind it. +func contributorDecisionAdvisory(questions []string) string { + const lead = "no security finding — the PR keeps moving; a person has the last word at the merge gate" + var cleaned []string + for _, q := range questions { + if q = strings.TrimSpace(q); q != "" { + cleaned = append(cleaned, q) + } + } + sort.Strings(cleaned) + if len(cleaned) == 0 { + return lead + } + return lead + "; recorded as advisory: " + strings.Join(cleaned, " | ") +} + +// contributorHandsFreeAggregate resolves a contributor-PR review hold that +// no security finding backs: to the fixer lane when the review left +// something to fix (the clanker / adoption path is the mover), otherwise +// to approve so the PR reaches the merge gate, where a person decides. +// Either way nobody is asked while the PR is in CI/Review. +func contributorHandsFreeAggregate(agg Aggregate, opts AggregateOptions, needsFix bool, maxFix int, advisory []string) Aggregate { + if needsFix { + if opts.FixAttempts >= maxFix { + // The clanker ran out of attempts: there is no mover left, and + // that — not the question — is what the person is told. + agg.Verdict = VerdictRequiresHuman + agg.RequiresHuman = true + agg.DecisionRequested = false + agg.DecisionQuestion = "" + agg.DecisionFinding = fmt.Sprintf("fix cycle cap reached (%d/%d)", opts.FixAttempts, maxFix) + agg.Reasons = []string{agg.DecisionFinding} + return agg + } + agg.Verdict = VerdictChangesRequested + agg.FixCycle = true + markRequiresHumanPerspectivesAsChangesRequested(&agg) + } else { + agg.Verdict = VerdictApprove + agg.MergeEligible = true + markRequiresHumanPerspectivesAsApprove(&agg) + agg.Reasons = nil + } + agg.RequiresHuman = false + agg.DecisionRequested = false + agg.DecisionQuestion = "" + agg.Reasons = append(append([]string{}, agg.Reasons...), contributorDecisionAdvisory(advisory)) + sortReasons(agg.Reasons) + return agg +} diff --git a/src/pkg/stageengine/derive_pr_no_decision_in_ci_test.go b/src/pkg/stageengine/derive_pr_no_decision_in_ci_test.go index 0d39457653..e7f38b8e9d 100644 --- a/src/pkg/stageengine/derive_pr_no_decision_in_ci_test.go +++ b/src/pkg/stageengine/derive_pr_no_decision_in_ci_test.go @@ -65,3 +65,75 @@ func TestClassifyStageContributorLaneNoDecisionDuringCIReview(t *testing.T) { }) } } + +// ciReviewStages are the PR stages the tracker draws in the CI/Review +// column and its detours: the ones that must always have a non-human +// mover (CI, the review swarm, the clanker, the hive adopting, the author +// fixing) and never an operator decision (hivecommons/hive#15640, owner +// rule: "we dont want to create a log jam during pr in progress"). +var ciReviewStages = map[stagelabels.Stage]bool{ + stagelabels.ReviewPending: true, + stagelabels.Reviewed: true, + stagelabels.Fixing: true, + stagelabels.NeedsAuthor: true, + stagelabels.ReturnedToContributor: true, + stagelabels.AdoptedByHive: true, +} + +// securityHoldReasons are the lane reasons that are themselves a concrete +// security / trust finding and so may take a contributor PR out of +// hands-free CI/Review to 085. +var securityHoldReasons = map[string]bool{ + contributorLaneReasonSentinelBlocked: true, + contributorLaneReasonWorkflowPath: true, + contributorLaneReasonTestsRemoved: true, + contributorLaneReasonReporterTrustHold: true, +} + +// operatorFaultReasons are not review decisions at all: the hive itself +// cannot run (no reviewer agent configured, App login unknown, the files +// API refused). Only the operator can fix the hive, so 085 is right. +var operatorFaultReasons = map[string]bool{ + contributorLaneReasonNoReviewer: true, + contributorLaneReasonNoAppBotLogin: true, + contributorLaneReasonFilesEvidence: true, +} + +// TestContributorLaneCIReviewNeverParksOnAHuman sweeps every contributor +// lane reason against the verdicts the aggregate can now produce for a +// contributor PR (none yet, approve, changes_requested, requires_human +// with a named finding) and asserts the invariant: a CI/Review stage is +// never human-owned, and 085 is reached only through a security lane +// reason, a verdict that names its finding, or an answered human request. +func TestContributorLaneCIReviewNeverParksOnAHuman(t *testing.T) { + reasons := []string{ + contributorLaneReasonAppAuthored, contributorLaneReasonAuthorAssociation, contributorLaneReasonChangesRequested, + contributorLaneReasonClaimAuthor, contributorLaneReasonClaimOtherHive, contributorLaneReasonClaimTier, + contributorLaneReasonClaimUnverified, contributorLaneReasonFilesEvidence, contributorLaneReasonNoAppBotLogin, + contributorLaneReasonNoAuthor, contributorLaneReasonNoClaim, contributorLaneReasonNoLinkedIssue, + contributorLaneReasonNoReviewer, contributorLaneReasonNoVerdict, contributorLaneReasonReporterTrustHold, + contributorLaneReasonSentinelBlocked, contributorLaneReasonSoaking + "(remaining=5m)", contributorLaneReasonTestsRemoved, + contributorLaneReasonWorkflowPath, "check-pending", "check-failing:unit", "conflicting", "", + } + verdicts := map[string]stageDetail{ + "no verdict": {}, + "approve": {VerdictKnown: true, Verdict: ContributorLaneVerdict{Configured: true, Approved: true, Verdict: "approve"}}, + "changes_requested": {VerdictKnown: true, Verdict: ContributorLaneVerdict{Configured: true, Verdict: "changes_requested"}}, + "security finding": {VerdictKnown: true, Verdict: ContributorLaneVerdict{Configured: true, Verdict: "requires_human", DecisionRequested: true, DecisionQuestion: "accept this workflow trigger?", DecisionFinding: "sensitive-paths question from the security review"}}, + } + for _, reason := range reasons { + for name, detail := range verdicts { + v := ClassifyStage(stageObservation{Lane: stageLaneContributor, Reason: reason, HeadSHA: goldenHead, Detail: detail}) + if ciReviewStages[v.Stage] && v.Human { + t.Errorf("reason %q verdict %s: CI/Review stage %s is human-owned (%+v) — a log jam", reason, name, v.Stage, v) + } + if v.Stage != stagelabels.NeedsDecision { + continue + } + finding := detail.VerdictKnown && detail.Verdict.DecisionFinding != "" + if !finding && !securityHoldReasons[reason] && !operatorFaultReasons[reason] { + t.Errorf("reason %q verdict %s: 085 with no security finding and no security lane reason (%+v)", reason, name, v) + } + } + } +} From 1b8b470368c7cfc5c1d94739f75327d52babbb3b Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 23:30:42 -0400 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=8C=B1=20changelog:=20move=20fragment?= =?UTF-8?q?=20to=20changelog.d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andrew Anderson --- .../fixed-contributor-decision-needs-finding.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {src/changelog.d => changelog.d}/fixed-contributor-decision-needs-finding.md (100%) diff --git a/src/changelog.d/fixed-contributor-decision-needs-finding.md b/changelog.d/fixed-contributor-decision-needs-finding.md similarity index 100% rename from src/changelog.d/fixed-contributor-decision-needs-finding.md rename to changelog.d/fixed-contributor-decision-needs-finding.md From 035974a4b612fbf0b573f66c3307fbc046ad4fc0 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 23:57:15 -0400 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=8C=B1=20test:=20relay=20verdict=20te?= =?UTF-8?q?sts=20follow=20the=20security-finding=20contract?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bare correctness requires_human or product decision marker on a contributor PR aggregates to advisory approve; the security perspective's hold and a sensitive-paths question survive with DecisionFinding set. Signed-off-by: Andrew Anderson --- src/pkg/github/review_verdict_relay_test.go | 98 +++++++++++++++++++-- 1 file changed, 93 insertions(+), 5 deletions(-) diff --git a/src/pkg/github/review_verdict_relay_test.go b/src/pkg/github/review_verdict_relay_test.go index 583efd8400..82eb175dd4 100644 --- a/src/pkg/github/review_verdict_relay_test.go +++ b/src/pkg/github/review_verdict_relay_test.go @@ -126,11 +126,57 @@ func TestRecordReviewVerdictIsCollectable(t *testing.T) { if got.HeadSHA != "abc123" { t.Fatalf("dispatch head SHA was not bound into the recorded verdict: %q", got.HeadSHA) } - if !got.RequiresHuman { - t.Fatalf("requires_human verdict did not survive into the aggregate: %+v", got) + // A bare correctness requires_human with no security finding is advisory + // on a contributor PR (hivecommons/hive#15640): the verdict is recorded + // and aggregated, but the PR keeps moving. + if got.RequiresHuman || got.Verdict != review.VerdictApprove { + t.Fatalf("non-security requires_human did not resolve to advisory approve: %+v", got) + } + if !reasonsContain(got.Reasons, "recorded as advisory:") { + t.Fatalf("Reasons = %v, want the requires_human recorded as advisory", got.Reasons) + } + if got.Perspectives[review.PerspectiveCorrectness] != review.VerdictApprove { + t.Fatalf("perspectives = %v, want the relayed verdict collected and resolved", got.Perspectives) + } +} + +// The security perspective's requires_human is a security finding in its +// own right and does survive into the aggregate with the finding named. +func TestRecordReviewVerdictSecurityHoldSurvivesAggregate(t *testing.T) { + dir := t.TempDir() + c := &Client{logger: testLogger()} + raw := validVerdictJSON(t, "projectbluefin/common", 1121, "security", "requires_human") + pending := pendingVerdict("projectbluefin/common", 1121, review.PerspectiveSecurity, "reviewer") + pending.HeadSHA = "abc123" + withVerdictDispatchState(t, review.DispatchState{Pending: []review.PendingReview{pending}}) + + c.recordReviewVerdict(context.Background(), ReviewRequest{Repo: "projectbluefin/common", Number: 1121, Agent: "reviewer", Report: raw}, dir) + + artifact, err := review.Collect(dir, review.AggregateOptions{}) + if err != nil { + t.Fatalf("Collect: %v", err) + } + if len(artifact.Items) != 1 { + t.Fatalf("want 1 aggregated item, got %d", len(artifact.Items)) + } + got := artifact.Items[0] + if !got.RequiresHuman || got.Verdict != review.VerdictRequiresHuman { + t.Fatalf("security requires_human did not survive into the aggregate: %+v", got) + } + if !strings.Contains(got.DecisionFinding, "security review withheld approval") { + t.Fatalf("DecisionFinding = %q, want the security hold named", got.DecisionFinding) } } +func reasonsContain(reasons []string, needle string) bool { + for _, r := range reasons { + if strings.Contains(r, needle) { + return true + } + } + return false +} + func TestRecordReviewVerdictPromotesDecisionMarker(t *testing.T) { dir := t.TempDir() c := &Client{logger: testLogger()} @@ -156,15 +202,57 @@ func TestRecordReviewVerdictPromotesDecisionMarker(t *testing.T) { t.Fatalf("Collect: %v", err) } got := artifact.Items[0] - if got.Verdict != review.VerdictRequiresHuman || !got.DecisionRequested || - !strings.Contains(got.DecisionQuestion, "groundwork lands before its consumer") { - t.Fatalf("aggregate = %+v, want decision request", got) + // The marker is relayed, but a product question with no security + // finding behind it is advisory on a contributor PR + // (hivecommons/hive#15640): the aggregate approves and keeps the + // question in its reasons; a person meets the PR at the merge gate. + if got.Verdict != review.VerdictApprove || got.DecisionRequested || got.RequiresHuman { + t.Fatalf("aggregate = %+v, want advisory approve", got) + } + if !reasonsContain(got.Reasons, "recorded as advisory: @clubanderson should decide whether this groundwork lands before its consumer.") { + t.Fatalf("Reasons = %v, want the question recorded as advisory", got.Reasons) } if got.BodyDigest != "body-v1" { t.Fatalf("BodyDigest = %q, want dispatch digest", got.BodyDigest) } } +// A decision marker whose question is a security-class one (sensitive +// paths) is a finding: it survives as a decision request with the finding +// named, so the 085 comment can say what the review found. +func TestRecordReviewVerdictPromotesSecurityDecisionMarker(t *testing.T) { + dir := t.TempDir() + c := &Client{logger: testLogger()} + raw := validVerdictJSONWithHeadAndBodyDigest(t, "projectbluefin/common", 1121, "correctness", "approve", "abc123", "body-v1") + withVerdictDispatchState(t, review.DispatchState{Recent: []review.RecentReview{{ + Repo: "projectbluefin/common", + Number: 1121, + Perspective: review.PerspectiveCorrectness, + Agent: "reviewer", + HeadSHA: "abc123", + BodyDigest: "body-v1", + Confirmed: time.Now().UTC(), + }}}) + body := "No defects; trust surface.\n\n\n" + + recorded := c.recordReviewVerdict(context.Background(), ReviewRequest{Repo: "projectbluefin/common", Number: 1121, Agent: "reviewer", Report: raw, Body: body}, dir) + if len(recorded) != 1 || recorded[0].Verdict != review.VerdictRequiresHuman || !recorded[0].DecisionRequested { + t.Fatalf("recorded = %+v, want promoted decision request", recorded) + } + artifact, err := review.Collect(dir, review.AggregateOptions{}) + if err != nil { + t.Fatalf("Collect: %v", err) + } + got := artifact.Items[0] + if got.Verdict != review.VerdictRequiresHuman || !got.DecisionRequested || + !strings.Contains(got.DecisionQuestion, "workflow trigger change") { + t.Fatalf("aggregate = %+v, want decision request", got) + } + if !strings.Contains(got.DecisionFinding, "sensitive-paths question") { + t.Fatalf("DecisionFinding = %q, want the sensitive-paths finding named", got.DecisionFinding) + } +} + func TestRecordReviewVerdictMarksConcreteRemediationFromBody(t *testing.T) { dir := t.TempDir() c := &Client{logger: testLogger()}