Skip to content

✨ feat(automerge): pick one merge-train front per group of file-overlapping approved PRs - #15149

Merged
hivecommons-hive[bot] merged 2 commits into
v5from
scanner/fix-15117
Oct 28, 2026
Merged

hivecommons-hive[bot] merged 2 commits into
v5from
scanner/fix-15117

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Approved PRs to the same base that touch the same files were merged in parallel; the first to land turned every sibling dirty, and the sweep logged them conflicting every cycle with nothing ordering them (six v5 PRs on stage_tracker.go/index.html had to be serialised by hand).

This adds the merge-train core:

  • The self-authored and trusted-author sweeps group lane-eligible PRs per repo + base branch by transitively overlapping changed files (GET /pulls/{n}/files, cached per head SHA) and let one front per group reach the merge path per pass: a head not last seen conflicting/red/held first, then the oldest, then the lowest number.
  • Siblings skip as merge-train-queued (stage left as last recorded) and are re-evaluated against the new base on later passes.
  • Fail-open: a group whose best member is itself blocked imposes no ordering; a PR whose files cannot be read stays out of every train.
  • One INFO automerge merge train line per slot change (front/position/size/overlap_files), not per cycle.
  • Config auto_merge.merge_train.enabled (default true; explicit false restores parallel merging). Additive only; documented in operator-reference.

Tests: table-driven planMergeTrains (disjoint, overlap, oldest, blocked front, all blocked, transitive, per-base, two trains), sweep-level front-only merge / disabled / disjoint, a conflicting front yielding to its mergeable sibling, and the head-SHA files cache.

Closes #15141
Part of #15117 (remaining: sibling update/rebase enqueue and tracker queued-behind state, tracked in #15143, #15144)

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 requested_by=@clubanderson

…apping approved PRs

Approved PRs to the same base that touch the same files were all merged
in parallel; the first to land turned every sibling dirty and the sweep
then logged them as conflicting every cycle with nothing ordering them.

The self-authored and trusted-author sweeps now group lane-eligible PRs
per repo and base branch by transitively overlapping changed files
(GET /pulls/{n}/files, cached per head SHA) and let one front per group
proceed to the merge path per pass: a head not last seen conflicting,
red or held first, then the oldest. Siblings skip as merge-train-queued
and are re-evaluated against the new base on later passes. A group whose
best member is itself blocked imposes no ordering, and a PR whose files
cannot be read stays out of every train, so the train never holds back a
merge that would have happened before. One INFO line per slot change.

auto_merge.merge_train.enabled defaults on; an explicit false restores
the previous parallel behaviour. Sibling update/rebase follow-through and
the tracker queued-behind state follow in #15143 and #15144.

Part of #15117

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
Co-authored-by: clubanderson <407614+clubanderson@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@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 clubanderson 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
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

hive/awaiting-ci: CI pending — sweep will merge when green.


🐝 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

@github-actions

github-actions Bot commented Oct 28, 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
#15158 🐛 fix: close issues for contributor PRs merged by the hive same files src/docs/operator-reference.md
#15134 🐛 Delegated decision on a capability gap: model the blocker, stop the un-park/re-park loop, name the missing App permission same files src/docs/operator-reference.md
#15156 🐛 Activity Monitor: an owner's Approve admits the untrusted-author PR head — no adoption, merge as-is; DCO warned before acting same files src/docs/operator-reference.md
#15122 🐛 Write-back containment: per-kind gate for every unsolicited GitHub write, with backfill guard same files src/cmd/hive/main.go
src/docs/operator-reference.md
src/pkg/config/config.go
src/pkg/config/testdata/agent_runtime_golden.json
#15104 🐛 Activity Monitor: Rebase, then merge as maintainer; fixer owns parked conflicting PRs; dismiss self-inflicted changes_requested same files src/docs/operator-reference.md
src/pkg/github/automerge/automerge_sweep.go
#15157 ✨ Conflict-aware merge train in the automerge lanes CONFLICT src/cmd/hive/main.go
src/pkg/config/automerge_merge_train_test.go
src/pkg/config/config.go
src/pkg/github/automerge/automerge_merge_train.go
src/pkg/github/automerge/automerge_merge_train_test.go
src/pkg/github/automerge/automerge_sweep.go
src/pkg/github/automerge/automerge_sweep_test.go
#15085 ✨ Activity Monitor: Adopt now and Reroute to another clanker for PRs waiting on a contributor's clanker same files src/cmd/hive/main.go
src/docs/operator-reference.md
src/pkg/config/config.go
src/pkg/config/testdata/agent_runtime_golden.json

