Skip to content

🐛 [reviewer] carry operator decision over the hive's base refresh - #15755

Merged
clubanderson merged 1 commit into
v5from
fix/decision-carry-base-refresh
Oct 30, 2026
Merged

clubanderson merged 1 commit into
v5from
fix/decision-carry-base-refresh

Conversation

@clubanderson

Copy link
Copy Markdown
Member

Closes #15751

Problem

On #15649 the operator approved via POST /api/repos/{o}/{r}/items/15649/decision on head A. The hive then merged v5 into the branch (require_current_base refresh: App-authored merge commit, PR diff vs base unchanged), producing head B (72246f98). The recorded decision was head-scoped, so the reviewer route logged decision_requested=true decision_answered=false, the automerge review gate held with outcome=requires-human, and the PR re-parked at stage/085-needs-decision. The operator had to approve again.

Fix

  • pkg/github/pr_decision_base_refresh.go: BaseRefreshChecker.HeadIsBaseRefreshOf is true iff the new head is a two-parent merge commit authored by the App, one parent is the old head, the other parent is the base...newHead merge-base, and base...oldHead / base...newHead change the identical file set with identical patches. Results are memoised per (repo, pr, old, new); the single-commit fetch happens once.
  • DecisionCarrier.Carry copies the newest recorded operator decision (source decision / stage-label, never a GitHub review) to the new head with CarriedFromHead, and logs one INFO decision carried over base refresh.
  • Applied in the reviewer-verdict fold (decision_answered stays true), the automerge review gate, operator admission, and the hold guard's operator-admission path.

Relation to #15722

#15722 makes the hold guard reject adoption-carried GitHub review approvals (approve (carried body) across heads. This change does not touch that path: review-sourced records never carry, bodies are kept verbatim, and any head change that is not a pure App base refresh (content push, non-App merge author, diff change, other parent not on base) still invalidates the decision. Tests cover all those refusals.

Tests

  • pkg/github: carried on pure refresh (+log once, memo); refused on content commit, diff change, non-App author, off-base parent, single parent, review source.
  • pkg/github/automerge: fold route / review gate / operator admission carry end-to-end against an httptest fake; commit fetched once.
  • cmd/hive: hold guard operator-admission carries over base refresh.
  • No time.Sleep.

Docs

  • src/docs/hive-merge.md decision-lifecycle paragraph.
  • changelog.d/fixed-15751-decision-carries-over-base-refresh.md.

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>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 30, 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label 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.

PR Title Relation Files
#15757 ✨ Auto-merge hive-authored superseding PRs without operator decision same files src/docs/hive-merge.md
src/pkg/github/automerge/automerge_sweep.go
src/pkg/github/client.go
#15748 🐛 [reviewer] park PRs at 085 Needs decision when the fixer exhausted its attempts same files src/docs/hive-merge.md
src/pkg/github/automerge/automerge_stage_labels.go
src/pkg/github/automerge/automerge_sweep.go
#15308 ✨ feature: enqueue eligible PRs into GitHub native merge queues same files src/pkg/github/automerge/automerge_contributor_lane.go
src/pkg/github/automerge/automerge_sweep.go
#15722 🐛 fix: reject carried approvals in the hold guard CONFLICT src/cmd/hive/main_helpers.go
#15763 🐛 merge train: ready PRs lead; odometer rolls only after the bee lands same files src/docs/hive-merge.md

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

docs-currency — one operator-facing statement is now contradicted by this change.

  1. src/docs/maintainer-commands.md:103-106 still says a /hive decision "answered for an older head is left alone ([#14679])". After this PR that is true for every head change except the App's require_current_base refresh (src/pkg/github/pr_decision_base_refresh.go:222-262 re-records the newest operator decision on the new head). The new paragraph in src/docs/hive-merge.md:218-237 describes the exception, but a maintainer reading the /hive decision reference will be told the opposite.
