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-adopted-review-fix-undo-guard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- An adopted PR whose hive fix does what its review asked is no longer stuck at `stage/085-needs-decision` as "Fixing CI would undo this PR's change". On projectbluefin/utah-packages#943 the review asked that the PR's two wontfix entries stay pending; the hive adopted the PR for those asks and pushed a commit that did exactly that, and the undo guard parked it because the push kept only 2 of the PR's 20 changed lines. The park held until the head moved, so a later approve could not release it. When the hive adopts a PR for the review swarm's requested changes (CI not red), a push the guard refuses is now taken once the reviewer approves that exact head, whether the approve comes before or after the push is checked; the park is released with no second note. A fix for red CI that undoes the PR (projectbluefin/utah#1091) stays refused even if the reviewer approves it, and any verdict other than approve keeps the park.
11 changes: 10 additions & 1 deletion src/docs/labels-and-control-signals/stage-labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,16 @@ When a contributor-agent PR goes red the hive does not just relabel it (a human-
and one "Fixing CI would undo this PR's change" note per head, and the
contributor lane will not merge that head; stale-red recovery may re-run
its CI but never releases the refusal (projectbluefin/utah#1091: the
fixer re-added the 25 entries the PR removed). Until the check has
fixer re-added the 25 entries the PR removed). One exception: when the
hive adopted the PR for the review swarm's requested changes with CI
not red (`adopted_for_review`), the review may have asked for part of
the change to go, so a refused push is taken once the reviewer's
verdict on that exact head is approve. The approve is read on every
sweep, so a park posted before the verdict arrived is released then,
with no second note (projectbluefin/utah-packages#943: the review asked
for both wontfix entries to stay pending, and the hive's push did
that). Any other verdict keeps the park, and an adoption for red CI
never takes this path, approve or not. Until the check has
passed, the lane refuses the head as
`contributor-lane:adoption-intent-pending`, and the relay rewrites an
agent's `hive/awaiting-ci: … sweep will merge when green` note on a hive
Expand Down
57 changes: 56 additions & 1 deletion src/pkg/github/automerge/automerge_adoption_intent.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func (c *Engine) checkAdoptedPushIntent(ctx context.Context, store *stagelabels.
c.warn("stage labels: adopted PR advanced by the hive; diff unreadable, intent check deferred", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "error", err)
return 0, nil
}
if intent.Reverts() && c.reviewApprovedFixerRevert(prev, obs.Owner, obs.Repo, obs.Number, obs.HeadSHA) {
c.info("stage labels: hive push drops most of the adopted PR's change, as its review asked; the reviewer approved this head", "repo", obs.Display, "pr", obs.Number, "intent_base", base, "head", obs.HeadSHA, "own_lines", intent.Own, "kept_lines", intent.Kept)
store.MarkAdoptedHead(key, obs.HeadSHA)
return 0, nil
}
if !intent.Reverts() {
if intent.Unjudged {
c.info("stage labels: adopted PR advanced by the hive; diff too large to judge intent", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA)
Expand All @@ -139,6 +144,50 @@ func (c *Engine) checkAdoptedPushIntent(ctx context.Context, store *stagelabels.
return n, nil
}

// adoptedForReview reports whether an in-place adoption of obs is taken
// over for the review swarm's requested changes with CI not red
// (Record.AdoptedForReview). A fix for review asks may rightly drop part of
// the PR's change: on projectbluefin/utah-packages#943 the review asked that
// the PR's two wontfix entries go back to pending, the hive's push did
// exactly that, and the intent check parked it as a CI fix undoing the PR.
func adoptedForReview(obs stageObservation) bool {
if adoptionWaitFor(obs).red {
return false
}
return obs.Reason == contributorLaneReasonChangesRequested || obs.Reason == stagelabels.LaneReasonChangesRequested || verdictBlocks(obs.Detail)
}

// reviewApprovedFixerRevert reports whether a hive push that drops most of
// an adopted PR's change is still the hive's to merge: the adoption was for
// the review swarm's requested changes (never for red CI, the utah#1091
// shape) and the reviewer's verdict on this exact head is approve. The
// reviewer then judged the narrowed diff and agreed with it; a CI-only fix
// that undoes the PR stays refused, and no verdict yet means refused.
func (c *Engine) reviewApprovedFixerRevert(rec stagelabels.Record, owner, repo string, number int, head string) bool {
if c == nil || head == "" || !rec.AdoptedInPlace() || !rec.AdoptedForReview {
return false
}
return c.contributorLaneVerdictFor(owner+"/"+repo, number, head).Approved
}

// releaseApprovedFixerRevert clears a fixer-reverts refusal on obs.HeadSHA
// once reviewApprovedFixerRevert holds: the park is a verdict on the head's
// content, and the reviewer's approve of that content, which arrives after
// the push was judged, answers it. Without this the 085 park held until the
// head moved, so a fix the review asked for and then approved still waited
// on a person. Reports whether it released.
func (c *Engine) releaseApprovedFixerRevert(store *stagelabels.Store, key string, obs stageObservation, rec stagelabels.Record) bool {
if !rec.AdoptionEscalated(obs.HeadSHA) || rec.AdoptEscalatedReason != stagelabels.LaneReasonAdoptionFixerReverts {
return false
}
if !c.reviewApprovedFixerRevert(rec, obs.Owner, obs.Repo, obs.Number, obs.HeadSHA) {
return false
}
store.ClearAdoptionEscalation(key)
c.info("stage labels: fixer-reverts refusal released; the reviewer approved the head the review asked for", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA)
return true
}

// AdoptionFixerRevertsComment is the one note on a head whose hive push
// undid the PR's change.
func AdoptionFixerRevertsComment(obs stageObservation, before string, intent adoptionIntent) string {
Expand Down Expand Up @@ -178,5 +227,11 @@ func (c *Engine) adoptionIntentGate(owner, repo string, number int, headSHA stri
if !ok {
return ""
}
return adoptionIntentRefused(rec, headSHA)
reason := adoptionIntentRefused(rec, headSHA)
if reason == stagelabels.LaneReasonAdoptionFixerReverts && c.reviewApprovedFixerRevert(rec, owner, repo, number, headSHA) {
// The lane may run before the stage pass releases the park; the
// approve it is about to read admits the head either way.
return ""
}
return reason
}
192 changes: 192 additions & 0 deletions src/pkg/github/automerge/automerge_adoption_intent_review_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
package automerge

import (
"strings"
"testing"
"time"

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

// projectbluefin/utah-packages#943: the PR marks two packages wontfix (2
// lines in config/factory-build-backlog.toml) and adds 18 lines of guidance.
// The review asked for both entries to stay pending. The hive adopted the PR
// for those asks and pushed eed6933, which drops both entries and rewrites
// the guidance, keeping 2 of the PR's 20 changed lines.
func utahPackages943Files(fixed bool) []map[string]string {
if fixed {
return []map[string]string{{"filename": "docs/skills/factory-build-backlog.md", "status": "modified",
"patch": "@@ -355,0 +355,6 @@\n+### Packages removed from Fedora\n+\n" + strings.Repeat("+defer to the kernel-module gate\n", 3) + "+import the negativo17 recipe"}}
}
return []map[string]string{
{"filename": "config/factory-build-backlog.toml", "status": "modified",
"patch": "@@ -912,0 +913,2 @@\n+intel-vaapi-driver = \"wontfix: dropped from Fedora\"\n+kmod-v4l2loopback = \"wontfix: upstream gone\""},
{"filename": "docs/skills/factory-build-backlog.md", "status": "modified",
"patch": "@@ -355,0 +355,18 @@\n+### Packages removed from Fedora\n+\n" + strings.Repeat("+removed packages with unreachable upstream go to wontfix\n", 16)},
}
}

// adopt943ForReview adopts PR #7 in place at head aaa for the review swarm's
// requested changes, CI green: the utah-packages#943 adoption.
func adopt943ForReview(t *testing.T) (*adoptHarness, func(), []string) {
t.Helper()
p := adoptPolicy()
p.AdoptInPlace = true
h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "comment"}, p)
h.adopt.allowMaintainerEdits(7, true)
h.adopt.comparePatches = map[string][]map[string]string{"aaa": utahPackages943Files(false)}
h.observe(adoptPR(7, "aaa"), contributorLaneReasonChangesRequested)
labels := []string{"stage/072-returned-to-contributor", "role/contributor", "author/clanker"}
h.clock.advance(30 * time.Minute)
h.observe(adoptPR(7, "aaa", labels...), contributorLaneReasonChangesRequested)
h.observe(adoptPR(7, "aaa", labels...), contributorLaneReasonChangesRequested)
rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7))
if !rec.AdoptedInPlace() || rec.AdoptedHead != "aaa" {
done()
t.Fatalf("not adopted in place: %+v", rec)
}
if nudges := nudgeComments(h.api); len(nudges) != 1 || !strings.Contains(nudges[0], "the review swarm requested changes") {
done()
t.Fatalf("PR was not returned for the review asks: %v", h.api.comments)
}
return h, done, []string{"stage/074-adopted-by-hive", "role/contributor", "author/clanker"}
}