@hivecommons-hive hivecommons-hive Bot added author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 28, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

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 merge train must also cover the one-shot runAutoMergeSweepIfDue path and cross-lane (bot + trusted-human) overlap in this PR, or whether those are accepted gaps tracked in #15143/#15144.

The planner itself reads correctly to me (planMergeTrains, automerge_merge_train.go:46-110: union-find per base\0file, blocked-before-mergeable ordering, blocked front → no slots, so it fails open as the body says). Two things I verified against the tree at 3a85cb8 that I think need a decision before this lands.

1. The merge-train memory is discarded on the run-loop path, so "a conflicting front yields" never happens there.
mergeTrainState lives on the Engine (automerge_sweep.go:228). The persistent sweep (sweepPass, automerge_sweep.go:1543,1563) keeps one engine across ticks, so there blocked/files/logged work as designed. But run_loop_deps.go:89 calls runAutoMergeSweepIfDue, which goes through the package wrappers automerge.SweepQueuedAutoMerges / automerge.SweepTrustedAuthorAutoMerges (main.go:9383,9404) — and each wrapper is New(transport, opts).Sweep… (automerge_sweep.go:419-431), a one-shot engine. On that path, every pass starts with empty mergeTrain.blocked, so:

  • noteMergeTrainOutcome (automerge_merge_train.go:159) marks a conflicting front blocked and the mark dies with the engine; next pass the same conflicting PR fronts again and its siblings skip as merge-train-queued again (automerge_sweep.go:1304-1308). Siblings never reach trySweepTrustedAuthorPR, so they get no fresh verdict either.
  • mergeTrainChangedFiles (:183) never hits its cache: every eligible PR on a base with ≥2 candidates costs a GET /pulls/{n}/files per pass.
  • logMergeTrainTransitions (:259) logs every pass, not once per slot change.

Severity: medium — the persistent sweepPass engine does eventually clear the stall for the trusted lane, but the body's "fail-open", "cached per head SHA" and "one INFO line per slot change" claims are only true on one of the two live paths. Simplest fix I can see is to hang mergeTrainState off something that survives the one-shot wrappers (package-level keyed by repo, or a field on the shared transport/config), or give runAutoMergeSweepIfDue a long-lived engine.

2. Trains are built per lane, so a bot PR and a trusted-human PR on the same files are still unordered.
The self-authored lane's eligible is prefilterSelfAuthoredPR(pr) == "" (automerge_sweep.go:1044), which rejects not-app-authored; the trusted lane's eligible (:1255-1264) explicitly returns false for bot-lane authors. sweepPass runs both lanes in one pass (:1543 then :1563), so the first lane can merge its front and the second lane's overlapping front still goes to the merge path in the same pass — exactly the "first to land turned every sibling dirty" symptom. The body scopes this to "lane-eligible PRs", so it is declared, but the motivating case (six v5 PRs on stage_tracker.go/index.html) is a mix of hivecommons-hive[bot] and @clubanderson authors in this very queue, which this PR will not serialise. Worth either widening the group to all lanes' candidates (the file-overlap key is already base-scoped, so a shared members list across the two sweeps would do) or stating the cross-lane gap in #15143/#15144 so it isn't assumed fixed.

