Skip to content

✨ feature: enqueue eligible PRs into GitHub native merge queues - #15226

Closed
thatguywob wants to merge 1 commit into
hivecommons:v5from
thatguywob:feature/15198-native-merge-queue
Closed

thatguywob wants to merge 1 commit into
hivecommons:v5from
thatguywob:feature/15198-native-merge-queue

Conversation

@thatguywob

Copy link
Copy Markdown
Contributor

PRs targeting a GitHub native merge queue currently stop at merge-queue-required even after Hive approves the merge. The four automerge sweep lanes now detect the target queue and enqueue the validated head with GraphQL expectedHeadOid through the App installation transport.

The existing eligibility gates stay in place. Already queued PRs are left alone; rejected candidates are dequeued only when their entry belongs to this Hive App, with provenance checked again immediately before the write. Paused and automerge-disabled repositories receive the same cleanup. All writes use the existing mutation boundary. Queue removal events distinguish subsequent enqueue attempts in the effect journal, and uncertain writes reconcile against GitHub's current queue state.

Queue position/state is reported in the sweep reason and mapped to stage 100. Enqueueing emits no completed-merge audit or issue closure. Static-token clients retain their existing behavior. Mixed-authorship PRs that require a merge commit verify that the queue uses MERGE before enqueueing.

Validation: added regression coverage for all four lanes, pinned heads, idempotency, re-enqueue after removal, gate withdrawal, human/other-App ownership, paused repositories, mutation-boundary denials, GraphQL failures and stage classification. gofmt -l and git diff --check are clean. Tests were not run locally per AGENTS.md; CI owns test execution.

Operator details and workflow requirements are documented in src/docs/native-merge-queue.md. Automatic diagnosis of workflows missing merge_group remains the optional follow-up described in the issue. Withdrawal is periodic/event-driven and can race GitHub's eventual merge; it never bypasses a write denial.

Closes #15198

— hive: backend=codex


🐝 Hive Agent: contributor | SHA: 4412365d6

Use the App installation transport to detect and enqueue native merge
queues after the existing automerge gates, pinning the validated head.
Reconcile Hive-owned queue entries when gates break and report queue
position/state without recording enqueue as a completed merge.

Co-authored-by: jeefy <1394552+jeefy@users.noreply.github.com>
Hive-Run: hivecommons#15198
Hive-Plan: native-merge-queue
Hive-Spec: issue-15198#proposed-solution
Signed-off-by: thatguywob <thatguywob@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 29, 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 29, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

@thatguywob is auto-promoted for contributor-lane merging on this PR: the last 5 merged PRs by this author in this hive's repositories have no revert or sentinel-alert evidence. CI, reviewer verdict, diff fences, soak, holds and branch protection still apply.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

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

PR Title Relation Files
#15306 ✨ React to failed CI checks via webhook instead of waiting for the next sweep same files src/pkg/github/automerge/automerge_sweep.go

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

