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-fork-guard-nudge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- A fork pull request red only on a fork-guard check (such as a required `Canary` that cannot run on forks) is no longer nudged ("Failing checks: Canary") or adopted on each new head before it is parked: the guard's checks are remembered on the PR, a later head red on nothing else goes straight to `stage/085-needs-decision`, the nudge never lists a fork-guard check, and automatic adoption refuses a head whose only blocker is the guard (projectbluefin/utah-packages#862, #869).
2 changes: 1 addition & 1 deletion src/docs/labels-and-control-signals/stage-labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ used to admit the PR:
| `head-changed-since-eval`, `merge-failed`, `merge-queue-required` (the base branch's ruleset only accepts merges through GitHub's merge queue and the transport is a static token that cannot enqueue, so the direct REST merge is refused; with App auth on a repo opted in through `auto_merge.native_merge_queue` these bases are enqueued instead, see [native-merge-queue.md](../native-merge-queue.md); logged as a skip rather than a merge error, [#14018](https://github.com/hivecommons/hive/issues/14018); the self-authored sweep then skips the direct merge on that base for 30 minutes and logs the skip once per PR head, [#14068](https://github.com/hivecommons/hive/issues/14068); the trusted-author, queued and contributor-lane sweeps skip it the same way), `required-checks-expected`, `behind`, `updated-branch`, `behind-update-budget-exhausted` (a behind self-authored PR the sweep did not update only because this tick's branch-update budget was spent; retried next tick, waits on the hive, [#12607](https://github.com/hivecommons/hive/issues/12607)), `release-hold*`, `native-merge-queued: queued (position N, STATE)` (the PR was enqueued into GitHub's native merge queue) and the failures `native-merge-queue-read`, `native-merge-queue-enqueue`, `native-merge-queue-method` — and no red check on the head | `100-merge-queue` |
| CI red (required or optional check) while the PR is deferred to an open `[shared-ci]` incident (`<!-- hive-shared-ci-<n> -->`, the governor's `deferred_incident`) for the same head | `050-review-pending` / `060-reviewed`, reason `shared-ci-incident:<n>`: the base or a shared check is what is red, so the PR is never sent to 070/071/072, never nudged and never stalled; once the incident closes a still-red head is handed back as usual. Conflicts and requested changes stay author-facing ([#12606](https://github.com/hivecommons/hive/issues/12606)) |
| CI red (required or optional) while **every** failing check on the head is also red on the base branch's tip — the governor's `base_red_checks` / `base_red`, set during CI enrichment when a same-named latest check run on the base ref (meta checks excluded) concluded failure / timed_out / cancelled / action_required / startup_failure / stale **and** the PR's changed files include none of `.github/workflows/*`, `Dockerfile` / `Dockerfile.*` / `*.Dockerfile`, `go.mod` / `go.sum` (a PR touching those plausibly owns the check and stays author-facing; a lookup error or a diff beyond the file-list page budget also stays author-facing) | `050-review-pending` / `060-reviewed`, reason `base-branch-red:<check>,<check>` ("waiting for the base branch's CI to recover (…) — not this PR's fault"): never 070/071/072, never nudged, never stalled, still not merged (the lane's skip reason is the same token). The fix loop counts no attempt, kicks no fixer, and posts one `<!-- hive-base-branch-red -->` hold comment per head; an escalation the hive itself raised (ledger `label_applied`) over such a head has its `needs-human` removed with the hold wording. The next evaluation after the base goes green re-evaluates the head: a still-red PR is handed back as usual. Conflicts and requested changes stay author-facing (seen on [#13270](https://github.com/hivecommons/hive/pull/13270) and [#13258](https://github.com/hivecommons/hive/pull/13258), 2026-10-20) |
| CI red (required or optional) on a **fork** PR while **every** failing check's annotation says the check refuses forks (case-insensitive `fork pull request(s) cannot`, `maintainer must push this branch`, or `cannot publish` together with `fork` — a fork-publication / fork-secrets guard) | `085-needs-decision`, reason `fork-guard:<check>,<check>`: never 070/071/072, never nudged, never adopted (074) — neither the author nor the hive can turn the check green by pushing to the fork. The entry comment names the check and says a maintainer must push the branch to the repository (or approve the run as the repository requires). A same-repo PR with the same message, or a fork PR with any other red check, is handed back as usual ([#14273](https://github.com/hivecommons/hive/issues/14273)) |
| CI red (required or optional) on a **fork** PR while **every** failing check's annotation says the check refuses forks (case-insensitive `fork pull request(s) cannot`, `maintainer must push this branch`, or `cannot publish` together with `fork` — a fork-publication / fork-secrets guard) | `085-needs-decision`, reason `fork-guard:<check>,<check>`: never 070/071/072, never nudged, never adopted (074) — neither the author nor the hive can turn the check green by pushing to the fork. The entry comment names the check and says a maintainer must push the branch to the repository (or approve the run as the repository requires). The guard's checks are remembered on the PR's stage record: a head the CI-enriched enumeration has not classified yet (a new push, or a snapshot that dropped the PR) parks the same way when every red check in its check digest is one the guard refused before, so a fork PR is not nudged and adopted on each new head first ([projectbluefin/utah-packages#869](https://github.com/projectbluefin/utah-packages/pull/869)). A same-repo PR with the same message, or a fork PR with any other red check, is handed back as usual ([#14273](https://github.com/hivecommons/hive/issues/14273)) |
| any **non-required** check on the current head is red, whatever the lane's reason (the lane gates on required checks only, so it still soaks and merges; a reader of the rollup sees ✗). Parking modifiers (`hold`, `needs-human`, admission reasons) still win | `070-fixing` / `071-needs-author` / `072-returned-to-contributor` (by author kind), reason `optional-check-failing:<check>` (the nudge lists every red check); never 080 or 100. A red *required* check is the lane's own `required-check-failing:*` → 070/071/072 ([#12538](https://github.com/hivecommons/hive/issues/12538), seen on [#12457](https://github.com/hivecommons/hive/pull/12457)) |
| `label:hold`, `held`, `label:needs-human`, `exempt-label`, `excluded-label:*`, `sentinel`, `human-merge-path*`, `intent-*`, `contributor-lane:workflow-path` / `tests-removed` / `no-reviewer` / `reporter-trust-hold` | human hand-off, **decision** cause → routed by the head's evidence (below); lands at `085-needs-decision` when the head is otherwise clean. `contributor-lane:workflow-path` reads "awaiting owner approval": a trusted merger's `APPROVED` review on the current head (or a dashboard `/hive decision approve`) releases the fence and the lane merges the PR itself (`owner_approval_releases_workflow_fence`, [#14664](https://github.com/hivecommons/hive/issues/14664)); only with the toggle off, or when the App lacks `workflows: write` for the merge (`hive:unauthorized`, `merge-workflow-path`), does an approved head park at `090-ready-for-human-merge` for a person's click |
| `merge-refused:review-required` (GitHub answered the merge with 405 "At least N approving review(s) is/are required by reviewers with write access"), `merge-refused:method-not-allowed` (405 "Merge commits / Squash merges / Rebase merges are not allowed on this repository") | human hand-off, **decision** cause, as above: lands at `085-needs-decision` when the head is otherwise clean, and the entry comment names the rule GitHub refused the merge on. Every sweep (self-authored, trusted-author, queued, contributor lane) logs these as skips, not `merge-failed` errors, and stops calling merge: a review refusal is remembered per PR head and re-armed when the head moves, when GitHub's `mergeable_state` for the PR changes (an approving review turns `blocked` into `clean`), or after 30 minutes; a method refusal is remembered per repository and method for 30 minutes. The hive never switches the merge method on its own (a forward merge or a `merge-method/merge` PR must not be squashed), so `method-not-allowed` is a manual-merge park. Any other 405, 409 or 422 is still `merge-failed` |
Expand Down
21 changes: 21 additions & 0 deletions src/pkg/github/automerge/automerge_contributor_adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,15 @@ func (c *Engine) adoptContributorPR(ctx context.Context, store *stagelabels.Stor
if !due {
return 0, nil
}
if !requested && !forced && adoptionForkGuardOnly(obs) {
// The guard asks a maintainer to publish the branch; an in-place
// push cannot turn it green and an automatic copy would publish it
// without that maintainer (projectbluefin/utah-packages#862). The
// PR stays parked at 085; nothing is recorded, so a maintainer's
// adopt-supersede request still goes through.
c.debug("stage labels: adoption due but only a fork guard is red; left for a maintainer", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "checks", obs.ForkGuardChecks)
return 0, nil
}
if l := adoptionBlocked(obs.Labels); l != "" {
c.info("stage labels: adoption due but blocked by label", "repo", obs.Display, "pr", obs.Number, "label", l)
return 0, nil
Expand Down Expand Up @@ -1936,6 +1945,18 @@ func adoptionOptionalCheckOnly(obs stageObservation) bool {
return strings.HasPrefix(nonEmpty(obs.Reason, obs.LaneReason), stageReasonOptionalCheckFailing) && !verdictBlocks(obs.Detail) && !verdictNeedsHuman(obs.Detail)
}

// adoptionForkGuardOnly reports a head whose only blocker is a fork guard:
// every red check refuses the PR only because it is from a fork
// (ForkGuardChecks, hivecommons/hive#14273) and the stage reason is that
// guard or the red CI it explains. A review or DCO ask is still adoptable.
func adoptionForkGuardOnly(obs stageObservation) bool {
if len(obs.ForkGuardChecks) == 0 {
return false
}
r := nonEmpty(obs.Reason, obs.LaneReason)
return strings.HasPrefix(r, stageReasonForkGuard) || strings.HasPrefix(r, stageReasonOptionalCheckFailing) || classifyCIReason(r) == ciReasonRed
}

// adoptionStale reports whether the adopted head has sat unchanged for the
// 074 dwell with CI not running. A record whose head clock was never
// stamped (pre-hivecommons/hive#13040) is not stale: AdoptedAt may predate
Expand Down
27 changes: 27 additions & 0 deletions src/pkg/github/automerge/automerge_contributor_nudge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package automerge
import (
"context"
"fmt"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -283,6 +284,17 @@ func (c *Engine) nudgeContributor(ctx context.Context, store *stagelabels.Store,
return 0, nil
}
checks, asks, human := nudgeDiagnosisRouted(obs.Reason, obs.Detail, obs.Route)
// A fork guard is a maintainer's to clear (hivecommons/hive#14273): the
// author is never asked to fix it, and a head red on nothing else is not
// nudged at all — no nudge, no adoption grace
// (projectbluefin/utah-packages#869).
if kept := withoutForkGuard(checks, obs.ForkGuardChecks); len(kept) < len(checks) {
checks = kept
if len(checks) == 0 && len(asks) == 0 {
c.debug("stage labels: contributor nudge skipped, only a fork guard is red", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "checks", obs.ForkGuardChecks)
return 0, nil
}
}
n := ContributorNudge{
Owner: obs.Owner, Repo: obs.Repo, Display: obs.Display, Number: obs.Number,
HeadSHA: obs.HeadSHA, Title: obs.Title, URL: obs.URL, Author: obs.Author, OpenedAt: obs.OpenedAt,
Expand All @@ -306,6 +318,21 @@ func (c *Engine) nudgeContributor(ctx context.Context, store *stagelabels.Store,
return 1, nil
}

// withoutForkGuard drops the fork-guard checks from a nudge's failing
// checks; checks is returned unchanged when there is no guard.
func withoutForkGuard(checks, guard []string) []string {
if len(guard) == 0 {
return checks
}
var out []string
for _, name := range checks {
if !slices.Contains(guard, strings.TrimSpace(name)) {
out = append(out, name)
}
}
return out
}

// resolveNudge tells the sink a PR that was in stage 072 last cycle has
// left it (new head went green, closed, merged, adopted).
func (c *Engine) resolveNudge(ctx context.Context, rec stagelabels.Record, had bool, obs stageObservation) {
Expand Down
121 changes: 121 additions & 0 deletions src/pkg/github/automerge/automerge_fork_guard_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package automerge

import (
"context"
"reflect"
"slices"
"strings"
"testing"
"time"

hgithub "github.com/hivecommons/hive/pkg/github"
)

// projectbluefin/utah-packages#862 / #869: the fork-guard park only knew the
// head the last CI-enriched enumeration saw, so every new head of a fork PR
// red only on its `Canary` fork guard was handed back to its author first —
// a "fix Canary" nudge and, after the grace, an adoption — before the next
// enumeration parked it at 085 again. A head red on the guard alone now goes
// straight to the park; a head with any other red check keeps the
// author-facing route unchanged.
func TestForkGuardHeadNeitherNudgedNorAdopted(t *testing.T) {
cases := []struct {
name string
// red is the check digest of the second head, which the
// enumeration has not classified yet.
red []string
wantNudge bool
}{
{name: "fork guard only", red: []string{"Canary"}},
{name: "fork guard and a real failure", red: []string{"Canary", "unit"}, wantNudge: true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
var guard []string
p := adoptPolicy()
p.ForkGuard = func(string, int, string) []string { return guard }
h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "comment"}, p)
defer done()
h.e.checkSummary = func(_ context.Context, _, _, sha string) (hgithub.CommitChecksSummary, error) {
if sha == "aaa" {
return hgithub.CommitChecksSummary{Total: 3, Green: 2, Red: []string{"Canary"}, DCO: 1}, nil
}
return hgithub.CommitChecksSummary{Total: 3, Green: 3 - len(tc.red), Red: tc.red, DCO: 1}, nil
}
key := stageKey("acme", "widget", 7)

// The enumeration classified head aaa: parked, never nudged.
guard = []string{"Canary"}
h.observe(adoptPR(7, "aaa"), "required-check-failing:Canary")
parked := []string{"stage/085-needs-decision", "role/contributor", "author/clanker"}
h.observe(adoptPR(7, "aaa", parked...), "required-check-failing:Canary")
if got := nudgeComments(h.api); len(got) != 0 || len(h.sink.nudges) != 0 {
t.Fatalf("fork-guard head nudged: %v", got)
}
if rec, _ := h.e.stageStoreOrShared().Get(key); !slices.Equal(rec.ForkGuardChecks, []string{"Canary"}) {
t.Fatalf("fork guard not remembered: %+v", rec.ForkGuardChecks)
}

// A new head the enumeration has not seen: the policy knows nothing.
guard = nil
h.api.reset()
h.observe(adoptPR(7, "bbb", parked...), "required-check-failing:Canary")
nudges := nudgeComments(h.api)
if !tc.wantNudge {
if len(nudges) != 0 || len(h.sink.nudges) != 0 {
t.Fatalf("new fork-guard head nudged: %v", nudges)
}
} else if len(nudges) != 1 || !strings.Contains(nudges[0], "head=bbb n=1") || !strings.Contains(nudges[0], "`Canary`") {
t.Fatalf("new head with a real failure not nudged: %v", h.api.comments)
}

// Past every grace: adopted only when a real failure is red.
returned := []string{"stage/072-returned-to-contributor", "role/contributor", "author/clanker"}
labels := parked
if tc.wantNudge {
labels = returned
}
h.api.reset()
h.clock.advance(3 * time.Hour)
h.observe(adoptPR(7, "bbb", labels...), "required-check-failing:Canary")
adopted := len(h.adopt.pulls) > 0 || len(adoptionComments(h.api)) > 0
if adopted != tc.wantNudge {
t.Fatalf("adopted = %v, want %v: pulls=%d comments=%v", adopted, tc.wantNudge, len(h.adopt.pulls), h.api.comments)
}
})
}
}

// A nudge never lists a fork-guard check; adoption refuses a head whose
// only blocker is the guard but not one with a review or DCO ask.
func TestForkGuardNudgeChecksAndAdoptionPredicate(t *testing.T) {
guard := []string{"Canary"}
if got := withoutForkGuard([]string{"Canary"}, guard); len(got) != 0 {
t.Fatalf("guard-only checks = %v", got)
}
if got := withoutForkGuard([]string{"Canary", "unit"}, guard); !reflect.DeepEqual(got, []string{"unit"}) {
t.Fatalf("guard plus real failure = %v", got)
}
if got := withoutForkGuard([]string{"Canary"}, nil); !reflect.DeepEqual(got, []string{"Canary"}) {
t.Fatalf("no guard evidence = %v", got)
}

cases := []struct {
name string
obs stageObservation
want bool
}{
{name: "parked on the guard", obs: stageObservation{Reason: stageReasonForkGuard + "Canary", ForkGuardChecks: guard}, want: true},
{name: "guard is the red required check", obs: stageObservation{Reason: "required-check-failing:Canary", ForkGuardChecks: guard}, want: true},
{name: "guard is the red optional check", obs: stageObservation{Reason: stageReasonOptionalCheckFailing + "Canary", ForkGuardChecks: guard}, want: true},
{name: "review ask beside the guard", obs: stageObservation{Reason: "reviewer-verdict:changes_requested", LaneReason: "required-check-failing:Canary", ForkGuardChecks: guard}},
{name: "real failure, no guard evidence", obs: stageObservation{Reason: "required-check-failing:Canary"}},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := adoptionForkGuardOnly(tc.obs); got != tc.want {
t.Fatalf("adoptionForkGuardOnly = %v, want %v", got, tc.want)
}
})
}
}
1 change: 1 addition & 0 deletions src/pkg/github/automerge/automerge_stage_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ func (c *Engine) ApplyStageLabels(ctx context.Context) (StageLabelResult, error)
result.Items++
c.foldHumanReturnLabel(ctx, store, list)
c.foldRecordedDecision(ctx, list)
c.foldForkGuard(ctx, tracker, store, list, now)
verdict, role, obs := resolveStage(list)
key := stageKey(obs.Owner, obs.Repo, obs.Number)
if verdict.Rank == stageRankNone {
Expand Down
Loading
Loading