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-review-verdict-survives-base-sync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **An approved PR keeps its swarm approve when the hive merges the base into it.** The hive's own update-branch (or merge-forward) gave an approved PR a new head with no verdict, so it fell back to `review-gate:no-review-bundle` and waited for a reviewer to read base code already reviewed and merged upstream (projectbluefin/fsdk-containers#482, projectbluefin/finpilot#599). The review planner now re-stamps the prior approve onto the merge head at any delta size, with `delta.base_sync: true`, when every commit since the reviewed head is a GitHub-made merge of the base authored by the hive App and the base's changes miss every file the PR changes. A merge by anyone else, any other commit, a base change to a PR file, or a prior `changes_requested`/`requires_human` keeps the delta review. CI still runs on the merge head, and a negative `review.delta_trivial_lines` turns the carry off. The proof costs two compare calls, made only for a head whose delta is all hive merges.
20 changes: 12 additions & 8 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11186,10 +11186,11 @@ func parseReviseCutoff(raw string, logger *slog.Logger) time.Time {
// 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).
// (review.delta_rereview), which also proves a hive base-sync against the
// PR's base branch.
type reviewPlannerGitHub interface {
ReviewPRChangedFiles(ctx context.Context, repo string, number int) ([]string, bool)
ReviewDeltaDiff(ctx context.Context, repo, previousHead, head string) review.DeltaDiff
ReviewDeltaDiff(ctx context.Context, repo, baseRef, 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 Down Expand Up @@ -11224,8 +11225,9 @@ func reviewBotRouteFilesFor(ctx context.Context, cfg *config.Config, lister revi
// 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 {
// nil otherwise, which the planner reads as "not fetched". baseRef lets the
// compare recognise the hive's own merge of the base (DeltaDiff.BaseSync).
func reviewDeltaDiffFor(ctx context.Context, cfg *config.Config, differ reviewPlannerGitHub, artifact review.Artifact, state review.DispatchState, repo string, number int, baseRef, headSHA, bodyDigest string) *review.DeltaDiff {
if differ == nil || !cfg.Review.DeltaRereviewEnabled() || strings.TrimSpace(headSHA) == "" {
return nil
}
Expand All @@ -11239,7 +11241,7 @@ func reviewDeltaDiffFor(ctx context.Context, cfg *config.Config, differ reviewPl
if !ok {
return nil
}
diff := differ.ReviewDeltaDiff(ctx, repo, prior.HeadSHA, headSHA)
diff := differ.ReviewDeltaDiff(ctx, repo, baseRef, prior.HeadSHA, headSHA)
return &diff
}

Expand Down Expand Up @@ -11333,8 +11335,9 @@ func planReviewDispatchWith(ctx context.Context, cfg *config.Config, actionable
// 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),
// re-review, its trivial skip and the hive base-sync carry
// (review.delta_rereview).
DeltaDiff: reviewDeltaDiffFor(ctx, cfg, ghr, artifact, state, fullRepo, pr.Number, pr.BaseRef, 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
Expand Down Expand Up @@ -11451,7 +11454,8 @@ func recordReviewDeltaRestamps(plan review.DispatchPlan, logger *slog.Logger) {
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)
baseSync := r.Aggregate.Delta != nil && r.Aggregate.Delta.BaseSync
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, "base_sync", baseSync, "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))
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/hive/review_bot_route_wiring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (f *fakeChangedFilesLister) ReviewPRChangedFiles(context.Context, string, i
return f.files, f.known
}

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

Expand Down
48 changes: 45 additions & 3 deletions src/cmd/hive/review_delta_wiring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (
)

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

func (f *fakeDeltaDiffer) ReviewDeltaDiff(_ context.Context, repo, previousHead, head string) review.DeltaDiff {
func (f *fakeDeltaDiffer) ReviewDeltaDiff(_ context.Context, repo, baseRef, previousHead, head string) review.DeltaDiff {
f.calls = append(f.calls, repo+"#"+previousHead+".."+head)
f.baseRefs = append(f.baseRefs, baseRef)
out := f.diff
out.PreviousHead = previousHead
return out
Expand Down Expand Up @@ -101,3 +103,43 @@ func TestPlanReviewDispatch_DeltaNotFetchedWithoutPriorOrWhenOff(t *testing.T) {
t.Fatalf("nil differ: kicks=%+v restamps=%d", plan.ReviewKicks, len(plan.DeltaRestamps))
}
}

// The hive's own update-branch of an approved PR (projectbluefin/fsdk-containers#482):
// the planner hands the PR's base branch to the compare, and a base-sync whose
// files miss the PR's carries the approve onto the merge head at any size.
func TestPlanReviewDispatch_HiveBaseSyncCarriesApprove(t *testing.T) {
redirectReviewPaths(t)
writePriorVerdict(t, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", review.VerdictApprove)
actionable := actionableWithPR("hive-bot")
actionable.PRs.Items[0].BaseRef = "main"
differ := &fakeDeltaDiffer{diff: review.DeltaDiff{
Known: true, BaseSync: true,
Files: []review.DeltaFile{{Path: "pkg/base/b.go", Additions: 400}},
BaseFiles: []string{"pkg/base/b.go"},
PRFiles: []string{"pkg/x/x.go"},
}}
plan := planReviewDispatchWith(context.Background(), reviewSwarmConfig(), actionable, nil, nil, differ, restoreTestLogger())
if len(differ.baseRefs) != 1 || differ.baseRefs[0] != "main" {
t.Fatalf("base refs passed to the compare = %v, want [main]", differ.baseRefs)
}
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.BaseSync {
t.Fatalf("base-sync restamp not recorded: %+v ok=%v", got, ok)
}

// The base changed one of the PR's files: a delta review, not a carry.
redirectReviewPaths(t)
writePriorVerdict(t, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", review.VerdictApprove)
differ.diff.PRFiles = append(differ.diff.PRFiles, "pkg/base/b.go")
plan = planReviewDispatchWith(context.Background(), reviewSwarmConfig(), actionable, nil, nil, differ, restoreTestLogger())
if len(plan.ReviewKicks) != 1 || len(plan.DeltaRestamps) != 0 || plan.ReviewKicks[0].DeltaPreviousHead == "" {
t.Fatalf("intersecting base-sync: kicks=%+v restamps=%d, want one delta kick", plan.ReviewKicks, len(plan.DeltaRestamps))
}
}
6 changes: 5 additions & 1 deletion src/docs/hive-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ The same section's **Per-repository merge policy** block edits
hive's `project.repos`. Saving writes each key in full as `owner/repo` (the form
the sweep matches); an empty selection clears it, and a repo outside
`project.repos` or a malformed glob is refused with a 400. The sweep reads all
three live, so a change applies on the next pass without a restart.
three live, so a change applies on the next pass without a restart. An
update-branch of an approved PR keeps its swarm approve when the base's changes
miss every PR file: the review planner re-stamps the verdict onto the merge
head instead of holding it at `review-gate:no-review-bundle`, and CI still
re-runs on that head (see [Delta re-review](review-swarm.md#delta-re-review-reviewdelta_rereview-reviewdelta_trivial_lines-reviewdelta_max_age)).

### Event-driven sweeps on the ForgeState cache

Expand Down
6 changes: 6 additions & 0 deletions src/docs/review-swarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ A re-review is a review of a PR the hive already judged at an earlier head SHA.

- 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.
- An **approve** also survives the hive's own merge of the base into the PR, at any delta size. When the hive brings an approved PR up to date (update-branch for `auto_merge.require_current_base`, a `behind` sweep, the hold guard's mergeability upkeep or `review.contributor_prs.base_sync`; GitHub's merges API for merge-forward), the new head used to have no verdict and the PR fell back to `review-gate:no-review-bundle` until a reviewer "delta reviewed" base code that had already been reviewed and merged upstream ([projectbluefin/fsdk-containers#482](https://github.com/projectbluefin/fsdk-containers/pull/482)). The approve is re-stamped (`delta.base_sync: true`, note `hive base-sync; the base's changes … are disjoint from the PR's files`) when all of these hold:
- every commit between the two heads is a two-parent merge whose first parent is the commit before it, authored by the hive App and committed by GitHub itself (`web-flow`): what update-branch and the merges API make. A merge by a person or another bot, a merge pushed with git (agents may commit under the App-linked identity), or any non-merge commit in the delta does not count;
- the last merge's second parent is the base branch's merge base with the head, so the base contains it, and any earlier merge's second parent is on the base below it (the hold guard's hygiene-merge shape, [#14535](https://github.com/hivecommons/hive/issues/14535));
- the files the delta changes are exactly the files the base changed since the reviewed head's merge base, and none of them is one of the PR's own files.

Together those mean every file at the new head is either the reviewed head's or the base's, as a clean merge of a base that touched none of the PR's files produces. GitHub refuses a conflicting update-branch or merge rather than resolve it, and a merge whose tree is anything else fails the file checks, unless all it did was take the base's version of a file both sides changed. That is the same result as a PR whose change already landed on the base. When the base touched a PR file, the planner falls back to the delta review above. A prior `changes_requested` or `requires_human` is never carried this way: its delta review re-checks what the reviewer or a person still has open. A negative `delta_trivial_lines` turns this re-stamp off too. Only the review verdict is carried: CI still runs on the merge head, which is what `auto_merge.require_current_base` asks for ([#13634](https://github.com/hivecommons/hive/issues/13634)). The proof costs two more compare calls (the PR's files against the base branch, and the base's side of the merge), and only for a head whose delta is all hive merges.
- 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.
Expand Down
Loading
Loading