Skip to content

🐛 fix(automerge): read ruleset required checks when classic protection lists none - #15372

Merged
hivecommons-hive[bot] merged 1 commit into
v6from
fix/required-checks-rulesets
Oct 29, 2026
Merged

hivecommons-hive[bot] merged 1 commit into
v6from
fix/required-checks-rulesets

Conversation

@Danathar

Copy link
Copy Markdown
Contributor

Summary

On a rulesets-only repository, the automerge sweep read the required checks as "none". A registry-trusted contributor's held fork runs were then never approved, and the PR sat at ci-unverified.

Seen on hosted-projectbluefin-knuckle-gjvq (build f950551), 2026-10-29:

What GitHub returns for both repos (read 2026-10-29):

Endpoint Answer
branches/main/protection/required_status_checks 404 Branch not protected (403 for an App without Administration)
branches/main protected:true, protection.enabled:false, empty contexts, enforcement_level:"off"
rules/branches/main required_status_checks: Lint & syntax, Behave dry-run, pytest (testsuite)

RequiredStatusCheckContextsDetailedWithSource (pkg/github/commit_ci.go) accepted the first two answers as a known-empty set and returned before it reached the rules endpoint. With a known-empty set, commitGreen asks only for positive CI evidence. A head whose runs are all held has none, so the lane reason is ci-unverified. approveHeldRunsForRegistryTrusted acts only on required-check-missing:<ctx>, so it never fired.

The serialized lane's ReadBranchRules (pkg/github/branch_rules.go, #10894 / #10985) already treats a classic "branch not protected" as not authoritative. This brings the sweep's reader in line with it.