// reviewerVerdicts stands in for the review swarm: approve for the heads in
// approved, changes requested for every other head.
func reviewerVerdicts(h *adoptHarness, approved ...string) {
h.e.contributorLaneVerdict = func(_ string, _ int, head string) ContributorLaneVerdict {
for _, a := range approved {
if head == a {
return ContributorLaneVerdict{Configured: true, Approved: true, Verdict: "approve"}
}
}
return ContributorLaneVerdict{Configured: true, Verdict: "changes_requested"}
}
}

// The utah-packages#943 order: the push is judged at once and parked (no
// verdict on it yet), then the reviewer approves that head. The approve
// answers the park: it is released, the lane admits the head, and no second
// note is posted.
func TestAdoptedReviewFixThatDropsChangeIsReleasedByApprove(t *testing.T) {
h, done, adopted := adopt943ForReview(t)
defer done()
reviewerVerdicts(h)
h.adopt.comparePatches["eed6933"] = utahPackages943Files(true)
h.adopt.setCommitAuthor("eed6933", testHiveAppBotLogin)
h.api.reset()
h.clock.advance(time.Minute)
h.observe(adoptPR(7, "eed6933", adopted...), "ci-pending")
if notes := fixerRevertsComments(h.api); len(notes) != 1 || !strings.Contains(notes[0], "leaves 2 of the 20 lines") {
t.Fatalf("before the verdict: notes = %v (all comments %v)", notes, h.api.comments)
}
if got := h.e.adoptionIntentGate("acme", "widget", 7, "eed6933"); got != stagelabels.LaneReasonAdoptionFixerReverts {
t.Fatalf("merge gate before the verdict = %q, want the refusal", got)
}

// The reviewer approves eed6933.
reviewerVerdicts(h, "eed6933")
if got := h.e.adoptionIntentGate("acme", "widget", 7, "eed6933"); got != "" {
t.Fatalf("merge gate after the approve = %q, want none", got)
}
h.api.reset()
h.clock.advance(time.Minute)
h.observe(adoptPR(7, "eed6933", "stage/085-needs-decision", "role/contributor", "author/clanker"), "ci-pending")
rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7))
if rec.AdoptionEscalated("eed6933") || rec.Stage == stagelabels.NeedsDecision || rec.AdoptedHead != "eed6933" {
t.Fatalf("park not released after the approve: %+v", rec)
}
if len(fixerRevertsComments(h.api)) != 0 || strings.Contains(strings.Join(h.addedLabels(), ","), "stage/085") {
t.Fatalf("after the approve: comments=%v added=%v", h.api.comments, h.api.added)
}
}

