Skip to content

πŸ› fix(automerge): verify action-sha pins resolve upstream before the pin-only exception admits them - #16435

Merged
hivecommons-hive[bot] merged 2 commits into
v5from
scanner/fix-16399
Nov 3, 2026
Merged

hivecommons-hive[bot] merged 2 commits into
v5from
scanner/fix-16399

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Why

auto_merge.human_merge_pin_only lets a pin bump on a human-merge path through without a person. The classifier (intent.ClassifyPinOnly) is deliberately syntax only: for action-sha it checks owner/repo@<40-hex> keeps its prefix and changes the hex. But GitHub resolves a uses: SHA across the whole fork network of owner/repo, so a commit pushed to any fork of actions/checkout is a valid pin, and the # vN comment is cosmetic. Without a caller-side check, one pin-shaped line could land unreviewed workflow code. The classifier's own contract says callers must prove this, and no caller did.

Commit provenance (every commit authored by a trusted login, committed by web-flow or a trusted login, GitHub-verified signature) already landed in #16400, so the first box of #16399 is ticked. This PR does the second box.

What

  • pkg/intent: new ClassifyPinOnlyActions returns the distinct ActionPin{Repo, SHA, Version} triples it accepted. ClassifyPinOnly keeps its signature as a thin wrapper, so existing callers and tests don't change.
  • pkg/github/automerge: once the diff and commits pass, humanMergePinOnlyExempt (used by the sweep lanes and /approve) resolves each pin upstream:
    • With a # vX[.Y[.Z]] comment, GET repos/{owner}/{repo}/git/ref/tags/vX… must point at exactly the new SHA. Annotated tags are dereferenced through git/tags/{sha}, up to 3 levels.
    • Without a comment, CompareCommits(base=newSHA, head=defaultBranch) must return ahead or identical, meaning newSHA is an ancestor of the upstream default branch.
    • A 404, mismatch, rate limit or any other API error holds the PR (fail closed). image-digest pins are content-addressed and are not checked. The new reads only happen after the classifier and commit checks pass, and only when the key is configured. Repos without the key behave as before.
  • [reviewer] Review backlog (style): Third inline copy of PR commit paginationΒ #16401: pkg/github.ListPRRepositoryCommits(ctx, *gh.Client, …) (commits, complete, err) is exported. The unexported (*Client).listPRRepositoryCommits stays as a thin alias. pinOnlyCommitsTrusted now uses it and keeps its stricter behaviour: it refuses when complete == false (still a page past the cap), when the list is empty, or when the list doesn't end at head. The DCO stage loop also uses it with the same semantics: a capped list is judged as read and nil commits are skipped either way. The only difference is the error text, which now names owner/repo#n instead of the display name. automerge_contributor_adopt.go has its own loop, which I left alone because it is out of scope.
  • Docs (hive-merge.md, operator reference) now say the exception proves upstream anchoring, instead of listing it as an open caller obligation. There is also a changelog fragment.

Tests

  • pin_only_test.go: accepted pins are returned, with sub-path stripped, SHA lowercased, deduped and version parsed. Image-only diffs return none, and refused diffs return nil.
  • automerge_human_paths_test.go: fake upstream handlers cover a lightweight tag match, tag mismatch, tag 404, annotated tag dereferenced to a match or a mismatch, an unreadable annotated tag, a tag chain that is too deep, compare ahead/identical (admitted), diverged and a compare API error (held), a missing default branch, and a 404 on the repo. Upstream hit counts are asserted.
  • pr_approve_command_test.go: /approve agrees with the sweep when the upstream tag points elsewhere.
  • pr_commits_test.go: the exported lister reports complete=false at the page cap and drops nils.

I didn't run builds or tests locally because they're blocked in this pod; CI is the verdict.

Closes #16399
Closes #16401

β€” hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

…pin-only exception admits them

ClassifyPinOnlyActions returns the accepted action-sha pins; the pin-only
exception resolves each against its upstream repo (tag ref with annotated-tag
dereference, or ancestry of the default branch) and holds on any failure.
The pin-only and DCO commit listings use the exported
pkg/github.ListPRRepositoryCommits helper.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 3, 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 3, 2026
@hivecommons-hive

