diff --git a/changelog.d/fixed-no-base-sync-on-merge-queue-base.md b/changelog.d/fixed-no-base-sync-on-merge-queue-base.md new file mode 100644 index 0000000000..6701ce7382 --- /dev/null +++ b/changelog.d/fixed-no-base-sync-on-merge-queue-base.md @@ -0,0 +1 @@ +- With `auto_merge.require_current_base` on, the hive no longer merges the base into a PR whose base branch only accepts merges through GitHub's merge queue (projectbluefin/finpilot#599). The hive cannot enqueue and the queue tests base plus PR itself, so each `base-moved` update only moved the head off its review and the PR waited for a fresh one, three times in a day. The gate now skips the update for 24 hours after the last `merge-queue-required` refusal on that base, and the PR holds at `100-merge-queue`; the 30-minute merge-queue memory no longer has to stay fresh between refusals for that. diff --git a/src/docs/labels-and-control-signals.md b/src/docs/labels-and-control-signals.md index 23249cc7f6..b41ff0efac 100644 --- a/src/docs/labels-and-control-signals.md +++ b/src/docs/labels-and-control-signals.md @@ -464,7 +464,7 @@ used to admit the PR: | a trusted maintainer answered that question on the same head — `/hive decision ` or a CHANGES_REQUESTED review (recorded in `review-human-change-requests.json`, head-scoped) | `070-fixing`, reason `contributor-lane:decision-answered`: the answer is folded into the reviewer verdict for that head on every tick and after a restart, so the stage never re-derives 085 from the stale `requires_human` verdict. A bare `/hive decision approve` instead clears the hold like a trusted Approve review. A new head draws a new verdict with no answer and asks again ([#14679](https://github.com/hivecommons/hive/issues/14679)) | | CI red (`check-failing:*`, `required-check-failing:*`, `status-*`), `conflicting`, `not-mergeable`, `changes-requested`, verdict changes_requested/reject, `needs-rebase` present | `070-fixing` (self-authored lane or `author/hive`) / `071-needs-author` (`author/human`) / `072-returned-to-contributor` (`author/clanker`) — see [Stage 07x by author kind](#stage-07x-by-author-kind). A head whose App-linked commits carry a `Signed-off-by` the squash would misattribute to the PR author (`hive-signoff-attribution`) follows the same split: the branch owner is the only one who can rewrite them. | | `contributor-lane:soaking(...)` — and no red check on the head | `095-pre-merge-soak` | -| `head-changed-since-eval`, `merge-failed`, `merge-queue-required` (the base branch's ruleset only accepts merges through GitHub's merge queue, so the direct REST merge is refused; logged as a skip rather than a merge error, [#14018](https://github.com/hivecommons/hive/issues/14018); the self-authored sweep then skips the direct merge on that base for 30 minutes and logs the skip once per PR head, [#14068](https://github.com/hivecommons/hive/issues/14068); the trusted-author, queued and contributor-lane sweeps skip it the same way, sharing one memory of such bases; while a base is remembered the dashboard shows its otherwise-green PRs as a person's to merge, not Merge-eligible), `required-checks-expected`, `behind`, `updated-branch`, `behind-update-budget-exhausted` (a behind self-authored PR the sweep did not update only because this tick's branch-update budget was spent; retried next tick, waits on the hive, [#12607](https://github.com/hivecommons/hive/issues/12607)), `release-hold*` — and no red check on the head | `100-merge-queue` | +| `head-changed-since-eval`, `merge-failed`, `merge-queue-required` (the base branch's ruleset only accepts merges through GitHub's merge queue, so the direct REST merge is refused; logged as a skip rather than a merge error, [#14018](https://github.com/hivecommons/hive/issues/14018); the self-authored sweep then skips the direct merge on that base for 30 minutes and logs the skip once per PR head, [#14068](https://github.com/hivecommons/hive/issues/14068); the trusted-author, queued and contributor-lane sweeps skip it the same way, sharing one memory of such bases; while a base is remembered the dashboard shows its otherwise-green PRs as a person's to merge, not Merge-eligible; with `auto_merge.require_current_base` on, a head behind such a base is not updated for 24 hours after the last refusal and holds here instead, so the base moving does not reset its review), `required-checks-expected`, `behind`, `updated-branch`, `behind-update-budget-exhausted` (a behind self-authored PR the sweep did not update only because this tick's branch-update budget was spent; retried next tick, waits on the hive, [#12607](https://github.com/hivecommons/hive/issues/12607)), `release-hold*` — and no red check on the head | `100-merge-queue` | | CI red (required or optional check) while the PR is deferred to an open `[shared-ci]` incident (``, the governor's `deferred_incident`) for the same head | `050-review-pending` / `060-reviewed`, reason `shared-ci-incident:`: the base or a shared check is what is red, so the PR is never sent to 070/071/072, never nudged and never stalled; once the incident closes a still-red head is handed back as usual. Conflicts and requested changes stay author-facing ([#12606](https://github.com/hivecommons/hive/issues/12606)) | | CI red (required or optional) while **every** failing check on the head is also red on the base branch's tip — the governor's `base_red_checks` / `base_red`, set during CI enrichment when a same-named latest check run on the base ref (meta checks excluded) concluded failure / timed_out / cancelled / action_required / startup_failure / stale **and** the PR's changed files include none of `.github/workflows/*`, `Dockerfile` / `Dockerfile.*` / `*.Dockerfile`, `go.mod` / `go.sum` (a PR touching those plausibly owns the check and stays author-facing; a lookup error or a diff beyond the file-list page budget also stays author-facing) | `050-review-pending` / `060-reviewed`, reason `base-branch-red:,` ("waiting for the base branch's CI to recover (…) — not this PR's fault"): never 070/071/072, never nudged, never stalled, still not merged (the lane's skip reason is the same token). The fix loop counts no attempt, kicks no fixer, and posts one `` hold comment per head; an escalation the hive itself raised (ledger `label_applied`) over such a head has its `needs-human` removed with the hold wording. The next evaluation after the base goes green re-evaluates the head: a still-red PR is handed back as usual. Conflicts and requested changes stay author-facing (seen on [#13270](https://github.com/hivecommons/hive/pull/13270) and [#13258](https://github.com/hivecommons/hive/pull/13258), 2026-10-20) | | CI red (required or optional) on a **fork** PR while **every** failing check's annotation says the check refuses forks (case-insensitive `fork pull request(s) cannot`, `maintainer must push this branch`, or `cannot publish` together with `fork` — a fork-publication / fork-secrets guard) | `085-needs-decision`, reason `fork-guard:,`: never 070/071/072, never nudged, never adopted (074) — neither the author nor the hive can turn the check green by pushing to the fork. The entry comment names the check and says a maintainer must push the branch to the repository (or approve the run as the repository requires). A same-repo PR with the same message, or a fork PR with any other red check, is handed back as usual ([#14273](https://github.com/hivecommons/hive/issues/14273)) | diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index 892449bbe3..07efe45a66 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -482,7 +482,7 @@ advanced into the merge path. | `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.queue_on_approve_and_unhold` | empty (off) | Per-repo opt-in, ACMM L5 only (#13629). When one trusted merger both submits an Approve review on an agent PR's current head and removes its level `hold`, the queued sweep queues the PR through the same path as the dashboard's queue-auto-merge button. Nothing else counts as consent; the self-merge floor (L6), head-SHA re-check, hold guard and Sentinel are unchanged. See [hive-merge.md](hive-merge.md#one-human-step-at-l5-approve-and-unhold). | | `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 `` 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 (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). A base that refused a direct merge as merge-queue-only (`merge-queue-required`) in the last 24 hours is not updated: GitHub's merge queue tests base plus PR itself, and each update only moved the head off its review (projectbluefin/finpilot#599); the PR stays at `100-merge-queue` for a person to enqueue. 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 `` note naming the files both sides changed. Fork heads are never written. Attempted once per head (#13636). | | `auto_merge.squash_only` | unset (no repo) | Repo list (`owner/repo`) whose branch policy forbids merge commits. Elsewhere, a `role/trusted` PR (or one whose current head a trusted merger approved) 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: ` 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). | diff --git a/src/pkg/github/automerge/automerge_current_base.go b/src/pkg/github/automerge/automerge_current_base.go index 627e233f76..b90eb9b6d0 100644 --- a/src/pkg/github/automerge/automerge_current_base.go +++ b/src/pkg/github/automerge/automerge_current_base.go @@ -35,6 +35,14 @@ func (c *Engine) requireCurrentBaseFor(repo string) bool { // merge waits for CI on the new head. holdReason is returned instead when // the caller may not update the branch this tick. // +// A base that refused a direct merge as merge-queue-only is not updated +// (hivecommons/hive#14068): the hive cannot enqueue, so the PR never merges +// from here, and GitHub's merge queue tests base plus PR itself. Updating +// only moved the head off the review it was held on, so the PR waited for a +// fresh review each time the base moved (projectbluefin/finpilot#599). The +// gate lets the PR through instead, and the sweep holds it at +// merge-queue-required after the review gate. +// // stop is false when the merge may proceed; otherwise the caller returns the // event, reason and error as-is. func (c *Engine) currentBaseGate(ctx context.Context, displayRepo, owner, repo string, number int, baseBranch, headSHA string, branchUpdateAllowed bool, holdReason string, fork bool) (AutoMergeSweepEvent, string, bool, error) { @@ -52,6 +60,10 @@ func (c *Engine) currentBaseGate(ctx context.Context, displayRepo, owner, repo s if cmp.GetBehindBy() <= 0 { return AutoMergeSweepEvent{}, "", false, nil } + if c.mergeQueueBaseHoldsRefresh(owner, repo, baseBranch) { + c.debug("automerge head is behind a merge-queue-only base; not updating", "repo", displayRepo, "pr", number, "base", baseBranch, "behind_by", cmp.GetBehindBy()) + return AutoMergeSweepEvent{}, "", false, nil + } if !branchUpdateAllowed { return AutoMergeSweepEvent{}, holdReason, true, nil } diff --git a/src/pkg/github/automerge/automerge_current_base_test.go b/src/pkg/github/automerge/automerge_current_base_test.go index 2b2ed39427..02459b0b3a 100644 --- a/src/pkg/github/automerge/automerge_current_base_test.go +++ b/src/pkg/github/automerge/automerge_current_base_test.go @@ -101,6 +101,7 @@ type currentBaseLaneAPI struct { mu sync.Mutex statusState string // combined-status / check-run state for the head behindBy int + mergeQueue bool // the merge call is refused as merge-queue-only compares int updates int merges int @@ -170,6 +171,11 @@ func newCurrentBaseLaneServer(t *testing.T, a *currentBaseLaneAPI) *httptest.Ser _, _ = w.Write([]byte(`{"message":"Updating pull request branch."}`)) case r.Method == http.MethodPut && r.URL.Path == "/repos/acme/widget/pulls/7/merge": a.merges++ + if a.mergeQueue { + w.WriteHeader(http.StatusMethodNotAllowed) + _ = json.NewEncoder(w).Encode(map[string]any{"message": mergeQueueRequiredTestMessage}) + return + } _ = json.NewEncoder(w).Encode(map[string]any{"merged": true, "sha": "merge7"}) default: t.Errorf("unexpected request: %s %s", r.Method, r.URL.String()) @@ -311,3 +317,163 @@ func TestContributorLaneCurrentBaseGateAfterGreen(t *testing.T) { }) } } + +// TestCurrentBaseGateMergeQueueBase pins that the gate never merges the base +// into a behind head on a base that refused a direct merge as +// merge-queue-only (projectbluefin/finpilot#599): it lets the PR through to +// the merge-queue hold instead, without an update-branch call, and marks the +// base held so the sweep does not probe it with that behind head. A base +// whose last refusal is older than mergeQueueBaseRefreshHold is updated as +// before. +func TestCurrentBaseGateMergeQueueBase(t *testing.T) { + const head = "sha-head" + t0 := time.Date(2026, 10, 28, 9, 31, 0, 0, time.UTC) + cases := []struct { + name string + refusedAgo time.Duration // 0: the base never refused + updateAllowed bool + wantStop bool + wantReason string + wantUpdates int + wantRequired bool + }{ + {name: "normal base is updated", updateAllowed: true, wantStop: true, wantReason: "check-pending", wantUpdates: 1}, + {name: "merge-queue base inside the old recheck is not updated", refusedAgo: 10 * time.Minute, updateAllowed: true, wantRequired: true}, + {name: "merge-queue base past the old recheck is not updated", refusedAgo: 101 * time.Minute, updateAllowed: true, wantRequired: true}, + {name: "merge-queue base without update budget is not held behind", refusedAgo: 101 * time.Minute, updateAllowed: false, wantRequired: true}, + {name: "merge-queue refusal past the refresh hold updates again", refusedAgo: mergeQueueBaseRefreshHold, updateAllowed: true, wantStop: true, wantReason: "check-pending", wantUpdates: 1}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + var mu sync.Mutex + compares, updates := 0, 0 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mu.Lock() + defer mu.Unlock() + switch { + case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/compare/main..."+head: + compares++ + _ = json.NewEncoder(w).Encode(map[string]any{"behind_by": 2, "ahead_by": 1}) + case r.Method == http.MethodPut && r.URL.Path == "/repos/acme/widget/pulls/7/update-branch": + updates++ + w.WriteHeader(http.StatusAccepted) + _, _ = w.Write([]byte(`{"message":"Updating pull request branch."}`)) + default: + t.Errorf("unexpected request %s %s", r.Method, r.URL.Path) + w.WriteHeader(http.StatusNotFound) + } + })) + defer srv.Close() + + c := newAutoMergeSweepClient(srv.URL) + c.requireCurrentBase = func(string) bool { return true } + now := t0 + c.now = func() time.Time { return now } + if tc.refusedAgo > 0 { + now = t0.Add(-tc.refusedAgo) + c.noteMergeQueueBase("acme", "widget", "main") + now = t0 + } + _, reason, stop, err := c.currentBaseGate(context.Background(), "acme/widget", "acme", "widget", 7, "main", head, tc.updateAllowed, "behind", false) + if err != nil { + t.Fatal(err) + } + if stop != tc.wantStop || reason != tc.wantReason { + t.Fatalf("stop, reason = %v, %q; want %v, %q", stop, reason, tc.wantStop, tc.wantReason) + } + mu.Lock() + defer mu.Unlock() + if compares != 1 || updates != tc.wantUpdates { + t.Fatalf("compares, updates = %d, %d; want 1, %d", compares, updates, tc.wantUpdates) + } + if got := c.mergeQueueBaseKnown("acme", "widget", "main"); got != tc.wantRequired { + t.Fatalf("merge-queue base known after the gate = %v, want %v", got, tc.wantRequired) + } + }) + } +} + +// TestSelfAuthoredLaneNoBaseRefreshOnMergeQueueBase replays +// projectbluefin/finpilot#599 through the self-authored lane: a green +// current head is refused as merge-queue-only, then the base keeps moving. +// Every later sweep, hours past the 30-minute merge-queue recheck, holds the +// PR at merge-queue-required without an update-branch call (each one used to +// reset the review) and without a direct-merge probe of the behind head. A +// head that is current again re-probes the base once no behind head was held +// for mergeQueueBaseRecheck, and a probe that is refused again re-arms the +// hold, so the hold lasts while the refusals continue. +func TestSelfAuthoredLaneNoBaseRefreshOnMergeQueueBase(t *testing.T) { + api := ¤tBaseLaneAPI{statusState: "success", mergeQueue: true} + srv := newCurrentBaseLaneServer(t, api) + defer srv.Close() + c := newAutoMergeSweepClient(srv.URL) + c.requireCurrentBase = func(repo string) bool { return strings.EqualFold(repo, "acme/widget") } + t0 := time.Date(2026, 10, 28, 9, 31, 0, 0, time.UTC) + now := t0 + c.now = func() time.Time { return now } + + sweep := func(step string, at time.Duration, behindBy int, wantReason string, wantUpdates, wantMerges int) { + t.Helper() + now = t0.Add(at) + api.mu.Lock() + api.behindBy = behindBy + api.mu.Unlock() + _, beforeUpdates, beforeMerges := api.counts() + event, reason, err := c.trySweepSelfAuthoredPR(context.Background(), "acme/widget", "acme", "widget", 7, true) + if err != nil { + t.Fatalf("%s: %v", step, err) + } + _, updates, merges := api.counts() + if reason != wantReason || event.BranchUpdated != (wantUpdates > 0) { + t.Fatalf("%s: reason = %q, BranchUpdated = %v; want %q, %v", step, reason, event.BranchUpdated, wantReason, wantUpdates > 0) + } + if updates-beforeUpdates != wantUpdates || merges-beforeMerges != wantMerges { + t.Fatalf("%s: updates, merges = %d, %d; want %d, %d", step, updates-beforeUpdates, merges-beforeMerges, wantUpdates, wantMerges) + } + } + + sweep("current head is refused by the merge queue", 0, 0, autoMergeReasonMergeQueueRequired, 0, 1) + sweep("base moved inside the recheck", 15*time.Minute, 2, autoMergeReasonMergeQueueRequired, 0, 0) + sweep("base moved 1h41m after the refusal (the 11:13Z refresh)", 101*time.Minute, 3, autoMergeReasonMergeQueueRequired, 0, 0) + sweep("base moved 5h45m after the refusal (the 15:16Z refresh)", 345*time.Minute, 4, autoMergeReasonMergeQueueRequired, 0, 0) + sweep("current head right after a hold is not probed", 350*time.Minute, 0, autoMergeReasonMergeQueueRequired, 0, 0) + sweep("current head re-probes once no hold for the recheck", 345*time.Minute+mergeQueueBaseRecheck, 0, autoMergeReasonMergeQueueRequired, 0, 1) + reprobe := 345*time.Minute + mergeQueueBaseRecheck + sweep("behind head a day after the first refusal is still held", reprobe+20*time.Hour, 2, autoMergeReasonMergeQueueRequired, 0, 0) + sweep("no refusal for the refresh hold: the base is updated again", reprobe+mergeQueueBaseRefreshHold, 2, "check-pending", 1, 0) +} + +// TestSelfAuthoredLaneMergeQueueRuleRemoved pins the way out of the hold: +// once the queue rule is gone, the probe of a current head merges it, and a +// behind head on that base is updated again after mergeQueueBaseRefreshHold +// at the latest, never merged behind its base. +func TestSelfAuthoredLaneMergeQueueRuleRemoved(t *testing.T) { + api := ¤tBaseLaneAPI{statusState: "success", behindBy: 2} + srv := newCurrentBaseLaneServer(t, api) + defer srv.Close() + c := newAutoMergeSweepClient(srv.URL) + c.requireCurrentBase = func(repo string) bool { return strings.EqualFold(repo, "acme/widget") } + t0 := time.Date(2026, 10, 28, 9, 31, 0, 0, time.UTC) + now := t0 + c.now = func() time.Time { return now } + c.noteMergeQueueBase("acme", "widget", "main") + + for _, at := range []time.Duration{time.Hour, 6 * time.Hour, 23 * time.Hour} { + now = t0.Add(at) + _, reason, err := c.trySweepSelfAuthoredPR(context.Background(), "acme/widget", "acme", "widget", 7, true) + if err != nil || reason != autoMergeReasonMergeQueueRequired { + t.Fatalf("at +%s: reason, err = %q, %v; want %q", at, reason, err, autoMergeReasonMergeQueueRequired) + } + } + if _, updates, merges := api.counts(); updates != 0 || merges != 0 { + t.Fatalf("held behind head: updates, merges = %d, %d; want 0, 0", updates, merges) + } + now = t0.Add(mergeQueueBaseRefreshHold) + event, reason, err := c.trySweepSelfAuthoredPR(context.Background(), "acme/widget", "acme", "widget", 7, true) + if err != nil || reason != "check-pending" || !event.BranchUpdated { + t.Fatalf("after the refresh hold: reason, BranchUpdated, err = %q, %v, %v; want check-pending, true", reason, event.BranchUpdated, err) + } + if _, updates, merges := api.counts(); updates != 1 || merges != 0 { + t.Fatalf("after the refresh hold: updates, merges = %d, %d; want 1, 0", updates, merges) + } +} diff --git a/src/pkg/github/automerge/automerge_merge_queue_bases.go b/src/pkg/github/automerge/automerge_merge_queue_bases.go index 97bea84bcd..cef597774e 100644 --- a/src/pkg/github/automerge/automerge_merge_queue_bases.go +++ b/src/pkg/github/automerge/automerge_merge_queue_bases.go @@ -16,14 +16,26 @@ import ( // on that base finds out again, so removing the queue rule is picked up // without a restart. The memory is in-process only: after a restart a base // is unknown until a sweep tries to merge into it once. +// +// The current-base gate also reads it (HoldBaseRefresh), over the longer +// mergeQueueBaseRefreshHold, so the hive stops merging the base into a PR it +// can never merge directly (hivecommons/hive#13634, #14068). type MergeQueueBases struct { mu sync.Mutex - seen map[string]time.Time + seen map[string]mergeQueueBase +} + +// mergeQueueBase is one remembered base. refused is the last time GitHub +// refused a direct merge into it as merge-queue-only; held is the last time +// the current-base gate kept a behind head off it instead of updating it. +type mergeQueueBase struct { + refused time.Time + held time.Time } // NewMergeQueueBases returns an empty memory. func NewMergeQueueBases() *MergeQueueBases { - return &MergeQueueBases{seen: make(map[string]time.Time)} + return &MergeQueueBases{seen: make(map[string]mergeQueueBase)} } func mergeQueueBaseKey(repo, base string) string { @@ -38,13 +50,17 @@ func (m *MergeQueueBases) Note(repo, base string, now time.Time) { m.mu.Lock() defer m.mu.Unlock() if m.seen == nil { - m.seen = make(map[string]time.Time) + m.seen = make(map[string]mergeQueueBase) } - m.seen[mergeQueueBaseKey(repo, base)] = now + key := mergeQueueBaseKey(repo, base) + entry := m.seen[key] + entry.refused = now + m.seen[key] = entry } // Required reports whether base of repo ("owner/name") refused a direct merge -// as merge-queue-only within mergeQueueBaseRecheck of now. +// as merge-queue-only within mergeQueueBaseRecheck of now, or the current-base +// gate held a behind head on it within mergeQueueBaseRecheck (HoldBaseRefresh). func (m *MergeQueueBases) Required(repo, base string, now time.Time) bool { if m == nil || strings.TrimSpace(base) == "" { return false @@ -52,13 +68,54 @@ func (m *MergeQueueBases) Required(repo, base string, now time.Time) bool { key := mergeQueueBaseKey(repo, base) m.mu.Lock() defer m.mu.Unlock() - seen, ok := m.seen[key] + entry, ok := m.seen[key] + if !ok { + return false + } + if now.Sub(entry.refused) >= mergeQueueBaseRefreshHold { + delete(m.seen, key) + return false + } + last := entry.refused + if entry.held.After(last) { + last = entry.held + } + return now.Sub(last) < mergeQueueBaseRecheck +} + +// HoldBaseRefresh reports whether base of repo ("owner/name") refused a direct +// merge as merge-queue-only within mergeQueueBaseRefreshHold of now, so the +// current-base gate must not merge the base into a behind head +// (hivecommons/hive#13634, #14068). The hive cannot enqueue, the merge queue +// tests base plus PR itself, and each refresh only moved the head off its +// review (projectbluefin/finpilot#599: three refreshes in a day, each +// followed by a wait for a fresh review, never a merge). +// +// A true answer also marks the base held, which keeps Required true for +// mergeQueueBaseRecheck: the sweep then holds the behind head at +// merge-queue-required instead of re-probing the base with a direct merge of +// a head that does not contain it (if the queue rule had been removed, that +// probe would merge a stale head past auto_merge.require_current_base). The +// direct-merge probe still runs on a head that is current once no behind +// head was held for mergeQueueBaseRecheck; a hold never extends refused, so +// with no new refusal the gate goes back to updating after +// mergeQueueBaseRefreshHold. +func (m *MergeQueueBases) HoldBaseRefresh(repo, base string, now time.Time) bool { + if m == nil || strings.TrimSpace(base) == "" { + return false + } + key := mergeQueueBaseKey(repo, base) + m.mu.Lock() + defer m.mu.Unlock() + entry, ok := m.seen[key] if !ok { return false } - if now.Sub(seen) >= mergeQueueBaseRecheck { + if now.Sub(entry.refused) >= mergeQueueBaseRefreshHold { delete(m.seen, key) return false } + entry.held = now + m.seen[key] = entry return true } diff --git a/src/pkg/github/automerge/automerge_merge_queue_bases_test.go b/src/pkg/github/automerge/automerge_merge_queue_bases_test.go index 5c545ff401..398bbf4461 100644 --- a/src/pkg/github/automerge/automerge_merge_queue_bases_test.go +++ b/src/pkg/github/automerge/automerge_merge_queue_bases_test.go @@ -38,3 +38,58 @@ func TestMergeQueueBasesSharedAcrossEngines(t *testing.T) { t.Error("a nil memory reports a base") } } + +// TestMergeQueueBasesHoldBaseRefresh pins the refresh hold the current-base +// gate reads (projectbluefin/finpilot#599): it outlasts the 30-minute merge +// recheck by mergeQueueBaseRefreshHold after the last refusal, each hold +// keeps Required true for another mergeQueueBaseRecheck, a hold never extends +// the refusal itself, and a new refusal re-arms it. +func TestMergeQueueBasesHoldBaseRefresh(t *testing.T) { + t0 := time.Date(2026, 10, 28, 9, 31, 0, 0, time.UTC) + m := NewMergeQueueBases() + if m.HoldBaseRefresh("projectbluefin/finpilot", "main", t0) { + t.Fatal("a base that never refused holds the refresh") + } + m.Note("projectbluefin/finpilot", "main", t0) + + at := t0.Add(101 * time.Minute) + if m.Required("projectbluefin/finpilot", "main", at) { + t.Fatal("Required past mergeQueueBaseRecheck with no hold") + } + if !m.HoldBaseRefresh("ProjectBluefin/FinPilot", "main", at) { + t.Fatal("refresh not held 1h41m after the refusal") + } + if !m.Required("projectbluefin/finpilot", "main", at.Add(mergeQueueBaseRecheck-time.Second)) { + t.Fatal("a hold did not keep Required true for mergeQueueBaseRecheck") + } + if m.Required("projectbluefin/finpilot", "main", at.Add(mergeQueueBaseRecheck)) { + t.Fatal("a hold kept Required true past mergeQueueBaseRecheck") + } + if m.HoldBaseRefresh("projectbluefin/finpilot", "testing", at) || m.HoldBaseRefresh("projectbluefin/finpilot", "", at) { + t.Fatal("another base, or an unknown one, holds the refresh") + } + + // Holds alone never outlast the refusal. + for at = at.Add(time.Hour); at.Before(t0.Add(mergeQueueBaseRefreshHold)); at = at.Add(time.Hour) { + if !m.HoldBaseRefresh("projectbluefin/finpilot", "main", at) { + t.Fatalf("refresh not held %s after the refusal", at.Sub(t0)) + } + } + if m.HoldBaseRefresh("projectbluefin/finpilot", "main", t0.Add(mergeQueueBaseRefreshHold)) { + t.Fatal("holds extended the refresh hold past mergeQueueBaseRefreshHold") + } + if m.Required("projectbluefin/finpilot", "main", t0.Add(mergeQueueBaseRefreshHold)) { + t.Fatal("expired entry still Required") + } + + // A refusal that keeps coming keeps the hold. + t1 := t0.Add(30 * time.Hour) + m.Note("projectbluefin/finpilot", "main", t1) + if !m.HoldBaseRefresh("projectbluefin/finpilot", "main", t1.Add(mergeQueueBaseRefreshHold-time.Minute)) { + t.Fatal("a new refusal did not re-arm the refresh hold") + } + var nilMem *MergeQueueBases + if nilMem.HoldBaseRefresh("o/r", "main", t0) { + t.Error("a nil memory holds the refresh") + } +} diff --git a/src/pkg/github/automerge/automerge_sweep.go b/src/pkg/github/automerge/automerge_sweep.go index c375f5e9e2..688a2cb897 100644 --- a/src/pkg/github/automerge/automerge_sweep.go +++ b/src/pkg/github/automerge/automerge_sweep.go @@ -608,6 +608,16 @@ var mergeQueueRequiredRE = regexp.MustCompile(`(?i)must be made through the merg // so a ruleset change is picked up without a restart. const mergeQueueBaseRecheck = 30 * time.Minute +// mergeQueueBaseRefreshHold is how long after the last merge-queue refusal +// the current-base gate keeps from updating behind heads on that base +// (MergeQueueBases.HoldBaseRefresh). It is longer than mergeQueueBaseRecheck +// because a hold re-probes nothing: the 30-minute memory had expired between +// refusals and the gate went back to merging the base into a PR that could +// only ever merge through the queue. A day bounds how long a removed queue +// rule goes unnoticed when no head on that base is current to probe it; a +// restart forgets it at once. +const mergeQueueBaseRefreshHold = 24 * time.Hour + // mergeMethodFor returns the GitHub merge method the sweep should use for pr. // Forward-merge / top-up PRs between release lines must land as true merge // commits so the target line keeps the source line's ancestry; everything else @@ -3143,6 +3153,16 @@ func (c *Engine) noteMergeQueueBase(owner, repo, base string) { c.mergeQueueMemory().Note(owner+"/"+repo, base, c.clock()) } +// mergeQueueBaseHoldsRefresh reports whether the current-base gate must not +// update a behind head on base because the base refused a direct merge as +// merge-queue-only within mergeQueueBaseRefreshHold. +func (c *Engine) mergeQueueBaseHoldsRefresh(owner, repo, base string) bool { + if c == nil { + return false + } + return c.mergeQueueMemory().HoldBaseRefresh(owner+"/"+repo, base, c.clock()) +} + // mergeQueueBaseKnown reports whether base refused a direct merge as // merge-queue-only within mergeQueueBaseRecheck. func (c *Engine) mergeQueueBaseKnown(owner, repo, base string) bool {