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-14621-review-delta-rereview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `review.delta_rereview` (default on), `review.delta_trivial_lines` (default 20) and `review.delta_max_age` (default 72h): a PR already judged at an earlier head is re-reviewed by its diff since that head, with the previous verdict and findings in the kick; an empty or trivial delta in files the previous verdict passed re-stamps that verdict onto the new head without a model call. Aggregates record `delta.previous_head` / `delta.trivial` so the cost dashboard can split delta reviews from full ones ([#14621](https://github.com/hivecommons/hive/issues/14621)).
76 changes: 64 additions & 12 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 := planReviewDispatchWith(ctx, cfg, actionable, agentMgr, beadStores, reviewChangedFilesListerFor(ghClient), logger)
reviewPlan := planReviewDispatchWith(ctx, cfg, actionable, agentMgr, beadStores, reviewPlannerGitHubFor(ghClient), logger)
auditWithheldReviewFixes(reviewPlan, dashSrv, logger)
if ghClient != nil {
postReviewAcknowledgements(ctx, ghClient, reviewPlan, logger)
Expand Down Expand Up @@ -10561,11 +10561,14 @@
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 {
// reviewPlannerGitHub is the slice of the GitHub client the review planner
// reads: a PR's changed paths for the bot-author model route
// (review.bot_author_full_review_paths) and the compare between the head
// the hive last judged and the current one for the delta re-review
// (review.delta_rereview).
type reviewPlannerGitHub interface {
ReviewPRChangedFiles(ctx context.Context, repo string, number int) ([]string, bool)
ReviewDeltaDiff(ctx context.Context, repo, previousHead, head string) review.DeltaDiff
}

func planReviewDispatch(cfg *config.Config, actionable *github.ActionableResult, agentMgr crux.Runtime, beadStores map[string]*beads.Store, logger *slog.Logger) review.DispatchPlan {
Expand All @@ -10583,7 +10586,7 @@
// 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) {
func reviewBotRouteFilesFor(ctx context.Context, cfg *config.Config, lister reviewPlannerGitHub, 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
}
Expand All @@ -10596,7 +10599,30 @@
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 {
// reviewDeltaDiffFor fetches the delta compare for one PR when it is a
// delta re-review candidate: delta mode on, no verdict yet at this head, no
// dispatch entry for it (a compare per cycle for a review in flight would be
// API spend for nothing), and a prior verdict at another head to diff from.
// nil otherwise, which the planner reads as "not fetched".
func reviewDeltaDiffFor(ctx context.Context, cfg *config.Config, differ reviewPlannerGitHub, artifact review.Artifact, state review.DispatchState, repo string, number int, headSHA, bodyDigest string) *review.DeltaDiff {
if differ == nil || !cfg.Review.DeltaRereviewEnabled() || strings.TrimSpace(headSHA) == "" {
return nil
}
if _, judged := artifact.AggregateForBody(repo, number, headSHA, bodyDigest); judged {
return nil
}
if !state.PendingSince(repo, number, headSHA).IsZero() {
return nil
}
prior, ok := artifact.PriorAggregateFor(repo, number, headSHA)
if !ok {
return nil
}
diff := differ.ReviewDeltaDiff(ctx, repo, prior.HeadSHA, headSHA)
return &diff
}

func planReviewDispatchWith(ctx context.Context, cfg *config.Config, actionable *github.ActionableResult, agentMgr crux.Runtime, beadStores map[string]*beads.Store, ghr reviewPlannerGitHub, logger *slog.Logger) review.DispatchPlan {
if cfg == nil || actionable == nil || !cfg.Review.RequireApproval || !cfg.Review.FanOut {
return review.DispatchPlan{}
}
Expand Down Expand Up @@ -10685,11 +10711,14 @@
// 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),
// The compare from the last judged head, for the delta
// re-review and its trivial skip (review.delta_rereview).
DeltaDiff: reviewDeltaDiffFor(ctx, cfg, ghr, artifact, state, fullRepo, pr.Number, pr.HeadSHA, pr.BodyDigest),
}
// 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)
item.ChangedFiles, item.ChangedFilesKnown = reviewBotRouteFilesFor(ctx, cfg, ghr, 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
Expand Down Expand Up @@ -10730,7 +10759,11 @@
ReviewBotMinPriority: reviewBots.MinPriority,
PerspectiveModels: cfg.Review.PerspectiveModels,
BotAuthorRoute: botRoute,
DeltaRereview: cfg.Review.DeltaRereviewEnabled(),
DeltaTrivialLines: cfg.Review.EffectiveDeltaTrivialLines(),
DeltaMaxAge: cfg.Review.EffectiveDeltaMaxAge(),
})
recordReviewDeltaRestamps(plan, logger)
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)
Expand All @@ -10756,10 +10789,29 @@
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 {
// recordReviewDeltaRestamps writes the verdicts the planner carried forward
// onto a new head without a session (trivial delta, review.delta_rereview)
// into the verdict artifact, and logs each one. A write failure is logged,
// not fatal: the next cycle plans the same restamp again.
func recordReviewDeltaRestamps(plan review.DispatchPlan, logger *slog.Logger) {
if len(plan.DeltaRestamps) == 0 {
return
}
for _, r := range plan.DeltaRestamps {
note := ""
if r.Aggregate.Delta != nil {
note = r.Aggregate.Delta.Note
}
logger.Info("review delta re-stamped verdict without a session", "repo", r.Repo, "pr", r.Number, "head", r.HeadSHA, "previous_head", r.PreviousHead, "verdict", r.Aggregate.Verdict, "note", note)
}
if _, err := review.RecordDeltaRestamps("", plan.DeltaRestamps, time.Now().UTC()); err != nil {
logger.Warn("failed to record review delta re-stamps", "error", err, "count", len(plan.DeltaRestamps))
}
}

// reviewPlannerGitHubFor returns the GitHub client as a reviewPlannerGitHub,
// or nil for a nil client: a typed nil in the interface would not read as nil.
func reviewPlannerGitHubFor(c *github.Client) reviewPlannerGitHub {
if c == nil {
return nil
}
Expand Down
6 changes: 6 additions & 0 deletions src/cmd/hive/review_bot_route_wiring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"context"
"testing"

"github.com/hivecommons/hive/pkg/review"
)

type fakeChangedFilesLister struct {
Expand All @@ -16,6 +18,10 @@ func (f *fakeChangedFilesLister) ReviewPRChangedFiles(context.Context, string, i
return f.files, f.known
}

func (f *fakeChangedFilesLister) ReviewDeltaDiff(_ context.Context, _, previousHead, _ string) review.DeltaDiff {
return review.DeltaDiff{PreviousHead: previousHead}
}

func TestPlanReviewDispatch_BotAuthorRouteUsesCheapModel(t *testing.T) {
redirectReviewPaths(t)
cfg := reviewSwarmConfig()
Expand Down
103 changes: 103 additions & 0 deletions src/cmd/hive/review_delta_wiring_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package main

import (
"context"
"strings"
"testing"
"time"

"github.com/hivecommons/hive/pkg/review"
)

type fakeDeltaDiffer struct {
calls []string
diff review.DeltaDiff
}

func (f *fakeDeltaDiffer) ReviewDeltaDiff(_ context.Context, repo, previousHead, head string) review.DeltaDiff {
f.calls = append(f.calls, repo+"#"+previousHead+".."+head)
out := f.diff
out.PreviousHead = previousHead
return out
}

func (f *fakeDeltaDiffer) ReviewPRChangedFiles(context.Context, string, int) ([]string, bool) {
return nil, false
}

func writePriorVerdict(t *testing.T, headSHA string, verdict review.Verdict) {
t.Helper()
art := review.Artifact{Items: []review.Aggregate{{
Repo: "hivecommons/hive", Number: 4321, HeadSHA: headSHA, Verdict: verdict,
MergeEligible: verdict == review.VerdictApprove, RecordedAt: time.Now().UTC().Add(-time.Hour),
Perspectives: map[review.Perspective]review.Verdict{review.PerspectiveCorrectness: verdict},
}}}
if err := review.WriteArtifact(review.ReviewVerdictsPath, art); err != nil {
t.Fatal(err)
}
}

func TestPlanReviewDispatch_DeltaReReviewFetchesCompareAndScopesKick(t *testing.T) {
redirectReviewPaths(t)
writePriorVerdict(t, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", review.VerdictApprove)
differ := &fakeDeltaDiffer{diff: review.DeltaDiff{Known: true, Files: []review.DeltaFile{{Path: "pkg/x/x.go", Additions: 40}}}}
plan := planReviewDispatchWith(context.Background(), reviewSwarmConfig(), actionableWithPR("hive-bot"), nil, nil, differ, restoreTestLogger())
if len(differ.calls) != 1 || differ.calls[0] != "hivecommons/hive#bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.."+reviewTestSHA {
t.Fatalf("compare calls = %v", differ.calls)
}
if len(plan.ReviewKicks) != 1 || len(plan.DeltaRestamps) != 0 {
t.Fatalf("kicks=%d restamps=%d, want 1/0", len(plan.ReviewKicks), len(plan.DeltaRestamps))
}
if k := plan.ReviewKicks[0]; k.DeltaPreviousHead == "" || !strings.Contains(k.Message, "DELTA RE-REVIEW") || !strings.Contains(k.Message, "pkg/x/x.go") {
t.Fatalf("kick is not a delta re-review: %+v", k)
}
}

func TestPlanReviewDispatch_DeltaTrivialRestampIsRecorded(t *testing.T) {
redirectReviewPaths(t)
writePriorVerdict(t, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", review.VerdictApprove)
differ := &fakeDeltaDiffer{diff: review.DeltaDiff{Known: true}}
plan := planReviewDispatchWith(context.Background(), reviewSwarmConfig(), actionableWithPR("hive-bot"), nil, nil, differ, restoreTestLogger())
if len(plan.ReviewKicks) != 0 || len(plan.DeltaRestamps) != 1 {
t.Fatalf("kicks=%d restamps=%d, want 0/1", len(plan.ReviewKicks), len(plan.DeltaRestamps))
}
art, err := review.LoadArtifact("")
if err != nil {
t.Fatal(err)
}
got, ok := art.AggregateForBody("hivecommons/hive", 4321, reviewTestSHA, "")
if !ok || got.Verdict != review.VerdictApprove || got.Delta == nil || !got.Delta.Trivial {
t.Fatalf("restamp not recorded in the artifact: %+v ok=%v", got, ok)
}
// The next cycle sees the head as judged: no compare, no kick, no restamp.
differ.calls = nil
again := planReviewDispatchWith(context.Background(), reviewSwarmConfig(), actionableWithPR("hive-bot"), nil, nil, differ, restoreTestLogger())
if len(differ.calls) != 0 || len(again.ReviewKicks) != 0 || len(again.DeltaRestamps) != 0 {
t.Fatalf("judged head re-planned: calls=%v kicks=%d restamps=%d", differ.calls, len(again.ReviewKicks), len(again.DeltaRestamps))
}
}

func TestPlanReviewDispatch_DeltaNotFetchedWithoutPriorOrWhenOff(t *testing.T) {
redirectReviewPaths(t)
differ := &fakeDeltaDiffer{diff: review.DeltaDiff{Known: true}}
plan := planReviewDispatchWith(context.Background(), reviewSwarmConfig(), actionableWithPR("hive-bot"), nil, nil, differ, restoreTestLogger())
if len(differ.calls) != 0 || len(plan.ReviewKicks) != 1 || plan.ReviewKicks[0].DeltaPreviousHead != "" {
t.Fatalf("first review touched the compare API or became a delta: calls=%v kicks=%+v", differ.calls, plan.ReviewKicks)
}

writePriorVerdict(t, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", review.VerdictApprove)
cfg := reviewSwarmConfig()
off := false
cfg.Review.DeltaRereview = &off
plan = planReviewDispatchWith(context.Background(), cfg, actionableWithPR("hive-bot"), nil, nil, differ, restoreTestLogger())
if len(differ.calls) != 0 || len(plan.ReviewKicks) != 1 || plan.ReviewKicks[0].DeltaPreviousHead != "" || len(plan.DeltaRestamps) != 0 {
t.Fatalf("delta_rereview: false still planned a delta: calls=%v kicks=%+v restamps=%d", differ.calls, plan.ReviewKicks, len(plan.DeltaRestamps))
}

// A nil differ (no GitHub client) falls back to a delta kick without a
// file list rather than a full review: the prompt alone needs no compare.
plan = planReviewDispatch(reviewSwarmConfig(), actionableWithPR("hive-bot"), nil, nil, restoreTestLogger())
if len(plan.ReviewKicks) != 1 || plan.ReviewKicks[0].DeltaPreviousHead == "" || len(plan.DeltaRestamps) != 0 {
t.Fatalf("nil differ: kicks=%+v restamps=%d", plan.ReviewKicks, len(plan.DeltaRestamps))
}
}
12 changes: 12 additions & 0 deletions src/docs/review-swarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ review:
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
delta_rereview: true # optional; re-review a PR already judged at an earlier head by its diff since that head (default on)
delta_trivial_lines: 20 # optional; a delta under this many lines in files the prior verdict passed re-stamps it without a model call (default 20; negative disables)
delta_max_age: 72h # optional; a changes_requested verdict with findings older than this anchors no delta, the PR is reviewed in full (default 72h)
severity:
block_at: P2 # optional; P1 | P2 | P3, see "Blocking line" below
comment_below: true # default true
Expand Down Expand Up @@ -415,6 +418,15 @@ PRs opened by other bots (Dependabot, Renovate, github-actions) are mostly lockf
- `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.
### Delta re-review (`review.delta_rereview`, `review.delta_trivial_lines`, `review.delta_max_age`)

A re-review is a review of a PR the hive already judged at an earlier head SHA. Over Oct 13-27 2026 re-reviews were 28% of hive's attributed reviewer spend and 53% of Bluefin's, because every one re-read the whole PR. With `review.delta_rereview` on (the default) the planner looks for the most recent verdict for the same PR at another head within the artifact's retention and, when it finds one, builds the kick differently:

- The prompt opens with a **`DELTA RE-REVIEW`** block naming the previous head, when it was judged, the aggregate and per-perspective verdicts, and the exact `gh api repos/O/R/compare/<prev>...<new>` commands for the file list and the unified diff. It tells the reviewer to read only the hunks in that compare (and enough of their surroundings to judge them), to re-check each previous finding by file and line and say whether it is fixed, still present or no longer applies, and that its verdict is still for the whole PR at the new head. When the governor fetched the compare itself, the block also lists the changed files and line count.
- When the compare is known and the delta is **empty** (a force-push or rebase with the same tree), or under `review.delta_trivial_lines` changed lines (default 20) touching no file the previous verdict recorded a finding in, no reviewer is kicked: the previous aggregate is **re-stamped** onto the new head with the new `head_sha`, `body_digest` and `recorded_at`, a `delta` block (`previous_head`, `trivial: true`, `changed_lines`, `note`) and a `delta re-review: …` reason, and the governor logs `review delta re-stamped verdict without a session`. A negative `delta_trivial_lines` keeps the re-stamp for identical trees only. A head that already has a review in flight is never re-stamped.
- The **full** review stays for a first review (no prior verdict at another head), when the prior verdict was `reject` or `incomplete`, and when it was `changes_requested` with findings recorded more than `review.delta_max_age` ago (default `72h`): the flagged code has had time to move on and the record of it is stale. A verdict at the current head is never treated as a prior.

Every delta aggregate records `delta.previous_head` (and `delta_previous_head` on each perspective report, stamped from the dispatch state like `review_model`), so the cost dashboard can split delta reviews, re-stamps and full reviews. The compare is fetched once per candidate head (no verdict, no pending entry, a prior at another head) with one 300-file page; a bigger or failed compare still gets the delta instruction, just without the file list and never the re-stamp.

## Revising a recorded verdict

Expand Down
Loading
Loading