Repository navigation
✨ feat(dependency-bots): ask a stranded bot to rebase its own PR - #17591
Conversation
A dependency bot stops maintaining a branch once someone else has committed to it, and the hive never base-syncs a bot's branch, so on a base that requires up-to-date branches such a PR sat behind forever with nobody told. The dependency-bot hand-off sweep never looked at a PR that was only behind, and nothing ever asked the bot itself. The sweep now treats a dependency-bot PR that has been behind or conflicting for governor.dependency_bot_rebase_after_s (default 4h) as stranded when its head commit is not the bot's or its Renovate config rebases never. It asks the bot once per head through the bot's own mechanism: 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 with the reason "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 a new write-back kind, bot_rebase_request, defaulting to L6 with the opt-in label like base_refresh. When it refuses, a stranded PR that is only behind is handed to a person at the window, and a conflicting one keeps the 24-hour conflict hand-off. While a request is due or pending, the conflict and red-CI hand-offs wait, so a PR never gets the request and a person's comment at once. First-seen and requested heads persist beside the conflict ledger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Security perspective (read at head 6c227af). No blocker; two notes, worst first.
1. (low) The "never regenerate a branch carrying someone else's work" guard trusts the git author name when the commit has no linked login.
depBotCommitIsBots (src/cmd/hive/dependency_bot_rebase_request.go:151-154) accepts IsDependencyBotAuthor(a) on PRCommit.Author, and ListPRCommits (src/pkg/github/pr_commits.go:70-73) fills that field from rc.GetCommit().GetAuthor().GetName() whenever the commit's email is not linked to a GitHub account. So a commit pushed with git -c user.name='renovate[bot]' -c user.email=anything is counted as the bot's: ForeignWork stays false (:166-175), and the sweep ticks the box / posts @dependabot recreate, which drops that commit. The blast radius is small (whoever pushed it needs write access to the bot branch and mostly harms their own commit), and the write is still L6+label gated, so advisory only — but the guard's promise in the PR body ("Never when the branch carries someone else's non-merge commit") is only as strong as a git header. Suggested fix: carry whether the author came from a real login and require it for the bot match:
--- a/src/pkg/github/pr_commits.go
+++ b/src/pkg/github/pr_commits.go
@@ type PRCommit struct {
Author string
+ // AuthorIsLogin: Author is a GitHub login, not the git author name
+ // fallback (which anyone who can push can set to anything).
+ AuthorIsLogin bool
@@ func (c *Client) ListPRCommits(
author := safeGetLogin(rc.GetAuthor())
+ isLogin := author != ""
if author == "" {
author = rc.GetCommit().GetAuthor().GetName()
}
@@
Author: author,
+ AuthorIsLogin: isLogin,
--- a/src/cmd/hive/dependency_bot_rebase_request.go
+++ b/src/cmd/hive/dependency_bot_rebase_request.go
-func depBotCommitIsBots(pr github.PullRequest, author string) bool {
- a := strings.TrimSpace(author)
+func depBotCommitIsBots(pr github.PullRequest, c github.PRCommit) bool {
+ if !c.AuthorIsLogin {
+ return false // a git author name is not an identity
+ }
+ a := strings.TrimSpace(c.Author)
return github.IsDependencyBotAuthor(a) || (a != "" && strings.EqualFold(a, strings.TrimSpace(pr.Author)))
}(and pass c instead of c.Author at :167 and :172). A fallback-named commit then reads as foreign → hand-off to a person, which is the safe direction.
2. (info) The stranded check runs on any PR with a renovate/ head ref, whatever the author.
dependencyBotBranchCandidate (dependency_bot_rebase_request.go:120-129) → github.DependencyBotBranch (src/pkg/github/dependency_bot.go:30-32) matches on branch prefix alone, so a human (fork) PR named renovate/… enters this path, and its body is attacker-controlled: renovateRebasesNever is a plain strings.Contains (dependency_bot_conflicts.go:210-212), so the author can make their own PR "stranded" at the window and have the hive edit their PR body (tick) or post a needs-human hand-off that calls it a Renovate PR. The body edit is three bytes on a line they wrote and is L6+label gated, so I see no exploit — only a misleading hand-off. If you want to close it cheaply: require pr.Author == renovateBotAuthor || facts.ForeignHead before honouring rebasesNever for non-bot authors.
Verified as safe: commit-list truncation fails closed (depBotFactsFromCommits:159-161 requires the last listed commit to be the head; ListPRRepositoryCommits caps at maxPRCommitPages); RequestRenovateRebase re-reads the PR and refuses on head drift (src/pkg/github/dependency_bot_rebase.go:105-107); the Dependabot branch keys on the API pr.Author (dependency_bot_rebase_request.go:321), not on anything a contributor controls; both writes go through depBotWritebackAllowed/WritebackAllowed and are audited.
— hive: agent=ci-maintainer backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Test review — Failing test: Source: the new Two ways to go green, either is fine from the test side:
Everything else in the shard is green/informational ( Rest of the test surface looks solid: Branch is in a fork, so I can't push this; a one-file change plus the test should do it. 🐝 Hive Agent: — hive: agent=quality backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. Review findings from Test review — Failing test: Source: the new Two ways to go green, either is fine from the test side:
Everything else in the shard is green/informational ( Rest of the test surface looks solid: Branch is in a fork, so I can't push this; a one-file change plus the test should do it. Review findings from Read the new sweep ( What I verified:
One non-blocking observation: Review findings from Delta re-review (intent-alignment), head Previous finding — fixed. The unmarked-emitter ratchet nets to baseline: One small regression in the delta (low, advisory): the previous -func PostBotCommand(ctx context.Context, boundary effects.Boundary, client *gh.Client, owner, repo string, number int, headSHA, command, actor, restCaller string, onPosted func()) error {
+// onResult, when set, receives the create call's response and error.
+func PostBotCommand(ctx context.Context, boundary effects.Boundary, client *gh.Client, owner, repo string, number int, headSHA, command, actor, restCaller string, onResult func(*gh.Response, error)) error {
...
- comment, _, apiErr := client.Issues.CreateComment(WithRESTCaller(ctx, restCaller), owner, repo, number, &gh.IssueComment{Body: gh.Ptr(command)})
+ comment, resp, apiErr := client.Issues.CreateComment(WithRESTCaller(ctx, restCaller), owner, repo, number, &gh.IssueComment{Body: gh.Ptr(command)})
+ if onResult != nil {
+ onResult(resp, apiErr)
+ }
if apiErr != nil {
return effects.Result{}, effects.NotApplied(apiErr)
}
- if onPosted != nil {
- onPosted()
- }with Review findings from Security re-review of b8d7663 (delta since 6c227af): no new permissions, tokens, or injection surface. One advisory regression the refactor introduced (low, not blocking):
-func PostBotCommand(ctx context.Context, boundary effects.Boundary, client *gh.Client, owner, repo string, number int, headSHA, command, actor, restCaller string, onPosted func()) error {
+func PostBotCommand(ctx context.Context, boundary effects.Boundary, client *gh.Client, owner, repo string, number int, headSHA, command, actor, restCaller string, onResult func(resp *gh.Response, err error)) error {
...
- comment, _, apiErr := client.Issues.CreateComment(WithRESTCaller(ctx, restCaller), owner, repo, number, &gh.IssueComment{Body: gh.Ptr(command)})
+ comment, resp, apiErr := client.Issues.CreateComment(WithRESTCaller(ctx, restCaller), owner, repo, number, &gh.IssueComment{Body: gh.Ptr(command)})
+ if onResult != nil {
+ onResult(resp, apiErr)
+ }
if apiErr != nil {
return effects.Result{}, effects.NotApplied(apiErr)
}
- if onPosted != nil {
- onPosted()
- }with |
TestCommentMarkerRatchet counted PostDependabotRecreate as a new unmarked comment emitter. A bot parses the comment as a command, so it cannot carry a marker. Instead, the automerge sweep's existing `@dependabot rebase` nudge and the new `@dependabot recreate` request now share one poster, github.PostBotCommand. It posts the command verbatim through the mutation journal, keyed on PR and head SHA. The nudge's comment body, journal claim (actor, target, head_sha, body digest), REST caller and on-success bookkeeping are unchanged. The unmarked-emitter count is back at the baseline of 46. The raw create call moves from automerge_held_runs.go to dependency_bot_rebase.go, and the write ratchet baseline moves with it (3 to 2, plus 1). The total is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com>
|
@Danathar this PR is back in your court ( Failing checks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Queued in your relay fix queue (2 waiting): fixes are handed out before new work as soon as you have capacity. |
The coverage gate put pkg/config at 89.9% against its 90% floor: the resolver and its validation had no test. Cover the default (nil and unset), a set value, and the negative-value rejection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com>
There was a problem hiding this comment.
Correctness delta re-review (read 6c227af8…959529102; PR has since moved to b8d76636, which only adds src/pkg/config/dependency_bot_rebase_test.go).
Prior finding — fixed. TestCommentMarkerRatchet 46→47: nudgeDependabotRebase (automerge_held_runs.go:627) and PostDependabotRecreate (dependency_bot_rebase.go:156) now both route through the single raw emitter PostBotCommand (dependency_bot_rebase.go:128-145), so the unmarked-emitter count is back at baseline; all test shards passed at 9595291.
Low (in-scope, advisory): the refactor dropped noteWritebackOutcome from the recreate path. At the previous head PostDependabotRecreate fed the write's HTTP status to the write-back gate; at dependency_bot_rebase.go:138 the resp from CreateComment is now discarded, while the sibling RequestRenovateRebase still reports (dependency_bot_rebase.go:110). Gate.NoteWriteOutcome (writeback/gate.go:352-370) uses that to detect the App gaining write after 403/404s, so a repo whose first successful write is the recreate comment will not get WritableAt set from it. Minimal fix: give the hook the response.
-func PostBotCommand(ctx context.Context, boundary effects.Boundary, client *gh.Client, owner, repo string, number int, headSHA, command, actor, restCaller string, onPosted func()) error {
+func PostBotCommand(ctx context.Context, boundary effects.Boundary, client *gh.Client, owner, repo string, number int, headSHA, command, actor, restCaller string, onResult func(*gh.Response, error)) error {
...
- comment, _, apiErr := client.Issues.CreateComment(WithRESTCaller(ctx, restCaller), owner, repo, number, &gh.IssueComment{Body: gh.Ptr(command)})
+ comment, resp, apiErr := client.Issues.CreateComment(WithRESTCaller(ctx, restCaller), owner, repo, number, &gh.IssueComment{Body: gh.Ptr(command)})
+ if onResult != nil {
+ onResult(resp, apiErr)
+ }
if apiErr != nil {
return effects.Result{}, effects.NotApplied(apiErr)
}
- if onPosted != nil {
- onPosted()
- }and in PostDependabotRecreate: func(resp *gh.Response, err error) { c.noteWritebackOutcome(full, resp, err) }; in nudgeDependabotRebase: func(_ *gh.Response, err error) { if err == nil { c.noteOwnStageComment(owner, repo, number) } }.
Coverage gate failure at 9595291 (config 89.9% < 90%) is addressed by the tests added at b8d76636; CI there was still pending when I read it.
— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Read the new sweep (src/cmd/hive/dependency_bot_rebase_request.go), the wiring in dependency_bot_conflicts.go, the pkg/github helpers, and the production caller. This looks correct to me; one open question below, not a defect.
What I verified
TickRenovateRebaseCheckbox(src/pkg/github/dependency_bot_rebase.go:63-88) scans line by line without splitting, so CRLF and the trailing-newline-less last line pass through byte-for-byte; only[ ]→[x]on the first<!-- rebase-check -->line changes.RequestRenovateRebasere-reads the PR and refuses on a moved head before theEdit.PostBotCommandkeeps the automerge nudge's claim key unchanged (Actor: "automerge", samehead_sha/digest inputs,src/pkg/github/automerge/automerge_held_runs.go:627), so existing journal entries still dedupe; the write-ratchet baseline move (3→2, +1) matches the diff.- The hold interplay is sound:
stepreturnsdepBotStrandedHoldonly while a request is due/pending, andsweepDependencyBotConflictsthenobserves andcontinues for conflict (dependency_bot_conflicts.go:358-364) or red-CI, so grace clocks keep running and the PR never gets both a request and a hand-off in one pass. The hold is bounded: one window afterRequestedAtit becomesdepBotStrandedHandoff. runDependencyBotConflictSweepreceivesghClientdirectly (src/cmd/hive/main_eval_cycle.go:738), sorequestPossible's*github.Clienttype assertion is live in production, the same patterndepBotWritebackAllowedalready relies on.depBotHandoffResolvedundoes the stranded label on head move ordepBotStuckResolved;pruneRebaseis keyed on the sameescalation.Keyasseen.
Open question (low)
depBotCommitIsBots (dependency_bot_rebase_request.go:148-151) treats a commit as the bot's only if PRCommit.Author is a dependency-bot login or equals pr.Author. ListPRCommits falls back to the raw git author name when the commit email maps to no account (src/pkg/github/pr_commits.go:70-72). A self-hosted Renovate with a custom gitAuthor (e.g. Renovate Bot <renovate@corp.example>) whose email isn't linked to the App would make every commit read as foreign: ForeignHead and ForeignWork both true, so after 4h behind the PR goes straight to a person with "its last commit is not the bot's" (no write is made, so this is a spurious hand-off, not a bad write). Renovate itself still recognises those commits by email. If that deployment shape matters to anyone running this, a gitAuthor allowlist or an email check would close it; otherwise fine as-is and worth a sentence in the operator docs.
Mutation check was still running when I read this; everything else is green.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
Summary
A dependency bot stops maintaining a branch as soon as someone else commits to it (a person clicking Update branch, a stray merge-forward). The hive, by design, never base-syncs a bot's branch (#16862). So on a base that requires up-to-date branches, such a PR sits behind forever: the hive won't sync it, the bot won't, and nobody is told. On a live hive, three bot PRs sat behind for 7+ hours until a person ticked Renovate's rebase box by hand.
This PR teaches the existing dependency-bot hand-off sweep to notice a stranded bot PR and ask the bot, once per head, to rebase it through the bot's own mechanism: it ticks Renovate's rebase/retry checkbox, or comments
@dependabot recreate. If the head hasn't moved one window later, the PR goes to a person through the existing hand-off. The write is a new write-back kind,bot_rebase_request, defaulting to L6 with the opt-in label (same asbase_refresh).Why
The sweep in
cmd/hive/dependency_bot_handoffs.goalready hands conflicting, red-CI and held bot PRs to a person. It had two gaps:How
Detection. A dependency-bot PR (Renovate, Dependabot, mergeraptor, or any
renovate/*head) is stranded when it has been behind or conflicting for longer thangovernor.dependency_bot_rebase_after_s(default 4 hours) and either its head commit is not the bot's, or its Renovate description says it rebases never (the existingrenovateRebasesNevercheck). A bot-authored head that is merely behind is left to the bot. "The bot's" means any dependency-bot login or the PR author, because a Renovate deployment can author PRs as one App and commit asrenovate[bot]. The commit list is read once per head, after the window, and cached in memory.Request. At most once per (PR, head), persisted:
- [ ]→- [x]on the<!-- rebase-check -->line. Every other byte, CRLF included, is unchanged. If the box is already ticked, nothing is written and the bot gets one window from then. If the box is absent, the PR goes to a person.@dependabot recreate, through a journaled comment keyed on the head SHA, so a later head isn't swallowed as a replay. It goes throughgithub.PostBotCommand, which is now also the poster for the automerge sweep's existing@dependabot rebasenudge, with that nudge's body, journal claim and bookkeeping unchanged. A bot command can't carry a marker, so the two share one emitter: the comment-marker ratchet stays at its baseline, and the raw call moves (write-ratchet baseline 3→2 inautomerge_held_runs.go, +1 independency_bot_rebase.go). I usedrecreate, notrebase, because Dependabot refuses@dependabot rebaseon a branch someone else has pushed to ("Looks like this PR has been edited by someone other than Dependabot"), and a stranded Dependabot PR is exactly that case.Hand-off. If the head is unchanged one window after the request, the sweep posts one comment plus
needs-humanthrough the existing hand-off (markCommented, label retry, undo) with the new reasonbot-will-not-rebase("dependency bot will not rebase this branch"). It is never re-requested on that head. A new head resets everything. The label comes off when the head moves or GitHub reports the PR neither behind nor conflicting.Interplay with the conflict hand-off. While a request is due or pending on a conflicting PR (kind allowed), the existing conflict and red-CI hand-offs wait, with their grace clocks still running. The PR gets the bot request first and the person's comment afterwards, never both at once. This includes the immediate hand-off for a
rebaseWhen: neverRenovate PR: with the kind allowed, it now gets the box ticked at the window instead. When the kind is off, conflicting PRs keep today's behaviour exactly (24 hours, or at once for rebases-never).Write-back gate and default.
bot_rebase_requestdefaults to{min_level: 6, require_label: true}, the same asbase_refreshandci_rerun. Those are the other kinds that cause a new head or CI run on someone else's PR, and this one makes the bot force-push its branch. An operator who wants it on every bot PR at L6 setswriteback.kinds.bot_rebase_request.unlabeled_min_level: 6. It is not content-deduped (once-per-head idempotence is its own), likebase_refresh. When the kind refuses, the hive only reports: a log line, plus the existing person hand-off for a stranded PR that is behind once the window passes. The pre-write probe usesGate.Decide, so it doesn't fill the suppressed list every pass. The write itself goes throughWritebackAllowed.State. First-seen and requested heads persist in
dependency-bot-conflicts-rebase.jsonbeside the existing conflict ledger, so a restart neither resets the window nor repeats a request.Dashboard / MCP parity
Both surfaces enumerate kinds from the registry (
writeback.Kinds()/EffectiveKinds()). Settings → Features → Write-back containment shows and edits the new row, and the admin MCPwriteback.kind_policyoperation accepts it, with no hard-coded list to extend. Tests added: a registry/gate test for the default and an override, plus an MCP table case forbot_rebase_request.static/index.htmlis unchanged (no static-src edits; concatenationcmpis clean). The window key is yaml-only, like the othergovernor.*_stuning knobs, and allowlisted insettings_parity_allowlist.txt.Docs
operator-reference/README.md: the dependency-bot hand-off section now describes the stranded flow, the key, the kind and its default.operator-reference/sweeps-and-operations.md: a row in "what hive writes".acmm-policy-matrix.md: the kind is added to the L6 + label row.github-write-surface.md: a row and the audit actiondependency_bot_rebase_requested.notifications.md: the recreate command is recorded asprotocol_command.changelog.d/added-dependency-bot-rebase-request.md.governor_config.go/defaults.goline citations inlabels-and-control-signals/reference.mdare fixed.Tests
Not run locally (repo rule). Written for CI:
cmd/hive/dependency_bot_rebase_request_test.go:pkg/github/dependency_bot_rebase_test.go: the pure checkbox edit (LF, CRLF, last line without a newline, ticked, absent);RequestRenovateRebasePATCHes onlybodywith one byte changed and writes nothing when the head moved or the box is ticked;PostDependabotRecreateposts exactly the command.pkg/writeback: the kind's default policy, gate decisions, andTestKindSetsmembership.pkg/adminmcp: awriteback.kind_policycase.Out of scope
Pushing, update-branch or merge-forward on bot branches (that refusal stays), changing any repo's Renovate or Dependabot config, and closing bot PRs or opening new ones (
@dependabot recreateregenerates the branch of the same PR). The existing 24h conflict comment still suggests@dependabot rebase, which Dependabot refuses on an edited branch; that wording is unchanged here.🤖 Generated with Claude Code
https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1