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-self-authored-sensitive-path-ask.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Review: on a hive-authored PR, a `requires_human` or decision-requested perspective whose in-scope finding sits on a sensitive path (for example `.github/workflows/`) now stays a person's decision under `self_authored_decision_policy: resolve`. It parks at `stage/085-needs-decision`, and the comment names the finding and the reviewer's ask. Before, an ask worded without a risk-class term, such as "apply the `pr-validate.yml` hunk from the PR body", was turned into `changes_requested`. The PR then sat at `stage/070-fixing`, with `stage/stalled` coming and going, through fix attempts that could not land the workflow edit, and nobody was asked. A recorded `decision_finding` also stops the read-time verdict normalizers from turning the hold back into `changes_requested`. Asks for changes, and asks off the sensitive paths, still go to the fixer.
94 changes: 94 additions & 0 deletions src/cmd/hive/self_authored_workflow_ask_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package main

import (
"testing"
"time"

"github.com/hivecommons/hive/pkg/outputschema"
"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"
)

// projectbluefin/bonedigger#106 end to end: the review of the hive's own PR
// asks a maintainer to commit a hunk in a workflow file. The aggregate the
// review records, read back the way the lanes read it, must classify as
// 085 with the ask, not 070, and 085 has no stalled dwell, so the PR no
// longer flaps stage/stalled while it waits for the person.
func TestSelfAuthoredWorkflowAskParksAt085WithTheAsk(t *testing.T) {
const head = "a3c2a5b431c40c23b34c4dbe968cb52446d10faf"
const ask = "apply the `pr-validate.yml` + `BASELINE` hunks from the PR body on this branch before merging"
report := func(file string) review.PerspectiveReport {
return review.PerspectiveReport{
AgentReport: outputschema.AgentReport{
Lane: "review-swarm", Kind: outputschema.KindReview, Summary: "the title is not yet true",
Findings: []outputschema.Finding{{
Title: "pull-request check still installs the lint tool unpinned", Severity: outputschema.SeverityMedium,
ReviewScope: "in-scope", File: file, Line: 28,
Summary: "update the pipx step to install from .github/requirements-ci.txt",
}},
PRsOpened: []outputschema.PROpened{}, BeadsFiled: []outputschema.BeadFiled{},
},
Perspective: review.PerspectiveIntentAlignment, Verdict: review.VerdictRequiresHuman,
Repo: "projectbluefin/bonedigger", Number: 106, HeadSHA: head,
HiveAuthored: true, DecisionRequested: true, DecisionQuestion: ask,
}
}
classify := func(t *testing.T, file, laneReason string) (prstage.Verdict, review.Aggregate) {
t.Helper()
agg := review.AggregateReports([]review.PerspectiveReport{report(file)}, review.AggregateOptions{})
agg.RecordedAt = time.Date(2026, 10, 29, 18, 25, 47, 0, time.UTC)
verdict := contributorLaneVerdictFromArtifact(review.Artifact{Items: []review.Aggregate{agg}}, "projectbluefin/bonedigger", 106, head, false)
return stageengine.ClassifyStage(prstage.Observation{
Lane: prstage.StageLaneSelf, Number: 106, HeadSHA: head, Reason: laneReason,
Detail: prstage.Detail{VerdictKnown: true, Verdict: verdict},
}), agg
}

got, agg := classify(t, ".github/workflows/pr-validate.yml", "review-verdict-requires-human")
if got.Stage != stagelabels.NeedsDecision || !got.Human {
t.Fatalf("stage = %+v (aggregate %s), want 085 needs-decision", got, agg.Verdict)
}
if got.Reason != stageengine.StageReasonDecisionRequested {
t.Fatalf("reason = %q, want %q", got.Reason, stageengine.StageReasonDecisionRequested)
}
verdict := contributorLaneVerdictFromArtifact(review.Artifact{Items: []review.Aggregate{agg}}, "projectbluefin/bonedigger", 106, head, false)
if verdict.DecisionQuestion != ask || verdict.DecisionFinding == "" {
t.Fatalf("verdict = %+v, want the ask and the finding for the 085 comment", verdict)
}

entered := time.Date(2026, 10, 29, 19, 3, 12, 0, time.UTC)
parked := stagelabels.Record{Stage: got.Stage, EnteredAt: entered, LastActivityAt: entered}
if stagelabels.Stalled(parked, nil, entered.Add(40*time.Hour)) {
t.Fatalf("085 marked stalled after 40h; it must wait for the person without the stalled label")
}

// The ask the hive can make itself still goes to the fixer at 070,
// and 070 still stalls when nobody works it.
fixing, _ := classify(t, "tests/test_python_install_pins.py", "changes-requested")
if fixing.Stage != stagelabels.Fixing {
t.Fatalf("stage = %+v, want 070 fixing for a fix off the sensitive paths", fixing)
}
working := stagelabels.Record{Stage: fixing.Stage, EnteredAt: entered, LastActivityAt: entered}
if !stagelabels.Stalled(working, nil, entered.Add(3*time.Hour)) {
t.Fatalf("070 not stalled after 3h quiet; the fixing dwell must be unchanged")
}
}

