diff --git a/changelog.d/fixed-holdguard-renovate.md b/changelog.d/fixed-holdguard-renovate.md new file mode 100644 index 0000000000..92c91deb86 --- /dev/null +++ b/changelog.d/fixed-holdguard-renovate.md @@ -0,0 +1 @@ +- Hold guard no longer merges the base branch into held Renovate/dependency-bot PRs (a `renovate/*` head branch or a `renovate[bot]`, `dependabot[bot]` or `mergeraptor[bot]` author); the bot keeps those branches current itself, and a hive commit made Renovate stop rebasing them. diff --git a/src/cmd/hive/hold_guard_mergeability_test.go b/src/cmd/hive/hold_guard_mergeability_test.go index f7dcda9b4e..7dfe81d46d 100644 --- a/src/cmd/hive/hold_guard_mergeability_test.go +++ b/src/cmd/hive/hold_guard_mergeability_test.go @@ -284,3 +284,58 @@ func TestMaintainHeldPRMergeabilityIgnoresCleanPR(t *testing.T) { t.Fatalf("update-branch calls for a clean held PR = %d, want 0", calls) } } + +// projectbluefin/utah#1097: Renovate stops rebasing a branch once another +// identity commits to it, so the hive's merge-from-base on a held Renovate PR +// stranded it behind its base. Branches a dependency bot owns are left to the +// bot (no update, no conflict notice, baseline pinned); an ordinary held PR +// still gets the base merged in. +func TestMaintainHeldPRMergeabilityLeavesDependencyBotBranchesToTheBot(t *testing.T) { + for _, tt := range []struct { + name string + headRef string + author string + state string + wantCalls int + wantHead string + }{ + {name: "renovate head ref behind", headRef: "renovate/actions-checkout-6.x", author: "projectbluefin-deps[bot]", state: "behind", wantHead: "c1"}, + {name: "renovate head ref dirty", headRef: "renovate/actions-checkout-6.x", author: "projectbluefin-deps[bot]", state: "dirty", wantHead: "c1"}, + {name: "renovate author", headRef: "deps/bump", author: "renovate[bot]", state: "behind", wantHead: "c1"}, + {name: "mergeraptor author", headRef: "deps/bump", author: "mergeraptor[bot]", state: "behind", wantHead: "c1"}, + {name: "ordinary PR", headRef: "feat/renovate-config", author: "castrojo", state: "behind", wantCalls: 1, wantHead: "c2"}, + } { + t.Run(tt.name, func(t *testing.T) { + store := newTestHoldGuardStore(t) + fake := &holdGuardServer{ + failUpdateBranch: tt.state == "dirty", + commits: map[int][]map[string]any{ + 7: {ghCommit("c1", tt.author, "chore(deps): update"), ghMergeCommit("c2", "hive-bot", "Merge branch 'main' into feature", "c1", "b1")}, + }, + } + client := newHoldGuardClient(t, fake) + cfg := escalationTestConfig() + store.Snapshot("acme/widgets", 7, "c1", []holdguard.Commit{{SHA: "c1", Author: tt.author}}) + + held := heldPRsActionable(github.PullRequest{Repo: "widgets", Number: 7, Author: tt.author, HeadRef: tt.headRef, HeadSHA: "c1", BaseSHA: "b1", MergeableState: tt.state}) + if got := enforceHoldGuard(context.Background(), cfg, client, client, held, discardLogger()); len(got) != 0 { + t.Fatalf("held-PR upkeep must not flag it for re-review, got %v", got) + } + + fake.mu.Lock() + calls := fake.updateBranchCalls[7] + comments := append([]string(nil), fake.comments...) + fake.mu.Unlock() + if calls != tt.wantCalls { + t.Fatalf("update-branch calls for PR 7 = %d, want %d", calls, tt.wantCalls) + } + if len(comments) != 0 { + t.Fatalf("held-PR upkeep must not comment here, saw %v", comments) + } + rec, ok := store.Recorded("acme/widgets", 7) + if !ok || rec.HeadSHA != tt.wantHead || rec.ConflictNoted { + t.Fatalf("snapshot = %+v ok=%v, want baseline %s and no conflict noted", rec, ok, tt.wantHead) + } + }) + } +} diff --git a/src/cmd/hive/main_helpers.go b/src/cmd/hive/main_helpers.go index 275a19e848..2d592b4a6e 100644 --- a/src/cmd/hive/main_helpers.go +++ b/src/cmd/hive/main_helpers.go @@ -327,6 +327,10 @@ func enforceHoldGuard( // runs first every tick, so this only ever sees a PR after its baseline is // pinned, and advancing a baseline that was never pinned would plant a wrong // one. +// +// Branches a dependency bot owns (dependencyBotBranch) are skipped too: the +// bot rebases them itself, and a hive commit on the branch makes Renovate stop +// rebasing it for good. func maintainHeldPRMergeability( ctx context.Context, ghClient *github.Client, @@ -350,6 +354,11 @@ func maintainHeldPRMergeability( if state != "behind" && state != "dirty" { continue } + if dependencyBotBranch(pr) { + logger.Debug("hold guard: held PR branch belongs to a dependency bot; leaving the base sync to the bot", + "repo", repo, "pr", pr.Number, "head_ref", pr.HeadRef, "author", pr.Author, "mergeable_state", state) + continue + } // Own-only (writeback.KindHoldGateNotice): the merge-from-base push // and the conflict notice are upkeep on the hive's OWN held PRs. A // human's prow-held PR is not the hive's branch to push to or @@ -439,6 +448,17 @@ func maintainHeldPRMergeability( } } +// dependencyBotBranch reports whether a PR's head branch belongs to a +// dependency bot that keeps it up to date itself: a `renovate/` head ref (any +// Renovate deployment, whatever App it runs as) or a dependencyBots author. +// Renovate refuses to rebase a branch once another identity has committed to +// it, so a hive merge-from-base on such a branch strands it behind its base +// for good (projectbluefin/utah#1097: three hive base merges, then "will not +// automatically rebase … does not recognize the last commit author"). +func dependencyBotBranch(pr github.PullRequest) bool { + return strings.HasPrefix(pr.HeadRef, "renovate/") || dependencyBots[pr.Author] +} + // intentConfigFromCfg maps config.IntentConfig onto the intent package's // classification config. Shared by writeIntentVerdicts (human merge lane) and // the App self-merge sweep's IntentGate (#6258) so both lanes classify with diff --git a/src/docs/operator-reference/sweeps-and-operations.md b/src/docs/operator-reference/sweeps-and-operations.md index 4b6c6e5156..590123e87b 100644 --- a/src/docs/operator-reference/sweeps-and-operations.md +++ b/src/docs/operator-reference/sweeps-and-operations.md @@ -424,7 +424,7 @@ that level, the power the write-back exists to govern? | Path (code) | Trigger | What it writes | Target set | Gate kind → default | | --- | --- | --- | --- | --- | | Sentinel sweep + webhook (`pkg/github/sentinel_sweep.go`, `pkg/sentinel`) | 15-min reconcile; `pull_request` webhook | `` "maintainer review required" comment + `sentinel-alert` label | every open PR in `project.repos`, human or bot | `sentinel` → L5 with opt-in label, L6 without; below: dashboard/API finding only | -| Hold guard (`cmd/hive/main_helpers.go` hold-drift, `maintainHeldPRMergeability`) | each governor eval | "⚠️ Hold-gate mergeability" / drift comment, re-applied `hold` label, **branch push** merging base | every `hold`-labelled PR, incl. human prow-held ones | `hold_gate_notice` → hive-authored PRs only, L≥4; never foreign PRs | +| Hold guard (`cmd/hive/main_helpers.go` hold-drift, `maintainHeldPRMergeability`) | each governor eval | "⚠️ Hold-gate mergeability" / drift comment, re-applied `hold` label, **branch push** merging base | every `hold`-labelled PR, incl. human prow-held ones; the base-merge push and conflict notice skip dependency-bot branches (`renovate/*` head, or a Renovate/Dependabot/Mergeraptor author), which the bot rebases itself | `hold_gate_notice` → hive-authored PRs only, L≥4; never foreign PRs | | Stage labeler (`pkg/github/stage_labeler.go`, `stage_writer.go`, `pkg/stagelabels`) | stage engine reconcile | `stage/NNN-*` add/remove, `hive:stage-needs-decision` comment, role/author labels | every tracked PR and issue | `stage_label`, `needs_decision_comment` → L5 + opt-in label on foreign PRs; issue stage labels follow the issue filter, not this gate | | Supersession sweep (`pr_supersession_sweep.go`, `_autoclose.go`, `_resolve.go`) | hourly sweep | supersession notice comment, `hive/superseded` close, `needs-human` label | contributor PRs overlapping a hive PR | `supersession_notice` → L5 + label; `supersession_close` → L6 + label | | Duplicate-fix sweep (`pr_duplicate_fix_sweep.go`, `open_pr_links.go`) | hourly sweep | `hive:duplicate-fix` comment, `has-open-pr` label, `hive/superseded` close | PR pairs fixing one issue | `duplicate_fix_notice` → L5 + label |