Skip to content

✨ Conflict-aware merge train in the automerge lanes - #15157

Merged
clubanderson merged 5 commits into
v5from
feat/automerge-merge-train
Oct 29, 2026
Merged

clubanderson merged 5 commits into
v5from
feat/automerge-merge-train

Conversation

@clubanderson

@clubanderson clubanderson commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #15117
Fixes #15141
Fixes #15143
Fixes #15144

Problem

Today on hive's own hosted spoke six approved PRs to v5 (#15070 #15072 #15074 #15085 #15087 #15097) all touched stage_tracker.go and index.html. The moment one merged the rest went mergeable_state=dirty; the automerge sweep logged automerge skip reason=conflicting / label:needs-rebase every cycle and nothing ordered or repaired them. A human serialized them by hand.

What this does

Engine (pkg/github/automerge/automerge_merge_train.go, all three lanes: hive, trusted-author, contributor)

  • Per sweep, groups open approved / mergeable-pending PRs per repo+base by overlapping changed files (GET /pulls/{n}/files, cached by head SHA; union-find grouping).
  • Picks ONE front per group (clean-mergeable first, then earliest approved) and merges it when green; siblings are skipped with lane reason merge-train:queued-behind#<front>:<pos>/<size>:....
  • Immediately after the front merges: sibling behind -> PUT update-branch; dirty -> RebaseResolver hook (RebaseRequest). Loop guard: auto_merge.merge_train.max_rebase_attempts (default 2) per PR per front; past it the PR carries rebase-exhausted and lands at stage/085.
  • One INFO merge train line per order change, not per cycle.
  • Config: auto_merge.merge_train.enabled (default true), auto_merge.merge_train.max_rebase_attempts (2).

Tracker (pkg/dashboard)

  • merge_gate.state=queued-behind with reason behind #15074 in merge train (3rd of 4, overlapping files: stage_tracker.go, index.html); merge_train{id,state,front,position,size,attempt,max_attempts,overlap_files,ahead} on items and linked PRs. Waiting siblings are never a human stage, never red; a needs-rebase label on one is reported under stale_labels.
  • SPA: train rows contiguous in merge order with a thin left rail and header chip ⛓ merge train · 4 PRs · front #15074; pills "Merging · front of train", "In merge train · 3rd of 4", "Rebasing · attempt 1/2", "Needs human decision · rebase failed twice" (option "Rebase, then merge as maintainer"); tooltip lists PRs ahead + overlapping files.

Coordination with #15104

#15104 (fix/rebase-then-merge) is not on v5 yet, so this PR defines the RebaseResolver / RebaseRequest hook in automerge with a TODO at the cmd/hive wiring; a dirty PR with no resolver falls through to the existing conflicting path (logged once). The "Rebase, then merge as maintainer" option is offered disabled with an honest reason until #15104 lands, since the #15087 decide:merge-now handler merges a mergeable head only. Expect a small conflict with #15104 in stage_tracker_merge_train.go (option wiring); whichever lands second drops the stub.

Tests

Table-driven grouping, front selection, post-merge sibling handling (behind -> update-branch, dirty -> resolver), loop guard, transition-log-once, files cache; dashboard Go payload test + node fixture test for rail/header/pill wording/tooltip; stageengine classify; config defaults. No time.Sleep. Coverage: automerge 89.3%, github 88.8%, dashboard 87.9%, config 90.3%.

Docs

src/docs/operator-reference.md (two config rows), src/docs/dashboard-sections.md ("Merge train"), changelog.d/added-automerge-merge-train.md.

Supersedes #15149

The scanner opened #15149 in parallel for the same issue (front selection only, items 1 + part of 2; self + trusted lanes). This PR covers the whole of #15117 and its three sub-issues:

