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-15578.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The "review dispatch promoted" warning is now logged once per PR while it stays promoted instead of every cycle, so it no longer trips the repeated-unclassified-error self-report ([#15578](https://github.com/hivecommons/hive/issues/15578)).
6 changes: 5 additions & 1 deletion src/cmd/hive/main_sweeps.go
Original file line number Diff line number Diff line change
Expand Up @@ -2477,9 +2477,13 @@ func planReviewDispatchWith(ctx context.Context, cfg *config.Config, actionable
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)
}
promotedNow := map[string]struct{}{}
for _, w := range plan.Promoted {
logger.Warn("review dispatch promoted: head starved of a reviewer walked ahead of the queue", "repo", w.Repo, "pr", w.Number, "head", w.HeadSHA, "reason", w.Reason, "cycles", w.Cycles, "since", w.FirstAt, "limit", review.ReviewWaitStarvationCycles)
key := prWarnKey(w.Repo, w.Number)
promotedNow[key] = struct{}{}
logger.Log(context.Background(), reviewPromotedWarn.level(key), "review dispatch promoted: head starved of a reviewer walked ahead of the queue", "repo", w.Repo, "pr", w.Number, "head", w.HeadSHA, "reason", w.Reason, "cycles", w.Cycles, "since", w.FirstAt, "limit", review.ReviewWaitStarvationCycles)
}
reviewPromotedWarn.retain(promotedNow)
for _, w := range plan.Waiting {
logger.Info("review dispatch waiting: perspectives still owed, no reviewer this cycle", "repo", w.Repo, "pr", w.Number, "head", w.HeadSHA, "reason", w.Reason)
}
Expand Down
5 changes: 3 additions & 2 deletions src/cmd/hive/warn_once_pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (w *prWarnOnce) retain(active map[string]struct{}) {
}

var (
humanLabelWarn prWarnOnce
reviewExpiredWarn prWarnOnce
humanLabelWarn prWarnOnce
reviewExpiredWarn prWarnOnce
reviewPromotedWarn prWarnOnce
)
75 changes: 75 additions & 0 deletions src/cmd/hive/warn_once_pr_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package main

import (
"bytes"
"context"
"fmt"
"log/slog"
"strings"
"testing"
"time"

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

func TestPRWarnOnce(t *testing.T) {
Expand All @@ -23,3 +31,70 @@ func TestPRWarnOnce(t *testing.T) {
t.Fatal("cleared condition should re-arm")
}
}

func promotedWarnCount(log string, pr int) (warns, debugs int) {
for _, line := range strings.Split(log, "\n") {
if !strings.Contains(line, "review dispatch promoted") || !strings.Contains(line, fmt.Sprintf("pr=%d ", pr)) {
continue
}
switch {
case strings.Contains(line, "level=WARN"):
warns++
case strings.Contains(line, "level=DEBUG"):
debugs++
}
}
return warns, debugs
}

func TestPlanReviewDispatch_PromotionWarnsOncePerPR(t *testing.T) {
redirectReviewPaths(t)
reviewPromotedWarn.retain(map[string]struct{}{})
t.Cleanup(func() { reviewPromotedWarn.retain(map[string]struct{}{}) })

const otherPR = 4322
// fillerPR has no wait record: promotion only reorders a list of two or
// more heads, so it keeps a pass with a single starved head promotable.
const fillerPR = 4399
pass := func(numbers ...int) string {
t.Helper()
var waits []review.ReviewWaitRecord
actionable := &github.ActionableResult{}
for _, n := range numbers {
waits = append(waits, review.ReviewWaitRecord{Repo: "hivecommons/hive", Number: n, HeadSHA: reviewTestSHA, Reason: review.ReviewWaitNoFreeReviewer, Cycles: review.ReviewWaitStarvationCycles, FirstAt: time.Now().Add(-time.Hour)})
actionable.PRs.Items = append(actionable.PRs.Items, github.PullRequest{Repo: "hivecommons/hive", Number: n, Title: "test: add coverage", Author: "hive-bot", HeadSHA: reviewTestSHA})
}
actionable.PRs.Items = append(actionable.PRs.Items, github.PullRequest{Repo: "hivecommons/hive", Number: fillerPR, Title: "test: add coverage", Author: "hive-bot", HeadSHA: reviewTestSHA})
if err := review.WriteDispatchState("", review.DispatchState{Waits: waits}); err != nil {
t.Fatal(err)
}
var buf bytes.Buffer
logger := slog.New(slog.NewTextHandler(&buf, &slog.HandlerOptions{Level: slog.LevelDebug}))
plan := planReviewDispatchWith(context.Background(), reviewSwarmConfig(), actionable, nil, nil, nil, logger)
if len(plan.Promoted) != len(numbers) {
t.Fatalf("promoted = %+v, want %d heads", plan.Promoted, len(numbers))
}
return buf.String()
}
expect := func(log string, pr, warns, debugs int) {
t.Helper()
if w, d := promotedWarnCount(log, pr); w != warns || d != debugs {
t.Fatalf("PR %d promotion logs: warn=%d debug=%d, want warn=%d debug=%d\n%s", pr, w, d, warns, debugs, log)
}
}

first := pass(4321, otherPR)
expect(first, 4321, 1, 0)
expect(first, otherPR, 1, 0)

second := pass(4321, otherPR)
expect(second, 4321, 0, 1)
expect(second, otherPR, 0, 1)

third := pass(4321)
expect(third, 4321, 0, 1)

fourth := pass(4321, otherPR)
expect(fourth, 4321, 0, 1)
expect(fourth, otherPR, 1, 0)
}
Loading