Skip to content

πŸ› fix(automerge): an approving review counts only for the content it approved - #16817

Merged
hivecommons-hive[bot] merged 4 commits into
hivecommons:v6from
Danathar:fix/owner-approval-carryover
Nov 5, 2026
Merged

hivecommons-hive[bot] merged 4 commits into
hivecommons:v6from
Danathar:fix/owner-approval-carryover

Conversation

@Danathar

@Danathar Danathar commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Executive summary

GitHub moves an existing approving review onto a later merge of the base into the branch. The hive read that review's commit_id as approval of the new head and released the workflow-path fence for content the owner never saw.

On projectbluefin/utah#1078, a review submitted 2026-11-04 01:17Z is reported on 9d8ceab, a merge made 2026-11-05 19:50Z. The hive posted "@Danathar approved head 9d8ceab" and merged the PR at 20:42Z. projectbluefin/utah-packages#877 (review 01:17:21Z, now on d071c67 made 05:42Z) and projectbluefin/common#1622 (01:17:16Z, now on 9204837 made 01:32Z) have the same shape. The opposite also happens: after the hive's own base merge, the review stays on the old head and the owner's answer to requires_human is asked for again.

This PR binds an approving review to the content it approved:

  • It counts when GitHub reports it on a non-merge head, or when it was submitted at or after the head commit's date.
  • Otherwise it counts only if the head adds nothing but base merges that leave the PR's diff unchanged, made by anyone. In that case the fence comment says "carried over a base merge … (PR diff unchanged)".
  • The 085 What to do no longer asks for an approval that is already recorded.

What

Shape Before After
Review reported on head, submitted before head existed, head adds content Counts: fence released Does not count: fence stays, person asked
Same, head is only base merges over the approved content Counts, "approved head X" Counts, "approved this PR's change, carried over a base merge to head X (PR diff unchanged)"
Review on the previous head, head is a diff-preserving base merge Not counted: requires_human re-asked Counts: answers requires_human and releases the fence
Review on the previous head, content pushed since Not counted Not counted (unchanged)
085 with the approval recorded, parked for another reason "a trusted merger approves this head …" "nothing more to approve: @x approved this head …; resolve the other reasons"

Why

  • latestTrustedHumanReview (automerge_human_changes_requested.go) took commit_id == head as proof. GitHub's move of a review onto a base merge makes that true for content committed after the review. All three PRs show it: the commit dates are hours to a day after submitted_at. Two of the merges were made by a person through the web UI (author Danathar, committer web-flow), and one by the App.
  • DecisionCarrier carries recorded decisions over the hive's own base refresh, but deliberately not review-sourced approvals (CarriesOverBaseRefresh). It also only accepts merges authored by the App.
  • DecisionActions (stagelabels/human.go) asked for the approval even when the route carried HumanApprover. On utah#1078 at 01:41Z the head line read "approved by @Danathar" directly above "a trusted merger approves this head (f166f40)".

How

  • automerge_review_head_binding.go (new): reviewReachesHead checks the head commit date against submitted_at. Otherwise it walks up to 5 base merges back from the head (hgithub.BaseMergeParent) until it reaches the approved commit, or a commit no newer than the review (the case where GitHub moved the review). The answer is memoised per (PR, head, review). A lookup failure is not memoised and reads as false. A review with no submitted_at keeps the old commit_id rule.
  • latestTrustedHumanReview: for APPROVED, uses reviewReachesHead after the cheap trust checks. CHANGES_REQUESTED still binds to its commit.
  • latestTrustedHumanApprovalReach: also returns whether the approval was carried. The fence's audit comment uses it.
  • pkg/github BaseMergeParent: mergeIsBaseRefreshOf without the App-author rule. The other parent must be the merge-base with the base branch, and the three-dot diff must be file-for-file unchanged.
  • stagelabels.DecisionActions: with HumanApprover set on a fence or requires_human route, the step says nothing more is needed.

Tests

