Skip to content

✨ feat(ci): approve gated workflows for trusted PR heads - #16681

Closed
hivecommons-hive[bot] wants to merge 10 commits into
v5from
hive/adopt-16615
Closed

hivecommons-hive[bot] wants to merge 10 commits into
v5from
hive/adopt-16615

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Supersedes #16615 (adopted in place, re-homed because a hive commit on the contributor branch cannot carry a squash-safe sign-off; original commits by @thatguywob preserved).

Closes #16603
Fixes #16603

This branch is #16615's head 94610bc8a15c as pushed by @thatguywob (fork thatguywob/hive), unchanged. Last lane reason on the original: check-failing:build-and-test.

Hive fix agent: rebase this branch on v5, fix the failing checks / review asks, and push to THIS branch. Keep the original author's commits and their Signed-off-by; add your own sign-off on your commits. Do not open another PR.

Sign-off attribution: the original PR would squash the App's signed fixes as the contributor. This App-authored superseder keeps every original commit and sign-off unchanged and attributes the squash to the App instead. DCO and all merge gates still apply here.

thatguywob and others added 7 commits November 4, 2026 13:18
Start trusted CI without waiting for a maintainer click when GitHub has created no check runs yet. Bind approvals to fresh PR and run evidence, suppress repeat attempts, and show permission refusals to operators.

Hive-Run: #16603
Hive-Plan: workflow-approval-sweep
Hive-Spec: #16603#proposal
Signed-off-by: thatguywob <thatguywob@users.noreply.github.com>
Co-authored-by: clubanderson <407614+clubanderson@users.noreply.github.com>
Signed-off-by: thatguywob <thatguywob@users.noreply.github.com>
Signed-off-by: thatguywob <thatguywob@users.noreply.github.com>
Signed-off-by: thatguywob <thatguywob@users.noreply.github.com>
The v5 base started using pluralVerb in stageTrackerUnreportedChecksSentence
after this branch had removed it as unused; the merge kept the removal and
build-go failed with 'undefined: pluralVerb'.

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 5, 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 hanthor 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

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

PR Title Relation Files
#16680 ✨ feat(settings): expose merge-train controls in Auto-merge same files src/pkg/config/config.go
src/pkg/dashboard/settings_parity_allowlist.txt
#16607 ✨ feat(github): enforce pin-only exception in merge-request relay same files src/pkg/config/config.go
src/pkg/github/client.go

@hivecommons-hive hivecommons-hive Bot added author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 5, 2026
@hivecommons-hive

hivecommons-hive Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor.

Hive filed review findings that do not block this PR as backlog items:

Cap: 10 backlog item(s) per PR per day.

Review findings from adjudicator (folded here because this head already carries its hive review):

Correctness review (head 94610bc, read against the diff plus pkg/github tree at head; GitHub reads were rate-capped mid-review, so CI status and the dashboard/config trees were not re-verified)

The decision path is well guarded (fresh PR re-read, per-run head-repo/SHA/PR match, claim-before-POST ledger, writeback gate) and the tests exercise once-per-head, concurrency, pagination and the 403/404 refusal. Two small gaps and one process note:

  1. Approval ledger never evicts — src/pkg/github/workflow_auto_approval.go:118-129 and :135-141 write attempts[workflowApprovalKey{repo,number,head}] and nothing ever deletes entries (the probe cache got evictStaleProbes, workflow_approval.go:177-183, but attempts did not). Every gated head seen for the life of the process stays in the map. Low, but the old package-global cache was explicitly bounded for this reason; drop entries whose head is no longer a PR head, or on a TTL.

  2. Refusal caption lost under API-budget mode — src/cmd/hive/main_eval_cycle.go:584-586 skips SweepWorkflowApprovals when budgetDecision.SkipOptional, but EnrichCIStatus (src/pkg/github/client.go:2566-2568) still sets CIActivity.WorkflowApproval from the probe. PermissionDenied is only applied by the sweep (workflow_auto_approval.go:73), so in budget mode the row regresses from "needs workflow approval on GitHub" to the plain count caption and the operator loses the "the click is on you" signal ✨ Auto-approve workflow runs gated on GitHub's approve-workflows for trusted bots and admitted PRs #16603 asked for. Carry permissionDenied into the probe result, or apply the ledger flag in EnrichCIStatus too.

  3. The PR body records this exact head as check-failing:build-and-test on ✨ feat(ci): approve gated workflows for trusted PR heads #16615. The head is unchanged here; I could not re-check the run. Rebase on v5 and get build-and-test green before this is merge-ready.