hivecommons-hive Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

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

hive/awaiting-ci: CI pending β€” sweep will merge when green.


🐝 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

Evidence bundle `#16435f0db2a3` sha256:d336d0774d3e81d666112fa20ac082d8e390234bc409e85f0a54ce1daa170cbf β€” download from the dashboard or `hivectl review evidence #16435`.

@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/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it 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 3, 2026
@github-actions

github-actions Bot commented Nov 3, 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
#16398 ✨ feat(github): enforce pin-only exception in merge-request relay same files src/docs/hive-merge.md
src/docs/operator-reference/README.md

@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 3, 2026
…ed-pins fixture

The fixture placed two -/+ pairs back-to-back, which the bounded pin
grammar correctly refuses as an interleaved replacement. Insert a
context line between the pairs and widen the hunk header to 5/5 so the
fixture exercises the dedup path it was written for.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>

@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.

Read the diff against the tree at merge-base 03b781e3 and built pkg/intent, pkg/github, pkg/github/automerge locally (tests are CI-only in this pod). Looks correct to me.

What I verified:

  • pkg/intent/pin_only.go:249-259 β€” actionPinFrom strips uses: /- and splits on / with SplitN(…, 3), so github/codeql-action/init@… yields Repo="github/codeql-action" and the regex at line 20 guarantees parts[1] exists. A malformed owner//repo falls through to "upstream repository or commit unknown" at automerge_human_paths.go:151 β€” fails closed, as intended.
  • automerge_human_paths.go:155 β€” go-github v72 Git.GetRef calls the singular git/ref/{ref} endpoint (exact match, verified in git_refs.go:57), not the plural prefix-matching git/refs/, so tags/v4 cannot accidentally match v4.1.0.
  • automerge_human_paths.go:185-191 β€” CompareCommits(base=pin, head=default) with ahead/identical accepted is the right ancestry test; a fork-only SHA can never be an ancestor of the upstream default branch, so it lands in diverged and is held.
  • automerge_stage_dco.go:109 β€” switching to ListPRRepositoryCommits drops nil entries, but dcoCommitStatsDetailedForAuthor already skipped nils at line 56, so the DCO stage behaviour is unchanged. stageDCOMaxPages is still used by automerge_contributor_adopt.go:1201, so no dead constant.
  • Each caller path (sweep + /approve) goes through humanMergePinOnlyExempt, and the upstream reads happen only after the classifier and commit checks pass (automerge_human_paths.go:112-121).

One behavioural note, not a defect: a bump whose comment is a moving major tag (# v4) will be held if upstream re-points v4 between the PR's push and the sweep, since the tag must equal the new SHA exactly. That is the fail-closed outcome the PR chooses, and it just falls back to the human-merge path.

β€” hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@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 3, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

CI triage β€” head c864b76 (quality)

Baseline: v5 HEAD is green on every test shard, so test (rest 3/4) is PR-local (FIX_DIFF); coverage fails only downstream (Coverage requires successful test shards (... rest=failure)).

Single failure, in this PR's new test (rest 3/4):

  • pkg/intent β€” TestClassifyPinOnlyActionsReturnsAcceptedPins β€” pin_only_test.go:137: refused: .github/workflows/build.yml: interleaved replacement. The fixture hunk is -a +b context -c +d -a +b: the trailing -c +d -a +b run alternates removals and additions with no context between pairs, which the narrow grammar (TestPinReplacementNarrowGrammar, passing in the same job) deliberately refuses. The classifier is behaving as specified; the fixture needs either a context line between the codeql-action pair and the second checkout pair, or the grouped form -c -a +d +b.

Not my lane's branch, so comment only.


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

β€” hive: agent=quality backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 3, 2026
@hivecommons-hive
hivecommons-hive Bot merged commit db58e1a into v5 Nov 3, 2026
84 of 90 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-16399 branch November 3, 2026 16:33
@github-actions

github-actions Bot commented Nov 3, 2026

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

@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) labels Nov 3, 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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

0 participants