Test Covers
TestApprovalBindsToApprovedContent (8 rows) submitted after head; non-merge head dated after the review (pusher clock ahead) still counts; moved onto merge-only head (carried); moved onto head with a content delta (refused); previous head + base merge (carried); previous head + content push or content-then-merge (refused); no submitted_at
TestApprovalBindingIsMemoised the second lookup reads only the review list
TestWorkflowApprovalCommentSaysCarried carried vs plain audit comment
TestBaseMergeParentAnyAuthor a person's diff-preserving merge accepted; diff change or single parent refused
TestDecisionActionsDoNotReaskARecordedApproval fence + requires_human routes with the approver recorded
Existing fence, review-gate, decision-carrier tests passing; the self-sweep fixture serves GET /commits/sha7
Mutants 15/15 caught (12 + 3 for the non-merge-head rule)
go test automerge, github, stagelabels, stageengine, review, writeback pass (one shared test fixture now serves the head commit, dated before its reviews)
check-docs-citations.py src/docs 2006 verified

Notes

  • Not root-caused: on utah#1078 the 01:52Z entry comment re-listed requires_human without the approver, although the lane logged "verdict cleared by trusted human approval" for the same head 4 seconds earlier. The two 085 comments came from the same writer with different reason sets. This PR fixes the text when the approver is known and the carry-over that drops it after a base merge; the alternating-template path is not identified here.
  • Commit dates are pusher-chosen. They are trusted only on the head that GitHub itself attributes the review to. A content push never inherits a review, because the walk accepts only diff-preserving base merges.
  • Cost: one commit read per (head, review) in the common case, memoised. The walk runs only for a review submitted before the head commit, or on another commit.
  • No duplicate open PR, and nothing on origin/v5 for these files.

πŸ€– Generated with Claude Code

https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1

…approved

GitHub moves an existing review onto a later merge of the base, so
commit_id == head does not prove the head was approved:
projectbluefin/utah#1078's review submitted 2026-11-04 01:17Z is reported
on 9d8ceab (made 2026-11-05 19:50Z) and released the workflow-path fence.

- reviewReachesHead: submitted_at >= head commit date, or head is a chain
  of diff-preserving base merges (any author, BaseMergeParent) back to the
  approved commit or one no newer than the review; memoised per review/head.
- the fence comment says "carried over a base merge ... (PR diff unchanged)".
- an approval on the previous head answers requires_human after such a merge.
- 085 What to do no longer asks for an approval already recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1
Signed-off-by: Danathar <Danathar@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 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

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 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: 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.

Read automerge_review_head_binding.go, BaseMergeParent in pr_decision_base_refresh.go, sameChangedFiles, the latestTrustedHumanReview callers, and the new test fixture at head 541c9c5. The content check is sound: sameChangedFiles (pr_decision_base_refresh.go:246) compares blob SHAs, so an "evil merge" that alters a PR-touched file, or touches a new one, is refused. Two things in the time-based branch need a look before this lands, because it gates the workflow-path fence.

1. Line 118 trusts the committer date of a walked ancestor, not the head (medium, security).
automerge_review_head_binding.go:115-121: after BaseMergeParent steps from the head merge to its PR-side parent prev, the walk returns ok, carried when reviewed == head && !submitted.Before(commitDate(prev)). prev is whatever the branch pusher committed, and commitDate is the git committer date they chose. Under this PR's own premise (GitHub reports the review on the base merge M), the sequence approve A β†’ push content B with a backdated committer date β†’ base merge M yields reviewed == head == M, line 98 falls through (M is newer than the review), hop 1 reaches B, and line 118 accepts because B's date is older than the review. The fence releases for content nobody approved. The PR body's note "Commit dates … are trusted only on the head that GitHub itself attributes the review to" describes line 98, not line 118. The fixture's content1 is dated after the review, so TestApprovalBindsToApprovedContent never exercises this path. Suggest: in the loop, only accept prev == reviewed (line 112) and drop the date test at 118, or constrain it to merges the App made (the rule mergeIsBaseRefreshOf keeps and this helper deliberately removes).