Decision needed: @clubanderson should decide whether the hive App may enqueue into GitHub native merge queues on its own behalf (a new merge path, #15198), and whether the own-entry withdrawal described below must be narrowed to non-transient reasons before it lands.

Read the new automerge_native_queue.go, the four lane insertion points in automerge_sweep.go / automerge_contributor_lane.go, and the gates that run before them on v5. The enqueue side is careful: expectedHeadOid pinning, enqueuer-provenance re-read immediately before any dequeue, no merged audit on enqueue, and the after_removal timeline cycle so the journal does not suppress a legitimate re-enqueue. CI is green.

One finding I could verify, with a dependency I could not — src/pkg/github/automerge/automerge_native_queue.go:107-160 (reconcileNativeQueueGate) and the hooks that call it:

  • In trySweepQueuedPR it is installed as a defer that fires with whatever reasonOut the function returns (automerge_sweep.go hunk at 2506); the self/trusted/contributor lanes call it from their stage(...) closures on every non-empty reason. The only reasons it skips are the native-merge-queued prefix and four routing reasons (lines 112-115). Everything else — not-mergeable, soak, review gate, head-changed-since-eval, etc. — withdraws the App's own queue entry.
  • The not-mergeable gate runs before tryNativeQueue in the queued lane (automerge_sweep.go:2598-2600 on v5), and mergeableFromState maps blocked → MergeableNo (src/pkg/github/client.go:1108).
  • So the question everything turns on: what does GitHub report as REST mergeable_state for a PR the App has just enqueued? If it is blocked while the entry awaits its merge group (GitHub's community discussion #73849 says it is; I could not confirm it against a live queue from here), the sweep after enqueue returns not-mergeable, the deferred gate sees Enqueuer.Login == AppBotLogin and dequeues it, the removal event opens a new after_removal cycle, and the following sweep enqueues again — an enqueue/dequeue flap in which the PR never reaches the front of the queue. The PR body says "Already queued PRs are left alone"; the code does that only while every earlier gate keeps returning empty.
  • The new tests do not reach this path: every fixture with IsInMergeQueue: true (automerge_native_queue_test.go hunk ~535) is paired with REST mergeable_state: "clean" (test hunks 469, 498), so a blocked-while-queued PR is never exercised.

Suggested narrowing, if the owner wants this in: skip withdrawal when state.IsInMergeQueue && state.HeadRefOid == pr.GetHead().GetSHA() and the reason is not-mergeable (or, more simply, treat only an explicit allow-list of eligibility reasons — label removed, held, draft, closed, untrusted merger, self-merge ban, head changed — as grounds to dequeue), plus one test with mergeable_state: "blocked" and the App as enqueuer asserting zero dequeues.

Routing: this is a fork PR (comment only) that adds a new merge path exercised under the App identity, which is merge-policy rather than a code nit, so I am leaving the decision to the owner rather than judging it alone. No other defects found; security and docs (src/docs/native-merge-queue.md) look in order.

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

@hivecommons-hive hivecommons-hive Bot added stage/085-needs-decision A human decision is owed: sentinel alert, hold/needs-decision label, human-only rule or parked issue and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 29, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

Needs a decision, not a merge:

Head: verdict requires_human @4412365, 57/57 checks green, DCO yes, soak 0s of 30m0s.

How to release it:

  • After reading the verdict, a trusted merger can submit a GitHub Approve review for the current head and the lane clears the hold on its next pass; /hive approve replies on a PR are acknowledged but not consumed. An ordinary contributor cannot release their own PR.

Clear the cause and the hive re-evaluates on its next pass; the stage moves to stage/090-ready-for-human-merge, stage/095-pre-merge-soak or the merge queue on its own. Approval does not bypass CI, hold labels or other merge gates.

@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 enqueue path itself reads correctly to me; the pause/disabled cleanup loop as written is a per-minute full-repo scan on every sub-L6 hive, which I think needs a design change before this lands.

What I verified (tree at merge-base db3be8d, PR head 4412365):

  • tryNativeQueue runs after each lane's existing gates and before knownMergeRefusal in all four lanes (automerge_sweep.go:1883, :2282, :2638; automerge_contributor_lane.go:1396). The claim keys it reads — expect_sha, method_reason — are exactly what mergeClaimFor writes at automerge_merge_commit.go:140-142. Head pinning via expectedHeadOid, mixed-authorship MERGE check, and the removal-event cycle key all match the body.
  • Dequeue provenance re-check immediately before the write (automerge_native_queue.go:136-147) and the enqueuer-login match are what the body claims. TestNativeQueueGateWithdrawsOnlyHiveEntries / TestNativeQueueDequeueHonorsBoundaryAndLaneOwnership cover it.
  • ClassifyStage prefix match on native-merge-queue (derive_pr_classify.go:453) routes both the native-merge-queued: queued (position N, S) reason and the native-merge-queue-{read,enqueue,method} failure reasons to stage/100-merge-queue. Whether a failure reason should land on stage 100 rather than a refusal stage is a judgement call for the author; flagging, not asserting.

Finding (high) — reconcileInactiveNativeQueues scans every open PR in every "inactive" repo once a minute, and below L6 every repo is inactive.

  • automerge_sweep.go:893 calls it unconditionally at the top of SweepQueuedAutoMerges, which runAutoMergeSweepIfDue runs every autoMergeSweepInterval = time.Minute (main.go:9243) with no ACMM gate (main.go:9358-9369).
  • automerge_native_queue.go:172 skips a repo only if active[display] && c.repoAutoMergeAllowed(display). repoAutoMergeAllowed → cfg.RepoAutoMergeEnabled, which is fail-closed: returns false for every repo when ACMM < L6 (src/pkg/config/repo_policy.go:517-520).
  • So on any hive below L6 with App auth, every repo falls through to :178 PullRequests.List(state=open, 100/page) over all pages, and :184 → reconcileNativeQueueGate("inactive", …) → :129 one GraphQL ReadNativeMergeQueue per open PR. The lane != "inactive" carve-out at :116 deliberately disables the author-ownership short-circuit, so nothing filters the set.
  • Consequence: for this repo alone (~hundreds of open PRs) that is several REST list pages plus hundreds of GraphQL node queries per minute, forever, to look for App-owned queue entries that a sub-L6 hive can never have created (it never reaches tryNativeQueue because the lanes bail on automerge-disabled repos first). At L6 the same cost applies to every repo an owner has switched off. ShedLowPriorityTick at main.go:9368 guards only entry to the sweep; the loop has no budget check of its own.
  • Suggested shape: remember which PRs this engine actually enqueued (the effect journal already has operation=enqueue claims) and dequeue from that set, or at minimum skip repos where IsMergeQueueEnabled was never observed true and run the inactive pass on a much longer interval. A cleanup for the rare "operator paused mid-queue" case should not cost a full scan per minute.

Low — the new REST calls are untagged. automerge_native_queue.go:178 and automerge_sweep.go:931 call PullRequests.List/Get with the bare ctx; every other REST call in this sweep wraps it in hgithub.WithRESTCaller(ctx, "hive:automerge_sweep") so /api/gh-rate-limits can attribute the load (restnegativecache.go:28-30). Given the volume above, this is the one call site you most want attributed. Also :931 adds a PullRequests.Get per prefiltered label-queued issue — the prefilter used to be free; now each held/exempt-label skip costs a REST read plus a GraphQL read.

Open question (not asserting a defect): a PR can be evaluated by more than one lane (e.g. a trusted-author PR that also carries the automerge label is seen by both the queued and trusted lanes). The gate's ownership guards cover self-authored vs. others and untrusted-author-role, but I did not find a guard preventing lane A from dequeuing an entry lane B enqueued when their gate sets differ (e.g. queued lane's label-approval gate vs. trusted lane's review gate). If the gates are identical in practice this is moot; if not, the entry could flap enqueue/dequeue each minute.

Body matches the diff throughout; the paused/disabled cleanup is described exactly as implemented, so this is a cost/design concern, not a mismatch. Fork PR, so I can't push — recommend the author rework the inactive pass before a maintainer spends time on the rest. I have not approved or changed anything.

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

@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/085-needs-decision A human decision is owed: sentinel alert, hold/needs-decision label, human-only rule or parked issue labels Oct 29, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

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

Review asks:

  • the review swarm requested changes

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

Copy link
Copy Markdown
Contributor

Superseded by hive: re-authored as #15308 with the same commits and sign-off because CI stayed red and the author was unavailable. This PR is closed; if #15308 fails, hive reopens it.

@hivecommons-hive hivecommons-hive Bot added the hive/superseded Closed by Hive: a different merged PR already landed this change label Oct 29, 2026
@hivecommons-hive hivecommons-hive Bot closed this Oct 29, 2026
@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 29, 2026
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. hive/superseded Closed by Hive: a different merged PR already landed this change role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. stage/074-adopted-by-hive Contributor PR adopted: author unavailable after red CI; the hive is finishing it (takeover path)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ feature: enqueue into GitHub's native merge queue instead of skipping with merge-queue-required

1 participant