Change

  • Required checks (commit_ci.go). When classic protection says nothing is required, the sweep now reads GET /repos/{o}/{r}/rules/branches/{b}. If the rules list required checks, they are the set, with source rules. "Nothing required" covers three answers:

    • the branch is unprotected;
    • protection has no required checks;
    • the branch payload lists no checks.

    If the rules endpoint fails or lists none, the classic known-empty answer stands as before. When classic protection lists checks, the rules endpoint is not read.

  • Held-run approver (automerge_contributor_held_runs.go). It also acts at ci-unverified, but only when every pull_request run for the PR's head repository is action_required. All other conditions are unchanged:

    • the author was admitted by the registry;
    • the toggle is on;
    • no sentinel or exclude label;
    • no .github/workflows/** diff;
    • once per head.

    This covers repositories whose required checks the hive cannot read at all. A head with any run already started is an ordinary evidence gap and is left alone.

  • Docs: hive-merge.md (contributor lane and required-check source) and the approve_held_runs_for_registry_trusted row of operator-reference.md.

  • Changelog: changelog.d/fixed-required-checks-rulesets.md.

Not included, and why

  • No union of classic and ruleset checks when both list some. GitHub enforces both, so the true set is the union. Reading rules on every evaluation would add a call per PR for every classic-protected repository. The merge endpoint still enforces any ruleset check the hive misses, so a missed check only means a failed merge call.
  • No cache for the rules read. It costs one extra call per evaluation, and only on branches whose classic answer is empty.

Testing

From src/, TZ=UTC, -count=1:

  • go test ./pkg/github/... ./cmd/hive/ ./pkg/mergelane/... ./pkg/dashboard/ passes.
  • go vet and gofmt are clean.
  • The changelog, docs-links and docs-citations checks pass.

New tests:

  • TestRequiredStatusCheckContexts, 7 new cases:
    • an unprotected branch, protection without checks, and a 403 with the live enabled:false branch payload each defer to ruleset checks;
    • no rulesets, or a ruleset rule with no contexts, keep the classic known-empty answer;
    • protection with checks does not read the rules endpoint.
  • TestContributorLaneApprovesHeldRunsOnRulesetsOnlyBranch: the testsuite shape, end to end through the lane. It stops at required-check-missing:<ctx> and approves the held fork runs once.
  • TestContributorLaneApprovesHeldRunsWhenCIUnverifiedAndAllHeld:
    • approves when every run is held;
    • leaves a head alone when one run is in progress;
    • never approves for a claim-marker author.

Five existing commitGreen / CI-trail fixtures failed on any unexpected request. They now serve an empty rules/branches answer: no rulesets, so the same result as before.

Mutation checks: 9 mutants, each restored from a backup copy, and every one fails a test:

  • the three rules fallbacks removed, one at a time;
  • an empty ruleset accepted as the set;
  • rules read even when protection lists checks;
  • the approver gate reverted, at the helper and at the call site;
  • the all-held check removed;
  • the all-held check counting other repositories' runs.

Still open

Contributor checklist

  • Changelog: changelog.d/fixed-required-checks-rulesets.md.
  • Targets v6.
  • The title uses the emoji convention.
  • Commits include DCO sign-off.
  • Docs updated (src/docs/hive-merge.md, src/docs/operator-reference.md).
  • No secrets, credentials or local runtime state are committed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1

…n lists none

On a rulesets-only branch the classic protection API answers "Branch not
protected" (403 without Administration) and the branch payload reports
protection disabled with no contexts. RequiredStatusCheckContextsDetailedWithSource
took either as a known-empty required set and never read the rules
endpoint, so projectbluefin/testsuite and bluefin-bling heads whose fork
runs GitHub holds sat at ci-unverified and the registry-trusted held-run
approver (which acts on required-check-missing) never fired.

A classic "nothing required" answer now defers to the branch's ruleset
required checks when it lists any. The held-run approver also acts at
ci-unverified when every pull_request run for the head repository is
action_required.

Signed-off-by: Danathar <Danathar@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 29, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v6

Conflicts are checked with every PR merged onto the current tip of v6, so a PR that only needs a rebase is not reported as conflicting with its siblings.

No conflicting open PRs or same-file overlaps were found.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no findings from this perspective.

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no findings from this perspective.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs-currency — one advisory, no blocker.

src/docs/hive-merge.md:484-492 (new paragraph) under-describes the behaviour src/pkg/github/commit_ci.go now has:

  • It names two "nothing required" cases (unprotected, protection without checks) but omits the third one the code handles (commit_ci.go:212-216, branch endpoint payload with no checks) — which per the PR body is the shape actually seen on projectbluefin/testsuite (403 without Administration → source=branch). An operator reading the doc against that log line will not find their case.
  • It does not say that rulesets are not read when classic protection already lists checks (no union; commit_ci.go:193-199), nor that a failed/empty rules read leaves the classic known-empty answer standing (commit_ci.go:237-243). The PR body states both explicitly under "Not included"; the operator doc should too, since a repo with both classic and ruleset checks will still see only the classic set.
The required checks come from classic branch protection first. When classic
protection says nothing is required (the branch is unprotected, protection
lists no checks, or — without **Administration: Read-only** — the branch
payload lists none), the sweep also reads the branch's rulesets
(`GET /repos/{owner}/{repo}/rules/branches/{branch}`) and uses their
`required_status_checks` if any (`source=rules`). If that read fails or lists
none, the classic empty answer stands. When classic protection already lists
checks the rulesets are not read, so the sets are not unioned; GitHub still
enforces any ruleset check the hive missed at merge time. On a rulesets-only
repository the classic answer is always empty, so before this the sweep logged
`automerge required checks source … source=branch known=false count=0`, a
held head stayed at `ci-unverified`, and its runs were never approved
(projectbluefin/testsuite, bluefin-bling).

operator-reference.md:503 row and the changelog fragment match the code paths at automerge_contributor_held_runs.go:67,124-128.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no findings from this perspective.

— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed (style/maintainability) — no blockers; two readability notes, both optional.

  1. src/pkg/github/automerge/automerge_contributor_held_runs.go:103 — the all-held gate tests missing == "" as a proxy for "the reason is ci-unverified". The intent only becomes clear after reading lines 85–88. Testing the reason directly reads as the comment describes it:
	if reason == contributorHeldRunsCIUnverified && len(held) != len(workflowRunsForHeadRepo(runs.WorkflowRuns, headRepo)) {
  1. automerge_contributor_held_runs.go:171 / :185 — heldWorkflowRunsForHead now duplicates the head-repo filter that workflowRunsForHeadRepo introduces. Composing them keeps the repo-matching rule in one place:
 func heldWorkflowRunsForHead(runs []*gh.WorkflowRun, headRepo string) []*gh.WorkflowRun {
 	var held []*gh.WorkflowRun
-	for _, run := range runs {
-		if run == nil || !strings.EqualFold(run.GetConclusion(), workflowRunConclusionActionRequired) {
-			continue
-		}
-		if run.GetHeadRepository() == nil || !strings.EqualFold(run.GetHeadRepository().GetFullName(), headRepo) {
-			continue
-		}
-		held = append(held, run)
+	for _, run := range workflowRunsForHeadRepo(runs, headRepo) {
+		if strings.EqualFold(run.GetConclusion(), workflowRunConclusionActionRequired) {
+			held = append(held, run)
+		}
 	}
 	return held
 }

Advisory: src/pkg/github/commit_ci.go:194, :202, :214 repeat the same if rules, ok := rulesetRequiredWhenClassicEmpty(...); ok { return rules, true, false, false, "rules" } block three times; fine as-is, but a single classicEmpty(source) closure would make the fallback shape read once. Tests cover all three paths (merge_ci_policy_gap_test.go:230-240).

— hive: agent=ci-maintainer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive
hivecommons-hive Bot merged commit 09e8dda into v6 Oct 29, 2026
76 of 79 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the fix/required-checks-rulesets branch October 29, 2026 10:51
@hivecommons-hive

Copy link
Copy Markdown
Contributor
Evidence bundle `#15372d5a777b` sha256:4bda194f6a0311258e96763c96d8ac34cefaf194dd55ad84a4d2b039382f73c9 — download from the dashboard or `hivectl review evidence #15372`.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

merged by Hive trusted-author auto-merge: author @Danathar holds role owner and GitHub permission maintain on repo; CI green at d5a777b.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant