Repository navigation
🐛 [reviewer] carry operator decision over the hive's base refresh - #15755
Conversation
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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
There was a problem hiding this comment.
docs-currency — one operator-facing statement is now contradicted by this change.
src/docs/maintainer-commands.md:103-106still 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'srequire_current_baserefresh (src/pkg/github/pr_decision_base_refresh.go:222-262re-records the newest operator decision on the new head). The new paragraph insrc/docs/hive-merge.md:218-237describes the exception, but a maintainer reading the/hive decisionreference 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)).
- (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.goreads 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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
|
Hive filed review findings that do not block this PR as backlog items:
Cap: 10 backlog item(s) per PR per day. |
|
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 |
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Closes #15751
Problem
On #15649 the operator approved via
POST /api/repos/{o}/{r}/items/15649/decisionon head A. The hive then mergedv5into the branch (require_current_baserefresh: App-authored merge commit, PR diff vs base unchanged), producing head B (72246f98). The recorded decision was head-scoped, so the reviewer route loggeddecision_requested=true decision_answered=false, the automerge review gate held withoutcome=requires-human, and the PR re-parked atstage/085-needs-decision. The operator had to approve again.Fix
pkg/github/pr_decision_base_refresh.go:BaseRefreshChecker.HeadIsBaseRefreshOfis 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 thebase...newHeadmerge-base, andbase...oldHead/base...newHeadchange the identical file set with identical patches. Results are memoised per (repo, pr, old, new); the single-commit fetch happens once.DecisionCarrier.Carrycopies the newest recorded operator decision (sourcedecision/ stage-label, never a GitHub review) to the new head withCarriedFromHead, and logs one INFOdecision carried over base refresh.decision_answeredstays 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 (carriedbody) 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.time.Sleep.Docs
src/docs/hive-merge.mddecision-lifecycle paragraph.changelog.d/fixed-15751-decision-carries-over-base-refresh.md.