The red test (rest 2/4) / coverage jobs are in the fixer lane's hands; I could not read the job log from here and have not treated them as a finding.

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

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Read the diff against v5 at 3a85cb8, then the two sweep paths it hooks. The core is correct and fails open where it says it does; one scope gap worth naming before this closes #15141.

Verified

  • Blocked marks only come from real blockers in the trained lanes. mergeTrainBlockingReason (automerge_merge_train.go:149-155) keys on "conflicting", red CI, terminal holds and permanent refusals; in trySweepSelfAuthoredPR a behind head goes to updateBranchAndSkip and only dirty/conflicting returns "conflicting" (automerge_sweep.go:1745-1754). "not-mergeable" — which would also cover GitHub's transient unknown — is only returned by trySweepQueuedPR (automerge_sweep.go:2576), a lane this PR does not train, so a head awaiting mergeability computation is never demoted.
  • Marks are per head SHA (mergeTrainSlots compares blocked[key] == pr.GetHead().GetSHA(), :236), a push clears them, and noteMergeTrainOutcome is only called on err == nil so an API error never poisons a mark.
  • All-blocked group → no slots → everyone is tried as before (planMergeTrains, :88-90); files-list failure → member omitted (:229-231). Both fail-open claims in the body hold.
  • Queued siblings continue after the prefilter/stage branches, so their stage is genuinely untouched, and the train's eligible predicate is the same prefilter (:1044-1046, :1255-1263), so a PR can only be queued if it would otherwise have reached trySweep*.
  • TestPlanMergeTrains / the sweep-level front-only tests fail without the planner and the two mergeTrainQueued hunks.

Gap (intent-alignment, low)
Trains are planned per lane: mergeTrainSlots is called once in SweepSelfAuthoredAutoMerges (automerge_sweep.go:1044) and once in SweepTrustedAuthorAutoMerges (:1255), and the trusted lane's predicate explicitly excludes self-lane authors (:1256-1262). A hive-authored PR and a trusted-human PR that touch the same files on the same base are therefore never in one group and still merge in parallel. The incident in #15117 was exactly that mix (#15070/#15085 are @clubanderson's, the rest hive-authored), so this head would not have serialised that set. The body lists sibling update/rebase and tracker state as the remainder (#15143, #15144) but not cross-lane grouping — suggest either folding a shared per-repo plan across the two sweeps here, or adding it to the tracked remainder so #15141 does not read as fully done.

Open question, not a finding
A front that is green-pending (CI running, or just branch-updated) holds every overlapping sibling until it resolves; only a terminal hold or red demotes it. That is the intended train semantics, but a front stuck in a non-terminal pending state has no timeout here. If the existing required-check hold timers cover that, fine; if not, a cap may be wanted later.

CI is red at this head (test (rest 2/4), coverage) and the PR is at stage/070-fixing, so I have not re-derived those.

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

clubanderson added a commit that referenced this pull request Oct 28, 2026
…oup is blocked

Folded in from #15149: a head the lane last saw red / terminally held /
permanently refused does not front a train, and a group whose best member
is blocked imposes no ordering. Ordinal cases from #15144 in the SPA test.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
@clubanderson

Copy link
Copy Markdown
Member

PR #15157 covers this one end to end for #15117 and is MERGEABLE against v5: the same grouping/front selection (all three lanes, not just self + trusted), plus the parts this PR leaves for later — post-merge sibling repair (behind → update-branch, dirty → rebase-resolve seam with max_rebase_attempts, #15143), the tracker's queued-behind / merge_train state with the Activity Monitor rail, header chip and pill wording (#15144), and the stage-engine classification. The one thing this PR had that #15157 lacked — blocked heads never fronting and an all-blocked group imposing no ordering (fail-open) — is folded into #15157 at 36b2755 with tests. Leaving this open for a maintainer to decide; #15157 has a side-by-side comparison in its body.

The merge_train sub-struct marshals as an empty object like its
auto_merge siblings; the golden must carry it or
TestAgentRuntimeConfigGolden reports the key as unexpected.

Part of #15117

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 Author

hive/awaiting-ci: CI pending — golden fixture updated for the new auto_merge.merge_train key (rest 2/4 TestAgentRuntimeConfigGolden). Sweep will merge when green.


🐝 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 stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Oct 28, 2026
@hivecommons-hive
hivecommons-hive Bot merged commit 9b01e1d into v5 Oct 28, 2026
76 of 78 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-15117 branch October 28, 2026 23:54
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author
Evidence bundle `#15149561120a` sha256:2e6695e7866aad83ff984cc9189bdd9c176f7fed86b88753a82ab330965e7074 — download from the dashboard or `hivectl review evidence #15149`.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 28, 2026
hivecommons-hive Bot added a commit that referenced this pull request Oct 29, 2026
…ront

One merge-train implementation: #15149's planner (planMergeTrains slots,
blocked-head memory incl. conflicting, per-PR transition log, files cache
via ListChangedFiles), config key auto_merge.merge_train.enabled and
Options.MergeTrainEnabled stay canonical. Layered on top from this branch:
max_rebase_attempts + Options.MergeTrainMaxRebaseAttempts, RebaseResolver
hook, prstage merge-train stage reasons for siblings and rebasing fronts,
after-front-merge update-branch/rebase follow-through, contributor-lane
wiring, dashboard tracker/UI and docs. An exhausted front is marked blocked
so it stops fronting. One changelog fragment covers the train.

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
clubanderson added a commit that referenced this pull request Oct 29, 2026
…oup is blocked