// The approve is already on the head when the push is first judged: no
// park and no note.
func TestAdoptedReviewFixApprovedBeforeCheckIsNotParked(t *testing.T) {
h, done, adopted := adopt943ForReview(t)
defer done()
reviewerVerdicts(h, "eed6933")
h.adopt.comparePatches["eed6933"] = utahPackages943Files(true)
h.adopt.setCommitAuthor("eed6933", testHiveAppBotLogin)
h.api.reset()
h.clock.advance(time.Minute)
h.observe(adoptPR(7, "eed6933", adopted...), "ci-pending")
if len(fixerRevertsComments(h.api)) != 0 || strings.Contains(strings.Join(h.addedLabels(), ","), "stage/085") {
t.Fatalf("approved review fix parked: comments=%v added=%v", h.api.comments, h.api.added)
}
rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7))
if rec.AdoptionEscalated("eed6933") || rec.AdoptedHead != "eed6933" {
t.Fatalf("record = %+v", rec)
}
if got := h.e.adoptionIntentGate("acme", "widget", 7, "eed6933"); got != "" {
t.Fatalf("merge gate = %q, want none", got)
}
}

// What the reviewer actually said on eed6933: the old asks are resolved but
// it still requests changes. That is no approve, so the park holds.
func TestAdoptedReviewFixWithoutApproveStaysParked(t *testing.T) {
h, done, adopted := adopt943ForReview(t)
defer done()
reviewerVerdicts(h)
h.adopt.comparePatches["eed6933"] = utahPackages943Files(true)
h.adopt.setCommitAuthor("eed6933", testHiveAppBotLogin)
h.clock.advance(time.Minute)
h.observe(adoptPR(7, "eed6933", adopted...), "ci-pending")
h.clock.advance(time.Minute)
h.observe(adoptPR(7, "eed6933", "stage/085-needs-decision", "role/contributor", "author/clanker"), "ci-pending")
rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7))
if !rec.AdoptionEscalated("eed6933") || rec.AdoptEscalatedReason != stagelabels.LaneReasonAdoptionFixerReverts {
t.Fatalf("record = %+v, want the park held", rec)
}
if got := h.e.adoptionIntentGate("acme", "widget", 7, "eed6933"); got != stagelabels.LaneReasonAdoptionFixerReverts {
t.Fatalf("merge gate = %q, want the refusal", got)
}
}

