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-14625-review-bot-author-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `review.bot_author_model` (default empty = off), `review.bot_authors` (default `dependabot[bot]`, `renovate[bot]`, `github-actions[bot]`, `*[bot]`; the hive's own App never matches) and `review.bot_author_full_review_paths` (default `.github/workflows/**`, `Dockerfile*`): reviews of PRs opened by other bots run on a configured cheaper model unless the PR touches a full-review path or its files could not be listed ([#14625](https://github.com/hivecommons/hive/issues/14625)).
63 changes: 60 additions & 3 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 @@ -7443,7 +7443,7 @@
dueBeforeDeferral := append([]string(nil), agentsDue...)
agentsDue = sched.FilterFirstScanDeferredAgents(agentsDue)
agentsSkipped = append(agentsSkipped, firstScanDeferredSkips(dueBeforeDeferral, agentsDue)...)
reviewPlan := planReviewDispatch(cfg, actionable, agentMgr, beadStores, logger)
reviewPlan := planReviewDispatchWith(ctx, cfg, actionable, agentMgr, beadStores, reviewChangedFilesListerFor(ghClient), logger)
auditWithheldReviewFixes(reviewPlan, dashSrv, logger)
if ghClient != nil {
postReviewAcknowledgements(ctx, ghClient, reviewPlan, logger)
Expand Down Expand Up @@ -10561,10 +10561,46 @@
return cutoff
}

// reviewChangedFilesLister is the slice of the GitHub client the bot-author
// model route needs (review.bot_author_full_review_paths): a PR's changed
// paths.
type reviewChangedFilesLister interface {
ReviewPRChangedFiles(ctx context.Context, repo string, number int) ([]string, bool)
}

func planReviewDispatch(cfg *config.Config, actionable *github.ActionableResult, agentMgr crux.Runtime, beadStores map[string]*beads.Store, logger *slog.Logger) review.DispatchPlan {
return planReviewDispatchWith(context.Background(), cfg, actionable, agentMgr, beadStores, nil, logger)
}

// reviewBotAuthorRoute is review.bot_authors / bot_author_model /
// bot_author_full_review_paths resolved for the planner.
func reviewBotAuthorRoute(cfg *config.Config) review.BotAuthorRoute {
backend, model := cfg.Review.BotAuthorModelRef()
return review.BotAuthorRoute{Authors: cfg.Review.EffectiveBotAuthors(), Backend: backend, Model: model, FullReviewPaths: cfg.Review.EffectiveBotAuthorFullReviewPaths()}
}

// reviewBotRouteFilesFor fetches a PR's changed paths when the bot-author
// route may apply to it: route on, author a listed bot, no verdict at this
// head and no review in flight (one listing per head, not per cycle). nil,
// false otherwise, which the planner reads as unknown: no downgrade.
func reviewBotRouteFilesFor(ctx context.Context, cfg *config.Config, lister reviewChangedFilesLister, route review.BotAuthorRoute, artifact review.Artifact, state review.DispatchState, repo string, number int, author, headSHA, bodyDigest string) ([]string, bool) {
if lister == nil || !route.Enabled() || !review.IsBotAuthor(author, route.Authors, cfg.EffectiveAIAuthor()) {
return nil, false
}
if _, judged := artifact.AggregateForBody(repo, number, headSHA, bodyDigest); judged {
return nil, false
}
if !state.PendingSince(repo, number, headSHA).IsZero() {
return nil, false
}
return lister.ReviewPRChangedFiles(ctx, repo, number)
}

func planReviewDispatchWith(ctx context.Context, cfg *config.Config, actionable *github.ActionableResult, agentMgr crux.Runtime, beadStores map[string]*beads.Store, lister reviewChangedFilesLister, logger *slog.Logger) review.DispatchPlan {
if cfg == nil || actionable == nil || !cfg.Review.RequireApproval || !cfg.Review.FanOut {
return review.DispatchPlan{}
}
botRoute := reviewBotAuthorRoute(cfg)
state, err := review.LoadDispatchState("")
if err != nil && !os.IsNotExist(err) {
logger.Warn("review dispatch state unavailable; starting fresh", "error", err)
Expand Down Expand Up @@ -10609,7 +10645,7 @@
for _, pr := range candidates {
lane := classify.Classify(github.Issue{Title: pr.Title, Labels: pr.Labels}).Lane
fullRepo := fullRepoName(pr.Repo, cfg.Project.Org)
prs = append(prs, review.PullRequest{
item := review.PullRequest{
Repo: pr.Repo,
Number: pr.Number,
Title: pr.Title,
Expand Down Expand Up @@ -10649,7 +10685,12 @@
// on this head (hivecommons/hive#13041): the planner kicks the
// fix lane with it instead of reviewing the head again.
HumanChangeRequest: review.HumanChangeRequestFor(review.DefaultHumanChangeRequests(), fullRepo, pr.Number, pr.HeadSHA),
})
}
// Changed paths for the bot-author model route's path exceptions
// (review.bot_author_full_review_paths); fetched only for a listed
// bot's PR that is about to be reviewed.
item.ChangedFiles, item.ChangedFilesKnown = reviewBotRouteFilesFor(ctx, cfg, lister, botRoute, artifact, state, fullRepo, pr.Number, pr.Author, pr.HeadSHA, pr.BodyDigest)
prs = append(prs, item)
}
// PRs a review webhook just fired for go first, so the early eval cycle
// it triggered spends its review budget on them (hivecommons/hive#11091).
Expand Down Expand Up @@ -10688,7 +10729,13 @@
ReviewBotLogins: reviewBotLogins,
ReviewBotMinPriority: reviewBots.MinPriority,
PerspectiveModels: cfg.Review.PerspectiveModels,
BotAuthorRoute: botRoute,
})
for _, k := range plan.ReviewKicks {
if k.BotAuthorRouted {
logger.Info("review routed bot-authored PR to bot_author_model", "repo", k.Repo, "pr", k.Number, "head", k.HeadSHA, "agent", k.Agent, "review_model", k.ReviewModel, "review_backend", k.ReviewBackend)
}
}
for _, sk := range plan.SkippedReviewModels {
logger.Info("review model fallback skipped perspective", "repo", sk.Repo, "pr", sk.Number, "head", sk.HeadSHA, "perspective", sk.Perspective, "agent", sk.Agent, "author_model", sk.AuthorModel)
}
Expand All @@ -10709,6 +10756,16 @@
return plan
}

