Skip to content

πŸ› fix: reject carried approvals in the hold guard - #15722

Closed
mendezr wants to merge 12 commits into
hivecommons:v5from
mendezr:fix/15698-carried-hold-approval
Closed

mendezr wants to merge 12 commits into
hivecommons:v5from
mendezr:fix/15698-carried-hold-approval

Conversation

@mendezr

@mendezr mendezr commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Reject approval records prefixed approve (carried when checking whether a trusted merger reviewed a drifted head.
  • Add a regression case requiring re-hold for a carried approval on the current head; existing direct-approval coverage remains unchanged.
  • Add a security changelog fragment. This is defense-in-depth hardening, not a claim of a practical exploit.

Fixes #15698

Validation

  • gofmt -l src/cmd/hive/main_helpers.go src/cmd/hive/hold_guard_test.go β€” clean.
  • Tests not run locally per AGENTS.md; CI runs the regression suite.

β€” hive: backend=pi model=openai-codex/gpt-6.1-sol


🐝 Hive Agent: contributor | SHA: 0fd4bf5bd

@kubestellar-prow kubestellar-prow Bot added dco-signoff: yes Indicates the PR's author has signed the DCO. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 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.

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.

Looks correct to me. Read on head 0fd4bf5 (based on v5 tip 390b92d, i.e. on top of #15645 which #15698 was blocked on β€” the merge is clean).

What I verified:

  • The only writer of a carried approval is carryAdmissionToCopy (src/pkg/github/automerge/automerge_operator_admission.go:115-123), whose Body is fmt.Sprintf("approve (carried from #%d head %s)", …) with Kind: HumanChangeRequestKindApprove and Source: …Decision. There is no structured "carried" field on review.HumanChangeRequest (src/pkg/review/human_change_request.go:57-75), so the prefix test at src/cmd/hive/main_helpers.go:69-73 is the only discriminator available without widening the record β€” and it is what #15698 proposed.
  • It sits after the head/kind check and before the trusted-merger check, so it only narrows the lift path; ordinary decision approvals (Body == "approve") and review-event approvals are unaffected. Other consumers of the ledger (the lanes reading a carried requires_human as answered) are untouched.
  • The new table case carried approval on the current head (hold_guard_test.go:1086) records a carried body on p1 by an owner and asserts the drift path still stands; without the new guard that case lifts the hold, so the test fails without the change.

One maintainability note, not a defect: the producer format string and the consumer prefix now live in two packages with nothing tying them together. If someone reworded the Sprintf in automerge_operator_admission.go:122, the guard would silently start accepting carried approvals again. A shared constant (e.g. exported from review alongside the kinds) would make that drift a compile error; fine as a follow-up if you'd rather keep this PR minimal. The Sign-off survives the squash check shows CANCELLED, which doesn't look related to the diff.

β€” 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.

Decision needed: @clubanderson should decide whether a carried adoption approval may lift a drifted hold on the hive's copy, or only a direct head-scoped approval may (this PR) β€” carryAdmissionToCopy's doc says the carried approval "stands for the content" while this guard says it does not.

Conclusion: the code is correct, fail-closed and matches the body's "defense-in-depth, not a practical exploit" framing. I'm routing it rather than calling it done because it changes merge-hold policy, and the two places in the tree now disagree on what a carried approval means.

Verified at head 0fd4bf5 against v5 390b92d88:

  • The prefix check strings.HasPrefix(req.Body, "approve (carried") (src/cmd/hive/main_helpers.go:71) matches the only writer exactly: carryAdmissionToCopy records Body: fmt.Sprintf("approve (carried from #%d head %s)", …) at src/pkg/github/automerge/automerge_operator_admission.go:122. No other code emits that body.
  • The check sits after the head/approval match and before the trusted-merger check, so it narrows an existing accept path (main_helpers.go:204 caller) and cannot widen anything. Existing cases in TestEnforceHoldGuardOperatorApprovalMustCoverCurrentHeadByTrustedMerger are unchanged; the new case records the carried body on the current head and expects the drift path to stand, which is the one behaviour the diff adds.
  • Policy tension worth the maintainer's one-line answer: automerge_operator_admission.go:111-114 and adoptionCarriedApprovalNote (automerge_contributor_adopt.go:1106-1111, "the approval travels with the content") document the carried record as standing for the approved tree, and the copy is opened when the original is conflicting/needs-rebase/DCO-missing (headNotMergeableAsIs, :96-109), i.e. precisely when the fixer will re-author it. This PR says a carried record is never evidence a person reviewed the copy's head. Both are defensible; they should not both be in the tree with contradictory comments.

Suggestion (not a defect): the writer and this reader now share a bare string literal across two packages. If the writer's wording ever changes, this guard silently re-opens. A shared exported constant (e.g. in pkg/review next to HumanChangeRequestKindApprove) used by both sides would make that impossible β€” small follow-up or fold it in here.

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

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Needs a decision, not a merge:

  • the reviewer swarm returned requires_human @0fd4bf5
  • the review found: the reviewer marked this change high-risk
  • reviewer question: @clubanderson should decide whether a carried adoption approval may lift a drifted hold on the hive's copy, or only a direct head-scoped approval may (this PR) β€” carryAdmissionToCopy's doc says the carried approval "stands for the content" while this guard says it does not.
  • the automerge lane will not merge this unattended

Head: verdict requires_human @0fd4bf5, 57/57 checks green, DCO yes, soak 17m0s of 30m0s.

How to release it:

  • After reading the verdict, a trusted merger can submit a GitHub Approve review for the current head and the lane clears the hold on its next pass; /hive approve replies on a PR are acknowledged but not consumed. An ordinary contributor cannot release their own PR.

Clear the cause and the hive re-evaluates on its next pass; the stage moves to stage/090-ready-for-human-merge, stage/095-pre-merge-soak or the merge queue on its own. Approval does not bypass CI, hold labels or other merge gates.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

stage 095-pre-merge-soak β†’ 085-needs-decision: contributor-lane:decision-requested

@hivecommons-hive

Copy link
Copy Markdown
Contributor

/lgtm

Posted by @clubanderson from the Hive dashboard; the merge gate decides from here.

@kubestellar-prow

Copy link
Copy Markdown
Contributor

@hivecommons-hive[bot]: changing LGTM is restricted to collaborators

Details

In response to this:

/lgtm

Posted by @clubanderson from the Hive dashboard; the merge gate decides from here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

/approve

Posted by @clubanderson from the Hive dashboard; the merge gate decides from here.

@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hivecommons-hive[bot]
Once this PR has been reviewed and has the lgtm label, please assign nicholasjackson 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

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

Looks correct to me, and it is the hardening #15698 asked for. Read the tree at c110880:

  • The only writer of carried approvals is carryAdmissionToCopy (src/pkg/github/automerge/automerge_operator_admission.go:122), whose body is fmt.Sprintf("approve (carried from #%d head %s)", …) β€” so the strings.HasPrefix(req.Body, "approve (carried") check at src/cmd/hive/main_helpers.go:71 matches exactly that record and nothing a person types via the dashboard//hive decision approve path. The check sits after the head/kind match and before the trusted-merger check, so it fails closed as the doc comment says.
  • Agreed with the issue that this is defence in depth: the guard only consults the ledger on the drift path (main_helpers.go:183-185 clears a head-unchanged lift first), so a carried record could lift a hold only if the branch returned to its creation SHA.
  • The new table case (hold_guard_test.go, "carried approval on the current head") would fail without the change β€” the actor is in the merger tier and the head matches, so only the body prefix rejects it.

One suggestion, not a defect: the marker now lives as a literal in two packages (automerge_operator_admission.go:122 and main_helpers.go:71). If someone later rewords the carried body, the guard silently goes back to accepting carried approvals with no test catching it (the hold-guard test builds its own body string). Exporting a single constant from pkg/review (e.g. review.CarriedApprovalBodyPrefix) and using it in both places β€” and in the test β€” would make that coupling visible. Fine to do as a follow-up.

Changelog fragment security-15698-carried-hold-approval.md matches the <category>-<pr-or-slug>.md rule. Could not run go test in this pod (blocked for agents).

β€” 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.

Traced the path before reading the body. holdGuardOperatorApproval is only consulted from main_helpers.go:204, after the head-unchanged clear at :178-185, so a carried record can only lift a hold when the branch is back on the copy's creation SHA while the hold snapshot names a different head β€” the force-push-back case #15698 describes. The new guard at main_helpers.go:69-73 closes that exactly as the issue prescribes, and the writer at src/pkg/github/automerge/automerge_operator_admission.go:122 emits "approve (carried from #%d head %s)", so the approve (carried prefix matches today. The new table case fails without the change (same head p1, trusted owner, approval kind) and the three existing cases are unchanged. Looks correct to me.

One maintainability note, not a defect: the writer and the reader are now coupled by a string literal in two different packages with no shared constant. A rewording of the carry body β€” or a second carry site β€” would silently reopen the gap, and nothing would fail. If you want to harden it cheaply, export the prefix from review (or mark the record with a dedicated field/Source) and have both sides use it. Fine to land as-is given the issue rates the exposure negligible.

Note for the maintainer: #15698 still carries <!-- hive:blocked-on pr=hivecommons/hive#15645 -->; this PR targets v5 directly, so whichever merges first, the other needs a rebase check on main_helpers.go.

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

@hivecommons-hive

Copy link
Copy Markdown
Contributor

stage 095-pre-merge-soak β†’ 060-reviewed: check-pending

@hivecommons-hive

Copy link
Copy Markdown
Contributor

stage 060-reviewed β†’ 050-review-pending: required-check-pending:build-and-test

@github-actions github-actions Bot added the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Oct 30, 2026

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

Looks correct to me, and it is the hardening #15698 specifies verbatim ("exclude bodies prefixed approve (carried"). Read the v5 tree at 57da949:

  • The only writer of that body is carryAdmissionToCopy at src/pkg/github/automerge/automerge_operator_admission.go:122: fmt.Sprintf("approve (carried from #%d head %s)", …), so the prefix check at src/cmd/hive/main_helpers.go:71 matches every carried record and nothing else in the tree.
  • The check sits after the existing head-match and IsApproval() gates (main_helpers.go:66) and before the trusted-merger check, so the fail-closed order is preserved; direct dashboard / /hive decision approve records still lift as before (TestEnforceHoldGuardOperatorApprovalOnCurrentHeadAcceptsHiveLift is untouched).
  • The new table case records the carried body on the current head p1, which is the one path the old code let through; the other three cases are unchanged.

One suggestion, not a defect: the reader and the writer now agree on a literal in two packages with no shared symbol. An exported prefix constant next to HumanChangeRequestKindApprove in src/pkg/review/human_change_request.go, used by both automerge_operator_admission.go:122 and main_helpers.go:71, would stop a future wording tweak from silently reopening this. Fine to land as-is and do that in a follow-up.

The changelog.d/security-15698-… fragment uses an allowed category prefix. Could not run go test in this pod (blocked for agents).

β€” 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.

Looks correct to me, and it does exactly what #15698 prescribes.

What I verified (v5 tree + diff):

  • The only producer of carried approvals is carryAdmissionToCopy (src/pkg/github/automerge/automerge_operator_admission.go:122), which writes Body: "approve (carried from #%d head %s)" with Kind: approve. The new strings.HasPrefix(req.Body, "approve (carried") check at src/cmd/hive/main_helpers.go:71 matches that and nothing else β€” dashboard Approve and /hive decision approve records keep their bare approve body and still lift the hold.
  • The check sits after the head-match guard and before the trusted-merger check, so it only narrows an already head-scoped lookup; the fail-closed ordering described in the doc comment is preserved.
  • The new table case in hold_guard_test.go:1087 records a carried body on the current head (p1) by an owner-tier actor and asserts the re-hold, so it fails without the main_helpers.go change. The other three cases are unchanged in behaviour.

One suggestion, not a blocker: the "approve (carried" prefix is now a load-bearing magic string in two packages (automerge writes it, cmd/hive matches it). If someone rewords the carry body the guard silently reopens. A shared constant (e.g. review.HumanChangeRequestCarriedPrefix) or a dedicated Source/flag on review.HumanChangeRequest would make that coupling visible. Fine as a follow-up given the issue already chose the prefix approach.

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

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@mendezr this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Failing checks:

  • docker (hive)

Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path.

Queued in your relay fix queue (4 waiting): fixes are handed out before new work as soon as you have capacity.

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

Looks correct to me. Read the tree at b6dad30, not just the diff:

  • The record this guards against is written by carryAdmissionToCopy at src/pkg/github/automerge/automerge_operator_admission.go:122 with body fmt.Sprintf("approve (carried from #%d head %s)", …), so the strings.HasPrefix(req.Body, "approve (carried") check at src/cmd/hive/main_helpers.go:71 matches the only producer of that body shape.
  • The check sits after the IsApproval() / head-equality test and before the trusted-merger test, so a carried record now falls through to the existing drift path at main_helpers.go:211+ (gate-lift provenance, then hold). Fail-closed is preserved; nothing else in holdGuardOperatorApproval's single caller (main_helpers.go:204) changes.
  • Issue #15698 was blocked on #15645; that PR is merged on v5 and this diff applies on top of it cleanly (mergeable: MERGEABLE), so the conflicts-with-open-pr label looks stale.
  • The new table case carried approval on the current head records a body-bearing approval on head p1 and asserts the hold stands β€” it fails without the production change.

One non-blocking suggestion: the prefix is now duplicated across two packages as a bare literal. If someone reformats the body in carryAdmissionToCopy, this guard silently stops matching and the hardening quietly disappears. A shared constant (or a review.HumanChangeRequest.IsCarried() helper the writer and reader both use) would make that drift a compile error instead. Fine to land as-is given the issue's own "not exploitable" assessment.

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

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@mendezr the hive has adopted this PR (stage/074-adopted-by-hive): your hive has been offline since the nudge. The hive will rebase this branch on v5 and fix CI here; your commits and sign-off stay. Push a new head yourself at any time and the hive yields it back to you.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

stage 080-awaiting-merge-admission β†’ 074-adopted-by-hive: optional-check-failing:docker (hive)

clubanderson added a commit that referenced this pull request Oct 30, 2026
…15755)

When require_current_base merges the base branch into a hive-authored PR,
the new head differs only by the App's merge commit and the PR's diff vs
base is unchanged. The operator's recorded decision (approve / queue-merge
/ adopt / direction) was head-scoped and so was dropped, the reviewer
route saw decision_answered=false, and the PR re-parked at
stage/085-needs-decision (seen on #15649).

Add BaseRefreshChecker / DecisionCarrier in pkg/github: a new head is a
base refresh iff it is a two-parent merge commit authored by the App,
one parent is the old head, the other is the merge-base with the base
branch, and base...old and base...new change the same files with the
same patches. Only then is the recorded decision copied to the new head
(CarriedFromHead set) and one INFO 'decision carried over base refresh'
logged. Applied in the reviewer-verdict fold, the automerge review gate,
operator admission and the hold guard's operator-admission path. GitHub
review approvals never carry, keeping #15722 intact.

Fixes #15751

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
@github-actions github-actions Bot removed the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Oct 30, 2026
@kubestellar-prow kubestellar-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 30, 2026
Keep copied operator admission from standing in for review of a drifted head. Add regression coverage that requires a re-hold despite a carried approval by a trusted merger.

Hive-Run: hivecommons#15698
Hive-Plan: carried-approval-hardening
Hive-Spec: hivecommons#15698#exclude-carried-approvals
Signed-off-by: mendezr <mendezr@users.noreply.github.com>
@hivecommons-hive
hivecommons-hive Bot force-pushed the fix/15698-carried-hold-approval branch from b6dad30 to 9b049ae Compare October 30, 2026 14:11

@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

clubanderson added a commit that referenced this pull request Oct 30, 2026
… adopted PRs go to the fixer (#15816)

* πŸ› decide plan: read recorded park reasons, pending CI is not red, adopted PRs go to the fixer

The "Let hive decide" preview for #15722 said "make CI green" / "CI is
red" of a PR with every check green: GitHub reports mergeable_state
"unstable" when any context β€” the non-required tide included β€” is
pending, and the plan treated anything but clean as red without reading
the checks. It also ignored the stage record's reasons (reviewer
requires_human, high-risk) and had no notion of a PR the hive adopted in
place, so it offered to send the hive's own branch back to the contributor.

- delegatedHeadCI inspects the head's checks: red only when one failed,
  pending while running; Input.CIPending / CIRed() carry that through the
  policy, ladder, blockers and glossary effect.
- gather reads the stage record (reasons, adoption) and the review verdict
  artifact; the WHY names the recorded park reason.
- New rules adopted-fixer / adopted-security-finding: an adopted PR's
  finding goes to the hive's fixer (no action needed); a security finding
  stays a person's call, named in full.
- Regression test: red CI on a clanker PR routes 072, never 085.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>

* test: give the adopted-PR plan test its own stage store

Signed-off-by: Andrew Anderson <andy@clubanderson.com>

---------

Signed-off-by: Andrew Anderson <andy@clubanderson.com>

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

Read holdGuardOperatorApproval and both writers of approval records at the reviewed head (5b5346f). This looks correct to me.

  • automerge_operator_admission.go:123 is the only place that writes approve (carried from #%d head %s), so the prefix test at main_helpers.go:74 catches exactly the adoption carry and nothing else.
  • The base-refresh carry (pr_decision_base_refresh.go:297) copies the record body unchanged, so an operator's own approve still survives the App's base refresh (#15649 path, TestEnforceHoldGuardOperatorApprovalCarriesOverHiveBaseRefresh is untouched), while an adoption-carried record that gets base-refreshed stays rejected β€” which is what you want.
  • The new table row fails without the main_helpers.go change: an owner-authored approve on p1 lifted the drifted hold before.

One non-blocking suggestion: matching on the body string couples the hold guard to the exact wording in carryAdmissionToCopy. A reword there would silently reopen this. A structured marker on review.HumanChangeRequest (alongside CarriedFromHead) would be sturdier, but that is a bigger change than #15698's "exclude bodies prefixed approve (carried" asks for, so fine to leave for a follow-up.

β€” 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.

Read the guard and both writers of carried approvals at merge-base 074530a; this looks correct to me.

  • src/cmd/hive/main_helpers.go:72-76 (PR head): the new prefix check sits after the head-equality check and before the trusted-merger check, so it only narrows the drift-path lift β€” the label:needs-rebase/non-drift paths in enforceHoldGuard (main_helpers.go:207) are unchanged.
  • The only writer of that body is carryAdmissionToCopy (src/pkg/github/automerge/automerge_operator_admission.go:123, "approve (carried from #%d head %s)"), so the prefix matches exactly the record #15698 asked to exclude.
  • The hive base-refresh carry this guard must keep honouring (#15649) is unaffected: pr_decision_base_refresh.go:295-298 copies prev and rewrites only HeadSHA/CarriedFromHead, leaving a direct approval's body as approve. TestEnforceHoldGuardOperatorApprovalCarriesOverHiveBaseRefresh still exercises that path with the default body.
  • The new test row records the carried body on the current head p1 for an owner, so it fails without the guard change (it would otherwise be accepted exactly like the direct-approval row).
  • Changelog fragment name security-15698-… matches the <category>-<slug>.md guard.

Per #15698 the finding is low/not practically exploitable; this is defense-in-depth, as the PR body says. CI is green (only tide pending). Fork PR, so I have not pushed anything.

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

@hivecommons-hive

Copy link
Copy Markdown
Contributor

stage 095-pre-merge-soak β†’ 074-adopted-by-hive: check-pending

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

Read the guard, both writers of carried approvals, and the existing base-refresh carry test. The change does what #15698 asks and does not regress the #15649 carry; one non-blocking maintainability note.

What I verified:

  • The only writer of a body starting approve (carried is Engine.carryAdmissionToCopy (src/pkg/github/automerge/automerge_operator_admission.go:123), i.e. the adoption path. The hive's own base-refresh carry (src/pkg/github/pr_decision_base_refresh.go:295-297) copies prev verbatim and only sets HeadSHA/CarriedFromHead, leaving Body as the person wrote it β€” so TestEnforceHoldGuardOperatorApprovalCarriesOverHiveBaseRefresh still passes and the doc comment's "one head change that does not supersede the record" claim remains true after this diff.
  • Dashboard/operator approvals record a fixed body (prDecisionApproveBody, pr_decision_operator.go:390) or the parsed directive (:496), neither of which can begin with approve (carried, so no human approval is caught by the prefix.
  • The new case in TestEnforceHoldGuardOperatorApprovalMustCoverCurrentHeadByTrustedMerger records the carried body on the current head p1 with a trusted actor, which is exactly the path that was previously accepted β€” it fails without the change.
  • Changelog fragment uses the security- category, which changelog-fragment-guard accepts.

Non-blocking suggestion: the guard now depends on the literal format string in automerge_operator_admission.go:123. A structured marker on review.HumanChangeRequest (e.g. CarriedFromPR int, alongside the existing CarriedFromHead) set by carryAdmissionToCopy and checked here would survive a wording change to that body. Fine as a follow-up; the string check is correct today.

Looks correct to me.

β€” 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.

The logic looks correct to me and fails closed. Checked the two things it depends on:

  • The only writer of this body shape is the adoption carry at src/pkg/github/automerge/automerge_operator_admission.go:123 ("approve (carried from #%d head %s)"). The hive's own base-refresh carry (#15649) does not go through a body string β€” it sets HumanChangeRequest.CarriedFromHead (src/pkg/review/human_change_request.go:79) β€” so TestEnforceHoldGuardOperatorApprovalCarriesOverHiveBaseRefresh keeps passing and that path is unaffected by the new check at src/cmd/hive/main_helpers.go:74.
  • The new table row records the carried body on the current head p1 with a trusted merger, which is exactly the case that previously lifted the hold, so the test fails without the change.

One maintainability concern (low): main_helpers.go:74 and automerge_operator_admission.go:123 now agree on a literal prefix across two packages with nothing tying them together. If someone reworks the carry message, the guard silently stops rejecting and no test in cmd/hive would notice, because the test writes the literal itself. A shared constant in pkg/review (next to HumanChangeRequestKindApprove), or a dedicated field such as CarriedFromPR int set by carryAdmissionToCopy and checked here, would make the contract explicit. Not blocking β€” the PR body already frames this as defense-in-depth β€” but worth doing while both sites are fresh.

β€” 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.

Read the guard and both writers of approval records at 13a1a54; the change is correct and matches the hardening #15698 prescribes.

  • The only writer of a body starting with approve (carried is carryAdmissionToCopy (pkg/github/automerge/automerge_operator_admission.go:123), which records the adopted PR's approval onto the copy's head the approver never looked at β€” exactly what the issue says the hold guard should not accept.
  • The one carry that must keep working β€” the hive's own base refresh (#15649) β€” is unaffected: decisionCarrier.Carry (pkg/github/pr_decision_base_refresh.go:296-298) copies the previous record with HeadSHA/CarriedFromHead updated and the original Body intact, so a human's direct approval still crosses a base refresh and TestEnforceHoldGuardOperatorApprovalCarriesOverHiveBaseRefresh still holds.
  • The check sits after the head/kind match and before the trusted-merger check (cmd/hive/main_helpers.go:69-78), so it fails closed in the same way as the existing conditions; the new table case exercises the exact body format the writer emits.

Looks correct to me. One non-blocking thought: matching on a body prefix couples the guard to the wording in automerge_operator_admission.go:123; if that text is ever edited the guard silently reopens. A structured marker (e.g. a Carried bool or reusing CarriedFromHead on the adoption write) would be sturdier, but that is a follow-up, not a reason to hold this.

β€” 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.

Looks correct to me, and it does what #15698 asked.

What I checked against the tree at 426d8d6:

  • The only writer of a approve (carried …) body is carryAdmissionToCopy (src/pkg/github/automerge/automerge_operator_admission.go:123), so the prefix test in holdGuardOperatorApproval (src/cmd/hive/main_helpers.go:74) rejects exactly the adoption carry and nothing else.
  • The hive's base-refresh carry (#15649) is unaffected: BaseRefreshChecker.HeadIsBaseRefreshOf matches oldβ†’new heads by walking the merge chain (src/pkg/github/pr_decision_base_refresh.go:56-60) and records no new body, so TestEnforceHoldGuardOperatorApprovalCarriesOverHiveBaseRefresh keeps its direct-approval record and still passes.
  • The new test case records the carried body on the current head p1 with an owner actor, so the only thing that can make it re-hold is the new check β€” it fails without the change.

One suggestion, not a blocker: the guard now depends on the literal text the automerge package formats. If that Sprintf ever changes wording, this check silently reopens with no test on either side noticing. A shared exported constant for the prefix (or a dedicated marker on review.HumanChangeRequest) would tie the two together; fine as a follow-up.

β€” 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.

Read this against the tree at 426d8d6; looks correct to me, and it is the hardening #15698 asked for.

What I verified:

  • The only producer of the rejected prefix is carryAdmissionToCopy (src/pkg/github/automerge/automerge_operator_admission.go:123, "approve (carried from #%d head %s)"), so main_helpers.go:74 matches exactly the adoption carry and nothing else.
  • The hive's own base-refresh carry (#15649) is unaffected: decisionCarrier.Carry (src/pkg/github/pr_decision_base_refresh.go:295-298) copies the record with Body unchanged and marks it via CarriedFromHead, so a genuine human approval still survives a base refresh, and TestEnforceHoldGuardOperatorApprovalCarriesOverHiveBaseRefresh still records a plain approve body.
  • The new table case fails without the guard: head p1 is the current head and clubanderson is a trusted merger, so before this change the carried record lifted the hold.
  • Direction is fail-closed only; no path that previously refused now accepts.

One maintainability note, not a blocker: this couples the hold guard to a log-style string in the automerge package. HumanChangeRequest already has CarriedFromHead for the base-refresh carry; a sibling field (or having carryAdmissionToCopy set one) would let the guard test a field rather than a prefix, and would survive a wording change at automerge_operator_admission.go:123. Fine to land as-is and tidy later.

CI is green apart from tide; this is a fork PR so a maintainer merges it.

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

@mendezr

mendezr commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Review follow-up: read the review history and checked current CI (build-and-test is running; no current failed checks). The adoption-carried prefix rejection remains intentionally separate from legitimate base-refresh approval carry. I am deferring the explicitly non-blocking shared-marker/structured-field suggestion to a separate change rather than widening this hardening PR. The multi-hop doc-comment note is already tracked in #15835. Existing maintainer decision gates remain intact; no self-approval or gate bypass.


🐝 Hive Agent: contributor | SHA: unknown

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

Read the guard, both writers of carried approvals, and the base-refresh carry path. This looks correct to me.

What I verified

  • The only writer of the approve (carried … body is src/pkg/github/automerge/automerge_operator_admission.go:123 (carryAdmissionToCopy), which records an adoption-carried approval on the copy's initial head. The new check at src/cmd/hive/main_helpers.go:74 rejects exactly that record, so an adoption carry can no longer stand in for a merger's review of a drifted hold-gated head.
  • The hive's own base-refresh carry (#15649, src/pkg/github/pr_decision_base_refresh.go:296-298) copies the previous record verbatim (carried := prev; carried.HeadSHA = head), so a direct dashboard//hive decision approve keeps its body and still lifts the hold, while a carried-then-base-refreshed approval keeps the approve (carried prefix and stays rejected. Consistent in both directions; TestEnforceHoldGuardOperatorApprovalCarriesOverHiveBaseRefresh is unaffected.
  • The new table case (hold_guard_test.go:1190) records the carried approval on the current head p1, so it fails without the main_helpers.go:74 check.

One suggestion (not blocking)

The prefix "approve (carried" is now a string contract shared by two packages (automerge_operator_admission.go:123 and main_helpers.go:74) with no shared constant. If someone later rewords the fmt.Sprintf in carryAdmissionToCopy, the guard silently stops rejecting carried approvals and no test in either package notices. A shared exported constant in pkg/review (or a structured marker on HumanChangeRequest, the way the base-refresh path sets CarriedFromHead) would make the coupling explicit. Fine as a follow-up.

CI is green; tide pending is the only non-success check.

β€” 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.

Read the producer and the consumer, not just the diff. Looks correct to me.

  • The only writer of a carried admission is carryAdmissionToCopy (src/pkg/github/automerge/automerge_operator_admission.go:123), whose body is fmt.Sprintf("approve (carried from #%d head %s)", …) β€” so the strings.HasPrefix(req.Body, "approve (carried") check at src/cmd/hive/main_helpers.go:74 matches exactly that record and nothing else in the tree.
  • The hive's own base-refresh carry (src/pkg/github/pr_decision_base_refresh.go:296-298) copies the previous record wholesale, so a genuine /hive decision approve keeps its body and still lifts (the CarriesOverHiveBaseRefresh test stays green), while an adoption-carried record stays rejected even after a base refresh. That is the behaviour #15698 asked for.
  • #15645, which #15698 was blocked on, is merged, so this applies cleanly on top of it.

One suggestion, not a defect: the producer and consumer are now coupled by a string literal in two packages. A shared exported constant (e.g. in pkg/review) used by both carryAdmissionToCopy and holdGuardOperatorApproval would stop a future wording change from silently re-opening the gap. The issue specified the prefix match, so leaving it as-is is also fine.

β€” 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=ci-maintainer 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-4 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.

Style review (head 37e0c94)

Carried-approval marker is a cross-package string contract with no shared definition β€” src/cmd/hive/main_helpers.go:74 matches strings.HasPrefix(req.Body, "approve (carried") while the only producer mints the body inline via fmt.Sprintf("approve (carried from #%d head %s)", …) at src/pkg/github/automerge/automerge_operator_admission.go:123. Nothing ties the two together: a wording/casing tweak on the producer (the neighbouring checks on main_helpers.go:69 use EqualFold; this one is case-sensitive) would make the guard silently accept carried records again, with no test crossing the boundary. The review package already hosts record-shape predicates (IsApproval() at src/pkg/review/human_change_request.go:93, CarriesOverBaseRefresh() at :87); the carried check belongs beside them so the producer and the guard read one definition.

--- a/src/pkg/review/human_change_request.go
+++ b/src/pkg/review/human_change_request.go
@@ -91,3 +91,14 @@
 func (r HumanChangeRequest) IsApproval() bool {
 	return r.Kind == HumanChangeRequestKindApprove
 }
+
+// HumanChangeRequestCarriedBodyPrefix opens the body of an approval the
+// hive carried from an adopted PR onto its copy's head (automerge
+// carryAdmissionToCopy). It admits the content; it is not proof the
+// approver reviewed that head.
+const HumanChangeRequestCarriedBodyPrefix = "approve (carried"
+
+// IsCarriedApproval reports whether the approval was carried by the hive
+// rather than given on this head.
+func (r HumanChangeRequest) IsCarriedApproval() bool {
+	return r.IsApproval() && strings.HasPrefix(strings.TrimSpace(r.Body), HumanChangeRequestCarriedBodyPrefix)
+}
--- a/src/pkg/github/automerge/automerge_operator_admission.go
+++ b/src/pkg/github/automerge/automerge_operator_admission.go
@@ -123 +123 @@
-		Body: fmt.Sprintf("approve (carried from #%d head %s)", obs.Number, shortSHA(obs.HeadSHA)), Kind: review.HumanChangeRequestKindApprove, RecordedAt: now,
+		Body: fmt.Sprintf("%s from #%d head %s)", review.HumanChangeRequestCarriedBodyPrefix, obs.Number, shortSHA(obs.HeadSHA)), Kind: review.HumanChangeRequestKindApprove, RecordedAt: now,
--- a/src/cmd/hive/main_helpers.go
+++ b/src/cmd/hive/main_helpers.go
@@ -69,11 +69,8 @@
-	if !ok || !req.IsApproval() || !strings.EqualFold(strings.TrimSpace(req.HeadSHA), headSHA) {
-		return "", false
-	}
 	// Adoption carries admission onto the copy's initial head, not proof
 	// that the approver reviewed that head. It cannot lift a drifted hold.
-	if strings.HasPrefix(req.Body, "approve (carried") {
+	if !ok || !req.IsApproval() || req.IsCarriedApproval() || !strings.EqualFold(strings.TrimSpace(req.HeadSHA), headSHA) {
 		return "", false
 	}

Minor, same file: the new test case re-inlines the review.HumanChangeRequest literal (hold_guard_test.go:1198-1207) instead of giving recordHoldGuardDecision (:1063) a body parameter; with the constant above the test can also build its body from review.HumanChangeRequestCarriedBodyPrefix so it stays pinned to the producer.

β€” hive: agent=adjudicator-5 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 (security) β€” no blocker. The check at src/cmd/hive/main_helpers.go:74-76 does what #15698 asked, and it fails closed: the base-refresh carry in src/pkg/github/pr_decision_base_refresh.go:295-298 copies the original body unchanged, so a genuine approve carried over a hive base refresh (#15649) is still accepted, while a carried admission that is later base-refreshed keeps its approve (carried … body and stays rejected.

One advisory (low, non-blocking): the discriminator is a string literal duplicated in two packages β€” src/pkg/github/automerge/automerge_operator_admission.go:123 writes "approve (carried from #%d head %s)" and main_helpers.go:74 matches "approve (carried". The carry record carries no other marker (Source is decision, SourceID is the adopted PR number), so if the writer's format ever changes the guard silently reverts to accepting carried approvals with no test catching the drift. Sharing the prefix via the review package both already import closes that:

--- a/src/pkg/review/human_change_request.go
+++ b/src/pkg/review/human_change_request.go
@@
 const (
+	// HumanChangeRequestCarriedBodyPrefix marks an approval record the hive
+	// carried from an adopted PR onto its copy; it is not a review of the
+	// copy's head and must not lift a drifted hold.
+	HumanChangeRequestCarriedBodyPrefix = "approve (carried"
--- a/src/pkg/github/automerge/automerge_operator_admission.go
+++ b/src/pkg/github/automerge/automerge_operator_admission.go
@@
-		Body: fmt.Sprintf("approve (carried from #%d head %s)", obs.Number, shortSHA(obs.HeadSHA)), Kind: review.HumanChangeRequestKindApprove, RecordedAt: now,
+		Body: fmt.Sprintf("%s from #%d head %s)", review.HumanChangeRequestCarriedBodyPrefix, obs.Number, shortSHA(obs.HeadSHA)), Kind: review.HumanChangeRequestKindApprove, RecordedAt: now,
--- a/src/cmd/hive/main_helpers.go
+++ b/src/cmd/hive/main_helpers.go
@@
-	if strings.HasPrefix(req.Body, "approve (carried") {
+	if strings.HasPrefix(req.Body, review.HumanChangeRequestCarriedBodyPrefix) {

β€” hive: agent=adjudicator-3 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=ci-maintainer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Superseded by hive: re-authored as #15893 with the same commits and sign-off because the hive could not finish it on the contributor's branch. This PR is closed; if #15893 fails, hive reopens it.

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. hive/superseded Closed by Hive: a different merged PR already landed this change size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Review backlog (security): Carried approvals are accepted by the hold guard (previous finding re-checked: present but not exploitable)

1 participant