Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.d/added-merge-train-front.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Automerge merge train: approved PRs whose changed files overlap are grouped per repo and base branch, and only one front per group (mergeable first, then oldest) merges per sweep pass, so parallel approvals no longer dirty each other; `auto_merge.merge_train.enabled` (default `true`) turns it off (#15141).
- Conflict-aware automerge merge train ([#15117](https://github.com/hivecommons/hive/issues/15117), #15141): in every automerge lane (hive self-authored, trusted-author, contributor) approved PRs to one base whose changed files overlap are grouped per repo, and only one front per group (a head not last seen conflicting, red or held first, then the oldest) merges per sweep pass, so parallel approvals no longer dirty each other. Siblings wait at stage/080 as `merge_gate.state=queued-behind` ("In merge train · 3rd of 4", never a human stage); after the front merges the lane updates `behind` siblings and asks the rebase-resolve hook for `dirty` ones (`auto_merge.merge_train.max_rebase_attempts`, default 2; past it: stage/085 "Needs human decision · rebase failed twice" with "Rebase, then merge as maintainer"). The Activity Monitor renders a train contiguously with a left rail and a `⛓ merge train · N PRs · front #X` header chip, and `/api/stage-tracker` items carry `merge_train{id,state,front,position,size,overlap_files,ahead}`. `auto_merge.merge_train.enabled` (default `true`) turns it off.
5 changes: 5 additions & 0 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2548,6 +2548,10 @@ func (b *boot) bootAgentsWith(deps bootAgentsDeps) {
autoMergeOpts.TrustedBotAuthors = func() map[string]bool { return b.cfg.AutoMerge.TrustedBotAuthorSet() }
autoMergeOpts.BotTakeoverEnabled = func() bool { return b.cfg.AutoMerge.BotTakeover.IsEnabled() }
autoMergeOpts.MergeTrainEnabled = func() bool { return b.cfg.AutoMerge.MergeTrain.IsEnabled() }
// Merge train rebase loop guard (#15117). RebaseResolver stays nil until
// the rebase-then-merge follow-through (#15104) lands and is wired here;
// a conflicting front then keeps its conflicting path.
autoMergeOpts.MergeTrainMaxRebaseAttempts = func() int { return b.cfg.AutoMerge.MergeTrain.EffectiveMaxRebaseAttempts() }
// Intent tier gate (#6258): the human lane only queues PRs that
// survive writeMergeEligible's intent check, but this sweep lists
// the App's PRs on its own, so it carries the same policy (same
Expand Down Expand Up @@ -9410,6 +9414,7 @@ func runAutoMergeSweepIfDue(ctx context.Context, ghClient *github.Client, cfg *c
opts.RequireCurrentBase = func(repo string) bool { return cfg.AutoMerge.RequireCurrentBaseFor(repo) }
opts.MergeForwardTrustedHuman = func(repo string) bool { return cfg.AutoMerge.MergeForwardTrustedHumanFor(repo) }
opts.MergeTrainEnabled = func() bool { return cfg.AutoMerge.MergeTrain.IsEnabled() }
opts.MergeTrainMaxRebaseAttempts = func() int { return cfg.AutoMerge.MergeTrain.EffectiveMaxRebaseAttempts() }
opts.TrustedBotAuthors = func() map[string]bool { return cfg.AutoMerge.TrustedBotAuthorSet() }
}
audit := func(event automerge.AutoMergeSweepEvent) {
Expand Down
2 changes: 2 additions & 0 deletions src/docs/dashboard-sections.md
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,8 @@ Fed by `GET /api/stage-tracker`. Every issue and pull request follows the same p

**Unauthorized pill.** A pull request the hive cannot move because its GitHub App lacks a permission for the next step — it wears `hive:unauthorized` ([#14589](https://github.com/hivecommons/hive/issues/14589)); first case: approving held `action_required` workflow runs needs `actions: write` — carries the `unauthorized` modifier in the tracker payload, drawn in the far-right pill column exactly like `stalled` / `hold` / `draft` but muted (dashed, `--text-muted`), never red: it is nothing wrong, just a step only a person may take. It counts under **Needs attention**. Before the merge gate only the held-workflow-runs step shows (see *Pills before the merge gate*). Its tooltip (payload `unauthorized`) names the missing permission and the human step; on the **Needs human decision** lane the lit chevron and the caption read **Awaiting human: approve workflow runs** (payload `unauthorized_step`, from the `unauthorized:<step>` stage reason). The pill, label and payload fields clear themselves in the tick the step is no longer needed.

**Merge train.** When several approved PRs to the same base touch the same files, the automerge lanes merge them one at a time ([#15117](https://github.com/hivecommons/hive/issues/15117)). The tracker renders every train contiguously, in merge order, with a thin left rail linking the rows and a header chip `⛓ merge train · 4 PRs · front #15074` (overlapping files listed beside it). Pill wording per state: the front reads "Merging · front of train"; siblings "In merge train · 3rd of 4"; once the front merged and the hive is rebasing a conflicting sibling, "Rebasing · attempt 1/2"; when the loop guard (`auto_merge.merge_train.max_rebase_attempts`) is spent, "Needs human decision · rebase failed twice" at stage/085 with the decision option "Rebase, then merge as maintainer". The tooltip lists the PRs ahead and the overlapping files. Waiting siblings are never red, never `needs human`; a `needs-rebase` label on one is reported under `stale_labels`, the train repairs it. Each item carries `merge_gate.state` (`queued-behind` / `rebasing` / `rebase-exhausted` / `front`, with an honest `reason` such as `behind #15074 in merge train (3rd of 4, overlapping files: stage_tracker.go, index.html)`) and `merge_train{id, state, front, position, size, attempt, max_attempts, overlap_files, ahead}`; the id is `<base>#<front>`.

**Pills before the merge gate.** Owner's rule (2026-10-27): until a pull request is in the merge gate there is nothing a person can do about a `sentinel`, `needs human` or `unauthorized` notice — the PR is still in motion — so the tracker must not show them. The server splits every marker into two classes (`stageTrackerModifiers` in `stage_tracker.go`; each carries an explicit `ActionableNow` flag) and the row's payload carries the pills it draws in `modifiers` and the ones it holds back in `deferred_modifiers`. A deferred pill is simply absent — no chip, no breathing chevron, no **Needs attention** count — until the PR's stage reaches the merge-gate band (`stage/080` and later: 080, 085, 090, 095, 100, the same boundary adoption yields at), when it renders exactly as before and counts; the row tooltip alone says "Pending at merge gate: sentinel, needs-human". The merge-gate cell's own words ("Sentinel alert · needs human", "Awaiting human: …") are unchanged — they only appear at the gate anyway. Issues on their own stages (Open, 010, 020, 045) keep every pill: a `needs-human` there is a park the person owes now; an issue riding its covering PR's stage follows the PR. The GitHub labels are untouched — this is presentation and counting only.

| pill | class | when shown |
Expand Down
3 changes: 2 additions & 1 deletion src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ advanced into the merge path.
| `auto_merge.squash_only` | unset (no repo) | Repo list (`owner/repo`) whose branch policy forbids merge commits. Elsewhere, a `role/trusted` PR whose head mixes the contributor's commits with App-linked, App-signed ones (the hive's own in-place adoption fixes), every commit self-signed, is labelled `merge-method/merge` and merged with a merge commit instead of parking at `stage/085` as `adoption-stalled:hive-signoff-attribution`; a listed repo keeps squash-only policy and re-homes an in-place adoption to an App-authored superseder instead (#13975). |
| `auto_merge.credit_issue_authors` | `true` | Append `Co-authored-by: <login> <id+login@users.noreply.github.com>` for the human authors of the issues a PR closes (`Fixes|Closes|Resolves #N`) to the squash (or merge) commit message on every hive-performed merge, so reporters land on the contributor graph when an external clanker fixed their issue. Bots, the PR author and logins already credited on the branch are skipped; the logins are recorded as `issue_authors=` on the merge audit entry and in review evidence. One cached `GET /issues/{n}` per newly referenced issue. `false` leaves GitHub's default squash message untouched (#14581). |
| `auto_merge.bot_takeover.enabled` | `true` | When `github-actions[bot]` is in `auto_merge.trusted_bot_authors`, re-author its same-repo PRs whose required `pull_request` checks can never run (the bot opened them with a workflow `GITHUB_TOKEN`). After the head is older than both `min_head_age` and 30 minutes with no `pull_request` run, the App pushes the same change as one signed-off commit to `hive/takeover-<n>`, opens a PR with the original title/body plus `Supersedes #<n>`, comments `Superseded by #N` on the bot PR and closes it. One attempt per bot head SHA. See [hive-merge.md](hive-merge.md#github-actionsbot-pr-takeover). |
| `auto_merge.merge_train.enabled` | `true` | Merge train for approved PRs whose changed files overlap (#15141). The self-authored and trusted-author sweeps group candidate PRs per repo and base branch by overlapping changed files (`GET /pulls/{n}/files`, cached per head SHA) and let only one front per group merge per pass: a head not last seen conflicting, red or held first, then the oldest. Siblings skip as `merge-train-queued` and are retried against the new base on later passes; a PR whose files cannot be read stays out of every train. One INFO `automerge merge train` line per slot change. `false` merges every green PR in parallel as before. |
| `auto_merge.merge_train.enabled` | `true` | Conflict-aware merge train for approved PRs whose changed files overlap, in every automerge lane (hive self-authored, trusted-author, contributor) (#15141, [#15117](https://github.com/hivecommons/hive/issues/15117)). Each sweep groups the lane's candidate PRs per repo and base branch by overlapping changed files (`GET /pulls/{n}/files`, cached per head SHA) and lets only one front per group merge per pass: a head not last seen conflicting, red or held first, then the oldest. Siblings skip as `merge-train-queued` and wait at stage/080 with lane reason `merge-train:queued-behind#<front>:<pos>/<size>:…` (tracker pill "In merge train · 3rd of 4", never a human stage); a PR whose files cannot be read stays out of every train. The moment the front merges, every sibling whose branch is merely `behind` gets `PUT /pulls/{n}/update-branch`; a `dirty` one is handed to the rebase-resolve hook (the #15104 task; until it lands a conflicting PR takes the plain `conflicting` path, logged once, and stops fronting its train). A group whose best member is itself blocked imposes no ordering (fail-open), so nobody waits behind a PR that is not moving. One INFO `automerge merge train` line per slot change, not per cycle. `false` merges every green PR in parallel as before. |
| `auto_merge.merge_train.max_rebase_attempts` | `2` | Loop guard: how many rebase-resolve requests the train makes for one PR behind one front. Past it the PR moves to stage/085 with the pill "Needs human decision · rebase failed twice" and the decision option "Rebase, then merge as maintainer", and it stops fronting its train so a sibling that can merge goes next. |
| `auto_merge.trusted_authors.enabled` | `false` | Enables the opt-in human-authored PR tier: Hive may merge a green PR only when the author already holds the required hive role and, by default, GitHub push/maintain/admin permission on that repo. |
| `auto_merge.trusted_authors.repos` | empty = all watched repos | Optional repo allow-list for the trusted-author tier. The dashboard renders this as a watched-repo multi-select; selecting nothing preserves the all-repos default. |
| `auto_merge.trusted_authors.require_role` | `merger` | Minimum `dashboard.authorized_users` role the PR author must hold (`merger` or `owner`). |
Expand Down
25 changes: 25 additions & 0 deletions src/pkg/config/automerge_merge_train_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,28 @@ func TestMergeTrainAutoMergeConfigDefaultsOn(t *testing.T) {
t.Fatal("zero AutoMergeConfig disables the merge train; want default on")
}
}

func TestMergeTrainAutoMergeConfigDefaults(t *testing.T) {
off, on := false, true
tests := []struct {
name string
cfg MergeTrainAutoMergeConfig
wantEnabled bool
wantMax int
}{
{"unset is on with the default guard", MergeTrainAutoMergeConfig{}, true, DefaultMergeTrainMaxRebaseAttempts},
{"explicit on", MergeTrainAutoMergeConfig{Enabled: &on, MaxRebaseAttempts: 3}, true, 3},
{"explicit off", MergeTrainAutoMergeConfig{Enabled: &off}, false, DefaultMergeTrainMaxRebaseAttempts},
{"negative guard falls back", MergeTrainAutoMergeConfig{MaxRebaseAttempts: -1}, true, DefaultMergeTrainMaxRebaseAttempts},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if got := tc.cfg.IsEnabled(); got != tc.wantEnabled {
t.Fatalf("IsEnabled = %v, want %v", got, tc.wantEnabled)
}
if got := tc.cfg.EffectiveMaxRebaseAttempts(); got != tc.wantMax {
t.Fatalf("EffectiveMaxRebaseAttempts = %d, want %d", got, tc.wantMax)
}
})
}
}
21 changes: 19 additions & 2 deletions src/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7938,8 +7938,10 @@ type AutoMergeConfig struct {
// open-time attribution. nil/unset means ON; `credit_issue_authors:
// false` sends the merge with GitHub's default message as before.
CreditIssueAuthors *bool `yaml:"credit_issue_authors,omitempty" json:"credit_issue_authors,omitempty"`
// MergeTrain orders approved PRs whose changed files overlap so they
// merge one at a time instead of dirtying each other
// MergeTrain orders approved PRs on the same base whose changed files
// overlap so they merge one at a time instead of dirtying each other:
// the siblings wait as "queued-behind" (stage 080, never a human stage)
// and are updated or rebased right after the front lands
// (hivecommons/hive#15117).
MergeTrain MergeTrainAutoMergeConfig `yaml:"merge_train,omitempty" json:"merge_train,omitempty"`
}
Expand All @@ -7951,13 +7953,28 @@ type MergeTrainAutoMergeConfig struct {
// pass: the mergeable one first, then the oldest. nil/unset means ON;
// an explicit `enabled: false` merges every green PR as before.
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
// MaxRebaseAttempts bounds how many rebase-resolve tasks the train
// asks for on one PR behind one front before it parks the PR for a
// person (stage 085). 0/unset means DefaultMergeTrainMaxRebaseAttempts.
MaxRebaseAttempts int `yaml:"max_rebase_attempts,omitempty" json:"max_rebase_attempts,omitempty"`
}

// DefaultMergeTrainMaxRebaseAttempts is the merge train's rebase loop guard.
const DefaultMergeTrainMaxRebaseAttempts = 2

// IsEnabled reports the auto_merge.merge_train.enabled switch; unset is on.
func (m MergeTrainAutoMergeConfig) IsEnabled() bool {
return m.Enabled == nil || *m.Enabled
}

// EffectiveMaxRebaseAttempts is max_rebase_attempts with the default applied.
func (m MergeTrainAutoMergeConfig) EffectiveMaxRebaseAttempts() int {
if m.MaxRebaseAttempts <= 0 {
return DefaultMergeTrainMaxRebaseAttempts
}
return m.MaxRebaseAttempts
}

// CreditIssueAuthorsEnabled reports the auto_merge.credit_issue_authors
// switch; unset is on.
func (a AutoMergeConfig) CreditIssueAuthorsEnabled() bool {
Expand Down
1 change: 1 addition & 0 deletions src/pkg/dashboard/settings_parity_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ auto_merge.merge_train.enabled # merge-train front selection (#15141); yaml-only
auto_merge.allow_unprotected_base[] # TODO #11854
auto_merge.human_merge_paths.<key> # TODO #11854
auto_merge.merge_forward_trusted_human[] # TODO #11854
auto_merge.merge_train.max_rebase_attempts # merge train rebase loop guard (#15117); yaml-only
auto_merge.no_ci_ok[] # TODO #11854
auto_merge.repos.<key>.required_checks[] # TODO #11854
auto_merge.require_current_base[] # TODO #11854
Expand Down
18 changes: 16 additions & 2 deletions src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ type StageTrackerItem struct {
// label on its next pass, hivecommons/hive#14586). Rendered as a muted
// operator tooltip, never as the stage word.
StaleLabels []string `json:"stale_labels,omitempty"`
// MergeTrain is set on a PR riding a conflict-aware merge train
// (hivecommons/hive#15117): its position, the front, the PRs ahead and
// the overlapping files. See stage_tracker_merge_train.go.
MergeTrain *StageTrackerMergeTrain `json:"merge_train,omitempty"`
// BlockedOn lists the open GitHub "blocked by" dependencies ("repo#N")
// of an issue the scheduler withholds from every kick until they close
// (scheduler.partitionBlockedIssues). Without it a sequenced sub-issue
Expand Down Expand Up @@ -542,8 +546,9 @@ type StageTrackerLinkedPR struct {
DecisionNeeded *StageTrackerDecision `json:"decision_needed,omitempty"`
// SoakRemainingSeconds / MergeGate mirror the PR item's (#15073): a
// nested Soaking sub-row shows its time left too.
SoakRemainingSeconds int64 `json:"soak_remaining_seconds,omitempty"`
MergeGate *StageTrackerMergeGate `json:"merge_gate,omitempty"`
SoakRemainingSeconds int64 `json:"soak_remaining_seconds,omitempty"`
MergeGate *StageTrackerMergeGate `json:"merge_gate,omitempty"`
MergeTrain *StageTrackerMergeTrain `json:"merge_train,omitempty"`
// Adoption mirrors the nested PR's own row field (hivecommons/hive#14524).
Adoption *StageTrackerAdoption `json:"adoption,omitempty"`
// LastOperatorAction / OperatorActionCount mirror the nested PR's own
Expand Down Expand Up @@ -1523,6 +1528,9 @@ func stageTrackerCaption(stage stagelabels.Stage, reason, author string, kind st
}
return joinClause(c, clause), "hive"
case stagelabels.AwaitingMergeAdmission:
if c := stageTrackerMergeTrainCaption(reason); c != "" {
return c, "automerge lane"
}
return joinClause("Green and approved; waiting for the automerge lane to admit it", clause), "automerge lane"
case stagelabels.NeedsDecision, stagelabels.IssueNeedsDecision:
switch stageTrackerAdoptedByState(rec) {
Expand All @@ -1536,6 +1544,9 @@ func stageTrackerCaption(stage stagelabels.Stage, reason, author string, kind st
// person may take; the gate cell says the same.
return joinClause("Awaiting human: "+step, clause), "maintainer"
}
if c := stageTrackerMergeTrainCaption(reason); c != "" {
return c, "maintainer"
}
return joinClause("A human decision is owed", clause), "maintainer"
case stagelabels.ReadyForHumanMerge:
if base, approver := stagelabels.HumanApprovedReason(reason); stageTrackerManualMergeReason(base) {
Expand Down Expand Up @@ -1802,6 +1813,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
}
it.Modifiers = slices.DeleteFunc(it.Modifiers, func(m string) bool { return m == modNeedsTriage })
}
stageTrackerApplyMergeTrain(it)
it.Caption, it.Actor = stageTrackerCaption(stage, it.Reason, it.Author, it.Kind, it.Mirrored, rec, hasRec, it.LinkedPR, it.Head)
// Adoption is clanker-only (a human's PR is never adopted), so a
// human-authored 072 row keeps its plain caption.
Expand Down Expand Up @@ -2005,6 +2017,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
}
}
resp.OpenIssues, resp.OpenPRs = stageTrackerOpenCounts(resp.Items)
stageTrackerMergeTrainPostPass(resp.Items)
s.applyOperatorActions(resp.Items, now)
resp.NeedsHuman, resp.OnHold = stageTrackerHumanCounts(resp.Items)
stageTrackerResolveLinkedPRs(resp.Items)
Expand Down Expand Up @@ -2740,6 +2753,7 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem) {
lp.BaseRef = pr.BaseRef
lp.DecisionNeeded = pr.DecisionNeeded
lp.SoakRemainingSeconds, lp.MergeGate = pr.SoakRemainingSeconds, pr.MergeGate
lp.MergeTrain = pr.MergeTrain
lp.LastOperatorAction, lp.OperatorActionCount = pr.LastOperatorAction, pr.OperatorActionCount
lp.Hold = pr.Hold
if len(pr.Modifiers) > 0 {
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/dashboard/stage_tracker_decision.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func stageTrackerDecisionNeeded(it StageTrackerItem, verdict *review.Aggregate,
func stageTrackerDecisionNeededAt(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel string, now time.Time) *StageTrackerDecision {
held := slices.Contains(it.Modifiers, modHold)
switch {
case it.Kind == "pr" && it.MergeTrain != nil && it.MergeTrain.State == MergeGateStateRebaseExhausted:
return decisionForMergeTrain(it, held)
case it.Kind == "pr" && (it.Stage == stagelabels.NeedsDecision.Number() || slices.Contains(it.Modifiers, modNeedsDecision)):
return decisionForPR(it, verdict, sentinelLabel, held)
case it.Kind == "pr" && it.Stage == stagelabels.ReadyForHumanMerge.Number():
Expand Down
Loading
Loading