// reviewChangedFilesListerFor returns the GitHub client as a
// reviewChangedFilesLister, or nil for a nil client: a typed nil in the
// interface would not read as nil.
func reviewChangedFilesListerFor(c *github.Client) reviewChangedFilesLister {
if c == nil {
return nil
}
return c
}

func refreshReviewVerdicts(cfg *config.Config, logger *slog.Logger) {
if cfg == nil || !shouldRefreshReviewVerdicts(cfg) {
return
Expand Down
73 changes: 73 additions & 0 deletions src/cmd/hive/review_bot_route_wiring_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package main

import (
"context"
"testing"
)

type fakeChangedFilesLister struct {
calls int
files []string
known bool
}

func (f *fakeChangedFilesLister) ReviewPRChangedFiles(context.Context, string, int) ([]string, bool) {
f.calls++
return f.files, f.known
}

func TestPlanReviewDispatch_BotAuthorRouteUsesCheapModel(t *testing.T) {
redirectReviewPaths(t)
cfg := reviewSwarmConfig()
cfg.Review.BotAuthorModel = "gpt-6-luna"
lister := &fakeChangedFilesLister{files: []string{"go.mod", "go.sum"}, known: true}
plan := planReviewDispatchWith(context.Background(), cfg, actionableWithPR("dependabot[bot]"), nil, nil, lister, restoreTestLogger())
if lister.calls != 1 || len(plan.ReviewKicks) != 1 {
t.Fatalf("calls=%d kicks=%d, want 1/1", lister.calls, len(plan.ReviewKicks))
}
if k := plan.ReviewKicks[0]; !k.BotAuthorRouted || k.ReviewModel != "gpt-6-luna" {
t.Fatalf("kick not routed: %+v", k)
}
}

func TestPlanReviewDispatch_BotAuthorRouteExceptionsAndGates(t *testing.T) {
redirectReviewPaths(t)
cfg := reviewSwarmConfig()
cfg.Review.BotAuthorModel = "gpt-6-luna"

// A workflow file keeps the full-strength model.
lister := &fakeChangedFilesLister{files: []string{"go.mod", ".github/workflows/ci.yml"}, known: true}
plan := planReviewDispatchWith(context.Background(), cfg, actionableWithPR("dependabot[bot]"), nil, nil, lister, restoreTestLogger())
if len(plan.ReviewKicks) != 1 || plan.ReviewKicks[0].BotAuthorRouted {
t.Fatalf("workflow change was downgraded: %+v", plan.ReviewKicks)
}

// The hive's own App (project.ai_author) is never a "bot author", and
// its files are not even listed.
lister = &fakeChangedFilesLister{files: []string{"go.mod"}, known: true}
plan = planReviewDispatchWith(context.Background(), cfg, actionableWithPR("hive-bot"), nil, nil, lister, restoreTestLogger())
if lister.calls != 0 || len(plan.ReviewKicks) != 1 || plan.ReviewKicks[0].BotAuthorRouted {
t.Fatalf("own app routed: calls=%d kicks=%+v", lister.calls, plan.ReviewKicks)
}

// Route off: no listing, no downgrade.
off := reviewSwarmConfig()
lister = &fakeChangedFilesLister{files: []string{"go.mod"}, known: true}
plan = planReviewDispatchWith(context.Background(), off, actionableWithPR("dependabot[bot]"), nil, nil, lister, restoreTestLogger())
if lister.calls != 0 || len(plan.ReviewKicks) != 1 || plan.ReviewKicks[0].BotAuthorRouted {
t.Fatalf("route off still acted: calls=%d kicks=%+v", lister.calls, plan.ReviewKicks)
}

// Listing failed: unknown files, full-strength review.
lister = &fakeChangedFilesLister{known: false}
plan = planReviewDispatchWith(context.Background(), cfg, actionableWithPR("dependabot[bot]"), nil, nil, lister, restoreTestLogger())
if len(plan.ReviewKicks) != 1 || plan.ReviewKicks[0].BotAuthorRouted {
t.Fatalf("unknown files downgraded: %+v", plan.ReviewKicks)
}

// No GitHub client at all (nil lister) behaves the same.
plan = planReviewDispatch(cfg, actionableWithPR("dependabot[bot]"), nil, nil, restoreTestLogger())
if len(plan.ReviewKicks) != 1 || plan.ReviewKicks[0].BotAuthorRouted {
t.Fatalf("nil lister downgraded: %+v", plan.ReviewKicks)
}
}
13 changes: 13 additions & 0 deletions src/docs/review-swarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ review:
priority_labels: false # optional; mirror the PR review queue rank onto review-priority/* labels (default off)
pending_ttl: 45m # optional; re-dispatch a review that has posted no verdict after this long (default 45m)
max_redispatch: 3 # optional; expiries per head before the PR is held for a human (default 3)
bot_author_model: "" # optional; model (or backend/model) that reviews PRs opened by bot_authors, e.g. gpt-6-luna (default empty = off)
bot_authors: [dependabot[bot], renovate[bot], github-actions[bot], "*[bot]"] # optional; logins routed to bot_author_model; the hive's own App never matches
bot_author_full_review_paths: [".github/workflows/**", "Dockerfile*", "**/Dockerfile*"] # optional; a bot PR touching these keeps the full-strength model
severity:
block_at: P2 # optional; P1 | P2 | P3, see "Blocking line" below
comment_below: true # default true
Expand Down Expand Up @@ -403,6 +406,16 @@ When the check refuses, the `changes_requested` verdict still stands and the rev

**Upgrading.** Older configs may still show `fix_human_prs: true` because a prior compatibility rule promoted `all_authors: true`. Both values are left in config for audit/UI continuity — `all_authors` no longer does anything, and branch-push fix kicks still require hive authorship.

### Cheaper model for bot-authored PRs (`review.bot_author_model`)

PRs opened by other bots (Dependabot, Renovate, github-actions) are mostly lockfile and version bumps, and over Oct 13-27 2026 they cost $38.61/day across three hosted hives ($30.60/day on the busiest), every one reviewed on the frontier model. Setting `review.bot_author_model` routes those reviews to a cheaper model:

- `review.bot_authors` is the login list. Entries match case-insensitively; a leading `*` matches a suffix, so the default `*[bot]` catches any GitHub App. The hive's own App login (`project.ai_author`, or the App's `[bot]` login when it authors PRs) never matches, whatever the list says: the hive's own PRs are reviewed as before.
- `review.bot_author_model` is `model` or `backend/model` (`gpt-6-luna`, `copilot/gemini-flash-3-5`). It replaces whatever the reviewer's `review_models` pool or `perspective_models` chose for that kick, the same way: the kick's independent-review instruction names it and the reviewer runs the review in a sub-agent with that `model`, so **the reviewer agent's engine must be able to launch it**. A pool decision to skip or hold for a human is kept. Recommended values from `pkg/tokens/pricing.go`: `gemini-flash-3-5` ($0.075/$0.30 per MTok) or `gpt-6-luna` ($0.10/$0.50), against `claude-fable-5.1` at $10/$50. Empty (the default) leaves the route off.
- `review.bot_author_full_review_paths` are globs (`**` spans directories; a pattern without `/` also matches the base name) that keep a bot PR on the full-strength model when any changed file matches. The default is CI workflows and Dockerfiles only; lockfiles are deliberately not excepted, since they are the bulk of bot PRs. Set it to `[]` for no exceptions. The planner lists the PR's files once per head (only for a listed bot's PR about to be reviewed) and a PR whose files could not be listed is **not** downgraded.

