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/fixed-review-fix-missing-body-digest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- review-fix: a `changes_requested` verdict whose report carries no `body_digest` is now treated as "digest unknown β†’ body unchanged" instead of "PR body edited β†’ re-review", so PRs at `stage/070-fixing` get a fix kick instead of being re-asked for review every cycle (#14665). Reports are now stamped with the PR body digest at collect time and when the relay records advisory verdicts; a starvation guard forces the fix path after 3 consecutive revisit-suppressed cycles, each suppressed cycle logs a WARN with its reason, and the planner summary line reports `fix_excluded` / `fix_excluded_reasons`.
35 changes: 32 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 @@ -10783,12 +10783,38 @@
for _, h := range plan.Exhausted {
logger.Warn("review dispatch exhausted; holding PR for a human", "repo", h.Repo, "pr", h.Number, "head", h.HeadSHA, "reason", h.Reason)
}
if len(plan.ReviewKicks)+len(plan.FixKicks) > 0 {
logger.Info("review swarm dispatch planned", "review_kicks", len(plan.ReviewKicks), "fix_kicks", len(plan.FixKicks))
for _, f := range plan.ForcedFixes {
logger.Warn("review fix forced: changes_requested head starved by the revisit path", "repo", f.Repo, "pr", f.Number, "head", f.HeadSHA, "reason", f.Reason, "cycles", f.Cycles, "limit", review.RevisitStarvationCycles)
}
if len(plan.ReviewKicks)+len(plan.FixKicks)+len(plan.FixExclusions) > 0 {
logger.Info("review swarm dispatch planned", "review_kicks", len(plan.ReviewKicks), "fix_kicks", len(plan.FixKicks), "fix_excluded", len(plan.FixExclusions), "fix_excluded_reasons", fixExclusionReasonSummary(plan.FixExclusions))
}
return plan
}

// fixExclusionReasonSummary renders the cycle's fix exclusions as
// "reason=count,..." (sorted) for the dispatch summary line, so fix_kicks: 0
// is never printed without saying why (hivecommons/hive#14665).
func fixExclusionReasonSummary(exclusions []review.FixDispatchExclusion) string {
if len(exclusions) == 0 {
return ""
}
counts := map[string]int{}
for _, x := range exclusions {
counts[x.Reason]++
}
reasons := make([]string, 0, len(counts))
for r := range counts {
reasons = append(reasons, r)
}
sort.Strings(reasons)
parts := make([]string, 0, len(reasons))
for _, r := range reasons {
parts = append(parts, fmt.Sprintf("%s=%d", r, counts[r]))
}
return strings.Join(parts, ",")
}

// 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,
Expand Down Expand Up @@ -11001,8 +11027,11 @@
// hivecommons/hive#12897). The planner reports each head once, so
// this does not repeat on every eval cycle.
func auditWithheldReviewFixes(plan review.DispatchPlan, auditor reviewFixAuditor, logger *slog.Logger) {
// One WARN per changes_requested head that ends the cycle without a fix
// kick: a PR shown as "Fixing" that nobody is fixing must be loud
// (hivecommons/hive#14665).
for _, x := range plan.FixExclusions {
logger.Info("review fix dispatch excluded",
logger.Warn("review fix dispatch excluded",
"repo", x.Repo, "pr", x.Number, "head_sha", x.HeadSHA, "author", x.Author, "reason", x.Reason, "attempts", x.Attempts)
}
for _, w := range plan.WithheldFixes {
Expand Down
50 changes: 33 additions & 17 deletions src/pkg/github/review_verdict_relay.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package github

import (
Expand Down Expand Up @@ -89,7 +89,8 @@
if decisionRequested || reviewReportsHoldForHuman(reports) {
tightening = c.workflowPermissionsTighteningOnly(ctx, req)
}
prHead := c.reviewedPRHeadFunc(ctx, req)
prSnapshot := c.reviewedPRSnapshotFunc(ctx, req)
prHead := func() string { return prSnapshot().Head }
var recorded []review.PerspectiveReport
for _, report := range reports {
if decisionRequested {
Expand All @@ -99,7 +100,7 @@
report.Verdict = review.VerdictRequiresHuman
}
report.PermissionsTighteningOnly = tightening
if written, ok := c.writeOneVerdict(ctx, req, report, dir, prHead); ok {
if written, ok := c.writeOneVerdict(ctx, req, report, dir, prHead, prSnapshot); ok {
recorded = append(recorded, written)
}
}
Expand Down Expand Up @@ -145,34 +146,44 @@
return head
}

// reviewedPRHeadFunc returns a memoized lookup of req's PR head SHA: one
// GitHub GET per relay pass at most, only when a verdict actually needs it,
// and "" when the client is unavailable or the fetch fails.
func (c *Client) reviewedPRHeadFunc(ctx context.Context, req ReviewRequest) func() string {
// reviewedPRSnapshot is what the relay reads from the PR itself: its head
// SHA, and the digest of its current title and body.
type reviewedPRSnapshot struct {
Head string
BodyDigest string
}

// reviewedPRSnapshotFunc returns a memoized lookup of req's PR head SHA and
// body digest: one REST call per relayed request at most, and none when
// nothing asks. A fetch failure is logged once and yields an empty snapshot.
func (c *Client) reviewedPRSnapshotFunc(ctx context.Context, req ReviewRequest) func() reviewedPRSnapshot {
var (
head string
snap reviewedPRSnapshot
fetched bool
)
return func() string {
return func() reviewedPRSnapshot {
if fetched {
return head
return snap
}
fetched = true
if c == nil || c.client == nil {
return ""
return snap
}
owner, name := c.splitRepo(strings.TrimSpace(req.Repo))
if owner == "" || name == "" || req.Number <= 0 {
return ""
return snap
}
pr, _, err := c.client.PullRequests.Get(WithRESTCaller(ctx, "hive:review_verdict_relay"), owner, name, req.Number)
if err != nil || pr == nil {
c.logger.Warn("review-request watcher: could not fetch PR head to widen abbreviated verdict head",
c.logger.Warn("review-request watcher: could not fetch PR to bind verdict head and body digest",
slog.String("repo", req.Repo), slog.Int("number", req.Number))
return ""
return snap
}
head = strings.TrimSpace(pr.GetHead().GetSHA())
return head
snap = reviewedPRSnapshot{
Head: strings.TrimSpace(pr.GetHead().GetSHA()),
BodyDigest: review.PullRequestBodyDigest(pr.GetTitle(), pr.GetBody()),
}
return snap
}
}

Expand Down Expand Up @@ -329,7 +340,7 @@
// always read β€” a combined review changes how verdicts arrive, not how they
// are stored, so nothing downstream needs to know the difference. It returns
// the report as stored and whether it was.
func (c *Client) writeOneVerdict(ctx context.Context, req ReviewRequest, report review.PerspectiveReport, dir string, prHead func() string) (review.PerspectiveReport, bool) {
func (c *Client) writeOneVerdict(ctx context.Context, req ReviewRequest, report review.PerspectiveReport, dir string, prHead func() string, prSnapshot func() reviewedPRSnapshot) (review.PerspectiveReport, bool) {
// The verdict must be about the PR that was actually reviewed. Without this
// an agent authorized to comment on one PR could record a binding
// requires_human/reject verdict against any other PR in the fleet.
Expand Down Expand Up @@ -393,7 +404,10 @@
// with no digest stamps an empty one, so every head's verdict for that
// PR and head SHA shares one aggregate instead of each landing under
// whatever the model wrote (hivecommons/hive#14594). An advisory verdict
// has no dispatch record and keeps the digest it reported.
// has no dispatch record and keeps the digest it reported; when it
// reported none, the digest of the PR's current title and body is
// stamped, so the planner can tell a later body edit from an unknown
// one (hivecommons/hive#14665).
if dispatchBodyDigest := strings.TrimSpace(auth.BodyDigest); auth.Dispatched {
if strings.TrimSpace(report.BodyDigest) != dispatchBodyDigest {
c.logger.Debug("review-request watcher: verdict body digest replaced by the dispatch digest",
Expand All @@ -402,6 +416,8 @@
slog.String("agent", req.Agent))
}
report.BodyDigest = dispatchBodyDigest
} else if strings.TrimSpace(report.BodyDigest) == "" && prSnapshot != nil {
report.BodyDigest = prSnapshot().BodyDigest
}

// Re-marshalled from the validated struct rather than written through from
Expand Down
144 changes: 136 additions & 8 deletions src/pkg/review/dispatch.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package review

import (
Expand Down Expand Up @@ -275,6 +275,32 @@
HeadRetries []HeadRetryCount `json:"head_retries,omitempty"`
MissingHeads []MissingHead `json:"missing_heads,omitempty"`
Acknowledged []AcknowledgedHead `json:"acknowledged,omitempty"`
// RevisitStarved counts, per head, the consecutive cycles in which a
// changes_requested verdict was sent down the revisit path instead of
// the fix path. At RevisitStarvationCycles the planner forces the fix
// (hivecommons/hive#14665). Cleared when the head is settled normally.
RevisitStarved []RevisitStarvation `json:"revisit_starved,omitempty"`
}

// RevisitStarvation is the per-head counter behind RevisitStarvationCycles.
type RevisitStarvation struct {
Repo string `json:"repo"`
Number int `json:"number"`
HeadSHA string `json:"head_sha,omitempty"`
Reason string `json:"reason"`
Cycles int `json:"cycles"`
LastAt time.Time `json:"last_at"`
}

// ForcedFix is a fix kick the planner took despite a revisit being due,
// because the head had been starved of its fix for RevisitStarvationCycles
// consecutive cycles. The caller logs each one.
type ForcedFix struct {
Repo string
Number int
HeadSHA string
Reason string
Cycles int
}

// RedispatchCount is the per-head expiry counter behind review.max_redispatch.
Expand Down Expand Up @@ -471,7 +497,10 @@
// trivial delta). The caller records them in the verdict artifact
// (RecordDeltaRestamps) and logs each one.
DeltaRestamps []DeltaRestamp
State DispatchState
// ForcedFixes are the changes_requested heads whose fix kick was forced
// this cycle after RevisitStarvationCycles revisit-suppressed cycles.
ForcedFixes []ForcedFix
State DispatchState
}

type FixDispatchExclusion struct {
Expand All @@ -490,6 +519,10 @@
FixDispatchExcludedNotHiveAuthored = "not-hive-authored"
FixDispatchExcludedNotHiveAuthoredDCO = "not-hive-authored-squash-signoff"
FixAttemptsExhaustedHumanDecisionReason = "fix-attempts-exhausted"
// The revisit reasons name why a changes_requested verdict was sent back
// to the reviewers instead of the fixer this cycle (hivecommons/hive#14665).
FixDispatchExcludedRevisitBodyEdited = "verdict-revisit:body-edited"
FixDispatchExcludedRevisitStale = "verdict-revisit:stale-reviewer"
)

func LoadDispatchState(path string) (DispatchState, error) {
Expand Down Expand Up @@ -596,7 +629,26 @@
// reviewer-side defect is found: without this, verdicts produced
// by a known-broken reviewer stay frozen until someone happens to
// push a commit.
if !staleVerdictRevisitable(pr.Repo, agg, opts) && !bodyEditedVerdictRevisitable(pr, agg) {
revisitReason := ""
if staleVerdictRevisitable(pr.Repo, agg, opts) {
revisitReason = FixDispatchExcludedRevisitStale
} else if bodyEditedVerdictRevisitable(pr, agg) {
revisitReason = FixDispatchExcludedRevisitBodyEdited
}
// A revisit re-asks the reviewers; it must not keep the fixer
// away from a changes_requested head indefinitely. After
// RevisitStarvationCycles consecutive revisit cycles with no fix
// kick, the fix path is taken regardless (hivecommons/hive#14665).
forcedFix := false
if revisitReason != "" && agg.Verdict == VerdictChangesRequested {
if starved := revisitStarvedCycles(plan.State, pr); starved >= RevisitStarvationCycles {
plan.ForcedFixes = append(plan.ForcedFixes, ForcedFix{Repo: pr.Repo, Number: pr.Number, HeadSHA: pr.HeadSHA, Reason: revisitReason, Cycles: starved})
revisitReason = ""
forcedFix = true
}
}
if revisitReason == "" {
plan.State.RevisitStarved = removeRevisitStarvedForHead(plan.State.RevisitStarved, pr)
if agg.Verdict == VerdictIncomplete {
// Every perspective that reported approved; some never
// reported. The head is not settled, it is under-asked:
Expand All @@ -619,7 +671,11 @@
}
plan.expirePending(pr, opts, now)
} else {
plan.State.Pending = removePendingForHead(plan.State.Pending, pr)
// A forced fix leaves the in-flight revisit's pending
// entries alone: the relay binds its verdicts to them.
if !forcedFix {
plan.State.Pending = removePendingForHead(plan.State.Pending, pr)
}
if headsMode {
plan.acknowledgeSkippedDecision(pr, agg, opts, now)
}
Expand All @@ -636,6 +692,9 @@
continue
}
} else {
if agg.Verdict == VerdictChangesRequested {
plan.noteRevisitStarvation(pr, revisitReason, now)
}
// Pending entries are the lifetime record of what this head has
// already been asked, and a PR with a verdict always has them β€”
// so left in place they make every perspective look covered and
Expand Down Expand Up @@ -1051,19 +1110,81 @@
p.State.Human = upsertHuman(p.State.Human, HumanReviewHold{Repo: pr.Repo, Number: pr.Number, HeadSHA: pr.HeadSHA, Reason: reason, UpdatedAt: now})
}

// bodyEditedVerdictRevisitable reports whether a non-approve verdict was
// judged against an earlier PR title/body than the one the PR carries now.
// Only a present-and-different digest proves an edit. A verdict with no
// digest is unknown, not edited: perspective reports may omit body_digest
// (the prompt allows it), and reading the gap as "edited" sent every such
// changes_requested verdict down the revisit path instead of the fix path,
// forever (hivecommons/hive#14665). The UpdatedAt fallback is for PR
// snapshots that predate digests altogether.
func bodyEditedVerdictRevisitable(pr PullRequest, agg Aggregate) bool {
if agg.Verdict == VerdictApprove || agg.Verdict == VerdictIncomplete {
return false
}
if strings.TrimSpace(pr.BodyDigest) != "" && strings.TrimSpace(agg.BodyDigest) != "" {
return strings.TrimSpace(pr.BodyDigest) != strings.TrimSpace(agg.BodyDigest)
}
if strings.TrimSpace(pr.BodyDigest) != "" && strings.TrimSpace(agg.BodyDigest) == "" {
return true
prDigest := strings.TrimSpace(pr.BodyDigest)
aggDigest := strings.TrimSpace(agg.BodyDigest)
if prDigest != "" {
if aggDigest == "" {
return false
}
return prDigest != aggDigest
}
return !pr.UpdatedAt.IsZero() && !agg.RecordedAt.IsZero() && pr.UpdatedAt.After(agg.RecordedAt)
}

// RevisitStarvationCycles is how many consecutive planner cycles a
// changes_requested head may be sent down the revisit path with no fix kick
// before the planner forces the fix path. The revisit exists to re-ask the
// reviewers; it must never become a reason the fixer is not asked at all.
const RevisitStarvationCycles = 3

// revisitStarvedCycles returns how many consecutive cycles this head's
// changes_requested verdict was suppressed by the revisit path so far.
func revisitStarvedCycles(state DispatchState, pr PullRequest) int {
for _, s := range state.RevisitStarved {
if samePRHead(s.Repo, s.Number, s.HeadSHA, pr.Repo, pr.Number, pr.HeadSHA) {
return s.Cycles
}
}
return 0
}

// noteRevisitStarvation counts one more cycle in which the revisit path
// suppressed this head's fix kick, and records the exclusion so the caller
// logs why fix_kicks stayed at zero.
func (p *DispatchPlan) noteRevisitStarvation(pr PullRequest, reason string, now time.Time) {
cycles := 0
found := false
for i := range p.State.RevisitStarved {
s := &p.State.RevisitStarved[i]
if samePRHead(s.Repo, s.Number, s.HeadSHA, pr.Repo, pr.Number, pr.HeadSHA) {
s.Cycles++
s.Reason = reason
s.LastAt = now
cycles = s.Cycles
found = true
break
}
}
if !found {
cycles = 1
p.State.RevisitStarved = append(p.State.RevisitStarved, RevisitStarvation{Repo: pr.Repo, Number: pr.Number, HeadSHA: pr.HeadSHA, Reason: reason, Cycles: cycles, LastAt: now})
}
p.recordFixExclusion(pr, reason, cycles)
}

func removeRevisitStarvedForHead(items []RevisitStarvation, pr PullRequest) []RevisitStarvation {
kept := items[:0]
for _, s := range items {
if samePRHead(s.Repo, s.Number, s.HeadSHA, pr.Repo, pr.Number, pr.HeadSHA) {
continue
}
kept = append(kept, s)
}
return kept
}

// effectivePendingTTL resolves PendingTTL: zero is the default, negative
// turns expiry off.
func (o DispatchOptions) effectivePendingTTL() time.Duration {
Expand Down Expand Up @@ -1730,6 +1851,13 @@
}
}
state.Redispatches = redispatches
var starved []RevisitStarvation
for _, s := range state.RevisitStarved {
if openHeads[reviewKey(s.Repo, s.Number, s.HeadSHA, "")] {
starved = append(starved, s)
}
}
state.RevisitStarved = starved
state = pruneReviewHeadState(state, openHeads)
return state
}
Expand Down
Loading
Loading