// The stage-side fallback normalizer rewrites a hive-authored requires_human
// with concrete wording to changes_requested. A verdict whose aggregate
// recorded a DecisionFinding is a person's by policy and must stay so.
func TestNormalizeReviewVerdictKeepsARecordedDecisionFinding(t *testing.T) {
v := prstage.ReviewVerdict{
Configured: true, Verdict: "requires_human", HiveAuthoredKnown: true, HiveAuthored: true,
HumanSummaries: []string{"update the pipx step in pr-validate.yml"},
}
if got := prstage.NormalizeReviewVerdict(v); got.Verdict != "changes_requested" {
t.Fatalf("without a finding: verdict = %q, want the existing changes_requested rewrite", got.Verdict)
}
v.DecisionFinding = `sensitive path .github/workflows/pr-validate.yml: intent-alignment finding "unpinned"`
if got := prstage.NormalizeReviewVerdict(v); got.Verdict != "requires_human" {
t.Fatalf("with a finding: verdict = %q, want requires_human kept", got.Verdict)
}
}
17 changes: 17 additions & 0 deletions src/docs/review-swarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,23 @@ parked for a person.) The risk classes are:
| `licensing-legal` | license, copyright, legal, privacy, compliance, trademark, CLA |
| `unverifiable` | the reviewer says it could not read, judge or test the change, or the requirement is ambiguous |