PR follows the normal merge path. An acknowledged decision whose record did
not survive a pod restart is rebuilt from the comment thread; a decision
answered for an older head is left alone
([#14679](https://github.com/hivecommons/hive/issues/14679)) — unless the only
thing that moved the head was the hive's own base refresh, in which case the
decision is carried to the new head (see
[A decision is head-scoped](hive-merge.md#a-decision-is-head-scoped--except-across-the-hives-own-base-refresh),
[#15751](https://github.com/hivecommons/hive/issues/15751)).
  1. (advisory) src/docs/operator-reference.md:500 — "A new push drops the admission and the row asks again." Operator admission now carries over the base refresh (automerge_operator_admission.go reads via the carrier), so "a new push" should say "a content push (not the hive's own base refresh)". Same one-clause fix.

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

Security perspective — no blocker; one advisory.

Low (advisory): "authored by the App" is email-attributed, not verified — src/pkg/github/pr_decision_base_refresh.go:184-193. CommitByGitHubLogin reads commit.GetAuthor().GetLogin() / GetCommitter().GetLogin(), and the comment says these are "server-resolved logins, never the forgeable git name or email". GitHub resolves that login from the commit's author/committer email, so anyone with push to the branch can set user.email to the App's <id>+<app>[bot]@users.noreply.github.com and the REST commit will carry the App's login (unverified). The carry stays safe because headIsBaseRefreshOf (lines 105-122) still requires the other parent to be base...newHead's merge-base and the three-dot file set/blob/patch to match base...oldHead, so a forged author only reaches a head with the same content the operator already approved. Still, the API-created require_current_base merge is GitHub-signed, so the identity check can be made real at no cost:

	if !CommitByGitHubLogin(commit, appBotLogin) || !commit.GetCommit().GetVerification().GetVerified() {
		return false
	}

and reword the doc comment at lines 184-186 to not claim the login is unforgeable. Add a test with Verification: &gh.SignatureVerification{Verified: gh.Ptr(false)} alongside the existing non-App-author refusal.

— hive: agent=adjudicator-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.

Style / maintainability review (head d1c0a8a)

1. A transient lookup failure is memoised as "not a base refresh" — permanently for that head pair (src/pkg/github/pr_decision_base_refresh.go:48-67, :93-97). headIsBaseRefreshOf folds every GetCommit/CompareCommits error into false (doc: "Lookup failures are false"), and HeadIsBaseRefreshOf caches that false unconditionally at :60-65. Carry then short-circuits on Known(...) == (false, seen) at :232-234 and never re-asks. One 5xx or secondary-rate-limit on the first tick after the refresh reproduces exactly the #15751 symptom (re-park at 085, operator approves again) until the 4096-entry cache resets. Only memoise answers GitHub actually gave:

-func headIsBaseRefreshOf(ctx context.Context, api BaseRefreshRepos, owner, repo, baseRef, oldHead, newHead, appBotLogin string) bool {
+// headIsBaseRefreshOf returns err only for lookup failures; a definite
+// "no" is (false, nil) and is safe to memoise.
+func headIsBaseRefreshOf(ctx context.Context, api BaseRefreshRepos, owner, repo, baseRef, oldHead, newHead, appBotLogin string) (bool, error) {
 	ctx = WithRESTCaller(ctx, "hive:decision_base_refresh")
 	commit, _, err := api.GetCommit(ctx, owner, repo, newHead, nil)
-	if err != nil || commit == nil || len(commit.Parents) != baseRefreshMergeParents {
-		return false
+	if err != nil {
+		return false, err
+	}
+	if commit == nil || len(commit.Parents) != baseRefreshMergeParents {
+		return false, nil
 	}
 	...
 	newCmp, newFiles, err := compareAllFiles(ctx, api, owner, repo, baseRef, newHead)
-	if err != nil || newCmp == nil {
-		return false
+	if err != nil {
+		return false, err
 	}
 	...
-	ok := headIsBaseRefreshOf(ctx, api, owner, repo, baseRef, oldHead, newHead, appBotLogin)
+	ok, err := headIsBaseRefreshOf(ctx, api, owner, repo, baseRef, oldHead, newHead, appBotLogin)
+	if err != nil {
+		return false // not memoised: the next tick asks again
+	}
 	b.mu.Lock()

2. Carry's own-head lookup bypasses the actor guard the callers used to have (pr_decision_base_refresh.go:220-222; automerge_review_gate.go:347-350). recordedHumanApprovalForHead dropped strings.TrimSpace(req.Actor) == "" because recordedDecisionFor goes through review.DecisionAnswerFor (human_change_request.go:392-401, which filters empty actors) — but when that returns false it falls into Carry, whose first step is a raw d.Store.For(...) that returns the same empty-actor record with ok=true. Record (human_change_request.go:198-224) does not require an actor, so the guard was load-bearing. Make the two entry points agree:

	if req, ok := review.DecisionAnswerFor(d.Store, fullRepo, number, head); ok {
		return req, true
	}

3. Two copies of the carrier wiring, two memos (automerge_decision_carry.go:15-32 vs pr_decision_base_refresh.go:275-292). The ResolveBase closure and field set are duplicated verbatim, and Engine.baseRefresh (automerge_sweep.go:274) is a separate cache from Client.baseRefresh (client.go:505), so the hold guard and the sweep each pay the commit read + two compares for the same (pr, old, new). A NewDecisionCarrier(client *gh.Client, store, appBotLogin, logger, checker) in pkg/github used by both would remove the copy; sharing one *BaseRefreshChecker would remove the double read. Nit in the same area: human_change_request.go:78 says "see CarryOverBaseRefresh" — the method is CarriesOverBaseRefresh.

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

Reviewed (intent-alignment) — diff matches #15751 (checker + carrier, applied to reviewer-verdict fold, review gate, operator admission, hold guard; review-sourced records never carry; Record at src/pkg/review/human_change_request.go:216 drops other-head items, so a second refresh chains from the carried record). No scope creep. One advisory:

Low — Carry's fast path drops the non-empty-Actor guard the callers previously had. recordedHumanApprovalForHead (src/pkg/github/automerge/automerge_review_gate.go:348-350) used to reject req.Actor == ""; it now goes through recordedDecisionFor → review.DecisionAnswerFor (actor-checked, human_change_request.go:396-399) and, on miss, DecisionCarrier.Carry, whose first lookup d.Store.For(fullRepo, number, head) (src/pkg/github/pr_decision_base_refresh.go:241-243) returns an on-head record with empty Actor as ok=true. The review gate would then release requires_human with approver="" (automerge_contributor_lane.go:1429-1435), and foldRecordedDecision folds an empty-actor answer. Current producers (automerge_stage_human_return.go:70-71, pr_unpark_decision.go:94,333) populate Actor, so this is defensive, but the fix is one line:

	if req, ok := d.Store.For(fullRepo, number, head); ok && strings.TrimSpace(req.Actor) != "" {
		return req, true
	}

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

Correctness review (head d1c0a8a) — no blocker; one small guard regression worth restoring.

Low — Carry's on-head fast path drops the empty-actor guard the old code had. recordedHumanApprovalForHead used to refuse a record whose Actor was blank (automerge_review_gate.go pre-diff: !ok || !req.IsApproval() || strings.TrimSpace(req.Actor) == ""). Now it goes through recordedDecisionFor (automerge_decision_carry.go:44-51): review.DecisionAnswerFor correctly rejects a blank actor (human_change_request.go:396-398), but the fall-through then calls DecisionCarrier.Carry, whose first step d.Store.For(fullRepo, number, head) (pr_decision_base_refresh.go:218-220) returns that same on-head record with ok=true and no actor check. Net effect: trustedHumanApprovalForRequiresHuman can return ("", true) and the contributor lane at automerge_contributor_lane.go:1428-1435 treats the verdict as human-cleared with approver="". Today's producers all skip blank actors (e.g. automerge_stage_human_return.go:70-72), so this is defense-in-depth, but it is a regression of an explicit guard. Suggested fix in Carry:

	if req, ok := d.Store.For(fullRepo, number, head); ok {
		if strings.TrimSpace(req.Actor) == "" {
			return review.HumanChangeRequest{}, false
		}
		return req, true
	}

Advisory (not blocking): the carry is single-hop by design (pr_decision_base_refresh.go:107-115 requires the decided head to be a direct parent). If two App base refreshes land before any gate reads the PR, Newest still points at the original head and the second refresh is not recognised — consistent with #15751's stated rule, just noting the limit.

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

@hivecommons-hive

Copy link
Copy Markdown
Contributor

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

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

@hivecommons-hive

Copy link
Copy Markdown
Contributor

stage 080-awaiting-merge-admission: no activity for 30m0s: merge-train:queued-behind#15748:3/6:0/0:hive-merge.md,operator-reference.md,config.go,stage_tracker_build.go,+6

@clubanderson
clubanderson merged commit c87e657 into v5 Oct 30, 2026
77 of 80 checks passed
@clubanderson
clubanderson deleted the fix/decision-carry-base-refresh branch October 30, 2026 13:46
@github-actions

Copy link
Copy Markdown
Contributor

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

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

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

Labels

conflicts-with-open-pr Open PR has a merge conflict with another open PR dco-signoff: yes Indicates the PR's author has signed the DCO. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [reviewer] operator decision is lost when the hive refreshes the PR's base; PR re-parks at 085

1 participant