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-rerun-refusal-keeps-real-blocker.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions src/docs/github-app-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 4 additions & 1 deletion src/pkg/github/automerge/automerge_stage_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/stageengine/derive_pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions src/pkg/stageengine/derive_pr_classify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
39 changes: 39 additions & 0 deletions src/pkg/stageengine/derive_pr_recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Loading