#15149 #15157 (this PR)
Group by overlapping files per repo+base, /files cached by head SHA yes yes (union-find, transitive)
One front per group; clean first, then oldest, then number yes yes
Lanes self, trusted-author self, trusted-author, contributor
Blocked head (red / terminal hold / permanent refusal) never fronts; all-blocked group imposes no ordering (fail-open) yes folded in from #15149 (commit 36b2755)
PR whose files cannot be read stays out of every train yes yes
One INFO line per slot change yes yes
auto_merge.merge_train.enabled (default true) yes yes
After the front merges: behind → update-branch, dirty → rebase-resolve hook, max_rebase_attempts loop guard (#15143) no yes
Tracker merge_gate.state=queued-behind, merge_train{…} on items, pills / rail / header chip / tooltip (#15144) no yes
Stage engine: queued-behind stays 080, exhausted → 085 no yes
Sibling stage while waiting left as last recorded honest queued-behind reason

Nothing else in #15149 is missing here. Sub-issues: #15141 fully covered (Fixes), #15143 fully covered (Fixes; the rebase enqueue is the RebaseResolver seam for #15104), #15144 fully covered (Fixes; ordinal cases 1st/2nd/3rd/4th/11th/12th/13th/21st are in the node fixture).

@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 needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 28, 2026
@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
#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/dashboard-sections.md
src/docs/operator-reference.md
src/pkg/dashboard/stage_tracker.go
src/pkg/dashboard/stage_tracker_decision.go
src/pkg/dashboard/static/index.html
#15186 🐛 Activity Monitor: one coherent post-decision state for Let hive decide rows; 060 reviewed in CI / Review same files src/docs/dashboard-sections.md
src/docs/operator-reference.md
src/pkg/dashboard/stage_tracker.go
src/pkg/dashboard/stage_tracker_decision.go
src/pkg/dashboard/static/index.html
#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/dashboard/static/index.html
#14822 🐛 fix: preserve owner intent through PR decision paths same files src/pkg/github/automerge/automerge_contributor_lane.go
#15206 🐛 Activity Monitor: delegated adopt-supersede reports executing → adopted/could-not-adopt, routes workflow-path to the workflows blocker, re-adoption survives the mutation journal same files src/pkg/dashboard/static/index.html
#14807 ✨ dashboard: stream Job pod logs in the terminal pane for sandbox.runtime: job agents same files src/pkg/dashboard/static/index.html
#15104 🐛 Activity Monitor: Rebase, then merge as maintainer; fixer owns parked conflicting PRs; dismiss self-inflicted changes_requested same files src/docs/dashboard-sections.md
src/docs/operator-reference.md
src/pkg/dashboard/stage_tracker.go
src/pkg/dashboard/stage_tracker_decision.go
src/pkg/dashboard/static/index.html
src/pkg/github/automerge/automerge_sweep.go
#15192 ✨ Conflict-aware merge train in the automerge lanes CONFLICT src/cmd/hive/main.go
src/docs/operator-reference.md
src/pkg/config/config.go
src/pkg/dashboard/settings_parity_allowlist.txt
src/pkg/github/automerge/automerge_contributor_lane.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
#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/dashboard-sections.md
src/docs/operator-reference.md
src/pkg/config/config.go
src/pkg/dashboard/stage_tracker.go
src/pkg/dashboard/stage_tracker_decision.go
src/pkg/dashboard/static/index.html
#15200 🐛 fix: tracker history column wears a history mark, not a ✓ same files src/docs/dashboard-sections.md
src/pkg/dashboard/static/index.html
#15191 🐛 Let hive decide on a ready-for-human-merge PR approves and lets the sweep merge it same files src/docs/dashboard-sections.md
src/docs/operator-reference.md
src/pkg/dashboard/static/index.html
#15211 🐛 Let hive decide on a ready-for-human-merge PR approves and lets the sweep merge it same files src/docs/dashboard-sections.md
src/docs/operator-reference.md
src/pkg/dashboard/static/index.html

@hivecommons-hive hivecommons-hive Bot added author/human A person pushed this PR themselves dco All commits are DCO signed-off stage/071-needs-author Human-authored PR: CI red, changes requested or conflicting; diagnosis posted, the author must act labels Oct 28, 2026
@thatguywob

Copy link
Copy Markdown
Contributor

This PR also implements the post-front sibling-repair scope of #15143, including the contributor lane requested in that issue: mergeTrainAfterFrontMerge updates behind siblings and calls the single RebaseResolver seam for dirty siblings, with a per-PR/per-front attempt key and a default cap of 2. Please include Fixes #15143 in the PR body if this is intended to close that child as well; only a maintainer editing the body makes that merge close it.

Two acceptance details to finish here rather than in a competing train implementation:

— hive: backend=codex


🐝 Hive Agent: contributor | SHA: unknown

@hivecommons-hive

Copy link
Copy Markdown
Contributor

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

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>
…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>
Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Signed-off-by: Andrew Anderson <andy@clubanderson.com>
@clubanderson
clubanderson force-pushed the feat/automerge-merge-train branch from 9919d2d to 26bfd3f Compare October 29, 2026 01:00
@github-actions github-actions Bot added the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Oct 29, 2026
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/074-adopted-by-hive Contributor PR adopted: author unavailable after red CI; the hive is finishing it (takeover path) labels Oct 29, 2026
@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 @26bfd3f, 65/66 checks green, 1 pending, 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.

@clubanderson
clubanderson merged commit 8fc50d5 into v5 Oct 29, 2026
85 of 88 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the feat/automerge-merge-train branch October 29, 2026 01:26
@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

clubanderson added a commit that referenced this pull request Oct 29, 2026
…e; the exhausted row's rebase-then-merge option goes live

v5 landed the conflict-aware merge train (#15157) with a RebaseResolver hook
reserved for this PR and a duplicate rebaseMergeFollowThroughLabel. The hook
now opens the shared rebase episode (requested_by: merge-train); the
mergeNowWired flag and its disabled reason go, since the option it guarded
is wired here.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
clubanderson added a commit that referenced this pull request Oct 29, 2026
…e; the exhausted row's rebase-then-merge option goes live

v5 landed the conflict-aware merge train (#15157) with a RebaseResolver hook
reserved for this PR and a duplicate rebaseMergeFollowThroughLabel. The hook
now opens the shared rebase episode (requested_by: merge-train); the
mergeNowWired flag and its disabled reason go, since the option it guarded
is wired here.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
clubanderson added a commit that referenced this pull request Oct 29, 2026
…e; the exhausted row's rebase-then-merge option goes live

v5 landed the conflict-aware merge train (#15157) with a RebaseResolver hook
reserved for this PR and a duplicate rebaseMergeFollowThroughLabel. The hook
now opens the shared rebase episode (requested_by: merge-train); the
mergeNowWired flag and its disabled reason go, since the option it guarded
is wired here.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
clubanderson added a commit that referenced this pull request Oct 29, 2026
…e; the exhausted row's rebase-then-merge option goes live

v5 landed the conflict-aware merge train (#15157) with a RebaseResolver hook
reserved for this PR and a duplicate rebaseMergeFollowThroughLabel. The hook
now opens the shared rebase episode (requested_by: merge-train); the
mergeNowWired flag and its disabled reason go, since the option it guarded
is wired here.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
clubanderson added a commit that referenced this pull request Oct 29, 2026
…e; the exhausted row's rebase-then-merge option goes live

v5 landed the conflict-aware merge train (#15157) with a RebaseResolver hook
reserved for this PR and a duplicate rebaseMergeFollowThroughLabel. The hook
now opens the shared rebase episode (requested_by: merge-train); the
mergeNowWired flag and its disabled reason go, since the option it guarded
is wired here.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
clubanderson added a commit that referenced this pull request Oct 29, 2026
…e; the exhausted row's rebase-then-merge option goes live

v5 landed the conflict-aware merge train (#15157) with a RebaseResolver hook
reserved for this PR and a duplicate rebaseMergeFollowThroughLabel. The hook
now opens the shared rebase episode (requested_by: merge-train); the
mergeNowWired flag and its disabled reason go, since the option it guarded
is wired here.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
clubanderson added a commit that referenced this pull request Oct 29, 2026
…e; the exhausted row's rebase-then-merge option goes live

v5 landed the conflict-aware merge train (#15157) with a RebaseResolver hook
reserved for this PR and a duplicate rebaseMergeFollowThroughLabel. The hook
now opens the shared rebase episode (requested_by: merge-train); the
mergeNowWired flag and its disabled reason go, since the option it guarded
is wired here.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
clubanderson added a commit that referenced this pull request Oct 29, 2026
…e; the exhausted row's rebase-then-merge option goes live

v5 landed the conflict-aware merge train (#15157) with a RebaseResolver hook
reserved for this PR and a duplicate rebaseMergeFollowThroughLabel. The hook
now opens the shared rebase episode (requested_by: merge-train); the
mergeNowWired flag and its disabled reason go, since the option it guarded
is wired here.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
clubanderson added a commit that referenced this pull request Oct 29, 2026
…e; the exhausted row's rebase-then-merge option goes live

v5 landed the conflict-aware merge train (#15157) with a RebaseResolver hook
reserved for this PR and a duplicate rebaseMergeFollowThroughLabel. The hook
now opens the shared rebase episode (requested_by: merge-train); the
mergeNowWired flag and its disabled reason go, since the option it guarded
is wired here.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
hivecommons-hive Bot pushed a commit that referenced this pull request Oct 29, 2026
…ed conflicting PRs; dismiss self-inflicted changes_requested (#15104)

* 🐛 Activity Monitor: Rebase, then merge as maintainer; autonomous rebase-resolve with loop guard; approve on a dirty PR queues the rebase; dismiss self-inflicted changes_requested

Squashed and rebased onto v5 after #15087 and #15074 landed.

Fixes #15103

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

* test: fix fixtures after the v5 rebase (mock fields, failingEntry rebase fields, import ratchet, window shim)

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

* test: lift pkg/rebasemerge coverage above its floor; drop an ineffectual assignment

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

* test: compare the shared singletons through named values (staticcheck SA4000)

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

* security: rebase-then-merge fails closed on a head the hive did not produce; document the new API shapes

The approval is bound to the head the operator read. A contributor PR whose
head moves after the click now counts as rebased only when GitHub reports
the hive (App bot or pane identity) as the commit's author or committer;
any other head settles the follow-through as failed (foreign-head) with
nothing merged, a note on the PR, and 'Approve the new head & merge' as the
way out. api-reference.md gains the 202 rebase-queued answer, the rebase
response field, and the rebase_merge / rebase row fields.

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

* merge train: hand a dirty member to the fixer's rebase-resolve episode; the exhausted row's rebase-then-merge option goes live

v5 landed the conflict-aware merge train (#15157) with a RebaseResolver hook
reserved for this PR and a duplicate rebaseMergeFollowThroughLabel. The hook
now opens the shared rebase episode (requested_by: merge-train); the
mergeNowWired flag and its disabled reason go, since the option it guarded
is wired here.

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

* test: approve toast wording follows #15213

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

* rebase onto v5: drop duplicate nonEmptyString, lift STAGE_TRACKER_ICONS for the history badge in the rebase-then-merge row test

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

* writeback ratchet: baseline the two operator-solicited comments of the rebase-then-merge follow-through

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

* automerge: superseded question precedes the label block (#15278) while a needs-rebase label on a merely-behind head stays stale

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/human A person pushed this PR themselves conflicts-with-open-pr Open PR has a merge conflict with another open PR dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. stage/085-needs-decision A human decision is owed: sentinel alert, hold/needs-decision label, human-only rule or parked issue

Projects

None yet

2 participants