Routed kicks carry `bot_author_routed` on the dispatch kick and the model lands in the verdict's `review_model` as usual; the governor logs `review routed bot-authored PR to bot_author_model`. The route applies to the swarm's per-perspective and combined kicks; the cadence (queue-mode) kick's `review_with=` annotation still comes from the agent's `review_models` pool alone.

## Revising a recorded verdict

Dispatch skips any PR that already carries a verdict for its head SHA. That is the right default — it stops the reviewer re-reviewing unchanged code every sweep — but it also makes a review final the moment it is written, even when the reviewer itself was defective. Two settings, both required, re-open such verdicts narrowly:
Expand Down
14 changes: 14 additions & 0 deletions src/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7377,6 +7377,20 @@ type ReviewConfig struct {
// may be re-sent when it posts no verdict (agents.<name>.review_heads,
// hivecommons/hive#13542). 0 means max_redispatch applies.
HeadMaxRetries int `yaml:"head_max_retries,omitempty" json:"head_max_retries,omitempty"`
// BotAuthors lists PR author logins whose PRs are reviewed with
// BotAuthorModel instead of the reviewer's usual model. Entries match
// case-insensitively; a leading `*` matches any login with that suffix
// (`*[bot]`). The hive's own GitHub App login never matches. Unset means
// DefaultReviewBotAuthors.
BotAuthors []string `yaml:"bot_authors,omitempty" json:"bot_authors,omitempty"`
// BotAuthorModel is the model (or backend/model) a review of a
// BotAuthors PR runs with. Empty (the default) leaves the route off. The
// reviewer agent's engine must be able to run the model.
BotAuthorModel string `yaml:"bot_author_model,omitempty" json:"bot_author_model,omitempty"`
// BotAuthorFullReviewPaths are path globs (`**` spans directories) that
// keep a bot-authored PR on the full-strength model when it touches any of
// them. Unset means DefaultReviewBotAuthorFullReviewPaths.
BotAuthorFullReviewPaths []string `yaml:"bot_author_full_review_paths,omitempty" json:"bot_author_full_review_paths,omitempty"`
// HumanDecisionLabel names an EXISTING repo label to apply when the review
// swarm holds a PR for a human. The review comment's in-body marker is
// always the primary signal and never depends on this: a label makes the
Expand Down
52 changes: 52 additions & 0 deletions src/pkg/config/review_dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,55 @@ func (r ReviewConfig) ValidatePendingReviewTTL() error {
}
return nil
}