// The hole hivecommons/hive#16816 closed stays closed: an adoption for red
// CI (utah#1091) whose fixer undid the PR is refused even when the reviewer
// approves the narrowed head, before or after the push is judged.
func TestAdoptedCIFixThatRevertsPRStaysRefusedWhenApproved(t *testing.T) {
h, done, adopted := adoptUtah1091InPlace(t)
defer done()
reviewerVerdicts(h, "a75a567")
h.adopt.comparePatches["a75a567"] = utah1091Files(false, "")
h.adopt.setCommitAuthor("a75a567", testHiveAppBotLogin)
h.api.reset()
h.clock.advance(time.Minute)
h.observe(adoptPR(7, "a75a567", adopted...), "ci-pending")
if notes := fixerRevertsComments(h.api); len(notes) != 1 {
t.Fatalf("notes = %v (all comments %v)", notes, h.api.comments)
}
h.clock.advance(time.Minute)
h.observe(adoptPR(7, "a75a567", "stage/085-needs-decision", "role/contributor", "author/clanker"), "ci-pending")
rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7))
if !rec.AdoptionEscalated("a75a567") || rec.AdoptEscalatedReason != stagelabels.LaneReasonAdoptionFixerReverts {
t.Fatalf("record = %+v, want the refusal held", rec)
}
if got := h.e.adoptionIntentGate("acme", "widget", 7, "a75a567"); got != stagelabels.LaneReasonAdoptionFixerReverts {
t.Fatalf("merge gate = %q, want the refusal", got)
}
}

// adoptedForReview reads the adoption's cause: review asks with CI not red.
func TestAdoptedForReview(t *testing.T) {
asked := stageDetail{VerdictKnown: true, Verdict: ContributorLaneVerdict{Configured: true, Verdict: "changes_requested"}}
for name, tc := range map[string]struct {
obs stageObservation
want bool
}{
"review asks, CI green": {stageObservation{Reason: contributorLaneReasonChangesRequested}, true},
"blocking verdict, CI pending": {stageObservation{Reason: "ci-pending", Detail: asked}, true},
"red CI": {stageObservation{Reason: "check-failing:unit"}, false},
"red CI and review asks": {stageObservation{Reason: "check-failing:unit", Detail: asked}, false},
"conflict": {stageObservation{Reason: "conflicting"}, false},
} {
if got := adoptedForReview(tc.obs); got != tc.want {
t.Errorf("%s: adoptedForReview = %v, want %v", name, got, tc.want)
}
}
}
3 changes: 3 additions & 0 deletions src/pkg/github/automerge/automerge_contributor_adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,9 @@ func (c *Engine) adoptContributorPR(ctx context.Context, store *stagelabels.Stor

if policy.AdoptInPlace && canPushInPlace && !dcoRehome {
store.MarkAdoptedInPlace(key, obs.HeadSHA, reason, now)
if adoptedForReview(obs) {
store.MarkAdoptedForReview(key, obs.HeadSHA)
}
c.recordContributorAbandon(ctx, obs, reason, 0, now)
body := AdoptionInPlaceComment(obs, policy.HiveID, reason, grace, rec.NudgeOnline) + adoptionFenceNote(fence)
if _, _, err := c.gh.Issues.CreateComment(ctx, obs.Owner, obs.Repo, obs.Number, &gh.IssueComment{Body: gh.Ptr(body)}); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/github/automerge/automerge_stage_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,9 @@ func (c *Engine) ApplyStageLabels(ctx context.Context) (StageLabelResult, error)
firstErr = err
}
prevRec, _ = store.Get(key)
if c.releaseApprovedFixerRevert(store, key, obs, prevRec) {
prevRec, _ = store.Get(key)
}
}
if hadPrev && prevRec.AdoptionLive(obs.HeadSHA) && verdict.Stage.YieldsToAdoptionFor(pass.Route) {
// The hive owns this PR: whether the lane sees it red,
Expand Down
Loading
Loading