2. A legitimate approval of a non-merge head is refused and memoised when the pusher's clock is ahead (medium, correctness regression).
reviewReachesHead β†’ walkApprovalToHead:98 requires submitted >= commitDate(head) for the plain commit_id == head case. If the author's machine clock runs a few minutes fast and the owner approves right after the push, submitted.Before(commitDate) is true, the walk runs, BaseMergeParent on a single-parent head returns !ok, and line 110 returns {} with known=true, so the miss is cached for that (head, review id). Today commit_id == head alone counts; after this PR that approval is silently dropped and the owner is asked again. No test row covers ownerReview("f166", <before f166's date>) with head f166. Suggest: when reviewed == head and the head is not a 2-parent merge, return ok regardless of date (the "GitHub moved it" case only ever lands on a merge).

Everything else I checked holds: CHANGES_REQUESTED still binds to its commit (automerge_human_changes_requested.go:70), lookup failures are not memoised, and the DecisionActions text change matches the described route.

@Danathar β€” both are inside the new helper; neither needs a design decision. I have not approved or requested changes as a review event.

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

@hivecommons-hive

hivecommons-hive Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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

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

Conclusion: the walk is sound for every shape in TestApprovalBindsToApprovedContent, and the plumbing (BaseMergeParent, DecisionActions) is correct. One branch of the walk trusts a date the contributor controls, on a fence that exists to gate contributor workflow edits β€” that is a trust call a maintainer should make, not me. Nothing else found.

What I verified (tree at merge-base 463e4ab + PR head 541c9c5)

  • pr_decision_base_refresh.go:170-194 BaseMergeParent: the merge-base of base...newHead must be one parent, and sameChangedFiles (:223-252) compares blob SHA / additions / deletions / patch per file, so "PR diff unchanged" is content-level, not filename-level. A content push cannot pass as a hop. Correct.
  • automerge_human_changes_requested.go:61-83: only APPROVED drops the commit_id == head test; CHANGES_REQUESTED still binds to its commit. Correct.
  • stagelabels/human.go:874: HumanApprover is only populated when HumanApprovalHead == HeadSHA (automerge_stage_human.go:446, automerge_stage_labels.go:336), so "nothing more to approve" cannot fire for a stale approval. Correct.
  • latestTrustedHumanApprovalReach calls reviewReachesHead a second time, but the answer is memoised per (PR, head, review id, commit) so it costs one map read. Fine.

Open question β€” automerge_review_head_binding.go:115-120 (security, medium if the premise holds)

The hop loop handles "GitHub moved the review onto the merge" by walking down from head and stopping at the first base-merge parent whose committer date is not after submitted_at:

if reviewed == head && !submitted.Before(commitDate(commit)) {
    // GitHub moved the review off this commit onto the merges above.
    return approvalReach{ok: true, carried: true}, true
}

commit here is prev β€” an intermediate PR-side commit, not the head GitHub attributed the review to. The PR body's Notes say commit dates "are trusted only on the head that GitHub itself attributes the review to"; this line trusts them one hop down. Shape: owner approves Q at 01:17Z; the contributor pushes content commit R whose committer date is earlier than 01:17Z (a local commit made before the approval and pushed after, or a deliberately backdated one); then "Update branch" produces H = merge(base, R). BaseMergeParent(H) β†’ R (H's diff equals R's, trivially). R != reviewed, so GetCommit(R), and reviewed == head && submitted >= date(R) β†’ carried: true. The fence releases for content in R the owner never saw. The fixture's content1 row is refused only because its date is 2026-11-05T10:00:00Z, after approvedAt; the same graph with content1 dated before the review would pass.