// DefaultReviewBotAuthors is review.bot_authors unset: the dependency and
// automation bots, plus any other `[bot]` login that is not the hive's own.
var DefaultReviewBotAuthors = []string{"dependabot[bot]", "renovate[bot]", "github-actions[bot]", "*[bot]"}

// DefaultReviewBotAuthorFullReviewPaths is review.bot_author_full_review_paths
// unset: a bot PR that edits CI workflows or container builds is reviewed at
// full strength. Lockfiles are deliberately not here: they are the bulk of
// bot PRs and the reason the route exists.
var DefaultReviewBotAuthorFullReviewPaths = []string{".github/workflows/**", "Dockerfile*", "**/Dockerfile*"}

// EffectiveBotAuthors resolves review.bot_authors, trimmed; unset means the
// default list.
func (r ReviewConfig) EffectiveBotAuthors() []string {
if r.BotAuthors == nil {
return append([]string(nil), DefaultReviewBotAuthors...)
}
return trimmedNonEmpty(r.BotAuthors)
}

// EffectiveBotAuthorFullReviewPaths resolves
// review.bot_author_full_review_paths; unset means the default list.
func (r ReviewConfig) EffectiveBotAuthorFullReviewPaths() []string {
if r.BotAuthorFullReviewPaths == nil {
return append([]string(nil), DefaultReviewBotAuthorFullReviewPaths...)
}
return trimmedNonEmpty(r.BotAuthorFullReviewPaths)
}