The `sensitive-paths` class also covers what the reviewer asks a person
about, not only how the question is worded. A `requires_human` or
decision-requested perspective whose in-scope finding sits on a sensitive
path (the sentinel defaults plus `security.sensitive_paths`) stays a
person's decision. The aggregate keeps `requires_human` with
`decision_finding: sensitive path <file>: …`, no fix is dispatched, and the
PR parks at `stage/085-needs-decision`. The 085 comment prints that finding
and the reviewer's question, so it names the change the maintainer must
commit. Before this, "apply the `pr-validate.yml` hunk from the PR body"
named no risk class, so the ask was routed to the fixer as
`changes_requested`. The PR then sat at `stage/070-fixing`, wearing
`stage/stalled` on and off, through six fix attempts that could not land a
workflow edit (projectbluefin/bonedigger#106). A perspective that asks for
changes on a workflow file still goes to the fixer, which may hold the
Workflows permission. The permissions-tightening carve-out applies as it
does to the question.

Set the policy to `escalate` to preserve the older behavior where every
decision marker parks the PR for a person. The reviewer template
(`policies/reviewer-queue.md`) also tells the swarm to check the linked
Expand Down
61 changes: 58 additions & 3 deletions src/pkg/review/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func aggregateReports(reports []PerspectiveReport, opts AggregateOptions) Aggreg
unresolvedRequiresHuman = true
}
}
if reportRequiresRiskEscalation(r) {
if reportRequiresRiskEscalation(r, opts) {
riskEscalation = true
}
if r.RedundantOf > 0 && agg.RedundantOf == 0 {
Expand Down Expand Up @@ -612,6 +612,13 @@ func aggregateReports(reports []PerspectiveReport, opts AggregateOptions) Aggreg
agg.Reasons = []string{"self-authored non-risk requires_human recorded as advisory"}
return agg
}
if agg.DecisionFinding == "" {
// The 085 comment prints it after "the review found:", and
// Normalize reads it as the reason the hold stays a person's.
if finding, ok := selfAuthoredSensitivePathAskAcross(reports, opts); ok {
agg.DecisionFinding = finding
}
}
agg.Verdict = VerdictRequiresHuman
agg.RequiresHuman = true
return agg
Expand Down Expand Up @@ -656,6 +663,12 @@ func (a Aggregate) Normalize() Aggregate {
if FixCycleCapReached(a) {
return a
}
if strings.TrimSpace(a.DecisionFinding) != "" {
// The aggregate recorded what makes the hold a person's (a
// sensitive-path ask on the hive's own PR); a re-read must not
// hand it to the fixer.
return a
}
if aggregateRequiresRiskEscalation(a) || (!aggregateHasConcreteRemediation(a) && !aggregateHasBlockingPerspective(a)) {
return a
}
Expand Down Expand Up @@ -781,7 +794,7 @@ func selfAuthoredRequiresHumanReportIsResolvable(r PerspectiveReport, opts Aggre
if !r.HiveAuthored || strings.EqualFold(strings.TrimSpace(opts.SelfAuthoredDecisionPolicy), "escalate") {
return false
}
if r.Verdict != VerdictRequiresHuman || reportRequiresRiskEscalation(r) {
if r.Verdict != VerdictRequiresHuman || reportRequiresRiskEscalation(r, opts) {
return false
}
if r.DecisionRequested {
Expand Down Expand Up @@ -819,11 +832,14 @@ func reportHasConcreteRemediation(r PerspectiveReport) bool {
return false
}

func reportRequiresRiskEscalation(r PerspectiveReport) bool {
func reportRequiresRiskEscalation(r PerspectiveReport, opts AggregateOptions) bool {
tightening := r.PermissionsTighteningOnly
if _, risk := DecisionQuestionRiskClassFor(r.DecisionQuestion, tightening); risk || r.DecisionRiskHigh {
return true
}
if _, onPath := selfAuthoredSensitivePathAsk(r, opts); onPath {
return true
}
if containsRiskEscalationTermFor(r.Summary, tightening) {
return true
}
Expand All @@ -835,6 +851,45 @@ func reportRequiresRiskEscalation(r PerspectiveReport) bool {
return false
}

// selfAuthoredSensitivePathAsk is the sensitive-paths risk class applied to
// what a hive-authored review asks a person about, not only to how the
// question is worded. A requires_human or decision-requested report whose
// in-scope finding sits on a sensitive path (sentinel.DefaultSensitivePaths
// plus `security.sensitive_paths`) stays a person's decision under the
// resolve policy, as a question naming the path already does.
//
// Seen on projectbluefin/bonedigger#106: the reviewer asked a maintainer to
// "apply the `pr-validate.yml` + `BASELINE` hunks from the PR body", with
// the finding on `.github/workflows/pr-validate.yml`. The wording named no
// risk class, so the ask was resolved to changes_requested and the PR sat at
// stage/070-fixing through six fix attempts that never pushed, then wore
// stage/stalled on and off until a maintainer applied the hunk 38h later;
// nobody was asked.
//
// A report that asks for changes is not covered: the fixer is still the one
// to try it. The permissions-tightening carve-out (hivecommons/hive#13068)
// applies here as it does to the question.
func selfAuthoredSensitivePathAsk(r PerspectiveReport, opts AggregateOptions) (string, bool) {
if !r.HiveAuthored || r.PermissionsTighteningOnly || strings.EqualFold(strings.TrimSpace(opts.SelfAuthoredDecisionPolicy), "escalate") {
return "", false
}
if r.Verdict != VerdictRequiresHuman && !r.DecisionRequested {
return "", false
}
return sensitivePathFinding(r, SecuritySensitivePaths(opts.SensitivePaths))
}

// selfAuthoredSensitivePathAskAcross returns the first report's
// selfAuthoredSensitivePathAsk finding.
func selfAuthoredSensitivePathAskAcross(reports []PerspectiveReport, opts AggregateOptions) (string, bool) {
for _, r := range reports {
if finding, ok := selfAuthoredSensitivePathAsk(r, opts); ok {
return finding, true
}
}
return "", false
}

// ConcreteRemediationText reports whether review prose names an actionable
// engineering fix instead of merely saying a person should decide.
func ConcreteRemediationText(text string) bool { return reviewtext.ConcreteRemediationText(text) }
Expand Down
29 changes: 19 additions & 10 deletions src/pkg/review/security_finding.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package review

import (
Expand Down Expand Up @@ -87,29 +87,38 @@
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)
if finding, ok := sensitivePathFinding(r, sensitivePaths); ok {
return finding, true
}
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
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
}

// sensitivePathFinding names r's first in-scope finding on a sensitive path
// (nil paths means the defaults).
func sensitivePathFinding(r PerspectiveReport, sensitivePaths []string) (string, bool) {
paths := sensitivePaths
if paths == nil {
paths = SecuritySensitivePaths(nil)
}
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 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
}
}
if securityTermIn(r.Summary, r.PermissionsTighteningOnly) {
return "the " + string(r.Perspective) + " review flags insecure behaviour", true
}
return "", false
}

Expand Down
Loading
Loading