This is exploitable only if GitHub re-attributes the review's commit_id to H when a content commit sits between the approved commit and the base merge. I could not confirm or rule that out from documentation, and the three cited PRs don't say whether any had an intervening content push β€” so I'm stating it as a question, not a defect. If the answer is "GitHub only moves reviews across pure base merges", the branch is unreachable by an attacker and this is a comment-only nit. If GitHub moves it regardless, the safer rule is to drop the date fallback at :118 and require the walk to reach reviewed itself (:112), or additionally require the walk's end commit to have been the PR head at submitted_at (via the PR's timeline/commit list).

Either way, a test row for "moved onto merge over a content push dated before the review" would pin whichever behaviour is chosen.

I have not approved, requested changes, or closed anything.

Evidence bundle `#16817671a783` sha256:9d1c032ed5ec16199b72af06de090fc85211af4334c553123fece94b813da286 β€” download from the dashboard or `hivectl review evidence #16817`.

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

HUMAN DECISION NEEDED β€” @Danathar / clubanderson: may the workflow-path fence be released by an approval whose carry-over rests on the pusher-chosen committer date of an intermediate commit (src/pkg/github/automerge/automerge_review_head_binding.go:118), or must the walk reach the reviewed commit itself?

Security delta re-review, head 1b6dbbb9 (previous head 541c9c5e).

The delta is only Merge branch 'v6' into fix/owner-approval-carryover: the three-dot diff against the new merge-base f193404f is byte-identical to the previous one apart from a hunk offset in src/pkg/stagelabels/human.go (the DecisionActions edit now starts at :877 instead of :871, with no textual change). No new code, no new trust surface.

Prior finding β€” still present, unchanged. automerge_review_head_binding.go:115-120 still accepts carried: true when the intermediate parent prev has a committer date no later than submitted_at, while reviewed == head. The structural bound is real β€” BaseMergeParent (src/pkg/github/pr_decision_base_refresh.go:170-194) only hops across merges whose three-dot diff is file-for-file unchanged, so the walk cannot cross a content push β€” but the branch only fires when GitHub itself has re-attributed the review to a head that sits above a backdated commit, and whether GitHub does that over an intervening content push remains the open question from the previous review. That is a merge-trust policy call, not something this reviewer can settle.

If the decision is to close the gap, the minimal change is to drop the date fallback and require the walk to reach the reviewed commit:

		if commit, _, err = c.gh.Repositories.GetCommit(ctx, owner, repo, prev, nil); err != nil || commit == nil {
			return approvalReach{}, false
		}
		cur = prev

(replacing the if reviewed == head && !submitted.Before(commitDate(commit)) { … } block at :118-121), plus a test row for "moved onto merge over a content push dated before the review".

I have not approved, requested changes, or closed anything.

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

…whatever the commit date

Reviewer finding 2 on hivecommons#16817: walkApprovalToHead required submitted_at >=
the head commit's date even when commit_id == head and the head is not a
merge, so a pusher clock a few minutes fast refused a real approval of that
exact head (and memoised the miss). GitHub only moves a review onto a merge,
so a review it reports on a non-merge head approved that head.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@Danathar

Danathar commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Addressed in 671a783:

Finding 2 (fixed). walkApprovalToHead now accepts a review GitHub reports on the head when the head is not a merge commit, whatever the head's committer date. GitHub moves a review only onto a merge, so a review it reports on a non-merge head approved that head; a pusher clock running ahead no longer refuses (or memoises a refusal of) a real approval. The date check and the base-merge walk still apply when the head is a merge. New row in TestApprovalBindsToApprovedContent: an owner review on head f166 submitted before f166's committer date is accepted; the existing refusals (content delta under a moved review, content push after an approval on the previous head) still refuse. 3 new mutants, all caught; pkg/github/automerge and pkg/stagelabels suites pass on the branch with v6 merged.

Finding 1 (unchanged). The date fallback for walked ancestors is left as it is, pending @Danathar's decision as the adjudicator raised it.

πŸ€– Generated with Claude Code

@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 diff against v6 plus the callers (trustedHumanApprovalForRequiresHuman, reconcileReviewBackedApproval, sameChangedFiles). The carry-over logic is sound; one low-severity edge in the date comparison is worth a maintainer's eye before merge.

What I verified

  • BaseMergeParent (pr_decision_base_refresh.go:171-195) only accepts a parent when sameChangedFiles matches, and that compares per-file blob SHA/additions/deletions (pr_decision_base_refresh.go:243-247). Identical blob SHAs mean identical file content at prev and head, so an approval is carried only onto byte-identical PR content β€” conflict-resolving merges fail the check and the fence stays. Conservative in the right direction.
  • latestTrustedHumanReview keeps the strict commit_id == head rule for CHANGES_REQUESTED and relaxes it only for APPROVED (automerge_human_changes_requested.go:61-71); the found selection still picks the latest submitted review, so an older approval cannot shadow a later change request.
  • Lookup failures return known=false and are not memoised (automerge_review_head_binding.go:85-88), so a transient GitHub error reads as "not approved" and retries next sweep rather than caching a wrong answer.
  • go build ./pkg/github/... ./pkg/stagelabels/ is clean at 365862c.

Low: a legitimate on-head approval is rejected when the head's committer date is later than the review's submitted_at β€” automerge_review_head_binding.go:96 (reviewed == head && !submitted.Before(commitDate(commit))). commitDate is the committer timestamp from the pusher's git client (:128-134), not a GitHub server time. A contributor whose clock runs a few minutes fast produces a head whose committer date post-dates an owner's prompt approval; the fast path fails, the walk at :104-120 finds the head is not a base merge, and the approval is dropped. Downstream, trustedHumanApprovalForRequiresHuman (automerge_review_gate.go:336-341) then calls reconcileReviewBackedApproval, which Forgets the persisted review-backed approval (automerge_human_changes_requested.go:171-177). It self-heals only if the clock skew later stops mattering, which for a fixed head it does not β€” the owner has to re-approve or type /hive decision approve. Before this PR, commit_id == head alone sufficed and that path was skew-immune. A small tolerance (e.g. treat reviewed == head as bound when submitted is within a few minutes of the committer date, or compare against the PR's pushed_at/commits-timeline instead of the committer field) would close it. Suggestion, not a blocker.

I have not independently confirmed the premise that GitHub re-points a review's commit_id onto a later base merge; I am taking the three cited PRs as the evidence for that.

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

@hivecommons-hive
hivecommons-hive Bot merged commit 5be5858 into hivecommons:v6 Nov 5, 2026
67 of 70 checks passed
@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 671a783.

@Danathar

Danathar commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Finding 1 (adjudicator's HUMAN DECISION): @Danathar decided to keep the base-merge carry-over and close the backdating gap by also requiring the hive's own first sighting of the commit. This PR merged before that landed, so it is a follow-up: #16839

What changed there: the date fallback (a merge head, and each walked ancestor) now counts only when the commit's date and the hive's first listing of it as this PR's head are both at or before the review's submitted_at. First listings are persisted per repo#pr@sha (pr-head-sightings.json, written by openPullRequests); no listing on record means nothing carries by date (fail closed). A non-merge head's review (finding 2) and the base-merge walk to the reviewed commit are unchanged. New rows: backdated content push under a later base merge β†’ refused; legitimate carry-over with first listing before the review β†’ accepted; unknown first listing β†’ refused. 7/7 mutants caught.

πŸ€– Generated with Claude Code

hivecommons-hive Bot pushed a commit that referenced this pull request Nov 5, 2026
…ing of the commit, not just its date (#16839)

Doug's decision on the adjudicator's HUMAN DECISION on #16817
(pullrequestreview-5792808876): keep the carry-over, but close the
backdating gap. The date fallback (merge head, walked ancestor) now also
requires that the hive first listed the commit as the PR head no later than
the review. HeadSightings persists repo#pr@sha -> first listing
(pr-head-sightings.json in the stage state dir), written by
openPullRequests, the listing every lane sweeps; no sighting on record means
nothing carries by date (fail closed). A non-merge head's review and the
base-merge walk to the reviewed commit are unchanged.


Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1

Signed-off-by: Danathar <Danathar@users.noreply.github.com>
Co-authored-by: Danathar <Danathar@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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