// BotAuthorModelRef splits review.bot_author_model into backend and model:
// `gpt-6-luna` is a model with no backend, `copilot/gpt-6-luna` names both.
// Both empty when the route is off.
func (r ReviewConfig) BotAuthorModelRef() (backend, model string) {
raw := strings.TrimSpace(r.BotAuthorModel)
if raw == "" {
return "", ""
}
if i := strings.Index(raw, "/"); i >= 0 {
return strings.TrimSpace(raw[:i]), strings.TrimSpace(raw[i+1:])
}
return "", raw
}

func trimmedNonEmpty(in []string) []string {
out := make([]string, 0, len(in))
for _, v := range in {
if v = strings.TrimSpace(v); v != "" {
out = append(out, v)
}
}
return out
}
24 changes: 24 additions & 0 deletions src/pkg/config/review_dispatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,27 @@ func TestEffectiveSelfAuthoredDecisionPolicy(t *testing.T) {
t.Fatalf("unknown policy = %q, want resolve", got)
}
}

func TestReviewBotAuthorRouteConfig(t *testing.T) {
var r ReviewConfig
if got := r.EffectiveBotAuthors(); len(got) != len(DefaultReviewBotAuthors) || got[0] != "dependabot[bot]" || got[len(got)-1] != "*[bot]" {
t.Fatalf("default bot_authors = %v", got)
}
if got := r.EffectiveBotAuthorFullReviewPaths(); len(got) != len(DefaultReviewBotAuthorFullReviewPaths) || got[0] != ".github/workflows/**" {
t.Fatalf("default full-review paths = %v", got)
}
r.BotAuthors = []string{" dependabot[bot] ", ""}
r.BotAuthorFullReviewPaths = []string{}
if got := r.EffectiveBotAuthors(); len(got) != 1 || got[0] != "dependabot[bot]" {
t.Fatalf("explicit bot_authors = %v", got)
}
if got := r.EffectiveBotAuthorFullReviewPaths(); len(got) != 0 {
t.Fatalf("explicit empty full-review paths = %v, want none (no exceptions)", got)
}
for in, want := range map[string][2]string{"": {"", ""}, "gpt-6-luna": {"", "gpt-6-luna"}, " copilot/gemini-flash-3-5 ": {"copilot", "gemini-flash-3-5"}} {
b, m := (ReviewConfig{BotAuthorModel: in}).BotAuthorModelRef()
if b != want[0] || m != want[1] {
t.Fatalf("bot_author_model %q -> %q/%q, want %q/%q", in, b, m, want[0], want[1])
}
}
}
3 changes: 3 additions & 0 deletions src/pkg/dashboard/settings_parity_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ project.repos[] # TODO #11854
providers.status.enabled # TODO #11854
removed_agents[] # TODO #11854
review.backlog.labels[] # TODO #11854
review.bot_author_full_review_paths[] # TODO #14625
review.bot_author_model # TODO #14625
review.bot_authors[] # TODO #14625
review.perspective_models.<key>.backend # TODO #13243
review.perspective_models.<key>.model # TODO #13243
review.perspective_prompts.<key> # TODO #11854
Expand Down
30 changes: 30 additions & 0 deletions src/pkg/github/review_bot_route.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package github

import (
"context"
"strings"

gh "github.com/google/go-github/v72/github"
)

// ReviewPRChangedFiles lists a PR's changed paths for the review planner's
// bot-author model route (review.bot_author_full_review_paths). known is
// false on any failure, including an incomplete list: a PR whose files cannot
// be checked against the full-review paths is not downgraded.
func (c *Client) ReviewPRChangedFiles(ctx context.Context, repo string, number int) (paths []string, known bool) {
if c == nil || c.client == nil || number <= 0 {
return nil, false
}
owner, name := c.splitRepo(strings.TrimSpace(repo))
files, err := ListPRChangedFiles(WithRESTCaller(ctx, "hive:review_bot_route"), c.client, owner, name, &gh.PullRequest{Number: gh.Ptr(number)})
if err != nil {
return nil, false
}
paths = make([]string, 0, len(files))
for _, f := range files {
if p := strings.TrimSpace(f.Filename); p != "" {
paths = append(paths, p)
}
}
return paths, true
}
Loading
Loading