Repository navigation
✨ feat(automerge): pick one merge-train front per group of file-overlapping approved PRs - #15149
Conversation
…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>
|
[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 |
|
hive/awaiting-ci: CI pending — sweep will merge when green. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
There was a problem hiding this comment.
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 asmerge-train-queuedagain (automerge_sweep.go:1304-1308). Siblings never reachtrySweepTrustedAuthorPR, so they get no fresh verdict either.mergeTrainChangedFiles(:183) never hits its cache: every eligible PR on a base with ≥2 candidates costs aGET /pulls/{n}/filesper 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
There was a problem hiding this comment.
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; intrySweepSelfAuthoredPRabehindhead goes toupdateBranchAndSkipand onlydirty/conflictingreturns"conflicting"(automerge_sweep.go:1745-1754)."not-mergeable"— which would also cover GitHub's transientunknown— is only returned bytrySweepQueuedPR(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 (
mergeTrainSlotscomparesblocked[key] == pr.GetHead().GetSHA(),:236), a push clears them, andnoteMergeTrainOutcomeis only called onerr == nilso 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
continueafter the prefilter/stage branches, so their stage is genuinely untouched, and the train'seligiblepredicate is the same prefilter (:1044-1046,:1255-1263), so a PR can only be queued if it would otherwise have reachedtrySweep*. TestPlanMergeTrains/ the sweep-level front-only tests fail without the planner and the twomergeTrainQueuedhunks.
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
|
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 |
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>
|
hive/awaiting-ci: CI pending — golden fixture updated for the new 🐝 Hive Agent: — hive: agent=scanner 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 |
…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>
* ✨ 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>
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 themconflictingevery cycle with nothing ordering them (six v5 PRs onstage_tracker.go/index.htmlhad to be serialised by hand).This adds the merge-train core:
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.merge-train-queued(stage left as last recorded) and are re-evaluated against the new base on later passes.automerge merge trainline per slot change (front/position/size/overlap_files), not per cycle.auto_merge.merge_train.enabled(default true; explicitfalserestores 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