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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **Breaking (merge behaviour):** the auto-merge current-base gate (`auto_merge.require_current_base`) is now on for every repository by default. A green head whose base has moved is brought up to date with GitHub update-branch and merges once CI is green on the new head; a stale-green merge (#15236) had broken `v5` for every open PR for 20 minutes. Opt a repo out with `auto_merge.skip_current_base: [owner/repo]`, or set `auto_merge.require_current_base_default: false` to return to opt-in only. Repos listed explicitly in `require_current_base` are strict; repos gated only by the default merge a head the App cannot update (fork without maintainer edits, branch protection) as tested, with one WARN per PR ([#15335](https://github.com/hivecommons/hive/issues/15335)).
4 changes: 4 additions & 0 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 @@ -2570,6 +2570,9 @@
// a reload of auto_merge.human_merge_paths applies without a restart.
autoMergeOpts.HumanMergePaths = func(repo string) []string { return humanMergePathsFor(b.cfg, repo) }
autoMergeOpts.RequireCurrentBase = func(repo string) bool { return b.cfg != nil && b.cfg.AutoMerge.RequireCurrentBaseFor(repo) }
autoMergeOpts.RequireCurrentBaseStrict = func(repo string) bool {
return b.cfg != nil && b.cfg.AutoMerge.RequireCurrentBaseStrictFor(repo)
}
autoMergeOpts.MergeForwardTrustedHuman = func(repo string) bool {
return b.cfg != nil && b.cfg.AutoMerge.MergeForwardTrustedHumanFor(repo)
}
Expand Down Expand Up @@ -9452,6 +9455,7 @@
opts.RepoOnGitHub = func(repo string) bool { return cfg.RepoOnGitHub(repo) }
opts.HumanMergePaths = func(repo string) []string { return humanMergePathsFor(cfg, repo) }
opts.RequireCurrentBase = func(repo string) bool { return cfg.AutoMerge.RequireCurrentBaseFor(repo) }
opts.RequireCurrentBaseStrict = func(repo string) bool { return cfg.AutoMerge.RequireCurrentBaseStrictFor(repo) }
opts.MergeForwardTrustedHuman = func(repo string) bool { return cfg.AutoMerge.MergeForwardTrustedHumanFor(repo) }
opts.MergeTrain = func() automerge.MergeTrainPolicy {
return automerge.MergeTrainPolicy{Enabled: cfg.AutoMerge.MergeTrain.IsEnabled(), MaxRebaseAttempts: cfg.AutoMerge.MergeTrain.EffectiveMaxRebaseAttempts()}
Expand Down
4 changes: 3 additions & 1 deletion src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ advanced into the merge path.
| `auto_merge.allow_unprotected_base` | deprecated no-op | Accepted for compatibility only. [`hive-merge`](hive-merge.md) no longer refuses solely because a base branch has no GitHub branch protection; it may merge into any branch the App can write after positive CI evidence. |
| `auto_merge.no_ci_ok` | unset (refuse) | **Merge-request watcher key, not a sweep key.** Per-repo opt-in that downgrades only the "unverified" CI verdict (zero statuses, check runs, and workflow runs) to green, for adopted repos with no CI by design. Red and pending verdicts are never downgraded (#6281). See [hive-merge.md](hive-merge.md). |
| `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.require_current_base` | unset | Repo list (`owner/repo`) explicitly opted into the current-base gate in its **strict** form. The gate itself is on for every repo by default (see `require_current_base_default`): the 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](https://github.com/hivecommons/hive/issues/13634), [#15335](https://github.com/hivecommons/hive/issues/15335)). Costs one compare call per merge candidate. Listing a repo here additionally makes it strict: a behind head the App cannot update (fork without maintainer edits, branch protection or a missing `contents: write`) is parked (`fork-not-editable` / `update-branch`) rather than merged as tested. |
| `auto_merge.require_current_base_default` | `true` | Fleet-wide default of the current-base gate for repos in neither `require_current_base` nor `skip_current_base`. On a default-gated repo a behind head the App cannot update merges as it was tested, with one WARN per PR (`automerge current-base gate: … merging as tested`), so fork-heavy repos are not parked wholesale. Set `false` to return to opt-in only. |
| `auto_merge.skip_current_base` | unset | Repo list (`owner/repo`) opted **out** of the current-base gate: a green head there merges even if the base has moved (the pre-#15335 behaviour). An explicit `require_current_base` entry wins over this list. |
| `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 queue · 3 of 4 · ~4m", 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 fixer's rebase-resolve episode (`requested_by: merge-train`, the shared two-attempt guard of [#15104](https://github.com/hivecommons/hive/pull/15104); the fixer router still requires a head the hive can push to, so a fork without maintainer edits stays on the plain `conflicting` path for a person). 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. The queue carries one PR per issue: when two open PRs declare the same `Fixes #N`, the sweep keeps one (green first, then the earlier-opened) and holds the other with lane reason `merge-train:duplicate-of#<winner>:<issue>/0:0/0:` (tracker pill "Duplicate of #15402 · needs a pick"; *Let hive decide* supersedes, [#15395](https://github.com/hivecommons/hive/issues/15395)). `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". |
Expand Down
34 changes: 28 additions & 6 deletions src/pkg/config/automerge_current_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@ package config
import "testing"

func TestRequireCurrentBaseFor(t *testing.T) {
cfg := AutoMergeConfig{RequireCurrentBase: []string{" HiveCommons/Hive ", ""}}
off := false
listed := AutoMergeConfig{RequireCurrentBase: []string{" HiveCommons/Hive ", ""}}
skipped := AutoMergeConfig{SkipCurrentBase: []string{"Acme/Legacy"}}
defaultOff := AutoMergeConfig{RequireCurrentBaseDefault: &off, RequireCurrentBase: []string{"hivecommons/hive"}}
both := AutoMergeConfig{RequireCurrentBase: []string{"acme/widget"}, SkipCurrentBase: []string{"acme/widget"}}
tests := []struct {
name string
cfg AutoMergeConfig
repo string
want bool
}{
{"unset", AutoMergeConfig{}, "hivecommons/hive", false},
{"not listed", cfg, "acme/widget", false},
{"listed case-insensitive", cfg, "hivecommons/hive", true},
{"listed with spaces", cfg, " HIVECOMMONS/HIVE ", true},
{"empty repo", cfg, "", false},
{"unset defaults on", AutoMergeConfig{}, "hivecommons/hive", true},
{"unlisted repo defaults on", listed, "acme/widget", true},
{"listed case-insensitive", listed, "hivecommons/hive", true},
{"listed with spaces", listed, " HIVECOMMONS/HIVE ", true},
{"empty repo", listed, "", false},
{"skip list opts out", skipped, "acme/legacy", false},
{"skip list leaves others on", skipped, "acme/widget", true},
{"default false turns unlisted off", defaultOff, "acme/widget", false},
{"default false keeps listed on", defaultOff, "hivecommons/hive", true},
{"explicit list beats skip list", both, "acme/widget", true},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand All @@ -24,3 +33,16 @@ func TestRequireCurrentBaseFor(t *testing.T) {
})
}
}

func TestRequireCurrentBaseStrictFor(t *testing.T) {
cfg := AutoMergeConfig{RequireCurrentBase: []string{"HiveCommons/Hive"}}
if !cfg.RequireCurrentBaseStrictFor("hivecommons/hive") {
t.Fatal("listed repo must be strict")
}
if cfg.RequireCurrentBaseStrictFor("acme/widget") {
t.Fatal("default-gated repo must not be strict")
}
if (AutoMergeConfig{}).RequireCurrentBaseStrictFor("hivecommons/hive") {
t.Fatal("unset list must not make any repo strict")
}
}
48 changes: 44 additions & 4 deletions src/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8037,9 +8037,27 @@ type AutoMergeConfig struct {
// A head that is green but was tested against an older base is updated
// (GitHub update-branch, a merge commit) and merged once CI is green on
// the new head, so a semantic conflict with anything merged since shows
// up as red CI instead of a broken base. Empty (the default) keeps the
// previous behavior: a green head merges even if the base has moved.
// up as red CI instead of a broken base.
//
// Since hivecommons/hive#15335 the gate is ON for every repo by default
// (RequireCurrentBaseDefault); this list is the STRICT form: a listed
// repo never falls back to merging an un-updated head, even when the App
// cannot update the branch (fork head without maintainer edits, branch
// protection or a missing contents:write). Repos covered only by the
// default merge the green head as tested in that case, with one WARN per
// PR, so a fork-heavy repo is not parked wholesale by the default.
RequireCurrentBase []string `yaml:"require_current_base,omitempty" json:"require_current_base,omitempty"`
// RequireCurrentBaseDefault is the fleet-wide default for the gate above
// on repos that appear in neither RequireCurrentBase nor
// SkipCurrentBase. nil/unset means true (hivecommons/hive#15335: a
// stale-green merge broke v5 for every open PR for 20 minutes because the
// repo was not listed). `false` restores the opt-in-only behaviour.
RequireCurrentBaseDefault *bool `yaml:"require_current_base_default,omitempty" json:"require_current_base_default,omitempty"`
// SkipCurrentBase lists owner/repo names opted OUT of the current-base
// gate: a green head there merges even if the base has moved (the
// pre-#15335 behaviour). An explicit RequireCurrentBase entry wins over
// this list.
SkipCurrentBase []string `yaml:"skip_current_base,omitempty" json:"skip_current_base,omitempty"`
// MergeForwardTrustedHuman lists owner/repo names where a role/trusted
// author/human PR that GitHub reports as conflicting ("dirty") gets the
// base merged into its same-repo head branch as a new App-authored,
Expand Down Expand Up @@ -8488,9 +8506,31 @@ func (a AutoMergeConfig) HumanMergePathsFor(repo string) []string {
return nil
}

// RequireCurrentBaseFor reports whether repo (owner/repo, matched
// case-insensitively) is listed in auto_merge.require_current_base.
// RequireCurrentBaseFor reports whether the automerge lanes must see a head
// that contains the current base tip before merging into repo (owner/repo,
// matched case-insensitively). Resolution order: an explicit
// auto_merge.require_current_base entry (on, strict), then
// auto_merge.skip_current_base (off), then
// auto_merge.require_current_base_default (unset means on).
func (a AutoMergeConfig) RequireCurrentBaseFor(repo string) bool {
key := strings.ToLower(strings.TrimSpace(repo))
if key == "" {
return false
}
if repoListSet(a.RequireCurrentBase)[key] {
return true
}
if repoListSet(a.SkipCurrentBase)[key] {
return false
}
return a.RequireCurrentBaseDefault == nil || *a.RequireCurrentBaseDefault
}

// RequireCurrentBaseStrictFor reports whether repo is explicitly listed in
// auto_merge.require_current_base. A strict repo never merges a head the App
// could not bring up to date; a repo gated only by the default falls back to
// merging the green head as tested when update-branch is unavailable.
func (a AutoMergeConfig) RequireCurrentBaseStrictFor(repo string) bool {
return repoListSet(a.RequireCurrentBase)[strings.ToLower(strings.TrimSpace(repo))]
}

Expand Down
2 changes: 2 additions & 0 deletions src/pkg/dashboard/settings_parity_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ auto_merge.merge_train.max_rebase_attempts # merge train rebase loop guard (#151
auto_merge.no_ci_ok[] # TODO #11854
auto_merge.repos.<key>.required_checks[] # TODO #11854
auto_merge.require_current_base[] # TODO #11854
auto_merge.require_current_base_default # current-base gate fleet default (#15335); yaml-only
auto_merge.required_checks[] # TODO #11854
auto_merge.skip_current_base[] # current-base gate per-repo opt-out (#15335); yaml-only
auto_merge.squash_only[] # merge-method policy; yaml-only
auto_merge.trusted_authors.exclude_labels[] # TODO #11854
auto_merge.trusted_authors.repos[] # TODO #11854
Expand Down
60 changes: 60 additions & 0 deletions src/pkg/github/automerge/automerge_current_base.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package automerge

import (
"context"
"errors"
"fmt"
"net/http"
"strings"

gh "github.com/google/go-github/v72/github"
Expand All @@ -16,6 +19,10 @@
// currentBaseUpdateReason is the update-branch claim reason recorded when
// a green head is refreshed because the base moved under it.
currentBaseUpdateReason = "base-moved"
// currentBaseFallbackMessage is the one-per-PR WARN emitted when a repo
// gated only by auto_merge.require_current_base_default has a behind head
// the App cannot update, so the head merges as it was tested.
currentBaseFallbackMessage = "automerge current-base gate: head is behind the base but the branch cannot be updated; merging as tested (list the repo in auto_merge.require_current_base to park it instead)"
)

func (c *Engine) requireCurrentBaseFor(repo string) bool {
Expand All @@ -25,6 +32,51 @@
return c.requireCurrentBase(repo)
}

func (c *Engine) requireCurrentBaseStrictFor(repo string) bool {
if c == nil || c.requireCurrentBaseStrict == nil {
return false
}
return c.requireCurrentBaseStrict(repo)
}

// currentBaseUpdateUnavailable reports whether an update-branch attempt
// failed because the App may not write the head at all — a fork head without
// maintainer edits, or a same-repo 403 (branch protection or a missing
// contents:write) — as opposed to a transient or conflict failure. Only
// these outcomes let a default-gated repo fall back to merging as tested;
// a conflict or an unknown error still stops the merge.
func currentBaseUpdateUnavailable(reason string, err error) bool {
if reason == autoMergeReasonForkNotEditable {
return true
}
var ghErr *gh.ErrorResponse
return err != nil && errors.As(err, &ghErr) && ghErr.Response != nil && ghErr.Response.StatusCode == http.StatusForbidden
}

// warnCurrentBaseFallbackOnce logs, once per repo#pr, that the default gate
// is letting a behind head merge as tested because the App cannot update it.
// Later ticks for the same PR log at Debug so a parked PR does not repeat
// the line every sweep.
func (c *Engine) warnCurrentBaseFallbackOnce(displayRepo string, number int, reason string, err error) {
if c == nil {
return
}
key := fmt.Sprintf("%s#%d", strings.ToLower(displayRepo), number)
c.currentBaseFallbackWarnedMu.Lock()
if c.currentBaseFallbackWarned == nil || len(c.currentBaseFallbackWarned) > 4096 {
c.currentBaseFallbackWarned = map[string]struct{}{}
}
_, seen := c.currentBaseFallbackWarned[key]
c.currentBaseFallbackWarned[key] = struct{}{}
c.currentBaseFallbackWarnedMu.Unlock()
args := []any{"repo", displayRepo, "pr", number, "reason", reason, "error", err, "opt_in_key", "auto_merge.require_current_base"}
if seen {
c.debug(currentBaseFallbackMessage, args...)
return
}
c.warn(currentBaseFallbackMessage, args...)
}

// currentBaseGate enforces auto_merge.require_current_base
// (hivecommons/hive#13634). GitHub only reports mergeable_state "behind" when
// branch protection requires up-to-date branches, so a head that was green
Expand Down Expand Up @@ -57,5 +109,13 @@
}
c.info("automerge head is behind the current base; updating before merge", "repo", displayRepo, "pr", number, "base", baseBranch, "behind_by", cmp.GetBehindBy())
event, reason, err := c.updateBranchAndSkip(ctx, displayRepo, owner, repo, number, headSHA, currentBaseUpdateReason, fork)
if currentBaseUpdateUnavailable(reason, err) && !c.requireCurrentBaseStrictFor(owner+"/"+repo) {
// Default-on gate (#15335) on a head the App may not write: parking
// it would turn every non-editable fork PR fleet-wide into a stall
// a human has to clear, so keep the pre-gate behaviour for this PR
// and say so once. Strict (explicitly listed) repos still park.
c.warnCurrentBaseFallbackOnce(displayRepo, number, reason, err)
return AutoMergeSweepEvent{}, "", false, nil
}
return event, reason, true, err
}
Loading
Loading