From 2514c31b2ebb35681a7376cfa410919cb640f1d9 Mon Sep 17 00:00:00 2001 From: Danathar <6772335+Danathar@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:43:54 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20automerge:=20an=20outdated=20cha?= =?UTF-8?q?nge=20request=20waits=20on=20its=20reviewer,=20not=20the=20auth?= =?UTF-8?q?or?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The contributor lane and the trusted-author lane checked for a standing CHANGES_REQUESTED review with hasOutstandingChangesRequested, which ignored which commit the review was on. A PR whose author had already pushed the fix stayed at 071/072, its clanker author was nudged, and once the adoption grace ran out the Activity monitor asked "@author has been offline ... take the PR over now?" (projectbluefin/chairlift#799, about 2h 45m after the author pushed). The wait was on the reviewer: GitHub keeps a change request blocking until it is re-reviewed or dismissed. hasOutstandingChangesRequested now sorts the standing change requests by whether they bind to the head. One on the head, with no commit, or carried to the head by a merge of the base (the walk an approval uses) keeps today's changes-requested reason. When every standing request is on an older commit with content pushed since, the lanes return re-review-requested:, which routes as a decision cause: red CI, a swarm changes_requested or a conflict on the new head is still the author's, otherwise 085. The 085 note names each review, its commit and the author's push (reusing the #633 re-review clause), and the monitor asks the reviewer to re-review or dismiss, with wait kind re-review-requested and who the reviewer. No nudge and no adoption clock at 085. The native queue withdraws such a PR. Refs #13041 Signed-off-by: Danathar <6772335+Danathar@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 --- .../fixed-rereview-outdated-change-request.md | 1 + .../stage-labels.md | 1 + src/pkg/dashboard/stage_tracker_caption.go | 3 + .../dashboard/stage_tracker_decision_pr.go | 42 +++++ .../dashboard/stage_tracker_rereview_test.go | 68 ++++++++ src/pkg/dashboard/stage_tracker_waiting.go | 22 ++- .../static-src/js/tracker-waiting.js | 4 +- src/pkg/dashboard/static/index.html | 4 +- .../automerge/automerge_contributor_lane.go | 11 +- .../automerge/automerge_native_queue.go | 8 +- .../automerge_rereview_requested_test.go | 163 ++++++++++++++++++ .../automerge_review_head_binding.go | 16 +- .../github/automerge/automerge_stage_human.go | 92 +++++++--- .../github/automerge/automerge_sweep_test.go | 8 +- .../automerge/automerge_sweep_trusted.go | 77 +++++++-- .../automerge_sweep_trusted_author_test.go | 6 +- src/pkg/stageengine/derive_pr_classify.go | 7 +- .../stageengine/derive_pr_rereview_test.go | 41 +++++ src/pkg/stageengine/prstage/reasons.go | 37 ++++ src/pkg/stageengine/prstage/rereview_test.go | 20 +++ 20 files changed, 575 insertions(+), 56 deletions(-) create mode 100644 changelog.d/fixed-rereview-outdated-change-request.md create mode 100644 src/pkg/dashboard/stage_tracker_rereview_test.go create mode 100644 src/pkg/github/automerge/automerge_rereview_requested_test.go create mode 100644 src/pkg/stageengine/derive_pr_rereview_test.go create mode 100644 src/pkg/stageengine/prstage/rereview_test.go diff --git a/changelog.d/fixed-rereview-outdated-change-request.md b/changelog.d/fixed-rereview-outdated-change-request.md new file mode 100644 index 0000000000..dcc9339617 --- /dev/null +++ b/changelog.d/fixed-rereview-outdated-change-request.md @@ -0,0 +1 @@ +- A pull request whose only standing change request is on an older commit the author has already pushed past now waits on the reviewer, not the author. The contributor and trusted-author lanes used to treat any standing `CHANGES_REQUESTED` review as the author's turn, whatever commit it was on. So a clanker PR whose author had pushed the fix sat at `stage/072-returned-to-contributor`, its author was nudged, and once the adoption grace ran out the Activity monitor asked "@author has been offline … take the PR over now?" On projectbluefin/chairlift#799 that lasted about 2h 45m after the author had pushed and commented. The lanes now return `re-review-requested:` and the PR routes to `stage/085-needs-decision`, where the 085 note and the monitor name the reviewer, the commit their review was on and the author's push since, and ask for a re-review or a dismissal. The author gets no nudge and no adoption clock runs. A request on the current head, one carried to it by a merge of the base, red CI or a swarm `changes_requested` on the new head is still the author's, as before. The hive never dismisses the review itself. diff --git a/src/docs/labels-and-control-signals/stage-labels.md b/src/docs/labels-and-control-signals/stage-labels.md index 687212b5d2..47746e17b5 100644 --- a/src/docs/labels-and-control-signals/stage-labels.md +++ b/src/docs/labels-and-control-signals/stage-labels.md @@ -408,6 +408,7 @@ used to admit the PR: | a posted reviewer decision question (`decision_requested`) on a conflicting / not-mergeable / changes-requested head | `085-needs-decision`, reason `contributor-lane:decision-requested` — no fixer is kicked for such a head, and a conflict is moot if the answer is to close it ([#14607](https://github.com/hivecommons/hive/issues/14607)) | | a trusted maintainer answered that question on the same head — `/hive decision ` or a CHANGES_REQUESTED review (recorded in `review-human-change-requests.json`, head-scoped) | `070-fixing`, reason `contributor-lane:decision-answered`: the answer is folded into the reviewer verdict for that head on every tick and after a restart, so the stage never re-derives 085 from the stale `requires_human` verdict. A bare `/hive decision approve` instead answers that `requires_human` question; it does not remove a `hold` label or provide the broad GitHub-review override for `changes_requested`/`reject`. A new head draws a new verdict with no answer and asks again ([#14679](https://github.com/hivecommons/hive/issues/14679)) | | CI red (`check-failing:*`, `required-check-failing:*`, `status-*`), `conflicting`, `not-mergeable`, `changes-requested`, verdict changes_requested/reject, `needs-rebase` present, `closing-contradiction:#N` (the PR body closes #N and also says #N stays open or is partial — a `Refs #N` line saying partial, remaining, deferred, follow-up or not (yet) addressed, or "#N stays open"; every lane refuses it right after its label checks, before admission, CI or soak, and a body edit releases it, [#15025](https://github.com/hivecommons/hive/issues/15025)), `closing-keyword-targets-pr:#N` (a closing keyword in the PR body, or in a commit message on a merge-ready head, names open pull request #N, which GitHub would close on merge; a closed pull request is left alone, since closing it again is a no-op; read with the linked-issue gate, [#15025](https://github.com/hivecommons/hive/issues/15025)). Neither applies to a PR whose base is not the repository's default branch (a forward-merge, say): GitHub acts on closing keywords only there, so such a PR closes nothing | `070-fixing` (self-authored lane or `author/hive`) / `071-needs-author` (`author/human`) / `072-returned-to-contributor` (`author/clanker`) — see [Stage 07x by author kind](#stage-07x-by-author-kind). A head whose App-linked commits carry a `Signed-off-by` the squash would misattribute to the PR author (`hive-signoff-attribution`) follows the same split: the branch owner is the only one who can rewrite them. | +| `re-review-requested:[,…]`: a change request is standing on the PR (that login's latest Approve / Request changes / Dismiss review is Request changes), and every one standing is on an older commit with content pushed since — not on the head, and not carried to it by a merge of the base (the walk an approval uses, `automerge_review_head_binding.go`). GitHub keeps such a review blocking until its reviewer re-reviews or it is dismissed, so the PR waits on the reviewer, not on the author who pushed the fix. A request on the head (or one with no commit) is still `contributor-lane:changes-requested` / `changes-requested` above. Both the contributor lane and the trusted-author lane return it | human hand-off, **decision** cause → routed by the head's evidence like the lane rules below: red CI, a swarm `changes_requested` or a conflict on the new head is still the author's (070 / 071 / 072), a head with no verdict yet is `050`, otherwise `085-needs-decision`. Never 071 / 072 for the old review, so the author is not nudged, no adoption clock runs, and the Activity monitor asks the reviewer ("@reviewer requested changes on an older commit; @author pushed `` since. Re-review it, or dismiss the review?", wait kind `re-review-requested`, who the reviewer) instead of calling the author offline. The 085 note names each review, its commit and a compare link to the push since. The hive never dismisses the review itself (projectbluefin/chairlift#799) | | `contributor-lane:soaking(...)` — and no red check on the head | `095-pre-merge-soak` | | `head-changed-since-eval`, `merge-failed`, `merge-queue-required` (the base branch's ruleset only accepts merges through GitHub's merge queue and the transport is a static token that cannot enqueue, so the direct REST merge is refused; with App auth on a repo opted in through `auto_merge.native_merge_queue` these bases are enqueued instead, see [native-merge-queue.md](../native-merge-queue.md); logged as a skip rather than a merge error, [#14018](https://github.com/hivecommons/hive/issues/14018); the self-authored sweep then skips the direct merge on that base for 30 minutes and logs the skip once per PR head, [#14068](https://github.com/hivecommons/hive/issues/14068); the trusted-author, queued and contributor-lane sweeps skip it the same way, sharing one memory of such bases; while a base is remembered the dashboard shows its otherwise-green PRs as a person's to merge, not Merge-eligible; with `auto_merge.require_current_base` on, a head behind such a base is not updated for 24 hours after the last refusal and holds here instead, so the base moving does not reset its review), `required-checks-expected`, `behind`, `updated-branch`, `behind-update-budget-exhausted` (a behind self-authored PR the sweep did not update only because this tick's branch-update budget was spent; retried next tick, waits on the hive, [#12607](https://github.com/hivecommons/hive/issues/12607)), `release-hold*`, `native-merge-queued: queued (position N, STATE)` (the PR was enqueued into GitHub's native merge queue) and the failures `native-merge-queue-read`, `native-merge-queue-enqueue`, `native-merge-queue-method` — and no red check on the head | `100-merge-queue` | | CI red (required or optional check) while the PR is deferred to an open `[shared-ci]` incident (``, the governor's `deferred_incident`) for the same head | `050-review-pending` / `060-reviewed`, reason `shared-ci-incident:`: the base or a shared check is what is red, so the PR is never sent to 070/071/072, never nudged and never stalled. A 072 nudge already posted for the head (the nudge goes out on entering 072, and the incident marker can land minutes later) is edited in place to say it was withdrawn, and the head's nudge count is reset. Once the incident closes the PR stays deferred until the shared-CI rerun sweep has re-run its failed jobs (at most 30 minutes); a head still red after that is handed back as usual, with a fresh nudge. Conflicts and requested changes stay author-facing ([#12606](https://github.com/hivecommons/hive/issues/12606)) | diff --git a/src/pkg/dashboard/stage_tracker_caption.go b/src/pkg/dashboard/stage_tracker_caption.go index 71f5e6e238..653b61cef9 100644 --- a/src/pkg/dashboard/stage_tracker_caption.go +++ b/src/pkg/dashboard/stage_tracker_caption.go @@ -331,6 +331,9 @@ func humanizeStageReason(reason string) string { if r == "" { return "" } + if reviewers, ok := stageengineprstage.ParseReReviewRequested(r); ok { + return "waiting on " + decisionReReviewNames(reviewers) + " to re-review: the change request is on an older commit" + } if rest, ok := strings.CutPrefix(r, "ci-reporting-stalled:"); ok { return "CI reporting stalled — " + rest } diff --git a/src/pkg/dashboard/stage_tracker_decision_pr.go b/src/pkg/dashboard/stage_tracker_decision_pr.go index d1773f6977..2eab481153 100644 --- a/src/pkg/dashboard/stage_tracker_decision_pr.go +++ b/src/pkg/dashboard/stage_tracker_decision_pr.go @@ -45,6 +45,10 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel // branch that bot regenerates, so the fix lands on the base branch. botAuthorFinding := lower == stagelabels.LaneReasonBotAuthorFinding hiveSupersederStop := stagelabels.HiveSupersederHardStopReason(base) + // Every standing change request is on an older commit the author has + // pushed past: the reviewer re-reviews, not the author + // (projectbluefin/chairlift#799). + reReviewers, reReview := stageengineprstage.ParseReReviewRequested(base) // WHAT it is waiting on: the question, most specific source first. A // reviewer's own question is quoted verbatim — it is the text the @@ -138,6 +142,9 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel d.Question = "The hive took this PR over but could not move it (" + decisionPlainReason(adoptionLane) + "). Give direction, or close it?" case forkGuarded: d.Question = "CI will not run for this fork PR (" + strings.ReplaceAll(forkGuard, ",", ", ") + "). A maintainer must push the branch to this repo — or close it?" + case reReview: + d.AskedBy = decisionAskedByReviewer + d.Question = decisionReReviewQuestion(reReviewers, it.Author, sha) case changes: d.AskedBy = decisionAskedByReviewer d.Question = "A reviewer requested changes" + at + ". Give direction for a new commit, or close it?" @@ -158,6 +165,9 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel switch { case it.UnauthorizedStep != "": // set above + case reReview: + d.Blocker = "GitHub keeps " + decisionReReviewNames(reReviewers) + "'s change request blocking until it is re-reviewed or dismissed. The author has nothing left to push for it." + approveOK, approveWhy = false, "Approving here does not clear "+decisionReReviewNames(reReviewers)+"'s change request on GitHub; they re-review, or a maintainer dismisses the review." case changes: d.Blocker = "A reviewer requested changes" + at + " — needs a new commit. Approving cannot override that." approveOK, approveWhy = false, d.Blocker @@ -236,6 +246,38 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel return d } +// decisionReReviewQuestion is the question for a re-review-requested PR: +// it names the reviewers, the author and the head they pushed, and never +// calls the author offline (projectbluefin/chairlift#799). +func decisionReReviewQuestion(reviewers []string, author, sha string) string { + who := "the author" + if a := strings.TrimSpace(author); a != "" { + who = "@" + a + } + pushed := " pushed new commits" + if sha != "" { + pushed = " pushed `" + sha + "`" + } + return decisionReReviewNames(reviewers) + " requested changes on an older commit; " + who + pushed + " since. Re-review it, or dismiss the review?" +} + +// decisionReReviewNames renders the reviewers as "@a", "@a and @b". +func decisionReReviewNames(reviewers []string) string { + var names []string + for _, r := range reviewers { + if r = strings.TrimSpace(r); r != "" { + names = append(names, "@"+r) + } + } + switch len(names) { + case 0: + return "the reviewer" + case 1: + return names[0] + } + return strings.Join(names[:len(names)-1], ", ") + " and " + names[len(names)-1] +} + // decisionApproveSignOffConsequence is the inline Approve pill's hover on // a sign-off ask. const decisionApproveSignOffConsequence = "Posts /lgtm + /approve as you; the merge queue takes it from there. Nothing merges here." diff --git a/src/pkg/dashboard/stage_tracker_rereview_test.go b/src/pkg/dashboard/stage_tracker_rereview_test.go new file mode 100644 index 0000000000..c2b8229338 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_rereview_test.go @@ -0,0 +1,68 @@ +package dashboard + +import ( + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/stageengine/prstage" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// projectbluefin/chairlift#799: @Danathar's change request was on an older +// commit and @castrojo had pushed the fix. The row asked "@castrojo has been +// offline … take the PR over now?". A re-review-requested 085 names the +// reviewer and the author's push, waits on the reviewer, and never offers +// the takeover or calls the author offline, even with the adoption grace +// run out on the row. +func TestReReviewRequestedRowWaitsOnTheReviewer(t *testing.T) { + reason := prstage.ReReviewRequestedReason([]string{"Danathar"}) + it := StageTrackerItem{ + Repo: "projectbluefin/chairlift", Number: 799, Kind: "pr", Stage: stagelabels.NeedsDecision.Number(), + Head: "948192f343abcdef", Author: "castrojo", Reason: reason, + Adoption: &StageTrackerAdoption{Author: "castrojo", Due: true}, + Takeover: &StageTrackerTakeover{GraceElapsed: true}, + } + d := stageTrackerDecisionNeededAt(it, nil, "", time.Date(2026, 11, 17, 16, 11, 0, 0, time.UTC)) + if d == nil { + t.Fatal("no decision for a re-review-requested row") + } + want := "@Danathar requested changes on an older commit; @castrojo pushed `" + shortHead(it.Head) + "` since. Re-review it, or dismiss the review?" + if d.Question != want { + t.Fatalf("question = %q\nwant %q", d.Question, want) + } + if strings.Contains(d.Question+d.Blocker, "offline") { + t.Fatalf("decision calls the author offline: %+v", d) + } + for _, o := range d.Options { + if o.Action == decisionActionApprove && o.Enabled { + t.Fatalf("approve option = %+v, want disabled: it does not clear the change request", o) + } + if o.Action == decisionActionAdopt { + t.Fatalf("decision offers adoption: %+v", o) + } + } + if kind, who := stageTrackerWaitKind(it); kind != waitKindReReview || who != "Danathar" { + t.Fatalf("wait kind/who = %s/%s, want %s/Danathar", kind, who, waitKindReReview) + } + if got := humanizeStageReason(reason); got != "waiting on @Danathar to re-review: the change request is on an older commit" { + t.Fatalf("caption clause = %q", got) + } + // Any other 085 keeps the operator's decision wait. + it.Reason = prstage.ContributorLaneReasonReporterTrustHold + if kind, who := stageTrackerWaitKind(it); kind != waitKindNeedsDecision || who != waitWhoOperator { + t.Fatalf("other 085 wait kind/who = %s/%s", kind, who) + } +} + +func TestDecisionReReviewNames(t *testing.T) { + for in, want := range map[string]string{"": "the reviewer", "a": "@a", "a,b": "@a and @b", "a,b,c": "@a, @b and @c"} { + var reviewers []string + if in != "" { + reviewers = strings.Split(in, ",") + } + if got := decisionReReviewNames(reviewers); got != want { + t.Errorf("%q: got %q, want %q", in, got, want) + } + } +} diff --git a/src/pkg/dashboard/stage_tracker_waiting.go b/src/pkg/dashboard/stage_tracker_waiting.go index e5c956874b..69fc70a7e8 100644 --- a/src/pkg/dashboard/stage_tracker_waiting.go +++ b/src/pkg/dashboard/stage_tracker_waiting.go @@ -5,6 +5,7 @@ import ( "sort" "time" + stageengineprstage "github.com/hivecommons/hive/pkg/stageengine/prstage" "github.com/hivecommons/hive/pkg/stagelabels" ) @@ -34,6 +35,10 @@ const ( // waitKindOther: any other stage only a person can advance (015 // triage-needed). waitKindOther = "other-human-wait" + // waitKindReReview: 085 because every change request standing on the + // PR is on an older commit the author pushed past; Who is the first + // reviewer, who re-reviews (or a maintainer dismisses the review). + waitKindReReview = "re-review-requested" ) // waitWhoOperator is the Who value for a wait that falls to the signed-in @@ -60,8 +65,9 @@ type StageTrackerWaitingItem struct { // recorded, else when the item entered its stage. Since *time.Time `json:"since,omitempty"` // Who is the login the wait is attributed to: "operator" for the - // signed-in operator / maintainers, else the contributor whose - // offline grace ran out (the operator is their fallback). + // signed-in operator / maintainers, the reviewer a re-review waits on, + // else the contributor whose offline grace ran out (the operator is + // their fallback). Who string `json:"who"` } @@ -81,6 +87,8 @@ func stageTrackerWaitKind(it StageTrackerItem) (kind, who string) { return "", "" } switch { + case it.Kind == "pr" && it.Stage == stagelabels.NeedsDecision.Number() && stageTrackerReReviewer(it) != "": + return waitKindReReview, stageTrackerReReviewer(it) case it.Stage == stagelabels.NeedsDecision.Number(), it.Stage == stagelabels.IssueNeedsDecision.Number(), slices.Contains(it.Modifiers, modNeedsDecision): return waitKindNeedsDecision, waitWhoOperator case it.Stage == stagelabels.ReadyForHumanMerge.Number(): @@ -105,6 +113,16 @@ func stageTrackerWaitKind(it StageTrackerItem) (kind, who string) { return "", "" } +// stageTrackerReReviewer is the first reviewer a re-review-requested row +// waits on, "" for any other row. +func stageTrackerReReviewer(it StageTrackerItem) string { + base, _ := stagelabels.HumanApprovedReason(it.Reason) + if reviewers, ok := stageengineprstage.ParseReReviewRequested(base); ok && len(reviewers) > 0 { + return reviewers[0] + } + return "" +} + // stageTrackerWaitStandingMeta reports whether it is a standing meta // issue: a bot Dependency Dashboard or the Hive Advisory Report, which the // enumeration files under the dependency_dashboard / hive_advisory buckets diff --git a/src/pkg/dashboard/static-src/js/tracker-waiting.js b/src/pkg/dashboard/static-src/js/tracker-waiting.js index 8a385f83a7..1598c250a3 100644 --- a/src/pkg/dashboard/static-src/js/tracker-waiting.js +++ b/src/pkg/dashboard/static-src/js/tracker-waiting.js @@ -2,7 +2,8 @@ The stage tracker payload carries waiting_on_human (stage_tracker_waiting.go): every open item parked on the signed-in operator / maintainers, with a kind (needs-decision, ready-for-human-merge, approve-needed, - returned-to-contributor-offline, other-human-wait) and who the wait + returned-to-contributor-offline, re-review-requested, + other-human-wait) and who the wait is attributed to. Three surfaces read it so a human wait is never silent (hivecommons/hive#15638): a second, attention-coloured badge on the "Hive activity monitor" sidebar item, a "Waiting on you · N" pill @@ -19,6 +20,7 @@ 'ready-for-human-merge': 'ready for you to merge', 'approve-needed': 'needs your approval', 'returned-to-contributor-offline': 'contributor offline — adopt or reroute', + 're-review-requested': 'waiting on a re-review', 'other-human-wait': 'needs a person', }; var _stageTrackerWaitingPrevCount = null; diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index a7bc93f87a..acdda6aa0e 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -30734,7 +30734,8 @@

All labels

The stage tracker payload carries waiting_on_human (stage_tracker_waiting.go): every open item parked on the signed-in operator / maintainers, with a kind (needs-decision, ready-for-human-merge, approve-needed, - returned-to-contributor-offline, other-human-wait) and who the wait + returned-to-contributor-offline, re-review-requested, + other-human-wait) and who the wait is attributed to. Three surfaces read it so a human wait is never silent (hivecommons/hive#15638): a second, attention-coloured badge on the "Hive activity monitor" sidebar item, a "Waiting on you · N" pill @@ -30751,6 +30752,7 @@

All labels

'ready-for-human-merge': 'ready for you to merge', 'approve-needed': 'needs your approval', 'returned-to-contributor-offline': 'contributor offline — adopt or reroute', + 're-review-requested': 'waiting on a re-review', 'other-human-wait': 'needs a person', }; var _stageTrackerWaitingPrevCount = null; diff --git a/src/pkg/github/automerge/automerge_contributor_lane.go b/src/pkg/github/automerge/automerge_contributor_lane.go index 3cd5b8a2d1..b029310e03 100644 --- a/src/pkg/github/automerge/automerge_contributor_lane.go +++ b/src/pkg/github/automerge/automerge_contributor_lane.go @@ -1619,10 +1619,15 @@ func (c *Engine) evaluateContributorLanePR(ctx context.Context, displayRepo, own } else if held { return eval, contributorLaneReasonReporterTrustHold, nil } - if blocked, err := c.hasOutstandingChangesRequested(ctx, owner, repo, number); err != nil { + // A change request on an older commit the author pushed past waits on + // its reviewer (re-review-requested), not on the author: routed as + // changes-requested it read as the author's turn, nudged them and ran + // the adoption clock against an author who had done the work + // (projectbluefin/chairlift#799). + if standing, err := c.hasOutstandingChangesRequested(ctx, owner, repo, number, headSHA); err != nil { return eval, "review-state-check", err - } else if blocked { - return eval, contributorLaneReasonChangesRequested, nil + } else if reason := standing.reason(contributorLaneReasonChangesRequested); reason != "" { + return eval, reason, nil } serialized, _ := c.serializedLane(displayRepo) mergeableState := strings.ToLower(strings.TrimSpace(pr.GetMergeableState())) diff --git a/src/pkg/github/automerge/automerge_native_queue.go b/src/pkg/github/automerge/automerge_native_queue.go index 9234901ddf..b2fcac22f7 100644 --- a/src/pkg/github/automerge/automerge_native_queue.go +++ b/src/pkg/github/automerge/automerge_native_queue.go @@ -145,8 +145,9 @@ func ownNativeQueueEntry(e *hgithub.NativeMergeQueueEntry, slug string) bool { // nativeQueueWithdrawReason reports whether a lane's rejection reason means // the PR lost merge eligibility (#15198): a hold, a withdrawn or stale -// approval, changes requested, a paused or disabled repo, a draft or closed -// PR, a release in progress, or a human-merge path. Anything else — pending or red checks, behind, a moved head, an +// approval, changes requested (on the head or awaiting a re-review), a +// paused or disabled repo, a draft or closed PR, a release in progress, or a +// human-merge path. Anything else — pending or red checks, behind, a moved head, an // API error, a routing observation — keeps the App's queue entry. A // breaking-change title or an auto_merge.human_merge_labels label added // while the PR waits in the queue withdraws it too: no lane merges it. @@ -161,7 +162,8 @@ func nativeQueueWithdrawReason(reason string) bool { return true } return strings.HasPrefix(reason, "label:do-not-merge") || strings.HasPrefix(reason, "excluded-label:") || - strings.HasPrefix(reason, autoMergeReasonReviewGatePrefix+ReviewGateOutcomeChangesRequested) + strings.HasPrefix(reason, autoMergeReasonReviewGatePrefix+ReviewGateOutcomeChangesRequested) || + strings.HasPrefix(reason, prstage.ReReviewRequestedReasonPrefix) } // nativeQueueEnabled reports whether the PR's base has a native merge queue diff --git a/src/pkg/github/automerge/automerge_rereview_requested_test.go b/src/pkg/github/automerge/automerge_rereview_requested_test.go new file mode 100644 index 0000000000..4c7630066f --- /dev/null +++ b/src/pkg/github/automerge/automerge_rereview_requested_test.go @@ -0,0 +1,163 @@ +package automerge + +import ( + "context" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/stageengine/prstage" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// TestContributorLaneOutdatedChangeRequestAsksForReReview pins +// projectbluefin/chairlift#799: a change request left on an older commit the +// author has pushed past waits on its reviewer (re-review-requested), not on +// the author. A request on the head, or carried to it by a base merge, is +// still the author's turn, and a later approval or a dismissal clears both. +func TestContributorLaneOutdatedChangeRequestAsksForReReview(t *testing.T) { + for _, tc := range []struct { + name string + mutate func(*contributorLaneFixture) + wantReason string + wantMerges int + }{ + { + name: "request on an older commit asks its reviewer to re-review", + mutate: func(fx *contributorLaneFixture) { + fx.reviews = []map[string]any{humanReview(1, "Danathar", "CHANGES_REQUESTED", "sha6", "three small asks")} + }, + wantReason: "re-review-requested:Danathar", + }, + { + name: "request on the head is the author's turn", + mutate: func(fx *contributorLaneFixture) { + fx.reviews = []map[string]any{humanReview(1, "Danathar", "CHANGES_REQUESTED", "sha7", "three small asks")} + }, + wantReason: contributorLaneReasonChangesRequested, + }, + { + name: "one request on the head outranks an outdated one", + mutate: func(fx *contributorLaneFixture) { + fx.reviews = []map[string]any{ + humanReview(1, "alice", "CHANGES_REQUESTED", "sha6", "old ask"), + humanReview(2, "bob", "CHANGES_REQUESTED", "sha7", "new ask"), + } + }, + wantReason: contributorLaneReasonChangesRequested, + }, + { + name: "every outdated reviewer is named, sorted", + mutate: func(fx *contributorLaneFixture) { + fx.reviews = []map[string]any{ + humanReview(1, "zed", "CHANGES_REQUESTED", "sha5", "old ask"), + humanReview(2, "alice", "CHANGES_REQUESTED", "sha6", "old ask"), + } + }, + wantReason: "re-review-requested:alice,zed", + }, + { + name: "a later approval from the reviewer clears it", + mutate: func(fx *contributorLaneFixture) { + fx.reviews = []map[string]any{ + humanReview(1, "Danathar", "CHANGES_REQUESTED", "sha6", "three small asks"), + humanReview(2, "Danathar", "APPROVED", "sha7", "thanks"), + } + }, + wantMerges: 1, + }, + { + name: "a dismissed request clears it", + mutate: func(fx *contributorLaneFixture) { + fx.reviews = []map[string]any{humanReview(1, "Danathar", "DISMISSED", "sha6", "three small asks")} + }, + wantMerges: 1, + }, + { + name: "a request with no commit stays the author's turn", + mutate: func(fx *contributorLaneFixture) { + fx.reviews = []map[string]any{{"id": 1, "state": "CHANGES_REQUESTED", "user": map[string]string{"login": "maintainer"}}} + }, + wantReason: contributorLaneReasonChangesRequested, + }, + { + // The head is a merge of the base into the reviewed commit: the + // reviewed change is unchanged, so the author still owes it. + name: "a base merge carries the request to the head", + mutate: func(fx *contributorLaneFixture) { + fx.reviews = []map[string]any{humanReview(1, "Danathar", "CHANGES_REQUESTED", "sha6", "three small asks")} + fx.headCommit = map[string]any{"sha": "sha7", "parents": []map[string]string{{"sha": "sha6"}, {"sha": "base1"}}} + files := []map[string]any{{"filename": "pkg/widget/widget.go", "status": "modified"}} + fx.compareFiles = map[string][]map[string]any{"sha7": files, "sha6": files} + fx.compareMergeBase = map[string]string{"sha7": "base1", "sha6": "base0"} + }, + wantReason: contributorLaneReasonChangesRequested, + }, + } { + t.Run(tc.name, func(t *testing.T) { + fx := validContributorFixture() + tc.mutate(&fx) + api := newContributorLaneAPI(t, &fx) + defer api.Close() + policy := defaultContributorLanePolicy() + clock := &contributorLaneClock{at: time.Date(2026, 11, 17, 16, 11, 0, 0, time.UTC)} + engine := newContributorLaneEngine(api.URL, policy, clock, Options{ContributorSoak: soakedTracker(clock)}) + _, reason, err := engine.trySweepContributorLanePR(context.Background(), "widget", "acme", "widget", 7, policy) + if err != nil { + t.Fatalf("err = %v", err) + } + if reason != tc.wantReason || fx.merges != tc.wantMerges { + t.Fatalf("reason=%q merges=%d, want %q/%d", reason, fx.merges, tc.wantReason, tc.wantMerges) + } + }) + } +} + +func TestChangeRequestStandingReason(t *testing.T) { + if got := (changeRequestStanding{}).reason("changes-requested"); got != "" { + t.Fatalf("nothing standing: %q, want empty", got) + } + if got := (changeRequestStanding{onHead: true, reReview: []string{"bob"}}).reason("changes-requested"); got != "changes-requested" { + t.Fatalf("on head with an outdated one too: %q, want the author's reason", got) + } + if got := (changeRequestStanding{reReview: []string{"bob", "Alice"}}).reason("changes-requested"); got != "re-review-requested:Alice,bob" { + t.Fatalf("outdated only: %q", got) + } +} + +// TestReReviewRequestedCauseNamesReviewerAndAuthor: the 085 note asks the +// reviewer to re-review and says the author pushed, never that the author +// owes anything or is offline. +func TestReReviewRequestedCauseNamesReviewerAndAuthor(t *testing.T) { + const head = "948192f343aa" + const reviewed = "298e8a5849bb" + url := "https://github.com/projectbluefin/chairlift/pull/799#pullrequestreview-1" + got := reReviewRequestedCause(head, "castrojo", []string{"Danathar"}, []prstage.ChangeRequestRef{ + {Login: "Danathar", CommitID: reviewed, SubmittedAt: time.Date(2026, 11, 17, 11, 30, 0, 0, time.UTC), URL: url}, + }) + for _, want := range []string{ + "@Danathar requested changes on 2026-11-17 at `" + stagelabels.ShortSHA(reviewed) + "`", + "@castrojo has pushed since ([changes since that review](https://github.com/projectbluefin/chairlift/compare/" + reviewed + "..." + head + "))", + "waits on the reviewer, not on @castrojo", + "@Danathar, please re-review this head", + "a maintainer can dismiss the review", + } { + if !strings.Contains(got, want) { + t.Fatalf("cause = %q\nwant it to contain %q", got, want) + } + } + if strings.Contains(got, "offline") || strings.Contains(got, "the hive has pushed") { + t.Fatalf("cause blames the wrong party: %q", got) + } + // From the reason alone (no review refs): still names the reviewer. + bare := decisionCause(prstage.ReReviewRequestedReason([]string{"Danathar"})) + if !strings.Contains(bare, "@Danathar requested changes on an older commit, and the author has pushed since") || !strings.Contains(bare, "@Danathar, please re-review this head") { + t.Fatalf("bare cause = %q", bare) + } +} + +func TestNativeQueueWithdrawsReReviewRequested(t *testing.T) { + if !nativeQueueWithdrawReason(prstage.ReReviewRequestedReason([]string{"alice"})) { + t.Fatal("a re-review-requested PR keeps its native queue entry; GitHub will not merge it") + } +} diff --git a/src/pkg/github/automerge/automerge_review_head_binding.go b/src/pkg/github/automerge/automerge_review_head_binding.go index c239ad99a5..d25fd2a360 100644 --- a/src/pkg/github/automerge/automerge_review_head_binding.go +++ b/src/pkg/github/automerge/automerge_review_head_binding.go @@ -73,24 +73,32 @@ func (c *approvalReachCache) put(key string, r approvalReach) { // review and head never changes, so it is memoised; a lookup failure is // not memoised and reads as false (the fence stays, the person is asked). func (c *Engine) reviewReachesHead(ctx context.Context, owner, repo string, number int, head string, rv *gh.PullRequestReview) approvalReach { + r, _ := c.reviewReachesHeadKnown(ctx, owner, repo, number, head, rv) + return r +} + +// reviewReachesHeadKnown is reviewReachesHead with known false when GitHub +// could not be read, for a caller whose safe answer on a failed read is +// not "does not reach" (changeRequestBindsHead). +func (c *Engine) reviewReachesHeadKnown(ctx context.Context, owner, repo string, number int, head string, rv *gh.PullRequestReview) (approvalReach, bool) { head = strings.TrimSpace(head) reviewed := strings.TrimSpace(rv.GetCommitID()) submitted := rv.GetSubmittedAt().Time if submitted.IsZero() { - return approvalReach{ok: reviewed == head} + return approvalReach{ok: reviewed == head}, true } if c == nil || c.gh == nil || head == "" { - return approvalReach{} + return approvalReach{}, false } key := owner + "/" + repo + "#" + strconv.Itoa(number) + "@" + head + "<-" + strconv.FormatInt(rv.GetID(), 10) + ":" + reviewed if r, ok := c.approvalReach.get(key); ok { - return r + return r, true } r, known := c.walkApprovalToHead(ctx, owner, repo, number, head, reviewed, submitted) if known { c.approvalReach.put(key, r) } - return r + return r, known } // walkApprovalToHead does the reads. known is false when GitHub could not be diff --git a/src/pkg/github/automerge/automerge_stage_human.go b/src/pkg/github/automerge/automerge_stage_human.go index 973cd3739c..15b6537a57 100644 --- a/src/pkg/github/automerge/automerge_stage_human.go +++ b/src/pkg/github/automerge/automerge_stage_human.go @@ -550,6 +550,11 @@ func (c *Engine) humanEvidence(ctx context.Context, tracker *StageTracker, key s e.CauseReason = cause } } + if reviewers, ok := prstage.ParseReReviewRequested(obs.Reason); ok { + // Name each reviewer's review, the commit it was on and the author's + // push since, from the lane's own ListReviews walk. + e.CauseReason = reReviewRequestedCause(obs.HeadSHA, obs.Author, reviewers, obs.Detail.StandingChangeRequests) + } if rec, ok := c.stageStoreOrShared().Get(key); ok && rec.AdoptedHead != "" && rec.AdoptDiffFence != "" && rec.AdoptDiffFence == obs.Reason && e.CauseReason != "" { // An adopted head whose diff fence is the blocker: the 085 note // says the hive repaired it and why it still will not merge it. @@ -736,6 +741,9 @@ func decisionCauseFor(reason string, workflowManual bool) string { } case reason == autoMergeReasonMergeRefusedReview: return "GitHub refused the merge: branch protection requires an approving review from someone with write access, and the Hive App cannot give it. A GitHub **Approve** review on this head (or an App bypass in the branch rules) lets the hive merge it; the hive retries once GitHub reports the PR unblocked, or within 30 minutes" + case strings.HasPrefix(reason, prstage.ReReviewRequestedReasonPrefix): + reviewers, _ := prstage.ParseReReviewRequested(reason) + return reReviewRequestedCause("", "", reviewers, nil) case reason == autoMergeReasonMergeRefusedMethod: return "GitHub refused the merge: the repository does not allow the merge method the hive chose for this PR. The hive does not switch methods on its own: a forward merge or a `" + stagelabels.MergeCommitLabel + "` PR must never be squashed. Merge it by hand with an allowed method, or allow the method in the repository settings and the hive retries within 30 minutes" case reason == "": @@ -764,28 +772,7 @@ func mergeRefusedReviewChangeRequestCause(head string, requests []prstage.Change continue } names = append(names, "@"+login) - var b strings.Builder - b.WriteString("@" + login + " requested changes") - if !r.SubmittedAt.IsZero() { - b.WriteString(" on " + r.SubmittedAt.UTC().Format("2006-01-02")) - } - commit := strings.TrimSpace(r.CommitID) - switch { - case commit != "" && commit == head: - b.WriteString(" on this head") - case commit != "": - b.WriteString(" at `" + stagelabels.ShortSHA(commit) + "`") - } - if url := strings.TrimSpace(r.URL); url != "" { - b.WriteString(" ([review](" + url + "))") - } - if commit != "" && head != "" && commit != head { - b.WriteString(", and the hive has pushed since") - if i := strings.Index(r.URL, "/pull/"); i > 0 { - b.WriteString(" ([changes since that review](" + r.URL[:i] + "/compare/" + commit + "..." + head + "))") - } - } - said = append(said, b.String()) + said = append(said, changeRequestClause(r, head, "the hive")) } if len(said) == 0 { return "" @@ -797,6 +784,67 @@ func mergeRefusedReviewChangeRequestCause(head string, requests []prstage.Change "The hive retries once GitHub reports the PR unblocked, or within 30 minutes" } +// changeRequestClause renders one standing change request: who, when, on +// which commit, a link to the review, and, when the commit is not head, +// that pusher ("the hive", "@author") has pushed since, with a compare +// link for what changed. +func changeRequestClause(r prstage.ChangeRequestRef, head, pusher string) string { + var b strings.Builder + b.WriteString("@" + strings.TrimSpace(r.Login) + " requested changes") + if !r.SubmittedAt.IsZero() { + b.WriteString(" on " + r.SubmittedAt.UTC().Format("2006-01-02")) + } + commit := strings.TrimSpace(r.CommitID) + switch { + case commit != "" && commit == head: + b.WriteString(" on this head") + case commit != "": + b.WriteString(" at `" + stagelabels.ShortSHA(commit) + "`") + } + if url := strings.TrimSpace(r.URL); url != "" { + b.WriteString(" ([review](" + url + "))") + } + if commit != "" && head != "" && commit != head { + b.WriteString(", and " + pusher + " has pushed since") + if i := strings.Index(r.URL, "/pull/"); i > 0 { + b.WriteString(" ([changes since that review](" + r.URL[:i] + "/compare/" + commit + "..." + head + "))") + } + } + return b.String() +} + +// reReviewRequestedCause is the 085 prose for a ReReviewRequestedReason: +// every change request standing on the PR is on an older commit the author +// has pushed past, so the PR waits on those reviewers, not on its author +// (projectbluefin/chairlift#799). requests are the lane's standing change +// requests; the clauses name the reviewers' own reviews when they are known +// and fall back to the logins the reason carries. +func reReviewRequestedCause(head, author string, reviewers []string, requests []prstage.ChangeRequestRef) string { + head = strings.TrimSpace(head) + pusher := "the author" + if a := strings.TrimPrefix(strings.TrimSpace(author), "@"); a != "" { + pusher = "@" + a + } + var said, names []string + for _, login := range reviewers { + names = append(names, "@"+login) + for _, r := range requests { + if strings.EqualFold(strings.TrimSpace(r.Login), login) && strings.TrimSpace(r.CommitID) != "" && strings.TrimSpace(r.CommitID) != head { + said = append(said, changeRequestClause(r, head, pusher)) + } + } + } + if len(names) == 0 { + names = []string{"the reviewer"} + } + lead := joinNames(names) + " requested changes on an older commit, and " + pusher + " has pushed since" + if len(said) > 0 { + lead = "A change request on an older commit still stands: " + strings.Join(said, "; ") + } + return lead + ". GitHub keeps a change request blocking across pushes until its reviewer re-reviews or it is dismissed, so this PR now waits on the reviewer, not on " + pusher + ": " + + joinNames(names) + ", please re-review this head; if the request no longer applies, a maintainer can dismiss the review" +} + // joinNames renders "a", "a and b", "a, b and c". func joinNames(names []string) string { switch len(names) { diff --git a/src/pkg/github/automerge/automerge_sweep_test.go b/src/pkg/github/automerge/automerge_sweep_test.go index 23af653b5c..d9fe8b8219 100644 --- a/src/pkg/github/automerge/automerge_sweep_test.go +++ b/src/pkg/github/automerge/automerge_sweep_test.go @@ -357,11 +357,11 @@ func TestTrustedAuthorGitHubSignals(t *testing.T) { if err != nil || permission.Allowed { t.Fatalf("bob permission = %+v err=%v, want denied", permission, err) } - if blocked, err := engine.hasOutstandingChangesRequested(context.Background(), "acme", "widget", 7); err != nil || blocked { - t.Fatalf("PR 7 blocked=%v err=%v, want cleared by later approval", blocked, err) + if standing, err := engine.hasOutstandingChangesRequested(context.Background(), "acme", "widget", 7, "sha7"); err != nil || standing.reason("changes-requested") != "" { + t.Fatalf("PR 7 standing=%+v err=%v, want cleared by later approval", standing, err) } - if blocked, err := engine.hasOutstandingChangesRequested(context.Background(), "acme", "widget", 8); err != nil || !blocked { - t.Fatalf("PR 8 blocked=%v err=%v, want outstanding changes requested", blocked, err) + if standing, err := engine.hasOutstandingChangesRequested(context.Background(), "acme", "widget", 8, "sha7"); err != nil || standing.reason("changes-requested") != "changes-requested" { + t.Fatalf("PR 8 standing=%+v err=%v, want outstanding changes requested", standing, err) } if !engine.isForkPR(&gh.PullRequest{ Head: &gh.PullRequestBranch{Repo: &gh.Repository{FullName: gh.Ptr("alice/widget")}}, diff --git a/src/pkg/github/automerge/automerge_sweep_trusted.go b/src/pkg/github/automerge/automerge_sweep_trusted.go index b4adf18351..9155b84f40 100644 --- a/src/pkg/github/automerge/automerge_sweep_trusted.go +++ b/src/pkg/github/automerge/automerge_sweep_trusted.go @@ -734,10 +734,10 @@ func (c *Engine) trySweepTrustedAuthorPR(ctx context.Context, displayRepo, owner return AutoMergeSweepEvent{}, "fork-non-member", nil } } - if blocked, err := c.hasOutstandingChangesRequested(ctx, owner, repo, number); err != nil { + if standing, err := c.hasOutstandingChangesRequested(ctx, owner, repo, number, pr.GetHead().GetSHA()); err != nil { return AutoMergeSweepEvent{}, "review-state-check", err - } else if blocked { - return AutoMergeSweepEvent{}, "changes-requested", nil + } else if reason := standing.reason("changes-requested"); reason != "" { + return AutoMergeSweepEvent{}, reason, nil } mergeableState := strings.ToLower(strings.TrimSpace(pr.GetMergeableState())) // See trySweepSelfAuthoredPR: the queue bypass is an explicit opt-in. @@ -1073,14 +1073,46 @@ func (c *Engine) executeUpdateBranchEffect(ctx context.Context, owner, repo stri return err } -func (c *Engine) hasOutstandingChangesRequested(ctx context.Context, owner, repo string, number int) (bool, error) { +// changeRequestStanding is what the change requests standing on a PR ask +// for at its head (hasOutstandingChangesRequested). +type changeRequestStanding struct { + // onHead: at least one standing change request still binds to the head + // (changeRequestBindsHead), so the author owes a change. + onHead bool + // reReview names the reviewers whose standing change requests are all + // on older commits the author has pushed past, when none binds to the + // head: the PR waits on them to re-review, not on its author. + reReview []string +} + +// reason is the lane reason for the standing change requests: onHeadReason +// (the lane's own changes-requested reason) when the author owes a change, +// a ReReviewRequestedReason when only the reviewers can move it, "" when +// nothing stands. +func (s changeRequestStanding) reason(onHeadReason string) string { + switch { + case s.onHead: + return onHeadReason + case len(s.reReview) > 0: + return prstage.ReReviewRequestedReason(s.reReview) + } + return "" +} + +// hasOutstandingChangesRequested reads every login's latest opinionated +// review (APPROVED / CHANGES_REQUESTED / DISMISSED), so a later approval or +// a dismissal clears a change request, and sorts the CHANGES_REQUESTED ones +// by whether they still bind to head. GitHub keeps a change request +// blocking across pushes until its reviewer re-reviews, so an outdated one +// still stops the merge; it just stops being the author's to answer. +func (c *Engine) hasOutstandingChangesRequested(ctx context.Context, owner, repo string, number int, head string) (changeRequestStanding, error) { opts := &gh.ListOptions{PerPage: 100} - latest := map[string]string{} + latest := map[string]*gh.PullRequestReview{} var seen []*gh.PullRequestReview for { reviews, resp, err := c.gh.PullRequests.ListReviews(ctx, owner, repo, number, opts) if err != nil { - return false, err + return changeRequestStanding{}, err } seen = append(seen, reviews...) for _, review := range reviews { @@ -1090,7 +1122,7 @@ func (c *Engine) hasOutstandingChangesRequested(ctx context.Context, owner, repo } state := strings.ToUpper(strings.TrimSpace(review.GetState())) if state == "APPROVED" || state == "CHANGES_REQUESTED" || state == "DISMISSED" { - latest[login] = state + latest[login] = review } } if resp.NextPage == 0 { @@ -1099,12 +1131,35 @@ func (c *Engine) hasOutstandingChangesRequested(ctx context.Context, owner, repo opts.Page = resp.NextPage } c.noteStageReviews(owner, repo, number, seen) - for _, state := range latest { - if state == "CHANGES_REQUESTED" { - return true, nil + var out changeRequestStanding + for _, review := range latest { + if !strings.EqualFold(strings.TrimSpace(review.GetState()), "CHANGES_REQUESTED") { + continue + } + if c.changeRequestBindsHead(ctx, owner, repo, number, head, review) { + out.onHead = true + continue } + out.reReview = append(out.reReview, strings.TrimSpace(hgithub.SafeGetLogin(review.GetUser()))) } - return false, nil + return out, nil +} + +// changeRequestBindsHead reports whether a standing CHANGES_REQUESTED review +// still asks the author for something at head. It does unless it names an +// older commit and the commits since are more than base merges: the walk +// an approval uses (reviewReachesHead) carries a review over a merge of the +// base, which leaves the reviewed change as it was. A review with no +// commit, no head, or a walk GitHub could not answer binds, which keeps the +// author's turn. The head-scoped rule is latestTrustedHumanChangesRequested's +// (hivecommons/hive#13041): the author already pushed past an older review. +func (c *Engine) changeRequestBindsHead(ctx context.Context, owner, repo string, number int, head string, rv *gh.PullRequestReview) bool { + commit, head := strings.TrimSpace(rv.GetCommitID()), strings.TrimSpace(head) + if commit == "" || head == "" || commit == head { + return true + } + reach, known := c.reviewReachesHeadKnown(ctx, owner, repo, number, head, rv) + return !known || reach.ok } func (c *Engine) commentTrustedAuthorMerge(ctx context.Context, owner, repo string, number int, author, role, permission, sha string) error { diff --git a/src/pkg/github/automerge/automerge_sweep_trusted_author_test.go b/src/pkg/github/automerge/automerge_sweep_trusted_author_test.go index dcd76aea42..66d0be0bc8 100644 --- a/src/pkg/github/automerge/automerge_sweep_trusted_author_test.go +++ b/src/pkg/github/automerge/automerge_sweep_trusted_author_test.go @@ -495,11 +495,11 @@ func TestTrustedAuthorGitHubSignalErrorsAndEdges(t *testing.T) { if p, err := engine.authorRepoPermission(context.Background(), "acme", "widget", "plain"); err != nil || !p.Allowed || p.Level != "admin" { t.Fatalf("plain permission = %+v err=%v, want allowed admin via permission", p, err) } - if _, err := engine.hasOutstandingChangesRequested(context.Background(), "acme", "widget", 9); err == nil { + if _, err := engine.hasOutstandingChangesRequested(context.Background(), "acme", "widget", 9, "sha"); err == nil { t.Fatal("hasOutstandingChangesRequested should surface API errors") } - if blocked, err := engine.hasOutstandingChangesRequested(context.Background(), "acme", "widget", 10); err != nil || blocked { - t.Fatalf("PR 10 blocked=%v err=%v, want dismissed on page 2 to clear the block", blocked, err) + if standing, err := engine.hasOutstandingChangesRequested(context.Background(), "acme", "widget", 10, "sha"); err != nil || standing.reason("changes-requested") != "" { + t.Fatalf("PR 10 standing=%+v err=%v, want dismissed on page 2 to clear the block", standing, err) } if page != 2 { t.Fatalf("review pages fetched = %d, want 2", page) diff --git a/src/pkg/stageengine/derive_pr_classify.go b/src/pkg/stageengine/derive_pr_classify.go index 7aa3016ed0..be09ae6b1a 100644 --- a/src/pkg/stageengine/derive_pr_classify.go +++ b/src/pkg/stageengine/derive_pr_classify.go @@ -563,8 +563,11 @@ func ClassifyStage(o stageObservation) stageVerdict { return WithHumanApprovalReason(stageVerdict{Stage: stagelabels.ReadyForHumanMerge, Rank: stageRankOwned, Human: true}, humanApprovalReason) } // An open issue the PR closes is held or parked on a person: - // removing the issue's label releases the PR on the next sweep. - if _, _, _, linked := prstage.ParseLinkedIssueReason(reason); linked || + // removing the issue's label releases the PR on the next sweep. A + // change request left on an older commit waits on its reviewer's + // re-review, never on the author who pushed past it. + _, reReview := prstage.ParseReReviewRequested(reason) + if _, _, _, linked := prstage.ParseLinkedIssueReason(reason); linked || reReview || strings.HasPrefix(reason, "excluded-label:") || stageNeedsHumanReasons[reason] { if HasLabelFold(o.Labels, "needs-rebase") { return stageVerdict{Stage: fixing, Rank: stageRankOwned} diff --git a/src/pkg/stageengine/derive_pr_rereview_test.go b/src/pkg/stageengine/derive_pr_rereview_test.go new file mode 100644 index 0000000000..38ab843959 --- /dev/null +++ b/src/pkg/stageengine/derive_pr_rereview_test.go @@ -0,0 +1,41 @@ +package stageengine + +import ( + "testing" + + "github.com/hivecommons/hive/pkg/authorkind" + "github.com/hivecommons/hive/pkg/stageengine/prstage" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// projectbluefin/chairlift#799: a change request left on an older commit +// the author pushed past waits on the reviewer. It is a person's decision +// (085), never the author's 071 / 072, so no nudge goes out and no adoption +// clock runs against an author who did the work. A needs-rebase label is +// still the author's. +func TestClassifyStageReReviewRequestedWaitsOnTheReviewer(t *testing.T) { + reason := prstage.ReReviewRequestedReason([]string{"Danathar"}) + for _, tc := range []struct { + name string + lane string + kind authorkind.Kind + labels []string + want stagelabels.Stage + human bool + }{ + {name: "clanker PR on the contributor lane", lane: stageLaneContributor, kind: authorkind.Clanker, want: stagelabels.NeedsDecision, human: true}, + {name: "human PR on the trusted-author lane", lane: stageLaneTrusted, kind: authorkind.Human, want: stagelabels.NeedsDecision, human: true}, + {name: "needs-rebase is still the author's", lane: stageLaneContributor, kind: authorkind.Clanker, labels: []string{"needs-rebase"}, want: stagelabels.ReturnedToContributor}, + } { + t.Run(tc.name, func(t *testing.T) { + v := ClassifyStage(stageObservation{Lane: tc.lane, Reason: reason, HeadSHA: goldenHead, AuthorKind: tc.kind, Labels: tc.labels}) + if v.Stage != tc.want || v.Human != tc.human { + t.Fatalf("classified as %+v, want stage=%s human=%v", v, tc.want, tc.human) + } + }) + } + // The head-scoped request keeps today's route: the author's turn. + if v := ClassifyStage(stageObservation{Lane: stageLaneContributor, Reason: contributorLaneReasonChangesRequested, HeadSHA: goldenHead, AuthorKind: authorkind.Clanker}); v.Stage != stagelabels.ReturnedToContributor { + t.Fatalf("changes requested on the head classified as %+v, want 072", v) + } +} diff --git a/src/pkg/stageengine/prstage/reasons.go b/src/pkg/stageengine/prstage/reasons.go index 45b5debc3c..aeddee5ffb 100644 --- a/src/pkg/stageengine/prstage/reasons.go +++ b/src/pkg/stageengine/prstage/reasons.go @@ -1,6 +1,7 @@ package prstage import ( + "slices" "strconv" "strings" @@ -187,6 +188,42 @@ func ParseLinkedIssueReason(reason string) (kindPrefix string, issue int, label return kindPrefix, n, label, true } +// ReReviewRequestedReasonPrefix: every change request still standing on the +// PR was left on an older commit, and the author has pushed content since. +// GitHub keeps such a review blocking until its reviewer re-reviews or a +// maintainer dismisses it, so the PR waits on the reviewer, not on its +// author. The rest names the reviewers, comma-separated. +const ReReviewRequestedReasonPrefix = "re-review-requested:" + +// ReReviewRequestedReason formats the lane reason for reviewers whose change +// requests are on older commits, sorted so the reason is stable across +// sweeps: `re-review-requested:alice,bob`. +func ReReviewRequestedReason(reviewers []string) string { + var logins []string + for _, r := range reviewers { + if r = strings.TrimPrefix(strings.TrimSpace(r), "@"); r != "" && !slices.Contains(logins, r) { + logins = append(logins, r) + } + } + slices.SortFunc(logins, func(a, b string) int { return strings.Compare(strings.ToLower(a), strings.ToLower(b)) }) + return ReReviewRequestedReasonPrefix + strings.Join(logins, ",") +} + +// ParseReReviewRequested returns the reviewers a ReReviewRequestedReason +// names. ok is false for any other reason. +func ParseReReviewRequested(reason string) (reviewers []string, ok bool) { + rest, found := strings.CutPrefix(strings.TrimSpace(reason), ReReviewRequestedReasonPrefix) + if !found { + return nil, false + } + for _, r := range strings.Split(rest, ",") { + if r = strings.TrimSpace(r); r != "" { + reviewers = append(reviewers, r) + } + } + return reviewers, true +} + // ClosingContradictionReason formats the refusal for a PR body that closes // issue and says it stays open: `closing-contradiction:#1023`. func ClosingContradictionReason(issue int) string { diff --git a/src/pkg/stageengine/prstage/rereview_test.go b/src/pkg/stageengine/prstage/rereview_test.go new file mode 100644 index 0000000000..730f3aa804 --- /dev/null +++ b/src/pkg/stageengine/prstage/rereview_test.go @@ -0,0 +1,20 @@ +package prstage + +import ( + "slices" + "testing" +) + +func TestReReviewRequestedReasonRoundTrip(t *testing.T) { + reason := ReReviewRequestedReason([]string{"zed", "@Alice", "", "zed"}) + if reason != "re-review-requested:Alice,zed" { + t.Fatalf("reason = %q, want sorted, deduped logins without @", reason) + } + got, ok := ParseReReviewRequested(reason) + if !ok || !slices.Equal(got, []string{"Alice", "zed"}) { + t.Fatalf("parse = %v %v", got, ok) + } + if _, ok := ParseReReviewRequested(ContributorLaneReasonChangesRequested); ok { + t.Fatal("changes-requested parsed as a re-review") + } +}