Repository navigation
π fix(automerge): hold merges whose closing keywords would close the wrong thing - #15079
Conversation
β¦wrong thing A PR could merge when GitHub would then close something it did not mean to close (projectbluefin/testsuite, 2026-10-28): - #1057's body said "Refs #1023 β partial β¦ remain open" and also "Closes #1023"; GitHub closed #1023 on merge. - #1054's only commit said "Apply the same fix #1036 makes"; the squash merge closed the open PR #1036. A. ClosingContradictions (pkg/github) returns each repo issue the body both closes with a GitHub closing keyword and says stays open or is partial. Every lane refuses it right after its label checks with closing-contradiction:#N, at no API cost, so the PR never reaches 090/095; a body edit releases it. A bare "Refs #N" next to "Closes #N" is unaffected (#10826). B. The linked-issue gate now also refuses with closing-keyword-targets-pr:#N when a closing keyword in the body, or in a commit message on the head (Options.ScanCommitClosingKeywords, on in the hive), names a pull request. Target kinds are cached per number and commit messages per head. Both reasons route to 070/071/072 by author kind, and the contributor nudge names the fix; for a contradiction it says a body edit is enough. Only the form GitHub acts on counts as a close (GitHubClosingRefs): "Fixes the bug in #12" does not. Hive-Run: #15025 Hive-Plan: #15025 Fix A (contradiction gate) + Fix B (closing keywords that target a PR) Hive-Spec: #15025#acceptance-criteria Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HRH6km45ugnaTypgmg1q61 Signed-off-by: Karibhou <Karibhou@users.noreply.github.com>
GitHub acts on closing keywords only when a PR merges into the repository's default branch, so a PR into another base (a forward-merge carrying upstream commit messages) closes nothing; both gates now pass it without a read. issueStaysOpenPhrase compiles its pattern once. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.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.
Read at 67a2d53 against v6 with the callers open; this looks correct to me and matches #15025.
What I verified:
- Both gates re-run from a fresh
PullRequests.Getevery pass (automerge_contributor_lane.go:1184,automerge_sweep.goself/trusted/queued), andclosingContradictionGatereads onlypr.GetBody(), so the nudge's "No new commit is needed" (automerge_contributor_nudge.go,closingLinkAsk) is true β a body edit releases the hold on the next tick, per the acceptance criteria. - Holding on a closed target PR (
automerge_closing_link_test.go:162) is what #15025 asks for ("open or closed PR"), so I did not count it as a defect. commitClosingRefscaches perrepo#PR@headandnumberIsPullRequestperrepo#N, andlinkedIssueGateseeds the kind cache from reads it already makes β one extra commit-list read per merge-ready head, no re-reads.closingKeywordsApplyfails toward the gate when the payload lacksbase.repo.default_branch. Note hive's default branch isv5, so on hive itself these gates skip PRs intov6β which is the intended scope per the issue, just worth knowing when checking it live.go build ./pkg/github/... ./pkg/stageengine/... ./cmd/hive/passes at the head.
One open question, info only: GitHubClosingRefs runs on stripClosingFalsePositiveText output, which drops URLs, so a body like Closes https://github.com/o/r/pull/N (which GitHub also acts on) is not caught. Not a wrong hold, just a gap; fine to leave for a follow-up if you agree.
#15035 is this same head as pushed by @Karibhou; this PR is the hive's adoption of it, so I have reviewed the code once and recorded the same verdict on both.
β hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Read the gate code against the v6 tree and the merge lanes that call it; the gate logic looks correct to me, but the PR's own new test fails deterministically in CI, so this needs one fixture change before it can merge.
TestClosingLinkGatesSkipNonDefaultBase fails in test (rest 1/4) β job 123059857672:
automerge_closing_link_test.go:289: reason = "release-hold-check", err = unexpected status code: 502 Bad Gateway, merges = 0
Mechanism: automerge_closing_link_test.go:282 sets front.baseRef = "v6", so for the first time in this fixture family the PR payload carries a non-empty base.ref. trySweepSelfAuthoredPR then reaches releaseHoldActive (automerge_sweep.go:1779), which does GetBranch(β¦, "v6") (automerge_sweep.go:1627). newSelfSweepGuardAPI has no route for /repos/acme/widget/branches/v6 and falls into its default: t.Fatalf("unexpected request β¦") (automerge_sweep_guards_test.go:177); the front turns that into a 502 and the sweep returns release-hold-check instead of merging. The other fixtures pass only because their payloads leave base.ref empty, which short-circuits releaseHoldActive at automerge_sweep.go:1624.
Fix is in the test only: serve /repos/acme/widget/branches/<baseRef> (a commit SHA with no release-in-progress status), plus the β¦/protection/required_status_checks and /rules/branches/<baseRef> reads that follow, the way automerge_contributor_lane_test.go:329-331 already does for its fx.baseRef. The coverage job is red only because it refuses to report while a shard failed.
What I verified and have no concerns about:
gitHubClosingRefPattern(pr_issue_link.go:405) uses the same three capture groups asclaimRefPattern, soparseRefsreads it correctly; dropping the 40-char prose gap is the right call for a merge gate β GitHub closes nothing on "Fixes the bug in #12".closingKeywordsApply(automerge_closing_link.go:45) matches GitHub's behaviour (closing keywords act only on the default branch) and fails toward the gate when the payload omitsdefault_branch. Note for operators:hivecommons/hive's default branch is currentlyv5, so neither gate holds anything onv6PRs in this repo β correct, since GitHub would not close anything either, but it means the fix is exercised first on repos like projectbluefin/testsuite.linkedIssueGatealready reads every closed issue;noteClosingTargetKindreuses those reads soclosingKeywordPRGatecosts no second GET for body refs. Commit-list read is bounded (3 pages) and cached per head; both caches reset at 4096 rather than growing unbounded.- Read errors fail closed via
linkedIssueReasonCheck;ClassifyStageroutes both new reasons tofixing, matching the labels doc change. go build ./...is clean at67a2d53.
Body matches the diff (two gates, default-branch-only, Closes #15025). Nothing here needs a maintainer decision β one fixture fix and this should go green.
β hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
A named base ref sends trySweepSelfAuthoredPR to the base branch for the required-check set and the release-hold tip status; the guard fixture only knows PR 7's head, so TestClosingLinkGatesSkipNonDefaultBase hit its default handler and returned release-hold-check instead of merging. Serve /branches/<base>, its (unprotected) required_status_checks and the base tip's combined status from the front when baseRef is set. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
There was a problem hiding this comment.
test (rest 1/4) fails on this head for a fixture gap, not a logic bug β one route short. The gate code itself reads correct to me; details below.
Why TestClosingLinkGatesSkipNonDefaultBase fails (same on #15035's newer head 5135709)
Job 123083153740:
automerge_sweep_guards_test.go:178: unexpected request: GET /repos/acme/widget/branches?per_page=100&protected=true
--- FAIL: TestClosingLinkGatesSkipNonDefaultBase
Mechanism:
- The test sets
front.baseRef = "v6"(automerge_closing_link_test.go:282). v6matchesreleaseLineBranchRe = ^v\d+$(src/pkg/github/pullrequest.go:35), so the forward-merge guard callsHeadMergesReleaseLine(pullrequest.go:82), which issuesRepositories.ListBranches(... Protected: true)(pullrequest.go:99-102).- Neither the stub added in
7819702(automerge_linked_issue_test.go:96-108: servesbranches/<ref>,.../protection/required_status_checks,commits/base1/status) nor #15035'sserveBaseBranch(addsrules/branches/<ref>andcompare/<ref>...sha7) answersbranches?protected=true, so the request falls through to the sweep-guards fixture'sdefault: t.Fatalf(automerge_sweep_guards_test.go:178).
The production path tolerates it (the guard logs head-history check failed and keeps the method, pullrequest.go:163-166) β it is only the fixture's Fatalf that fails the test. The coverage and test jobs are downstream of this.
Fix (one case in the stub):
case prefix + "branches": // forward-merge guard: HeadMergesReleaseLine lists protected branches
json.NewEncoder(w).Encode([]any{})Suggest taking #15035's serveBaseBranch (head 5135709) as the base since it already serves the rules/branches and compare reads this stub lacks, then add the branches case to it. Fatalf aborts on the first unknown route, so those may surface next.
Core logic β read, no defects found
closingKeywordsApply(automerge_closing_link.go:48-52) fails toward the gate whenbase.ref/default_branchare absent β correct direction for a partial payload.linkedIssueGaterecords kind for every number it already reads (automerge_linked_issue.go:77,83) soclosingKeywordPRGatecosts no second GET for body refs;numberIsPullRequesttreats 404/410 as not-a-PR and fails closed otherwise. Caches are bounded (closingLinkCacheMax), mutex-guarded.closingContradictionGateis placed before any API-costing step in all four lanes (automerge_sweep.go:1702,2294,2644;automerge_contributor_lane.go:1209).issueStaysOpenPatternword-bounds the number, so#12 stays openno longer matches#1β strictly better than the oldstrings.Containslist it replaces.
Open question (not a defect, fail-open only): GitHubClosingRefs runs on stripClosingFalsePositiveText output, which drops URLs (prclaims.go:539), so GitHub's Closes https://github.com/o/r/issues/N form is not seen by either gate. Consistent with the existing claim parser; noting so nobody expects it to catch that shape.
I have not approved or closed anything.
β hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Read the gate against the tree at merge-base 5aec2fd; it looks correct to me. The fixture gap that held #15035 (branches?protected=true falling through to t.Fatalf) is closed on this head and test (rest 1/4) / coverage are green at 80234a1.
What I verified:
closingKeywordsApply(automerge_closing_link.go:45-49) keys onbase.repo.default_branch. This repo's default branch isv5, so the gates no-op on v6-based PRs β including this one β which matches GitHub's own rule (closing keywords only act on PRs into the default branch). Partial payloads fail toward the gate.GitHubClosingRefs(pr_issue_link.go:412-421) uses the strictkeyword\s*:?\s+#Nform, notclaimRefPattern's 40-char prose gap, so "Fixes the bug in #12" is a hive claim but not a merge refusal.parseRefs(prclaims.go:547) reads refs fromm[0], so the new pattern's group layout is irrelevant to it.numberIsPullRequestreuses the kindslinkedIssueGatealready noted (automerge_linked_issue.go:77,83), so the body path costs no extra GET; the commit read is once perrepo#PR@headand bounded at 3 pages / 4096 entries.- All five lanes run
closingContradictionGatebefore admission andclosingKeywordPRGateonly vialinkedIssueGateon a would-merge head; the reason strings route tofixingviaParseClosingLinkReason(derive_pr_classify.go:414).
One low note, not blocking: nudgeHoldSentence (automerge_contributor_nudge.go) says "until the head changes" for closing-keyword-targets-pr:#N, but when the offending keyword is in the body (the ask text itself says "in the PR body or a commit message"), a body edit alone releases it β both gates are stateless. Consider "until the body or head changes".
β hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Read head 80234a1 against v6 with the callers open (automerge_sweep.go:1702/2294/2641, automerge_contributor_lane.go:1209, automerge_linked_issue.go:96). Both earlier asks are settled on this head: closingKeywordsApply (automerge_closing_link.go:45-49) skips non-default bases, and test (rest 1/4) / coverage are green. The parsing side and the contradiction gate look correct to me. One medium finding on the PR-target gate.
Medium β closingKeywordPRGate holds a merge for a closing keyword that names an already-closed PR, which GitHub would do nothing about.
numberIsPullRequest(automerge_closing_link.go:124-141) returnsissue.IsPullRequest()and never looks atissue.GetState();closingKeywordPRGate(:84-104) refuses onisPRalone.TestClosingKeywordInCommitMessageTargetingPRcase"closed pull request"(automerge_closing_link_test.go:162) pins this as intended.- Mechanism:
gitHubClosingRefPattern(pr_issue_link.go:405-406) is\b(close|closes|closed|fix|β¦)\b\s*:?\s+#N, so ordinary hive narration matches it. A live example sits in this queue: #15072's body (basev5, the default) says "the duplicate-fix sweep closed #14977 unmerged". #14977 is a closed PR βclosing-keyword-targets-pr:#14977βClassifyStagesends it to 071 (derive_pr_classify.go:411-415) and the nudge asks the author to rewrite that sentence as "same change as #14977" (automerge_contributor_nudge.go:245), which does not fit a historical statement. - Consequence: the harm the gate exists for (#15025:
#1054closed the open#1036) cannot occur against a closed PR β GitHub's close is a no-op there β but the cost is real: a green PR parks at 071 and a human gets a nudge comment. Hive-authored bodies ("Supersedes #N β¦ closed #N", adoption/revert narratives) will hit this regularly once the default branch is one these gates apply to.
Suggested fix: refuse only when the target is a PR and strings.EqualFold(issue.GetState(), "open"). The closingTargetKinds cache must then not treat a closed PR as settled forever (a closed PR can be reopened): either cache only the kind and re-read state for PR targets, or key the cached result by head like closingCommitRefs does. Flip the "closed pull request" case at :162 to expect a merge.
Info: the body still says this branch is 67a2d53 "unchanged"; the head is now 80234a1 with three fixture-only commits on top (7819702, e3310c9, 80234a1). Expected for the adoption flow, just noting it for whoever reads the body.
β hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1
GitHub's close of an already-closed pull request is a no-op, so a body or commit message that says "closed #N" about a merged PR must not park the merge. closingKeywordPRGate now refuses only for open pull-request targets, and the closing-link cache remembers only the permanent fact that a number is not a pull request; pull requests are read again each tick so a held merge releases once the target closes. The linked-issue gate hands its reads to the PR gate for the tick, so nothing is read twice. Hive-Fix-Attempt: 4/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
Hive filed review findings that do not block this PR as backlog items:
Cap: 10 backlog item(s) per PR per day. |
There was a problem hiding this comment.
Reviewed (intent-alignment, delta 80234a1β¦676316a) β previous findings resolved; one advisory.
- Fixed: PR body now lists
676316a(stale head reference). - Fixed:
closing-keyword-targets-prno longer holds on closed PR targets (src/pkg/github/automerge/automerge_closing_link.go:149-152isOpenPullRequest;automerge_linked_issue_test.go:236"closed pull request target does not block"). - Advisory (non-blocking): #15025's acceptance criteria say a closing keyword targeting "an open or closed PR" is not merged; this head deliberately passes closed PR targets (
automerge_closing_link.go:71-73, docssrc/docs/labels-and-control-signals.md:465, changelog). The narrowing preserves the issue's actual harm (GitHub cannot re-close a closed PR) and was requested by the prior correctness review, so I judge it in intent; noting so the deviation from the issue text is on record.
β hive: agent=ci-maintainer backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Read the gates against the callers and the merge path. The design is sound and fails toward holding; one low-severity heuristic worth a look before it bites a real body.
Verified
closingKeywordsApply(automerge_closing_link.go:45) matches GitHub semantics: closing keywords only act when the base is the default branch, so hive's own v5/v6 PRs are never held by either gate, and an emptydefault_branchin the payload fails toward the gate.- Commit-message scanning is justified for every merge method:
merge_credit.go:185builds a merge commit from the title only, but the branch commits still land; the squash path (merge_credit.go:198) rebuilds the message from the commits or leaves GitHub's default, which is also commit-derived. SocommitClosingRefsreading the head's messages is conservative in the right direction. linkedIssueGate(automerge_linked_issue.go:72-99) hands its reads toclosingKeywordPRGateviareadThisTick, so a number is fetched once per tick;closingNonPRTargetsis only populated for non-PRs (noteClosingTarget), so an open PR is re-read every tick as the comment promises. Both caches are bounded and mutex-guarded.- All three lanes run
closingContradictionGatebefore admission (automerge_contributor_lane.go:1209,automerge_sweep.go:1702,:2294) and reachclosingKeywordPRGateonly throughlinkedIssueGateon a merge-ready head, as the file header says.
Low β referenceLineSaysPartial can hold a body that is not contradictory (pr_issue_link.go:425,453). partialReferenceNotePattern includes remain(s|ing) and addresses is a reference keyword, so a body with Closes #1234 and a sentence like "This addresses the remaining test gaps noted in #1234" is flagged closing-contradiction:#1234 and routed to fixing β yet that sentence says the work finishes the remainder. Release cost is just a body edit (no new head, per nudgeHoldSentence), so this is a nuisance rather than a defect, but the "remaining" alternative is the loosest one; consider requiring it to be adjacent to the ref (remainβ¦ open), or dropping it in favour of the explicit issueStaysOpenPhrase forms, which already cover "stays/remains open". The 1057 fixture (pr_issue_link_test.go:497) would still trip on partial.
Not a blocker. Body read second: it matches the diff (supersedes #15035, closes #15025; 676316a narrows the PR-target hold to open PRs as described).
β hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Supersedes #15035 (adopted in place, re-homed because a hive commit on the contributor branch cannot carry a squash-safe sign-off; original commits by @Karibhou preserved).
Closes #15025
This branch is #15035's head
67a2d53dd35aas pushed by @Karibhou (forkKaribhou/hive), plus review-fix commits on top (7819702, e3310c9, 80234a1 add test coverage; 676316a holds closing-keyword PR targets only while they are open). Last lane reason on the original:reviewer-verdict:changes_requested.Hive fix agent: rebase this branch on
v6, fix the failing checks / review asks, and push to THIS branch. Keep the original author's commits and theirSigned-off-by; add your own sign-off on your commits. Do not open another PR.Sign-off attribution: the original PR would squash the App's signed fixes as the contributor. This App-authored superseder keeps every original commit and sign-off unchanged and attributes the squash to the App instead. DCO and all merge gates still apply here.