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-dependency-bot-rebase-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Dependency bots: a bot PR the bot has stopped rebasing no longer sits behind its base forever. Renovate and Dependabot stop maintaining a branch once someone else commits to it (a person's "Update branch", a stray merge-forward), and the hive never base-syncs a bot's branch, so on a base that requires up-to-date branches such a PR stayed behind with nobody told. The dependency-bot hand-off sweep now treats a bot PR that has been behind or conflicting for `governor.dependency_bot_rebase_after_s` (default 4 hours) as stranded when its head commit is not the bot's or its Renovate config rebases never, and asks the bot to rebase through the bot's own mechanism, once per head: it ticks Renovate's rebase/retry checkbox (only that line of the description changes) or comments `@dependabot recreate`. If the head has not moved one window later, the PR goes to a person through the existing hand-off (one comment plus `needs-human`, "dependency bot will not rebase this branch"). A branch carrying someone else's non-merge commit is never regenerated; it goes to a person instead. The request is the new write-back kind `bot_rebase_request` (default L6 with the opt-in label, editable in Settings → Features → Write-back containment and through the admin MCP `writeback.kind_policy` operation); when the kind refuses, a stranded PR that is only behind is still handed to a person once the window passes, and a conflicting one keeps the 24-hour conflict hand-off.
71 changes: 64 additions & 7 deletions src/cmd/hive/dependency_bot_conflicts.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ type depBotConflictStore struct {
// holds per PR head.
observed map[string]*depBotObservation
holds map[string]depBotHold

// rebase holds the persisted stranded-branch records
// (dependency_bot_rebase_request.go); branchFacts, in memory only, what
// each PR's commit list said about its current head.
rebase map[string]*depBotRebaseState
branchFacts map[string]depBotBranchFacts
}

func loadDepBotConflictStore(path string) *depBotConflictStore {
Expand All @@ -77,6 +83,9 @@ func loadDepBotConflictStore(path string) *depBotConflictStore {
noMarker: map[string]string{},
observed: loadDepBotObservations(depBotObservedPath(path)),
holds: map[string]depBotHold{},

rebase: loadDepBotRebaseStates(depBotRebasePath(path)),
branchFacts: map[string]depBotBranchFacts{},
}
data, err := os.ReadFile(path)
if err != nil {
Expand Down Expand Up @@ -236,23 +245,32 @@ func dependencyBotConflictComment(base string) string {
// - a failing required check that stayed red on the same head past
// depBotRedCIGrace (the PR stays out of the fix loop);
// - a terminal required-check hold the automerge sweep reported (held for
// approval, never started, never ran).
// approval, never started, never ran);
// - a stranded branch: behind or conflicting past
// governor.dependency_bot_rebase_after_s while the bot no longer rebases
// it, one window after a request to the bot through its own mechanism
// (dependency_bot_rebase_request.go) went unanswered, or as soon as the
// window passes when that request is not allowed or not safe.
//
// It takes that label back off once the reason is over (see
// depBotHandoffResolved) or the PR closes — only if this sweep is the one
// that added it. It never pushes, rebases, closes, approves or ticks.
// that added it. It never pushes, rebases, closes or approves; the only
// writes besides the hand-off are that one rebase request per head (a
// ticked Renovate rebase/retry box or `@dependabot recreate`), gated as
// write-back kind bot_rebase_request.
func runDependencyBotConflictSweep(ctx context.Context, cfg *config.Config, writer forge.IssueWriter, reader depBotPRReader, actionable *github.ActionableResult, logger *slog.Logger) {
org := ""
if cfg != nil {
org = cfg.Project.Org
}
sweepDependencyBotConflicts(ctx, getDepBotConflictStore(), org, writer, reader, actionable, time.Now, logger)
sweepDependencyBotConflicts(ctx, getDepBotConflictStore(), org, cfg.DependencyBotRebaseAfter(), writer, reader, actionable, time.Now, logger)
}

func sweepDependencyBotConflicts(
ctx context.Context,
store *depBotConflictStore,
org string,
rebaseAfter time.Duration,
writer forge.IssueWriter,
reader depBotPRReader,
actionable *github.ActionableResult,
Expand Down Expand Up @@ -282,16 +300,44 @@ func sweepDependencyBotConflicts(

undoDependencyBotConflicts(ctx, store, writer, reader, seen, logger)

if rebaseAfter <= 0 {
rebaseAfter = config.DefaultDependencyBotRebaseAfterS * time.Second
}
stranded := depBotRebaseCheck{store: store, reader: reader, window: rebaseAfter, now: now(), logger: logger}
store.pruneRebase(seen)

waiting := map[string]bool{}
defer store.pruneObservations(waiting)
for _, pr := range actionable.PRs.Items {
if pr.HeadSHA == "" || !dependencyBotHandoffCandidate(pr) {
if pr.HeadSHA == "" {
continue
}
botAuthor := dependencyBotHandoffCandidate(pr)
if !botAuthor && !dependencyBotBranchCandidate(pr) {
continue
}
repo := qualify(pr.Repo)
key := escalation.Key(repo, pr.Number)
heldReason := store.heldReason(key, pr.HeadSHA)
reason, ok := dependencyBotHandoffReason(pr, heldReason)
heldReason, reason, ok := "", "", false
if botAuthor {
heldReason = store.heldReason(key, pr.HeadSHA)
reason, ok = dependencyBotHandoffReason(pr, heldReason)
}
// A stranded branch (the bot stopped rebasing it) is asked about
// before any conflict or red-CI hand-off: holdHandoff keeps that
// comment back (its grace clock still runs) while a rebase request is
// due or pending, so the PR never gets the request and a person's
// comment at once.
holdHandoff := false
if heldReason == "" {
switch stranded.step(ctx, repo, key, pr) {
case depBotStrandedHandoff:
reason, ok = depBotHandoffStranded, true
case depBotStrandedHold:
holdHandoff = true
waiting[key] = true
}
}
if !ok {
continue
}
Expand All @@ -309,6 +355,13 @@ func sweepDependencyBotConflicts(
case depBotHandoffHeld:
comment = dependencyBotHeldCheckComment(pr.Author, heldReason)
case depBotHandoffConflict:
if holdHandoff {
// A rebase request is due or pending: keep the grace clock
// running, post nothing yet.
waiting[key] = true
store.observe(key, pr.HeadSHA, reason, now())
continue
}
if pr.Author == renovateBotAuthor && !store.lacksMarker(key, pr.HeadSHA) {
body, err := reader.GetPRBody(ctx, repo, pr.Number)
if err != nil {
Expand All @@ -332,10 +385,14 @@ func sweepDependencyBotConflicts(
}
case depBotHandoffRedCI:
waiting[key] = true
if now().Sub(store.observe(key, pr.HeadSHA, reason, now())) < depBotRedCIGrace {
if now().Sub(store.observe(key, pr.HeadSHA, reason, now())) < depBotRedCIGrace || holdHandoff {
continue
}
comment = dependencyBotRedCIComment(pr)
case depBotHandoffStranded:
st, _ := store.rebaseState(key)
facts, known := store.branchFactsFor(key, pr.HeadSHA)
comment = dependencyBotStrandedComment(pr, st, facts, known, rebaseAfter)
}
if !depBotWritebackAllowed(ctx, reader, repo, pr.Number, writeback.KindNeedsDecisionComment, comment, logger) {
continue
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/hive/dependency_bot_conflicts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (h *depBotHarness) pass(prs ...github.PullRequest) {
a := &github.ActionableResult{}
a.PRs.Items = prs
now := func() time.Time { return time.Date(2026, 10, 12, 12, 0, 0, 0, time.UTC) }
sweepDependencyBotConflicts(context.Background(), h.store, "acme", h.writer, h.reader, a, now, discardLogger())
sweepDependencyBotConflicts(context.Background(), h.store, "acme", 0, h.writer, h.reader, a, now, discardLogger())
}

const depBotKey = "acme/widgets#42"
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/hive/dependency_bot_handoffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func depBotHandoffResolved(rec depBotConflictRecord, pr github.PullRequest) bool
// A new head re-creates the checks; a check that completes green
// lets automerge merge (closed is handled by the caller).
return pr.HeadSHA != "" && pr.HeadSHA != rec.HeadSHA
case depBotHandoffStranded:
// The bot (or a person) moved the head, or the PR caught up.
return (pr.HeadSHA != "" && pr.HeadSHA != rec.HeadSHA) || depBotStuckResolved(pr)
default:
return depBotConflictResolved(pr)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/hive/dependency_bot_handoffs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (h *depBotHarness) passAt(at time.Time, prs ...github.PullRequest) {
h.t.Helper()
a := &github.ActionableResult{}
a.PRs.Items = prs
sweepDependencyBotConflicts(context.Background(), h.store, "acme", h.writer, h.reader, a, func() time.Time { return at }, discardLogger())
sweepDependencyBotConflicts(context.Background(), h.store, "acme", 0, h.writer, h.reader, a, func() time.Time { return at }, discardLogger())
}

func depBotPR(author, sha string, mut func(*github.PullRequest)) github.PullRequest {
Expand Down
Loading
Loading