diff --git a/changelog.d/fixed-rerun-refusal-keeps-real-blocker.md b/changelog.d/fixed-rerun-refusal-keeps-real-blocker.md new file mode 100644 index 0000000000..5c07f9fca3 --- /dev/null +++ b/changelog.d/fixed-rerun-refusal-keeps-real-blocker.md @@ -0,0 +1 @@ +- A refused shared-CI re-run (the App has no Actions write) no longer replaces a PR's real blocker. It takes the stage (085, "re-run CI") only when CI is what holds the PR; a reviewer's changes request, a requested decision or another 085 stays the stage and caption, and the re-run ask remains as the `hive:unauthorized` note. diff --git a/src/docs/github-app-setup.md b/src/docs/github-app-setup.md index 2caef7ed63..7545118051 100644 --- a/src/docs/github-app-setup.md +++ b/src/docs/github-app-setup.md @@ -143,6 +143,10 @@ baseline permission for every Hive App. A refusal is an operator handoff, not a source-code defect: Hive records `unauthorized:rerun-shared-ci`, posts one head-scoped actionable note using the existing unauthorized mechanism, and retries no more than once per repository per permission cooldown (one hour). +The refusal becomes the PR's stage (085, "re-run CI") only when CI is what +holds the PR. When a reviewer requested changes or asked for a decision, or +the PR is already at 085 for another reason, that stays the stage and the +re-run ask is only the extra note, so the real blocker is not hidden. An unchanged PR remains eligible after the cooldown; a successful rerun or observing no failed runs clears the recovery block. diff --git a/src/pkg/github/automerge/automerge_stage_labels.go b/src/pkg/github/automerge/automerge_stage_labels.go index 44a0c0636c..433c577851 100644 --- a/src/pkg/github/automerge/automerge_stage_labels.go +++ b/src/pkg/github/automerge/automerge_stage_labels.go @@ -1477,7 +1477,10 @@ func (c *Engine) ApplyStageLabels(ctx context.Context) (StageLabelResult, error) obs.Route = &route } } - if step := c.sharedCIRecoveryUnauthorized(ctx, obs); step != "" && verdict.Stage != stagelabels.None { + // The refusal's label and comment are written either way; it + // takes the stage only when CI is what holds the PR, never over a + // review gate or another 085 (stageengine.RecoveryUnauthorizedOwnsStage). + if step := c.sharedCIRecoveryUnauthorized(ctx, obs); step != "" && stageengine.RecoveryUnauthorizedOwnsStage(verdict, obs.Reason, obs.Detail) { pass.RecoveryUnauthorized = step verdict.Stage = stagelabels.NeedsDecision verdict.Rank = stageRankOwned diff --git a/src/pkg/stageengine/derive_pr.go b/src/pkg/stageengine/derive_pr.go index 8780b815ff..5c95acc908 100644 --- a/src/pkg/stageengine/derive_pr.go +++ b/src/pkg/stageengine/derive_pr.go @@ -339,7 +339,7 @@ func passDecision(verdict stageVerdict, role stagelabels.Role, obs stageObservat verdict.Rank = stageRankOwned obs.Reason = stagelabels.FixerExhaustedReason(pass.FixerExhausted) } - if !verdict.Terminal && verdict.Stage != stagelabels.None && pass.RecoveryUnauthorized != "" { + if pass.RecoveryUnauthorized != "" && RecoveryUnauthorizedOwnsStage(verdict, obs.Reason, obs.Detail) { verdict.Stage = stagelabels.NeedsDecision verdict.Rank = stageRankOwned obs.Reason = prstage.StageReasonUnauthorizedPrefix + pass.RecoveryUnauthorized diff --git a/src/pkg/stageengine/derive_pr_classify.go b/src/pkg/stageengine/derive_pr_classify.go index f79936f391..206d93eacc 100644 --- a/src/pkg/stageengine/derive_pr_classify.go +++ b/src/pkg/stageengine/derive_pr_classify.go @@ -973,3 +973,34 @@ func HeldWorkflowRunsStage(o stageObservation) (stageVerdict, bool) { } return stageVerdict{Stage: stagelabels.NeedsDecision, Rank: stageRankOwned, Human: true, Reason: prstage.WorkflowRunsHeldReason(o.HeldWorkflowRuns)}, true } + +// RecoveryUnauthorizedOwnsStage reports whether an exact-head CI recovery +// permission refusal (PRPassFacts.RecoveryUnauthorized; today the shared-CI +// rerun 403, hivecommons/hive#16277) becomes the PR's stage and reason. It +// does only when CI is what holds the PR (a red or pending check, a shared-CI +// or base-branch-red deferral, a red optional check) and no review gate +// stands: then re-running the jobs is the person's one step, and the PR is +// not sent to source fixing for an infrastructure failure. When the reviewer +// requested changes or asked for a decision, or the PR is already parked at +// 085 for something else, that is the blocker; showing "re-run CI" over it +// hid it (projectbluefin/utah#1313 read as re-run-blocked over a changes +// request, utah-packages#1013 over a withheld security approval). The +// refusal still posts its hive:unauthorized label and comment either way. +func RecoveryUnauthorizedOwnsStage(verdict stageVerdict, reason string, d stageDetail) bool { + if verdict.Terminal || verdict.Stage == stagelabels.None || verdict.Stage == stagelabels.NeedsDecision { + return false + } + d = NormalizeStageDetail(d) + if VerdictBlocks(d) || VerdictNeedsHuman(d) { + return false + } + if ClassifyCIReason(reason) != CIReasonNone { + return true + } + for _, prefix := range []string{stageReasonSharedCIIncident, stageReasonBaseBranchRed, stageReasonOptionalCheckFailing} { + if strings.HasPrefix(reason, prefix) { + return true + } + } + return false +} diff --git a/src/pkg/stageengine/derive_pr_recovery_test.go b/src/pkg/stageengine/derive_pr_recovery_test.go index 4635563e50..48b0755bb7 100644 --- a/src/pkg/stageengine/derive_pr_recovery_test.go +++ b/src/pkg/stageengine/derive_pr_recovery_test.go @@ -20,3 +20,42 @@ func TestDerivePRRecoveryPermissionBlockIsNotSourceFixing(t *testing.T) { t.Fatalf("cleared recovery block must preserve actual CI failure: %+v", d) } } + +// A rerun refusal takes the stage only when CI is what holds the PR. Over a +// changes request, a decision the reviewer asked for, or another 085 it hid +// the real blocker (projectbluefin/utah#1313, utah-packages#1013). +func TestRecoveryUnauthorizedOwnsStage(t *testing.T) { + changes := stageDetail{VerdictKnown: true, Verdict: ContributorLaneVerdict{Configured: true, Verdict: "changes_requested"}} + decision := stageDetail{VerdictKnown: true, Verdict: ContributorLaneVerdict{Configured: true, Verdict: "requires_human", DecisionRequested: true}} + for _, tc := range []struct { + name string + verdict stageVerdict + reason string + detail stageDetail + want bool + }{ + {name: "red required check", verdict: stageVerdict{Stage: stagelabels.Fixing}, reason: "required-check-failing:gosec", want: true}, + {name: "deferred to a shared-CI incident", verdict: stageVerdict{Stage: stagelabels.ReviewPending}, reason: "shared-ci-incident:1336", want: true}, + {name: "red optional check", verdict: stageVerdict{Stage: stagelabels.Fixing}, reason: "optional-check-failing:build", want: true}, + {name: "changes requested", verdict: stageVerdict{Stage: stagelabels.Fixing}, reason: contributorLaneReasonChangesRequested}, + {name: "red check under a changes request", verdict: stageVerdict{Stage: stagelabels.Fixing}, reason: "required-check-failing:gosec", detail: changes}, + {name: "decision requested", verdict: stageVerdict{Stage: stagelabels.Reviewed}, reason: "required-check-failing:gosec", detail: decision}, + {name: "already at 085", verdict: stageVerdict{Stage: stagelabels.NeedsDecision}, reason: "fork-guard:Canary"}, + {name: "no stage", verdict: stageVerdict{Stage: stagelabels.None}, reason: "required-check-failing:gosec"}, + {name: "terminal", verdict: stageVerdict{Terminal: true}, reason: "required-check-failing:gosec"}, + {name: "not a CI reason", verdict: stageVerdict{Stage: stagelabels.ReviewPending}, reason: contributorLaneReasonNoVerdict}, + } { + if got := RecoveryUnauthorizedOwnsStage(tc.verdict, tc.reason, tc.detail); got != tc.want { + t.Errorf("%s: owns stage = %v, want %v", tc.name, got, tc.want) + } + } +} + +func TestDerivePRRecoveryPermissionBlockKeepsAChangesRequest(t *testing.T) { + f := hiveFixingFacts(contributorLaneReasonChangesRequested) + f.PR.Pass = &PRPassFacts{AuthorIsApp: true, RecoveryUnauthorized: "rerun-shared-ci"} + d := DerivePR(f) + if d.Stage != stagelabels.Fixing || d.Reason == "unauthorized:rerun-shared-ci" { + t.Fatalf("a rerun refusal hid the changes request: %+v", d) + } +}