Skip to content
Merged
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
1 change: 1 addition & 0 deletions changelog.d/added-automerge-merge-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Conflict-aware merge train in every automerge lane ([#15117](https://github.com/hivecommons/hive/issues/15117)): approved PRs to one base with overlapping changed files are grouped per sweep, one front merges at a time, siblings wait at stage/080 as `merge_gate.state=queued-behind` ("In merge train · 3rd of 4", never a human stage), and after the front merges the lane updates `behind` branches 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 on) turns it off.
14 changes: 12 additions & 2 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

import (
Expand Down Expand Up @@ -2547,7 +2547,6 @@
// auto_merge.trusted_bot_authors takes effect without a restart.
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() }
// 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 All @@ -2571,6 +2570,15 @@
autoMergeOpts.MergeForwardTrustedHuman = func(repo string) bool {
return b.cfg != nil && b.cfg.AutoMerge.MergeForwardTrustedHumanFor(repo)
}
// Merge train (#15117): read live so a reload applies. 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.MergeTrain = func() automerge.MergeTrainPolicy {
if b.cfg == nil {
return automerge.DefaultMergeTrainPolicy
}
return automerge.MergeTrainPolicy{Enabled: b.cfg.AutoMerge.MergeTrain.IsEnabled(), MaxRebaseAttempts: b.cfg.AutoMerge.MergeTrain.EffectiveMaxRebaseAttempts()}
}
b.requestRelays = newRequestRelaySupervisor(b.ctx, func(ctx context.Context, client *github.Client) <-chan struct{} {
laneGate := relayLanePolicyGate(autoMergeOpts)(client)
setMergeEligibleLaneGate(laneGate)
Expand Down Expand Up @@ -9409,7 +9417,9 @@
opts.HumanMergePaths = func(repo string) []string { return humanMergePathsFor(cfg, repo) }
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.MergeTrain = func() automerge.MergeTrainPolicy {
return automerge.MergeTrainPolicy{Enabled: cfg.AutoMerge.MergeTrain.IsEnabled(), MaxRebaseAttempts: 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 @@ -431,10 +431,11 @@ advanced into the merge path.
| `auto_merge.human_merge_paths` | unset | Per-repo map of `owner/repo` to glob patterns (same syntax as `intent.guardrail_path_patterns`) for paths a person must merge, e.g. `Danathar/goodreads-mcp: [".claude/settings.json", ".claude/hooks/**"]`. Every App merge path honors it: the automerge sweep lanes (App self-merge, trusted-author, label-queued) and the agent merge-request relay refuse a PR that touches a listed path, add `hold`, and post one `<!-- hive-human-merge-path -->` comment naming the path(s); a person must merge it. If the changed-file list cannot be fetched completely for a configured repo, the merge is withheld (#11038, #11039). |
| `auto_merge.require_current_base` | unset (off) | Repo list (`owner/repo`) whose App self-merge, trusted-author and contributor lanes only merge a head that contains the current base tip. A green head tested against an older base is updated with GitHub update-branch (a merge commit; no author commit is rewritten) and merges once CI is green on the new head, so a semantic conflict with work merged since turns that PR red instead of breaking the base (#13634). Costs one compare call per merge candidate. |
| `auto_merge.merge_forward_trusted_human` | unset (off) | Repo list (`owner/repo`) where a `role/trusted` + `author/human` PR on a same-repo branch that GitHub reports as conflicting (`dirty`) gets the base merged into its head as one App-authored, signed-off merge commit via the GitHub merges API (no human commit is rewritten), then merges once CI is green on the new head. A real conflict pushes nothing and posts one `<!-- hive:merge-forward-conflict head=… -->` note naming the files both sides changed. Fork heads are never written. Attempted once per head (#13636). |
| `auto_merge.merge_train.enabled` | `true` | Conflict-aware merge train in every automerge lane (hive, trusted-author, contributor) ([#15117](https://github.com/hivecommons/hive/issues/15117)). Each sweep groups the open approved / mergeable-pending PRs of one repo+base by overlapping changed files (`GET /pulls/{n}/files`, cached per head SHA) and lets ONE front per group merge — the clean-mergeable PR approved earliest — while the others 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, never `needs-rebase` as a human flag). 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 the dirty PR falls through to the plain `conflicting` path, logged once). A head the lane last saw blocked on its own (red required check, terminal hold, permanent merge refusal) never fronts, and a group whose best member is blocked imposes no ordering (fail-open) — nobody waits behind a PR that is not moving. One INFO line `merge train` per order change, not per cycle. `false` restores independent per-PR evaluation. |
| `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". |
| `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.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
35 changes: 19 additions & 16 deletions src/pkg/config/automerge_merge_train_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ package config

import "testing"

func TestMergeTrainAutoMergeConfigDefaultsOn(t *testing.T) {
func TestMergeTrainAutoMergeConfigDefaults(t *testing.T) {
off, on := false, true
cases := []struct {
name string
cfg MergeTrainAutoMergeConfig
want bool
tests := []struct {
name string
cfg MergeTrainAutoMergeConfig
wantEnabled bool
wantMax int
}{
{"unset", MergeTrainAutoMergeConfig{}, true},
{"explicit on", MergeTrainAutoMergeConfig{Enabled: &on}, true},
{"explicit off", MergeTrainAutoMergeConfig{Enabled: &off}, false},
{"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 cases {
if got := tc.cfg.IsEnabled(); got != tc.want {
t.Errorf("%s: IsEnabled() = %v, want %v", tc.name, got, tc.want)
}
}
var a AutoMergeConfig
if !a.MergeTrain.IsEnabled() {
t.Fatal("zero AutoMergeConfig disables the merge train; want default on")
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)
}
})
}
}
30 changes: 23 additions & 7 deletions src/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7938,26 +7938,42 @@ 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
// (hivecommons/hive#15117).
// MergeTrain orders approved PRs on the same base whose changed files
// overlap: one front merges at a time, the siblings wait as
// "queued-behind" (stage 080, never a human stage) and are updated or
// rebased right after the front lands instead of each going
// `conflicting` with nothing owning the repair
// (hivecommons/hive#15117). Default ON.
MergeTrain MergeTrainAutoMergeConfig `yaml:"merge_train,omitempty" json:"merge_train,omitempty"`
}

// MergeTrainAutoMergeConfig is auto_merge.merge_train.*.
type MergeTrainAutoMergeConfig struct {
// Enabled groups each sweep's candidate PRs per repo and base branch by
// overlapping changed files and lets only one front per group merge per
// pass: the mergeable one first, then the oldest. nil/unset means ON;
// an explicit `enabled: false` merges every green PR as before.
// Enabled turns the train on. nil/unset means ON; `enabled: false`
// restores the independent per-PR evaluation.
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
3 changes: 2 additions & 1 deletion src/pkg/dashboard/settings_parity_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ agents.session_recycle.max_age # TODO #11854
agents.session_recycle.max_rss_mb # TODO #11854
agents.session_recycle.min_idle # TODO #11854
auto_merge.credit_issue_authors # merge-time Co-authored-by credit (#14581); yaml-only
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.enabled # conflict-aware merge train (#15117); yaml-only
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
Loading
Loading