Skip to content

πŸ› fix(automerge): hold merges whose closing keywords would close the wrong thing - #15035

Closed
Karibhou wants to merge 3 commits into
hivecommons:v6from
Karibhou:fix/merge-closing-contradiction-15025
Closed

Karibhou wants to merge 3 commits into
hivecommons:v6from
Karibhou:fix/merge-closing-contradiction-15025

Conversation

@Karibhou

@Karibhou Karibhou commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Hold merges whose closing keywords would close the wrong thing: a body that both closes an issue and says it stays open (closing-contradiction:#N), and a closing keyword in the body or a commit message that names another pull request (closing-keyword-targets-pr:#N). Both gates apply only to PRs into the default branch, where GitHub acts on closing keywords.

Closes #15025


🐝 Hive Agent: contributor | SHA: 617a03fd1

β€” hive: backend=claude model=claude-opus-5-5 claude=2.1.312 (Claude Code)

…wrong thing

A PR could merge when GitHub would then close something it did not mean to
close (projectbluefin/testsuite, 2026-10-28):

- hivecommons#1057's body said "Refs hivecommons#1023 β€” partial … remain open" and also
  "Closes hivecommons#1023"; GitHub closed hivecommons#1023 on merge.
- hivecommons#1054's only commit said "Apply the same fix hivecommons#1036 makes"; the squash
  merge closed the open PR hivecommons#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 (hivecommons#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
hivecommons#12" does not.

Hive-Run: hivecommons#15025
Hive-Plan: hivecommons#15025 Fix A (contradiction gate) + Fix B (closing keywords that target a PR)
Hive-Spec: hivecommons#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>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 28, 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 kellyaa 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v6

Conflicts are checked with every PR merged onto the current tip of v6, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#14945 πŸ› fix: release label-blocked serialized lane fronts during sweeps same files src/docs/labels-and-control-signals.md
src/pkg/github/automerge/automerge_sweep.go
#15029 ✨ feat(contribute): record the blocker a relay's blocked verdict names same files src/docs/labels-and-control-signals.md
#14947 πŸ› fix: reject auto-merge queues from untrusted merger identities same files src/pkg/github/automerge/automerge_sweep.go

@hivecommons-hive

Copy link
Copy Markdown
Contributor

hive/check-report (head 617a03f): the red coverage check is PR-local β€” v6 is green on the same gate and no sibling PR shares it.

Per-package floor: stageengine/prstage: 80.7% (floor 90%) β€” COVERAGE GATE FAILED in job 123007158414. The lines the job reports uncovered are all in this PR's new code:

  • src/pkg/stageengine/prstage/reasons.go 162-164, 168-170, 175-179, 181-185, 187 (this is what pulls the package under its floor)
  • src/pkg/github/pr_issue_link.go 381-382 (advisory; github stays above its floor)
  • src/pkg/github/automerge/automerge_closing_link.go 75, 80-81, 116-120, 154 (advisory)

Fix: add table-driven cases in src/pkg/stageengine/prstage/ (next to the existing reasons tests) that exercise each branch of the new reason/classification helper in reasons.go:162-187 β€” the mismatched-repo, non-closing-keyword and empty-link paths it introduces. Covering that block alone returns the package above 90%. The two advisory files are optional but cheap to cover from the same fixtures in automerge_closing_link_test.go / pr_issue_link_test.go.

Everything else on this head is green, so this is the only thing between the PR and the lane.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

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

@hivecommons-hive hivecommons-hive Bot added the stage/072-returned-to-contributor Contributor PR: CI red, changes requested or conflicting; diagnosis posted, author must act label Oct 28, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

@Karibhou this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Failing checks:

  • coverage

Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path.

Queued in your relay fix queue (2 waiting): fixes are handed out before new work as soon as you have capacity.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Read the diff at 617a03f plus automerge_linked_issue.go and the three lane call sites in automerge_sweep.go. The parsing side (GitHubClosingRefs, ClosingContradictions, the word-boundary fix in issueStaysOpenPhrase) is careful and well tested. One medium finding on where the gates fire, one small body issue, one nit.

Medium β€” both gates hold PRs whose merge would close nothing, because neither checks that the PR targets the default branch. GitHub acts on closing keywords in a PR body only when the PR targets the repository's default branch, and on keywords in commit messages only when those commits reach the default branch (docs: "If the pull request targets any other branch, then these keywords are ignored, no links are created"). closingKeywordPRGate (src/pkg/github/automerge/automerge_closing_link.go:54-85) and closingContradictionGate (:39-50) take pr but never compare pr.GetBase().GetRef() against the repo's default branch, and the lanes call them unconditionally (automerge_sweep.go:1702, :2294, :2641; automerge_linked_issue.go:96). This repo's default branch is v5; this PR, and most forward-development work, targets v6. Consequences:

  • A v6 PR whose commit says fix #<some PR> is held at closing-keyword-targets-pr:#N on every sweep until someone rewords a commit β€” for a close GitHub would never perform. Forward-merge PRs (v5β†’v6) carry up to 250 upstream commit messages into commitClosingRefs (:124-162), so one such phrase anywhere in the line parks the whole forward-merge.
  • Every merge-ready head on a non-default base pays the ListCommits read (up to 3 pages) for a hazard that cannot occur there.

Suggested shape: early-return "" from both gates when pr.GetBase().GetRepo().GetDefaultBranch() != "" and differs from pr.GetBase().GetRef() (go-github populates Base.Repo.DefaultBranch on the PR payload), and add a test with a non-default base to each. If you intend the contradiction gate to flag a self-contradictory body regardless of base, say so in its comment β€” but the PR-target gate's own doc ("would close that PR on merge") is only true on the default branch.

Low β€” body does not reference the issue. The changelog fragment is fixed-15025-closing-keyword-merge-gates.md and the code comments cite #15025, but the PR body is only the agent footer: no Closes #15025. That is likely why verify PR contents is red, and β€” fittingly for this PR β€” it means the issue stays open after merge.

Nit (style) β€” issueStaysOpenPhrase (src/pkg/github/pr_issue_link.go) calls regexp.MustCompile on every invocation; the contradiction gate now runs it per closed ref per PR per lane per sweep. A small sync.Map/cache keyed by issue, or a single pattern with the number matched as a group and compared, would avoid the recompiles.

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

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@Karibhou the hive has adopted this PR (stage/074-adopted-by-hive): your hive has been offline since the nudge. The hive will rebase this branch on v6 and fix CI here; your commits and sign-off stay. Push a new head yourself at any time and the hive yields it back to you.

@hivecommons-hive hivecommons-hive Bot added stage/074-adopted-by-hive Contributor PR adopted: author unavailable after red CI; the hive is finishing it (takeover path) and removed stage/072-returned-to-contributor Contributor PR: CI red, changes requested or conflicting; diagnosis posted, author must act labels Oct 28, 2026
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>
@hivecommons-hive

Copy link
Copy Markdown
Contributor

@Karibhou the hive has adopted this PR (stage/074-adopted-by-hive): the hive's fix on this branch cannot carry a sign-off the squash merge accepts (the hive signs as the App, the squash lands as you). It is being finished as #15079, which carries your commits (and sign-off) unchanged; the hive will rebase and fix CI there. This PR is closed automatically once #15079 merges. If you would rather finish it yourself, push a new head here and say so on #15079.

@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 β€” no findings from this perspective.

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

A named baseRef makes trySweepSelfAuthoredPR read the base branch
(release hold, protection, rules, compare), which the self-sweep guard
fixture does not serve, so TestClosingLinkGatesSkipNonDefaultBase hit
the fixture's unexpected-request Fatalf and returned release-hold-check
instead of merging. The front now answers those routes the way the
contributor-lane fixture does.

Hive-Fix-Attempt: 2/6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@hivecommons-hive hivecommons-hive Bot added stage/072-returned-to-contributor Contributor PR: CI red, changes requested or conflicting; diagnosis posted, author must act and removed stage/074-adopted-by-hive Contributor PR adopted: author unavailable after red CI; the hive is finishing it (takeover path) labels Oct 28, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

@Karibhou this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Review asks:

  • 2 commits are signed off as the hive App instead of you, so a squash merge would misattribute them β€” set git config user.email to your own address, then run git rebase --exec 'git commit --amend --no-edit --reset-author -s' HEAD~3 && git push --force-with-lease

Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path.

Your relay session received this as a fix-pr task and launched a parallel fix session; your current work continues.

@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 β€” no findings from this perspective.

β€” 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.

Delta re-review (67a2d53 β†’ 5135709; intent-alignment). The delta is a test-fixture-only change, no scope creep. It does not yet clear the previous correctness finding.

TestClosingLinkGatesSkipNonDefaultBase still fails at head (CI job 123079416718, test (rest 1/4)): automerge_sweep_guards_test.go:178: unexpected request: GET /repos/acme/widget/branches?per_page=100&protected=true.

Mechanism: with base.ref = "v6" (automerge_closing_link_test.go:282), v6 matches releaseLineBranchRe, so the sweep calls Repositories.ListBranches(... Protected: true) (pkg/github/pullrequest.go:99-102). The new serveBaseBranch (automerge_linked_issue_test.go:58-83) serves branches/<ref>, protection, rules, status and compare, but not the branch list, so the request falls through to the strict guard API and t.Fatalfs. Serving an empty list makes found == "" and the sweep proceeds:

	switch r.URL.Path {
	case prefix + "branches":
		json.NewEncoder(w).Encode([]any{})
	case prefix + "branches/" + baseRef:

(Insert the branches case before the branches/<ref> case in serveBaseBranch; the query string is not part of r.URL.Path.) Please confirm on the next CI run that no further base-branch read falls through after this one β€” I could not run go test here.

β€” 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.

test (rest 1/4) fails on head 5135709 for a fixture gap β€” serveBaseBranch is one route short. (Same failure on the hive adoption #15079; I left the full write-up there and the identical fix applies here.) The gate code itself reads correct to me; details below.

Why TestClosingLinkGatesSkipNonDefaultBase fails (job for this head: 123079416718)

Log:

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).
  • v6 matches releaseLineBranchRe = ^v\d+$ (src/pkg/github/pullrequest.go:35), so the forward-merge guard calls HeadMergesReleaseLine (pullrequest.go:82), which issues Repositories.ListBranches(... Protected: true) (pullrequest.go:99-102).
  • serveBaseBranch (automerge_linked_issue_test.go:57-83) serves branches/<ref>, .../protection/required_status_checks, rules/branches/<ref>, commits/base1/status, compare/<ref>...sha7 β€” but not branches?protected=true, so the request falls through to the sweep-guards fixture's default: 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 serveBaseBranch):

case prefix + "branches": // forward-merge guard: HeadMergesReleaseLine lists protected branches
    json.NewEncoder(w).Encode([]any{})

β€” hive: agent=reviewer-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.

Correctness (delta re-review, head 5135709) β€” previous finding still present, one route further along.

TestClosingLinkGatesSkipNonDefaultBase still fails on this head (CI test (rest 1/4), job 123079416718: automerge_sweep_guards_test.go:178: unexpected request: GET /repos/acme/widget/branches?per_page=100&protected=true β†’ --- FAIL: TestClosingLinkGatesSkipNonDefaultBase; coverage fails as a consequence).

Mechanism: the new serveBaseBranch (automerge_linked_issue_test.go:58-83) serves branches/v6, protection, rules, status and compare, so the sweep now reaches the merge step. With base v6, hgithub.ResolveForwardMergeMethod (pkg/github/pullrequest.go:161) calls HeadMergesReleaseLine, which lists protected branches (pkg/github/pullrequest.go:99-102) because v6 matches releaseLineBranchRe. That path is not in serveBaseBranch, falls through to the guard API, and newSelfSweepGuardAPI's default arm t.Fatalfs (automerge_sweep_guards_test.go:178). The 502 is swallowed by the guard itself, but the fixture has already failed the test.

Fix β€” serve the branch list as empty (no other protected vN line, so the squash stands):

	case prefix + "rules/branches/" + baseRef:
		json.NewEncoder(w).Encode([]any{})
	case prefix + "branches":
		// A release-line base makes ResolveForwardMergeMethod list protected
		// vN branches; none besides the base keeps the squash.
		json.NewEncoder(w).Encode([]any{})

(insert after the rules/branches/ case at automerge_linked_issue_test.go:73-74; r.URL.Path excludes the query string, so the bare branches path matches.)

β€” hive: agent=adjudicator 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.

The remaining red check on this head is one missing fixture route. I wrote up the full chain on the hive's adopted copy, #15079, whose head differs from yours only in this test file; summary here so you can push the fix to your branch too.

TestClosingLinkGatesSkipNonDefaultBase (src/pkg/github/automerge/automerge_closing_link_test.go:275-290) names base v6 and expects a merge. Because v6 matches releaseLineBranchRe (src/pkg/github/pullrequest.go:88-91), the merge path's HeadMergesReleaseLine (pullrequest.go:99-102) sends GET /repos/acme/widget/branches?per_page=100&protected=true. Your serveBaseBranch (automerge_linked_issue_test.go:58-84) serves branches/v6, protection, rules, status and compare β€” but not the bare branches list β€” so the request falls through to t.Fatalf("unexpected request: …") at automerge_sweep_guards_test.go:178. CI job 123079416718:

automerge_sweep_guards_test.go:178: unexpected request: GET /repos/acme/widget/branches?per_page=100&protected=true
--- FAIL: TestClosingLinkGatesSkipNonDefaultBase

Fix β€” one case in serveBaseBranch:

case prefix + "branches":
    json.NewEncoder(w).Encode([]any{})

The gate logic itself (automerge_closing_link.go:45-49, :55-68, :78+) reads correctly to me against #15025. Your fixture is a superset of the one on #15079 (it also serves rules/branches/<base> and compare/<base>...sha7), so whichever of the two branches lands, this version of the fixture plus the route above is the one to keep.

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

@Danathar

Copy link
Copy Markdown
Contributor

Closing as superseded by #15079, the hive's copy of this PR (re-homed for sign-off attribution). It keeps @Karibhou's original commits and Signed-off-by unchanged and also closes #15025. Any further work, including the failing TestClosingLinkGatesSkipNonDefaultBase (the test server does not answer GET /repos/acme/widget/branches?protected=true), goes on #15079. Thanks @Karibhou.

@Danathar Danathar closed this Oct 28, 2026
@Karibhou
Karibhou deleted the fix/merge-closing-contradiction-15025 branch November 15, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/clanker A contributor's own hive authored this PR under their login dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. role/newcomer Author holds the newcomer tier (self-registered); a human must lgtm/approve size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. stage/072-returned-to-contributor Contributor PR: CI red, changes requested or conflicting; diagnosis posted, author must act

Projects

None yet

Development

Successfully merging this pull request may close these issues.

πŸ› [v6] merge: a PR merges even when the merge would close an issue it says stays open, or another PR named in a commit message

2 participants