hive/awaiting-ci: the red Sign-off survives the squash check-run on head 94610bc belongs to the superseded fork PR #16615 (run 41944315137, PR_AUTHOR_LOGIN=thatguywob), which shares this exact SHA. This PR's own runs of that workflow (41944326862, 41944520869) passed. No branch change needed; it merges once review/approval clears.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

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

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Decision needed: @clubanderson should confirm that governor.ci.auto_approve_workflows ships default-on (per #16603), so every hive that upgrades starts approving GitHub-gated workflow runs for dependabot/renovate/App/lgtm heads without an explicit opt-in.

I read the tree at v5 plus the diff, not just the diff. No defect found; routing because this is a new CI-rights write that is on by default, and that sign-off belongs to a person.

What I verified

  • Trust decision src/pkg/github/workflow_auto_approval.go:17-36 matches #16603 exactly: PR author or triggering actor in the allowlist (default dependabot[bot], renovate[bot] at src/pkg/config/governor_ci.go:16-19), the App login, or the owner-admitted lgtm label. lgtm is AutoMergeQueuedLabel (src/pkg/github/client.go:1484) and the hive only applies it through the owner decision path (pkg/dashboard/api_repo_item_decision.go:625-627 → QueuePRAutoMerge… at client.go:3237), so admitted is not self-granting.
  • Before any POST the sweep re-fetches the PR (workflow_auto_approval.go:84-86) and bails if state/draft/head changed, then requires each run's head repo to equal the PR's head repo and the run to be linked to this PR number (:98-110). Hold/exempt/sentinel labels and repo pause short-circuit at :51 and :89. Writeback is gated as KindCIRerun (:138).
  • Once-per-head: attempted is claimed under the mutex before the first POST (:142-151), so a concurrent cycle cannot double-approve. 403/404 persists permissionDenied via record() (workflow_approval.go diff hunk, attempt.permissionDenied = true) and later cycles re-surface it at :76 without further writes — matches the issue's "record the refusal once".
  • Wiring: src/cmd/hive/main_eval_cycle.go calls SweepWorkflowApprovals after CI enrichment and skips it under SkipOptional budget.

One nit (info, not blocking)

workflow_auto_approval.go:15-16 says the check is "deliberately per run: one trusted triggering actor must not authorize other actors' runs on the same PR head", but the author branch of the same function authorizes every actor's run on a head whenever the PR author is trusted. The behaviour is what #16603 asked for; the comment just overstates the guarantee. Worth a one-line fix so the next reader does not rely on it.

Why a human, not the hive: this grants the App a new write (POST /actions/runs/{id}/approve) that lets fork-origin code run with the repository's CI rights, and AutoApproveWorkflowsEnabled() is true when the key is absent (governor_ci.go:10-12). #16603 chose that default; I am asking only that the owner knowingly accept it at merge time rather than discover it on the next upgrade. Checks: one early Sign-off survives the squash run failed, the later ones on this head pass — tide will settle that.

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

@hivecommons-hive hivecommons-hive Bot removed the stage/050-review-pending Review swarm requested; awaiting a verdict for the current head label Nov 5, 2026
@hivecommons-hive hivecommons-hive Bot added the stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it label Nov 5, 2026
Review follow-ups for #16681:

- The attempts ledger is now evicted: a sweep drops superseded heads of
  the same PR immediately and ages out entries no sweep has observed for
  24h, instead of retaining every gated head for the process lifetime.
- CI enrichment applies the ledger's permission-refusal flag itself, so
  budget-mode cycles that skip SweepWorkflowApprovals keep the "needs
  workflow approval on GitHub" caption instead of regressing to the count.
- The workflowApprovalTrusted doc comment now states the #16603 rule: a
  trusted author authorizes every run on the head; otherwise trust is
  per triggering actor.

Hive-Fix-Attempt: 1/6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: ci-maintainer <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 5, 2026
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Nov 5, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Decision needed: @clubanderson should confirm that hive may start approving GitHub's "Approve and run workflows" gate by default (governor.ci.auto_approve_workflows unset → on) for dependabot[bot]/renovate[bot], App-authored and lgtm-admitted PR heads, given CI runs on self-hosted runners.

Read against v5 at head e06da93. The code does what #16603 specifies and I found no correctness defect; this is routed to a person only because it hands the hive a new CI-execution permission, and that is an owner's call, not mine.

What I verified

  • Trust decision (src/pkg/github/workflow_auto_approval.go:21-39) is exactly the #16603 rule set: owner admission label, App login, or author/triggering-actor in the allowlist. Admission is c.AutoMergeLabel() (lgtm by default), which is applied by the owner/merger queue action at src/pkg/github/client.go:3237, so "admitted" really is an owner's act.
  • Freshness: before any POST it re-fetches the PR (workflow_auto_approval.go:83-85) and requires open, non-draft, and head SHA unchanged; runs are filtered to head_sha == PR head, event == pull_request (workflow_approval.go, workflowRunsAwaitingApproval), and head_repository == PR head repo (workflow_auto_approval.go:97). A run from a different fork or a superseded push cannot be approved against this PR.
  • Bounded: attempted is claimed under the mutex before the first POST (workflow_auto_approval.go:137-145), so a concurrent cycle or an unchanged head cannot repeat the pass; per-PR superseded heads and >24h entries are evicted in touchAttempt.
  • Gated by the existing writeback policy (WritebackAllowed(... KindCIRerun ...), line 131), hold/exempt/sentinel labels (workflowApprovalHeld), paused repos, and the governor budget (main_eval_cycle.go:584 skips it under SkipOptional).
  • 403/404 is recorded once as permission_error, surfaces PermissionDenied in the CI caption, and the loop breaks rather than hammering the API.
  • Defaults (src/pkg/config/governor_ci.go:10-20): enabled when unset; actors default to dependabot[bot], renovate[bot]; an explicit [] trusts only App + admission. All three are stated in #16603, so I am not re-asking them — only asking the owner to confirm the trust surface as a whole.

Facts for the decision

  • Author of record is the hive App (adoption of #16615 by @thatguywob, head preserved unchanged). The issue was filed by @clubanderson.
  • Behaviour change on upgrade: any hive without governor.ci configured starts approving gated runs for the default trust set on its next cycle. pull_request runs from forks get a read-only GITHUB_TOKEN and no secrets, but on self-hosted runners the approved job still executes the head's workflow files on hive infrastructure. For dependabot/renovate/App heads that is the intended trade; the owner should be the one to accept it.
  • Note that a trusted author authorizes every gated run on the head, including runs triggered by a later pusher to that branch (workflow_auto_approval.go:25-27). That is per #16603 ("the code under test is theirs"), just stating it plainly.

One low finding (docs-currency)

  • src/docs/operator-reference/runtime-and-quota.md and src/docs/webhooks.md:116 document the sibling yaml-only key governor.ci_failure_webhook_kick; the two new governor.ci.* keys appear only in hive.yaml.example and the parity allowlist. Suggest a row in the operator reference so the default-on behaviour is discoverable before an operator notices CI starting itself.

Not approving or requesting changes; the decision above is the only thing standing between this and a maintainer merge.

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

@hivecommons-hive hivecommons-hive Bot added stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 5, 2026
…eference

Review finding (docs-currency): the new governor.ci.auto_approve_workflows
and governor.ci.auto_approve_workflow_actors keys were only in
hive.yaml.example and the settings parity allowlist. Add them beside the
sibling governor.ci_failure_webhook_kick entries in
docs/operator-reference/runtime-and-quota.md (behaviour, trust set, guards,
default-on note, status counts, log lines) and the configuration table in
docs/webhooks.md.

Hive-Fix-Attempt: 2/6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: ci-maintainer <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Nov 5, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Decision needed: @clubanderson should confirm that the hive App may auto-approve GitHub's "Approve and run workflows" gate (default on when governor.ci.auto_approve_workflows is unset) for dependabot/renovate, App-triggered and owner-admitted heads on this org's runners — this is a CI-trust decision, not a code defect.

Routing to an approver because this grants the hive a new CI-trust capability (approving fork/bot workflow runs that then execute on the repository's runners). I read the full diff against v5, pkg/github/workflow_approval.go, the callers in main_eval_cycle.go:584 and client.go:2568, and the admission path. I found no defect; the guards are real and tested. The facts an approver needs:

What it does. SweepWorkflowApprovals (workflow_auto_approval.go:46) runs after EnrichCIStatus for open, non-draft, non-green PRs. For a head with action_required runs it re-reads GET /pulls/N (head SHA, state, draft, author, labels) before any write, then approves via POST /actions/runs/{id}/approve when workflowApprovalTrusted (:21) says yes.

Who gets trusted. Per #16603, exactly: PR author or run's triggering actor in governor.ci.auto_approve_workflow_actors (default dependabot[bot], renovate[bot]), or equal to AppBotLogin(), or the PR carries the automerge label. I checked the label path: it is only applied through an owner's dashboard decision (api_repo_item_decision.go:627 → QueuePRAutoMergeWithNoteResultAtHead, client.go:3237), so "admitted" really is owner-gated.

Guards I verified in code. Held / exempt / sentinel labels and repo pause skip the PR (:58, :166); runs are listed with event=pull_request and filtered again on exact head SHA (workflow_approval.go:159-174), so pull_request_target and foreign heads never reach the approve call; every run must have head_repository == fresh.head.repo (:101) and, when GitHub populates run.pull_requests, must link this PR; the writeback gate ci_rerun must allow it (:128); and the attempt is claimed before the first POST so a concurrent cycle cannot double-approve (:134-142, TestSweepWorkflowApprovalsConcurrentPasses). 403/404 is recorded once and surfaces as a caption instead of retrying (TestSweepWorkflowApprovalsPermissionRefusalOnce).

Defaults. Unset = on (governor_ci.go:11). That is what #16603 asked for and runtime-and-quota.md says so plainly, including the self-hosted-runner opt-out — so I am not re-asking the default, only whether the capability itself is wanted.

Two open questions, neither verified as a defect:

  1. Trust follows the triggering actor. A run on an untrusted fork head that the App itself re-triggers would have triggering_actor = App and be approved (:21-37, "trust is per run"). I could not find a path in this tree where the hive re-runs an action_required run (they have no check runs, so the CI-rerun writeback never sees them as failing), so I believe this is unreachable today; stating it so the approver knows the model.
  2. Denied heads are re-evaluated every cycle. attempted is only set after a successful claim (:134-139), so a gated PR from an untrusted contributor costs one GET /pulls/N per cycle (after the 90s probe TTL) until it is admitted or closed. That is intentional (TestSweepWorkflowApprovalsDeniedCanBeAdmittedLater) and cheap, just noting the API cost on repos with many first-time fork PRs.

Body ↔ diff: the superseder body says it is #16615's head unchanged plus fix commits; the branch is 94610bc + two signed commits (e06da93 ledger bounding + refusal evidence, c4b15fc docs), which matches. CI is green at c4b15fc.

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

@hivecommons-hive hivecommons-hive Bot added stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 5, 2026
runtime-and-quota.md and webhooks.md said the approval sweep runs after
every CI enrichment pass. main_eval_cycle.go only calls
SweepWorkflowApprovals when the eval budget decision does not shed
optional steps, so it is skipped in conserve/critical API-budget mode,
on off-cadence cycles and on cached (webhook-wake) cycles. Say so, and
note that EnrichCIStatus still runs on those cycles so the
`waiting on workflow approval` state stays visible until the next full
normal-mode cycle approves the head.

Hive-Fix-Attempt: 3/6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: ci-maintainer <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Nov 5, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Decision needed: @clubanderson should confirm this trust policy for auto-approving gated workflow runs (default on; App, dependabot[bot], renovate[bot] and lgtm-admitted PRs trusted) before it lands, since it lets the hive start CI on code the gate was holding.

Routing to a human rather than approving: this PR gives the hive the ability to start CI on code GitHub was holding behind "Approve and run workflows". I read the tree at 746fa2b; the code is correct as far as I can verify, and it implements #16603 as written. The facts a maintainer needs:

What is trusted (src/pkg/github/workflow_auto_approval.go:20-39, workflowApprovalTrusted): a run is approved when (a) the PR carries the auto-merge/lgtm label, (b) the PR author or the run's triggering actor is the App bot, or (c) either of those logins is in governor.ci.auto_approve_workflow_actors, defaulting to dependabot[bot], renovate[bot] (src/pkg/config/governor_ci.go:22-27). auto_approve_workflows is on by default (governor_ci.go:16-18). All three are exactly what #16603 specifies, so I am not re-asking them — only asking the owner to confirm before the capability goes live on every repo this hive serves.

Guards I verified exist: the sweep re-fetches the PR before acting and bails if head SHA, open state or draft changed (workflow_auto_approval.go:84-88); runs from a different head repository are skipped (:99-101); held/exempt/sentinel-labelled PRs and paused repos are skipped (:56, :91); the POST goes through WritebackAllowed(..., KindCIRerun, ...) (:134), so repos that already forbid CI-rerun writebacks also forbid this; one attempt per head, claimed before the first POST (:139-147); 403/404 recorded once and surfaced as "needs workflow approval on GitHub" (:150-156). Tests cover the decision table, once-per-head, concurrent passes and permission refusal (workflow_auto_approval_test.go).

One open question, not a defect: because the App is a trusted triggering actor, any hive-initiated rerun of a run on an otherwise-untrusted first-time contributor's PR would make that rerun approvable (:111, workflowTriggeringActor prefers triggering_actor). #16603 asks for App-as-actor trust explicitly, so this is by design; I mention it only so the owner is choosing it knowingly. If that is not wanted, the fix is to drop actor from the App check and keep it for the allowlist.

Superseder of #16615 with @thatguywob's commits preserved; checks green except mobile-shots still running. I have not approved or changed anything.

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

@hivecommons-hive hivecommons-hive Bot added stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 5, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Re-authoring: the hive's fixer gave up on this PR after 6 attempts on 746fa2b02df0. Closing it as superseded; the hive opens a fresh PR for #16603 from the current v5 on its next cycle. Nothing from this branch is merged.

@hivecommons-hive hivecommons-hive Bot added the hive/superseded Closed by Hive: a different merged PR already landed this change label Nov 5, 2026
@hivecommons-hive hivecommons-hive Bot closed this Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/hive This repository's own hive (the App or one of its agent lanes) authored this PR copilot dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. hive/superseded Closed by Hive: a different merged PR already landed this change role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Auto-approve workflow runs gated on GitHub's approve-workflows for trusted bots and admitted PRs

1 participant