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-merge-train-front.md
Original file line number Diff line number Diff line change
@@ -0,0 +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).
2 changes: 2 additions & 0 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,7 @@ func (b *boot) bootAgentsWith(deps bootAgentsDeps) {
// 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 Down Expand Up @@ -9372,6 +9373,7 @@ func runAutoMergeSweepIfDue(ctx context.Context, ghClient *github.Client, cfg *c
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.TrustedBotAuthors = func() map[string]bool { return cfg.AutoMerge.TrustedBotAuthorSet() }
}
audit := func(event automerge.AutoMergeSweepEvent) {
Expand Down
1 change: 1 addition & 0 deletions src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ 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.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
@@ -0,0 +1,25 @@
package config

import "testing"

func TestMergeTrainAutoMergeConfigDefaultsOn(t *testing.T) {
off, on := false, true
cases := []struct {
name string
cfg MergeTrainAutoMergeConfig
want bool
}{
{"unset", MergeTrainAutoMergeConfig{}, true},
{"explicit on", MergeTrainAutoMergeConfig{Enabled: &on}, true},
{"explicit off", MergeTrainAutoMergeConfig{Enabled: &off}, false},
}
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")
}
}
18 changes: 18 additions & 0 deletions src/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7918,6 +7918,24 @@ 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 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 *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
}

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

// CreditIssueAuthorsEnabled reports the auto_merge.credit_issue_authors
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/config/testdata/agent_runtime_golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,8 @@
"bot_takeover": {},
"trusted_authors": {},
"contributor_lane": {},
"contributor_tier": {}
"contributor_tier": {},
"merge_train": {}
},
"decisions": {
"delegate": {}
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 @@ -153,6 +153,7 @@ 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
Expand Down
Loading
Loading