Folded in from #15149: a head the lane last saw red / terminally held /
permanently refused does not front a train, and a group whose best member
is blocked imposes no ordering. Ordinal cases from #15144 in the SPA test.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
clubanderson added a commit that referenced this pull request Oct 29, 2026
* ✨ Conflict-aware merge train in the automerge lanes

Approved PRs to one base whose changed files overlap are grouped per
sweep; one front merges at a time, siblings wait at stage/080 as
merge_gate.state=queued-behind (never a human stage). After the front
merges the lane updates behind branches and asks the rebase-resolve hook
for dirty ones, bounded by auto_merge.merge_train.max_rebase_attempts
(default 2); past it the PR goes to stage/085 with the option
"Rebase, then merge as maintainer".

The Activity Monitor renders a train contiguously with a left rail and
a header chip, pills "Merging · front of train", "In merge train · 3rd
of 4", "Rebasing · attempt 1/2", "Needs human decision · rebase failed
twice"; tooltips list PRs ahead and overlapping files; items carry
merge_train{id,state,front,position,size,overlap_files,ahead}.

Fixes #15117

Signed-off-by: Andrew Anderson <andy@clubanderson.com>

* ✨ merge train: blocked heads never front, fail-open when the whole group is blocked

Folded in from #15149: a head the lane last saw red / terminally held /
permanently refused does not front a train, and a group whose best member
is blocked imposes no ordering. Ordinal cases from #15144 in the SPA test.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>

* 🌱 merge train CSS: spacing and radius through tokens (style ratchet)

Signed-off-by: Andrew Anderson <andy@clubanderson.com>

* 🌱 Cover merge-train reason parsing edge cases (prstage floor)

Signed-off-by: Andrew Anderson <andy@clubanderson.com>

* 🌱 merge train: close legacy-switch test scope

Signed-off-by: Andrew Anderson <andy@clubanderson.com>

---------

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/hive This repository's own hive (the App or one of its agent lanes) authored this PR conflicts-with-open-pr Open PR has a merge conflict with another open PR copilot dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[scanner] automerge: group approved PRs by overlapping changed files and pick one merge-train front per group

1 participant