diff --git a/changelog.d/fixed-adopted-fixer-pushability.md b/changelog.d/fixed-adopted-fixer-pushability.md new file mode 100644 index 0000000000..ca8e12323b --- /dev/null +++ b/changelog.d/fixed-adopted-fixer-pushability.md @@ -0,0 +1 @@ +- "Let hive decide" no longer hands an adopted PR to the hive's fixer when the hive cannot push its branch. projectbluefin/utah#919 (a fork the hive had recorded fork-rehome-refused on) and projectbluefin/testsuite#1037 (a fork changing `.github/workflows/e2e.yml`, whose fixer pushes GitHub refused three times) were decided "hive's fixer: … then it merges" and read "the hive is fixing it" for days. The delegate now checks push-ability first (same-repo, or a fork with maintainer edits and no workflow-file diff, with no fork-rehome-refused, workflow-path escalation or capability blocker recorded): a connected author gets the fix list back, otherwise the park stays with the person who asked (`adopted-push-refused`). An answer already recorded on such a PR's head shows as your turn (`adopted_push_refused`) instead of "the hive is fixing it". diff --git a/src/docs/dashboard.md b/src/docs/dashboard.md index 072293686a..f3886cff78 100644 --- a/src/docs/dashboard.md +++ b/src/docs/dashboard.md @@ -773,7 +773,7 @@ means the situation cannot occur at that level. | Same, but the PR touches files the merged PR did not | Yours — `REVIEW` (`superseded_extra_files_review`: names the extra files; keep open recommended until the extra change is reviewed) | same | same | same | | Hive PR with `needs-human` the adjudicator handed to a maintainer (`reviewer-handoff`) | — | — | Yours — `REVIEW` (`adjudicator_handed_off`) | same | | Person's PR with `needs-human` | Yours — `REVIEW` | same | same | same | -| PR of any author that `/api/review/pipeline` holds in `human_hold` for a review-swarm reason: a `requires_human` verdict (`review_requires_human`; one on an earlier head counts until a merge-eligible `approve` is recorded after it), a `reject` verdict (`review_rejected`) — either one released once a person's `APPROVED` review or `/hive approve` reply after the verdict has been recorded by the self-merge sweep, the release the sweep itself honours ([review-swarm.md](review-swarm.md)), a dispatch hold on the current head — reviews exhausted their retries, fix cap reached, no fixer agent (`review_dispatch_hold`; a hold on an older head does not count) — or the fix-cycle cap (`review_loop_cap`). `review.human_decision_label` does not change the decision. Once a person has answered the `requires_human` / `reject` verdict on the current head with an instruction (`/hive decision ` or a `CHANGES_REQUESTED` review, recorded after the verdict) the row is Not yours — "@who answered Hive's review on this head …; the hive is fixing it" — until a new head or a newer verdict; a dispatch hold or the loop cap stays `REVIEW`, and a bare approval is left to the release rules above | Yours — `REVIEW` | same | Yours — `REVIEW`; a Hive PR that also carries `needs-human` waits for the adjudicator first, as in the row above | same | +| PR of any author that `/api/review/pipeline` holds in `human_hold` for a review-swarm reason: a `requires_human` verdict (`review_requires_human`; one on an earlier head counts until a merge-eligible `approve` is recorded after it), a `reject` verdict (`review_rejected`) — either one released once a person's `APPROVED` review or `/hive approve` reply after the verdict has been recorded by the self-merge sweep, the release the sweep itself honours ([review-swarm.md](review-swarm.md)), a dispatch hold on the current head — reviews exhausted their retries, fix cap reached, no fixer agent (`review_dispatch_hold`; a hold on an older head does not count) — or the fix-cycle cap (`review_loop_cap`). `review.human_decision_label` does not change the decision. Once a person has answered the `requires_human` / `reject` verdict on the current head with an instruction (`/hive decision ` or a `CHANGES_REQUESTED` review, recorded after the verdict) the row is Not yours — "@who answered Hive's review on this head …; the hive is fixing it" — until a new head or a newer verdict, except on a PR the hive adopted whose branch it cannot push (fork-rehome-refused on the head, a fork without maintainer edits, an adoption escalated for a workflow-file diff, or a recorded capability blocker), which stays Yours — `DECIDE` (`adopted_push_refused`, naming why); a dispatch hold or the loop cap stays `REVIEW`, and a bare approval is left to the release rules above | Yours — `REVIEW` | same | Yours — `REVIEW`; a Hive PR that also carries `needs-human` waits for the adjudicator first, as in the row above | same | | Sentinel-flagged PR | Yours — `INSPECT` | same | same | same | | Issue Hive verified as done but could not close | Yours — `CLOSE` | same | same | same | | Issue covered by an open PR | Not yours — the PR closes it on merge | same | same | same | diff --git a/src/docs/labels-and-control-signals/glossary-and-operations.md b/src/docs/labels-and-control-signals/glossary-and-operations.md index 89aa20b1b1..f3dbd4f149 100644 --- a/src/docs/labels-and-control-signals/glossary-and-operations.md +++ b/src/docs/labels-and-control-signals/glossary-and-operations.md @@ -12,6 +12,7 @@ The plain-words comment the delegate posts has four lines — **Hive decided** ( | Token | Plain words | Detail | |---|---|---| +| `adopted-push-refused` | the hive adopted this PR but cannot push its branch | The hive adopted the PR, but it cannot push the branch: it recorded fork-rehome-refused on the head, the fork allows no maintainer edits or changes `.github/workflows/`, the adoption escalated for a workflow-file diff, or its fixer reported the push refused. A connected author gets the fix list back (`return-to-contributor`); otherwise the park stays with the person who asked, and no `/hive decision` is posted for the fixer. | | `already-fixed` | the issue was already fixed by a merged PR; closed as superseded | The issue this PR fixes is already closed and a merged PR closed it (or a merged PR declares it supersedes this one), so nothing is left to deliver. The hive closes the PR as superseded with a note naming the merging PR; it never adopts it. | | `capability-gap` | the GitHub App lacks a permission; deciding cannot clear it | The blocker is a missing GitHub App permission (for example `workflows`). Approving a direction would only re-apply needs-human, so the park stays until the owner grants the permission or a person applies the change. A claim that workflow files cannot be pushed is not a gap when the hive checked that it can push them in that repository: the App installation grants `workflows: write` and an enabled lane whose token carries it serves the repository. | | `ci-ratchet` | a CI hygiene gate, landed as a ratchet | A new CI hygiene gate lands as a ratchet: it records today's baseline and fails only on increases, so existing work is never blocked. | diff --git a/src/pkg/dashboard/adopted_push.go b/src/pkg/dashboard/adopted_push.go new file mode 100644 index 0000000000..f10609621f --- /dev/null +++ b/src/pkg/dashboard/adopted_push.go @@ -0,0 +1,105 @@ +package dashboard + +import ( + "strings" + + "github.com/hivecommons/hive/pkg/github" + stageengineprstage "github.com/hivecommons/hive/pkg/stageengine/prstage" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// An adopted-in-place PR is the hive's own fixer's to repair only while the +// hive can push its branch. projectbluefin/utah#919 (a fork the hive recorded +// fork-rehome-refused on) and projectbluefin/testsuite#1037 (a fork whose +// diff changes .github/workflows/e2e.yml; the fixer reported three times that +// GitHub refused its push) were both decided "hive's fixer: … then it merges" +// and read "the hive is fixing it" for days while nothing could be pushed. + +// OwnershipReasonAdoptedPushRefused: a person answered the review on an +// adopted PR's head, but the hive cannot push that branch, so the answer +// cannot be carried out by its fixer. +const OwnershipReasonAdoptedPushRefused = "adopted_push_refused" + +func init() { + ownershipReasonVerbs[OwnershipReasonAdoptedPushRefused] = OwnershipVerbDecide +} + +// adoptedPushFacts is what says whether the hive can push an adopted PR's +// branch: the PR's shape and what the hive recorded trying. +type adoptedPushFacts struct { + Fork bool + MaintainerCanModify bool + // WorkflowPath: the PR's diff against the base changes + // .github/workflows/ (known only where the files were listed). + WorkflowPath bool + // RehomeRefused: the adoption engine recorded fork-rehome-refused on + // this head (it can neither push the fork in place nor supersede it). + RehomeRefused bool + // Escalation is the adoption-stalled reason recorded on this head, if + // any; Capability is the short text of a capability blocker the ledger + // holds for the item ("App lacks workflows permission"). + Escalation string + Capability string + // Adopted: the stage store says the hive took this PR on (a live + // adoption, an escalated one at this head, or a refused re-home). + Adopted bool +} + +// refusal names why the hive cannot push the branch; "" when it can. +func (f adoptedPushFacts) refusal() string { + esc := strings.ToLower(f.Escalation) + switch { + case f.RehomeRefused || strings.HasSuffix(esc, "fork-rehome-refused"): + return "the hive recorded that it cannot finish this fork PR on the fork's own branch (fork-rehome-refused)" + case f.Fork && !f.MaintainerCanModify: + return "the fork does not allow edits by maintainers" + case f.Fork && f.WorkflowPath: + return "the PR changes .github/workflows/, which the hive cannot push to a fork" + case strings.Contains(esc, stageengineprstage.ContributorLaneReasonWorkflowPath): + return "the adoption stalled because the PR changes .github/workflows/ (" + f.Escalation + ")" + case f.Capability != "": + return "the hive's fixer reported it cannot push: " + f.Capability + } + return "" +} + +// recordedAdoptedPush fills what the stage store and the blocker ledger hold +// about pushing repo#number at head. +func recordedAdoptedPush(store *stagelabels.Store, repo string, number int, head string, f *adoptedPushFacts) { + if store != nil { + if rec, ok := store.Get(stagelabels.Key(repo, number)); ok { + f.RehomeRefused = rec.ForkRehomeRefused(head) + if rec.AdoptionEscalated(head) { + f.Escalation = strings.TrimSpace(rec.AdoptEscalatedReason) + } + f.Adopted = rec.AdoptionLive(head) || rec.AdoptionEscalated(head) || f.RehomeRefused + } + } + if e, ok := blockerLedger().Get(repo, number); ok && e.Blocks() && e.Blocker.Kind.IsCapability() { + f.Capability = e.Blocker.Kind.Short() + } +} + +// adoptedPushStore is the stage store the ownership pass reads; tests swap it. +var adoptedPushStore = stagelabels.Shared + +// adoptedPushRefusalFor is the ownership pass's check on a listed PR. It +// applies only to a PR the hive took on at its head: on any other PR the +// author's own agent is the one fixing. The listing carries no file names, +// so a fork's workflow-file diff counts only once the adoption or the fixer +// recorded it. +// A short repo name is qualified with org, as the decision-answer lookup does. +func adoptedPushRefusalFor(org string) func(pr github.PullRequest) string { + return func(pr github.PullRequest) string { + repo := strings.TrimSpace(pr.Repo) + if !strings.Contains(repo, "/") && strings.TrimSpace(org) != "" { + repo = strings.TrimSpace(org) + "/" + repo + } + f := adoptedPushFacts{Fork: pr.FromFork, MaintainerCanModify: pr.MaintainerCanModify} + recordedAdoptedPush(adoptedPushStore(), repo, pr.Number, strings.TrimSpace(pr.HeadSHA), &f) + if !f.Adopted { + return "" + } + return f.refusal() + } +} diff --git a/src/pkg/dashboard/adopted_push_test.go b/src/pkg/dashboard/adopted_push_test.go new file mode 100644 index 0000000000..981d002521 --- /dev/null +++ b/src/pkg/dashboard/adopted_push_test.go @@ -0,0 +1,86 @@ +package dashboard + +import ( + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/blocker" + "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +func TestAdoptedPushRefusal(t *testing.T) { + for _, tc := range []struct { + name string + f adoptedPushFacts + want string // substring; "" = pushable + }{ + {name: "same-repo branch", f: adoptedPushFacts{}}, + {name: "fork with maintainer edits, no workflow diff", f: adoptedPushFacts{Fork: true, MaintainerCanModify: true}}, + {name: "fork without maintainer edits", f: adoptedPushFacts{Fork: true}, want: "does not allow edits by maintainers"}, + {name: "fork changing workflows (testsuite#1037)", f: adoptedPushFacts{Fork: true, MaintainerCanModify: true, WorkflowPath: true}, want: ".github/workflows/"}, + {name: "same-repo PR changing workflows is pushable", f: adoptedPushFacts{WorkflowPath: true}}, + {name: "fork-rehome-refused recorded (utah#919)", f: adoptedPushFacts{Fork: true, MaintainerCanModify: true, RehomeRefused: true}, want: "fork-rehome-refused"}, + {name: "escalated on fork-rehome-refused", f: adoptedPushFacts{Escalation: "adoption-stalled:fork-rehome-refused"}, want: "fork-rehome-refused"}, + {name: "escalated on workflow path", f: adoptedPushFacts{Escalation: "adoption-stalled:contributor-lane:workflow-path"}, want: "workflow"}, + {name: "escalated on a check failure is still pushable", f: adoptedPushFacts{Escalation: "adoption-stalled:check-failure"}}, + {name: "capability blocker recorded", f: adoptedPushFacts{Capability: "App lacks workflows permission"}, want: "fixer reported it cannot push: App lacks workflows permission"}, + } { + t.Run(tc.name, func(t *testing.T) { + got := tc.f.refusal() + if (tc.want == "") != (got == "") || !strings.Contains(got, tc.want) { + t.Fatalf("refusal = %q, want %q", got, tc.want) + } + }) + } +} + +func TestRecordedAdoptedPush(t *testing.T) { + store := stagelabels.NewStore("", time.Now) + key := stagelabels.Key("o/r", 919) + store.Observe(key, stagelabels.AdoptedByHive, "contributor-lane:adopted-by-hive") + store.MarkForkRehomeRefused(key, "f0b5e2f") + var f adoptedPushFacts + recordedAdoptedPush(store, "o/r", 919, "f0b5e2f", &f) + if !f.RehomeRefused || !f.Adopted { + t.Fatalf("facts %+v, want rehome refused and adopted", f) + } + f = adoptedPushFacts{} + recordedAdoptedPush(store, "o/r", 919, "newhead", &f) + if f.RehomeRefused || f.Adopted { + t.Fatalf("a new head re-arms: %+v", f) + } + + l := blocker.NewLedger("") + prev := blockerLedger + blockerLedger = func() *blocker.Ledger { return l } + t.Cleanup(func() { blockerLedger = prev }) + l.Record("o/r", 1037, blocker.Blocker{Kind: blocker.CapabilityWorkflowsPermission}, "push of e2e.yml rejected") + f = adoptedPushFacts{} + recordedAdoptedPush(nil, "o/r", 1037, "9c0ec3d", &f) + if f.Capability == "" { + t.Fatalf("capability blocker not read: %+v", f) + } +} + +// The ownership check reads a short repo name under the org, and applies +// only to a PR the hive took on at this head: on any other PR the author's +// own agent is the one fixing. +func TestAdoptedPushRefusalForOwnership(t *testing.T) { + store := stagelabels.NewStore("", time.Now) + prev := adoptedPushStore + adoptedPushStore = func() *stagelabels.Store { return store } + t.Cleanup(func() { adoptedPushStore = prev }) + adopted := stagelabels.Key("o/adopted", 1037) + store.Observe(adopted, stagelabels.AdoptedByHive, "contributor-lane:adopted-by-hive") + store.MarkAdoptionEscalated(adopted, "9c0ec3d", "adoption-stalled:contributor-lane:workflow-path") + check := adoptedPushRefusalFor("o") + + if got := check(github.PullRequest{Repo: "adopted", Number: 1037, HeadSHA: "9c0ec3d", FromFork: true, MaintainerCanModify: true}); !strings.Contains(got, "workflows") { + t.Fatalf("escalated adopted fork: %q, want the workflow-path reason", got) + } + if got := check(github.PullRequest{Repo: "o/other", Number: 5, HeadSHA: "abc", FromFork: true}); got != "" { + t.Fatalf("a fork PR the hive never took on: %q, want no refusal (its author fixes it)", got) + } +} diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated.go b/src/pkg/dashboard/api_repo_item_decide_delegated.go index 34e6125b84..ad86ee989b 100644 --- a/src/pkg/dashboard/api_repo_item_decide_delegated.go +++ b/src/pkg/dashboard/api_repo_item_decide_delegated.go @@ -623,6 +623,7 @@ func (s *Server) gatherDelegatedInput(ctx context.Context, repoFull string, numb api := client.GoGitHub() owner, repoName, _ := strings.Cut(repoFull, "/") in := delegatedecision.Input{Repo: repoFull, Number: number, Kind: delegatedecision.KindIssue, ContributorOnline: true} + var push adoptedPushFacts reason := strings.TrimSpace(req.Reason) if reason != "" { in.Reasons = append(in.Reasons, reason) @@ -654,6 +655,9 @@ func (s *Server) gatherDelegatedInput(ctx context.Context, repoFull string, numb } in.HeadSHA = strings.TrimSpace(pr.GetHead().GetSHA()) in.Title, in.Body = pr.GetTitle(), pr.GetBody() + headRepo := pr.GetHead().GetRepo().GetFullName() + push.Fork = headRepo == "" || !strings.EqualFold(headRepo, repoFull) + push.MaintainerCanModify = pr.GetMaintainerCanModify() for _, l := range pr.Labels { if name := l.GetName(); name != "" && !slices.Contains(in.Labels, name) { in.Labels = append(in.Labels, name) @@ -732,6 +736,11 @@ func (s *Server) gatherDelegatedInput(ctx context.Context, repoFull string, numb if delegatedecision.CapabilityGap(in) { in.WorkflowsPushable = s.delegatedWorkflowsPushable(ctx, repoFull) } + if in.Kind == delegatedecision.KindPR && in.AdoptedByHive { + push.WorkflowPath = in.WorkflowPath + recordedAdoptedPush(s.stageStoreOrShared(), repoFull, number, in.HeadSHA, &push) + in.AdoptedPushRefused = push.refusal() + } return in, nil } diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go b/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go index 76c32c7319..22a30a2df7 100644 --- a/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go +++ b/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go @@ -332,7 +332,7 @@ func delegatedPlanWording(in delegatedecision.Input, d delegatedecision.Decision return "Close " + ref + " as superseded by #" + strconv.Itoa(target) + ".", []string{ref + " is closed with a comment pointing at #" + strconv.Itoa(target) + "."} case d.Verdict == delegatedecision.VerdictCloseDuplicate, d.Verdict == delegatedecision.VerdictCloseSuperseded: return "Close " + ref + ".", []string{ref + " is closed with a comment saying why."} - case d.Verdict == delegatedecision.VerdictDirection && in.AdoptedByHive: + case d.Verdict == delegatedecision.VerdictDirection && in.AdoptedByHive && d.Rule == delegatedecision.RuleAdoptedFixer: // The hive adopted the PR in place: it is the author now, so the // instruction is its own fixer's, not the contributor's // (hivecommons/hive#15722). diff --git a/src/pkg/dashboard/delegated_adopted_push_test.go b/src/pkg/dashboard/delegated_adopted_push_test.go new file mode 100644 index 0000000000..0d51b06f79 --- /dev/null +++ b/src/pkg/dashboard/delegated_adopted_push_test.go @@ -0,0 +1,59 @@ +package dashboard + +import ( + "net/http" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/delegatedecision" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// projectbluefin/utah#919: a fork PR the hive adopted and then recorded +// fork-rehome-refused on was decided "hive's fixer: … then it merges" at +// 19:52:57Z, and four seconds later the hive said the opposite. With the +// refusal recorded on the head, the delegate keeps the park for the person +// who asked, posts no `/hive decision`, and names why. +func TestDelegatedAdoptedForkRehomeRefusedStaysWithPerson(t *testing.T) { + for _, tc := range []struct { + name string + fork bool + refused bool + noEdits bool + rule string + }{ + {name: "same-repo adopted branch: the hive's fixer", rule: delegatedecision.RuleAdoptedFixer}, + {name: "fork with maintainer edits: the hive's fixer", fork: true, rule: delegatedecision.RuleAdoptedFixer}, + {name: "fork-rehome-refused on the head: the person", fork: true, refused: true, rule: delegatedecision.RuleAdoptedPushRefused}, + {name: "fork without maintainer edits: the person", fork: true, noEdits: true, rule: delegatedecision.RuleAdoptedPushRefused}, + } { + t.Run(tc.name, func(t *testing.T) { + mock := &repoItemDecisionMock{prForeign: true, prFork: tc.fork, prNoMaintainerEdits: tc.noEdits, prHeadSHA: "f0b5e2f", prLabels: []string{"stage/085-needs-decision"}} + srv := newDelegatedServer(t, mock) + srv.stageStore = stagelabels.NewStore("", time.Now) + key := stagelabels.Key("testorg/testrepo", 8) + srv.stageStore.Observe(key, stagelabels.AdoptedByHive, "contributor-lane:adopted-by-hive") + if tc.refused { + srv.stageStore.MarkForkRehomeRefused(key, "f0b5e2f") + } + w := postDelegated(t, srv, 8, "writer", `{"type":"pr","reason":"contributor-lane:adopted-by-hive reviewer-verdict:requires_human"}`, nil) + if w.Code != http.StatusOK { + t.Fatalf("code=%d body=%s", w.Code, w.Body.String()) + } + job := decodeDelegatedJob(t, w) + if job.Decision == nil || job.Decision.Rule != tc.rule { + t.Fatalf("decision = %+v err=%s", job.Decision, job.Error) + } + posted := strings.Join(mock.comments, "\n") + if tc.rule == delegatedecision.RuleAdoptedPushRefused { + if strings.Contains(posted, "/hive decision") || strings.Contains(posted, "hive's fixer") || !job.Decision.KeepsPark { + t.Fatalf("a refused push must post no direction for the fixer: keepsPark=%v comments=%v", job.Decision.KeepsPark, mock.comments) + } + if why := map[bool]string{true: "fork-rehome-refused", false: "maintainers"}[tc.refused]; !strings.Contains(job.Decision.Rationale, why) { + t.Fatalf("rationale %q does not say why", job.Decision.Rationale) + } + } + }) + } +} diff --git a/src/pkg/dashboard/ownership.go b/src/pkg/dashboard/ownership.go index bde6f7fcc8..703c2e4eff 100644 --- a/src/pkg/dashboard/ownership.go +++ b/src/pkg/dashboard/ownership.go @@ -248,6 +248,10 @@ type ownershipEnv struct { supersededPR func(repo string, number int) (github.ReviewQueueSuperseded, bool) repoLevel func(repo string) int selfAuthorizationHold func(repo string) bool + // adoptedPushRefused names why the hive cannot push a PR's branch + // (adopted_push.go); nil or "" lets a recorded answer read as the + // hive fixing it. + adoptedPushRefused func(pr github.PullRequest) string reviewerLaneAvailable func(repo string) bool escalatedAt func(repo string, number int) time.Time // laneCanOpenPR reports whether the running agent serving a routed lane @@ -989,6 +993,7 @@ func newOwnershipEnv(cfg *config.Config, agentStatuses map[string]*crux.Process, org = cfg.Project.Org } env.reviewSwarm.answer = decisionAnswerLookup(org) + env.adoptedPushRefused = adoptedPushRefusalFor(org) if leased := hub.leasedWorkItems(now, org); len(leased) > 0 { env.leased = func(repo string, number int) bool { return leased[leaseItemKey(org, repo, number)] } } diff --git a/src/pkg/dashboard/ownership_11565_test.go b/src/pkg/dashboard/ownership_11565_test.go index e87a37dc5f..898267c877 100644 --- a/src/pkg/dashboard/ownership_11565_test.go +++ b/src/pkg/dashboard/ownership_11565_test.go @@ -502,8 +502,8 @@ func TestOwnershipSafetyNet11565(t *testing.T) { } func TestOwnershipFixedSets11565(t *testing.T) { - if len(ownershipReasonVerbs) != 31+len(operatorWaitReasonVerbs) { - t.Fatalf("reason codes = %d, want the 20 of #11507, review_requires_human (#12329), blocked_unexplained (#12376), the three review-hold codes of #12377, the three PR gates of #12378, superseded_recommended_close (#13114), superseded_extra_files_review (#14176), adjudicator_handed_off (#13183) and the run and approval waits (#12380)", len(ownershipReasonVerbs)) + if len(ownershipReasonVerbs) != 32+len(operatorWaitReasonVerbs) { + t.Fatalf("reason codes = %d, want the 20 of #11507, review_requires_human (#12329), blocked_unexplained (#12376), the three review-hold codes of #12377, the three PR gates of #12378, superseded_recommended_close (#13114), superseded_extra_files_review (#14176), adjudicator_handed_off (#13183), adopted_push_refused and the run and approval waits (#12380)", len(ownershipReasonVerbs)) } verbs := map[string]bool{} for _, verb := range ownershipVerbOrder { diff --git a/src/pkg/dashboard/ownership_answered_review_hold_test.go b/src/pkg/dashboard/ownership_answered_review_hold_test.go index 4d51d1bf4c..70eb3b4e6f 100644 --- a/src/pkg/dashboard/ownership_answered_review_hold_test.go +++ b/src/pkg/dashboard/ownership_answered_review_hold_test.go @@ -115,3 +115,36 @@ func TestAnsweredReviewHoldLookupUsesProjectOrg(t *testing.T) { t.Fatal("an answer on another head must not count") } } + +// projectbluefin/testsuite#1037: the decision answered the review on +// 9c0ec3d for the hive's fixer, and the row read "the hive is fixing it" for +// days while every push was refused. An answer the hive cannot carry out on +// its branch stays with the person who gave it, with the reason. +func TestAnsweredReviewOnUnpushableAdoptedBranchStaysYourTurn(t *testing.T) { + pr := withHead12329(hivePR11565("stage/074-adopted-by-hive"), "head-2") + asked := verdict12377(pr, "head-2", review.VerdictRequiresHuman) + answer := decisionAnswer(pr, "head-2", review.HumanChangeRequestKindChanges, ownershipNow11565.Add(-time.Hour)) + for _, tc := range []struct { + name string + refusal string + }{ + {name: "pushable: waits on the hive"}, + {name: "fork-rehome-refused: your turn", refusal: "the hive recorded that it cannot finish this fork PR on the fork's own branch (fork-rehome-refused)"}, + } { + t.Run(tc.name, func(t *testing.T) { + env := answeredEnv(t, []review.Aggregate{asked}, review.DispatchState{}, answer) + env.adoptedPushRefused = func(github.PullRequest) string { return tc.refusal } + got := decidePROwnership(pr, false, env) + if tc.refusal == "" { + if got.YourTurn || !strings.Contains(got.Reason, "the hive is fixing it") { + t.Fatalf("got %+v, want waiting on the hive", got) + } + return + } + checkOwnership11565(t, got, want11565{OwnershipVerbDecide, OwnershipReasonAdoptedPushRefused}) + if strings.Contains(got.Reason, "the hive is fixing it") || !strings.Contains(got.Reason, "fork-rehome-refused") || !strings.Contains(got.Reason, "@Danathar answered") { + t.Fatalf("reason %q", got.Reason) + } + }) + } +} diff --git a/src/pkg/dashboard/ownership_review_holds.go b/src/pkg/dashboard/ownership_review_holds.go index 384768c729..36a29187b9 100644 --- a/src/pkg/dashboard/ownership_review_holds.go +++ b/src/pkg/dashboard/ownership_review_holds.go @@ -111,6 +111,16 @@ func answeredWaitReason(req review.HumanChangeRequest) string { return fmt.Sprintf("%s answered Hive's review on this head%s; the hive is fixing it, and the review comes back to you if the new head needs you", who, when) } +// answeredPushRefusedReason says the answer is recorded but cannot be +// carried out: the hive cannot push the branch. +func answeredPushRefusedReason(req review.HumanChangeRequest, why string) string { + who := "You" + if a := strings.TrimSpace(req.Actor); a != "" { + who = "@" + a + } + return fmt.Sprintf("%s answered Hive's review on this head, but the hive cannot push this branch: %s. Push the fix yourself, ask the author, or close it", who, why) +} + // loadReviewSwarm loads the verdict artifact, the dispatch state, the // review-links ledger and the review hold releases /api/review/pipeline // reads. A missing file reads as @@ -179,6 +189,14 @@ func (e ownershipEnv) reviewHoldOwnership(pr github.PullRequest, withinAdjudicat // 070-fixing on the owner's answer. A dispatcher hold (fix cap, no // fixer) or the loop cap is still the owner's. if req, ok := e.answeredChangeRequest(pr, holds); ok { + // An answer only the hive's fixer could carry out, on a branch the + // hive cannot push, leaves the PR with the person who answered + // (projectbluefin/utah#919, projectbluefin/testsuite#1037). + if e.adoptedPushRefused != nil { + if why := e.adoptedPushRefused(pr); why != "" { + return yourTurn(OwnershipReasonAdoptedPushRefused, answeredPushRefusedReason(req, why)), true + } + } var rest []pipeline.ReviewHold for _, h := range holds { if !answerableReviewHold(h) { diff --git a/src/pkg/dashboard/static-src/js/tracker-filter-fetch.js b/src/pkg/dashboard/static-src/js/tracker-filter-fetch.js index c438b8bc0c..29b46102e4 100644 --- a/src/pkg/dashboard/static-src/js/tracker-filter-fetch.js +++ b/src/pkg/dashboard/static-src/js/tracker-filter-fetch.js @@ -58,6 +58,7 @@ "adopted": {"kind": "action", "plain": "close this PR and open a fresh hive-authored PR with the same commits", "detail": "Supersede means the hive closes this PR and opens a fresh hive-authored PR carrying the same commits and sign-off, then finishes it itself."}, "adopted-fixer": {"kind": "rule", "plain": "the hive adopted this PR; its own fixer addresses the finding", "detail": "The hive adopted this PR in place and owns its branch, so the reviewer's finding and any blocker go to the hive's own fixer — not back to the contributor and not to a person. No action is needed."}, "adopted-security-finding": {"kind": "rule", "plain": "the hive adopted this PR, but the security finding is a person's call", "detail": "The hive adopted this PR in place, but the reviewer's finding is the security review's. That policy call is a person's: read the finding and reply /hive decision with the instruction for the hive's fixer, or close the PR."}, + "adopted-push-refused": {"kind": "rule", "plain": "the hive adopted this PR but cannot push its branch", "detail": "The hive adopted this PR, but it cannot push the branch: it recorded fork-rehome-refused, the fork allows no maintainer edits or the PR changes workflow files, or its fixer reported the push was refused. The author is offline, so a person pushes the fix or closes the PR."}, "adoption-disabled": {"kind": "reason", "plain": "adoption is switched off on this hive", "detail": "Stage adoption is disabled on this hive (governor.labels.stage.adoption), so a request to take a PR over is never carried out."}, "adoption-executing": {"kind": "reason", "plain": "the adoption engine is carrying it out", "detail": "The decision is recorded and the adoption engine picks it up on its next stage pass (a few minutes): it pushes the commits to a hive branch and opens the hive's copy. Nothing to do yet."}, "adoption-stalled:contributor-lane:workflow-path": {"kind": "reason", "plain": "the PR edits .github/workflows; the hive's App lacks the `workflows` permission, so it cannot adopt it", "detail": "The PR changes files under .github/workflows. The hive's GitHub App has no `workflows` permission, so the adoption fence refuses to publish those edits from the hive. Grant the App the `workflows` permission and re-run the decision, or have a person rebase and merge it on GitHub, or close it as superseded."}, diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index f6e2eb9b2c..3e982c5739 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -22710,6 +22710,7 @@

All labels

"adopted": {"kind": "action", "plain": "close this PR and open a fresh hive-authored PR with the same commits", "detail": "Supersede means the hive closes this PR and opens a fresh hive-authored PR carrying the same commits and sign-off, then finishes it itself."}, "adopted-fixer": {"kind": "rule", "plain": "the hive adopted this PR; its own fixer addresses the finding", "detail": "The hive adopted this PR in place and owns its branch, so the reviewer's finding and any blocker go to the hive's own fixer — not back to the contributor and not to a person. No action is needed."}, "adopted-security-finding": {"kind": "rule", "plain": "the hive adopted this PR, but the security finding is a person's call", "detail": "The hive adopted this PR in place, but the reviewer's finding is the security review's. That policy call is a person's: read the finding and reply /hive decision with the instruction for the hive's fixer, or close the PR."}, + "adopted-push-refused": {"kind": "rule", "plain": "the hive adopted this PR but cannot push its branch", "detail": "The hive adopted this PR, but it cannot push the branch: it recorded fork-rehome-refused, the fork allows no maintainer edits or the PR changes workflow files, or its fixer reported the push was refused. The author is offline, so a person pushes the fix or closes the PR."}, "adoption-disabled": {"kind": "reason", "plain": "adoption is switched off on this hive", "detail": "Stage adoption is disabled on this hive (governor.labels.stage.adoption), so a request to take a PR over is never carried out."}, "adoption-executing": {"kind": "reason", "plain": "the adoption engine is carrying it out", "detail": "The decision is recorded and the adoption engine picks it up on its next stage pass (a few minutes): it pushes the commits to a hive branch and opens the hive's copy. Nothing to do yet."}, "adoption-stalled:contributor-lane:workflow-path": {"kind": "reason", "plain": "the PR edits .github/workflows; the hive's App lacks the `workflows` permission, so it cannot adopt it", "detail": "The PR changes files under .github/workflows. The hive's GitHub App has no `workflows` permission, so the adoption fence refuses to publish those edits from the hive. Grant the App the `workflows` permission and re-run the decision, or have a person rebase and merge it on GitHub, or close it as superseded."}, diff --git a/src/pkg/delegatedecision/adopted_push_refused_test.go b/src/pkg/delegatedecision/adopted_push_refused_test.go new file mode 100644 index 0000000000..b4e6002d97 --- /dev/null +++ b/src/pkg/delegatedecision/adopted_push_refused_test.go @@ -0,0 +1,52 @@ +package delegatedecision + +import ( + "strings" + "testing" +) + +// projectbluefin/utah#919 (fork-rehome-refused on its head, author relay +// offline since 10-26) and projectbluefin/testsuite#1037 (a fork changing +// .github/workflows/e2e.yml; the fixer's pushes were refused) were decided +// "hive's fixer: … then it merges" on branches the hive cannot push. The +// fixer gets the direction only when it can push; otherwise a connected +// author does, else the person who asked. +func TestDecideAdoptedPushability(t *testing.T) { + base := Input{Kind: KindPR, Number: 919, Author: "arteeh", AdoptedByHive: true, + Reasons: []string{"reviewer-verdict:requires_human"}, ReviewerRequiresHuman: true, + ReviewerFinding: "address the changes @hanthor requested", CIGreen: true} + const refused = "the hive recorded that it cannot finish this fork PR on the fork's own branch (fork-rehome-refused)" + for _, tc := range []struct { + name string + refused string + online bool + rule string + keepsPark bool + comment bool + }{ + {name: "pushable, author offline: the hive's fixer", rule: RuleAdoptedFixer, comment: true}, + {name: "pushable, author online: still the hive's fixer", online: true, rule: RuleAdoptedFixer, comment: true}, + {name: "not pushable, author online: back to the author", refused: refused, online: true, rule: RuleReturnToContributor, comment: true}, + {name: "not pushable, author offline: the person who asked", refused: refused, rule: RuleAdoptedPushRefused, keepsPark: true}, + } { + t.Run(tc.name, func(t *testing.T) { + in := with(base, func(i *Input) { i.AdoptedPushRefused = tc.refused; i.ContributorOnline = tc.online }) + d := Run(in) + if d.Rule != tc.rule || d.KeepsPark != tc.keepsPark { + t.Fatalf("rule %s keepsPark %v, want %s %v: %q", d.Rule, d.KeepsPark, tc.rule, tc.keepsPark, d.Text) + } + hasComment := false + for _, a := range d.Actions { + if a.Kind == ActionCommentDecision { + hasComment = true + } + } + if hasComment != tc.comment { + t.Fatalf("decision comment = %v, want %v (actions %+v)", hasComment, tc.comment, d.Actions) + } + if tc.refused != "" && (!strings.Contains(d.Text+d.Rationale, "fork-rehome-refused") || strings.Contains(d.Text, "hive's fixer")) { + t.Fatalf("a refused push must name why and never promise the fixer: text %q rationale %q", d.Text, d.Rationale) + } + }) + } +} diff --git a/src/pkg/delegatedecision/decision_glossary.go b/src/pkg/delegatedecision/decision_glossary.go index c907653c6c..f55d40acf3 100644 --- a/src/pkg/delegatedecision/decision_glossary.go +++ b/src/pkg/delegatedecision/decision_glossary.go @@ -105,6 +105,8 @@ var glossary = []GlossaryEntry{ Detail: "The hive adopted this PR in place and owns its branch, so the reviewer's finding and any blocker go to the hive's own fixer — not back to the contributor and not to a person. No action is needed."}, {Slug: RuleAdoptedSecurityFinding, Kind: GlossaryRule, Plain: "the hive adopted this PR, but the security finding is a person's call", Detail: "The hive adopted this PR in place, but the reviewer's finding is the security review's. That policy call is a person's: read the finding and reply /hive decision with the instruction for the hive's fixer, or close the PR."}, + {Slug: RuleAdoptedPushRefused, Kind: GlossaryRule, Plain: "the hive adopted this PR but cannot push its branch", + Detail: "The hive adopted this PR, but it cannot push the branch: it recorded fork-rehome-refused, the fork allows no maintainer edits or the PR changes workflow files, or its fixer reported the push was refused. The author is offline, so a person pushes the fix or closes the PR."}, {Slug: RuleReturnToAuthor, Kind: GlossaryRule, Plain: "a person pushed this PR; the hive asked them, not adopted it", Detail: "The PR was pushed by a person (author/human or one of this hive's owners), so the hive never adopts it. It told the author by name what to fix (rebase, sign-off, CI) and relayed the reviewer's question."}, {Slug: "owner-only", Kind: GlossaryRule, Plain: "only the hive owner can do this", diff --git a/src/pkg/delegatedecision/policy.go b/src/pkg/delegatedecision/policy.go index 5674f60783..0e64370f8d 100644 --- a/src/pkg/delegatedecision/policy.go +++ b/src/pkg/delegatedecision/policy.go @@ -301,6 +301,12 @@ type Input struct { // the contributor's (hivecommons/hive#15722: "send #15722 back to its // author" on a PR the hive had adopted). AdoptedByHive bool + // AdoptedPushRefused names why the hive cannot push the adopted PR's + // branch (fork-rehome-refused, a fork without maintainer edits or with + // a workflow-file diff, a recorded capability blocker); "" when it can. + // The fixer cannot carry out a direction then (projectbluefin/utah#919, + // projectbluefin/testsuite#1037). + AdoptedPushRefused string // ReviewerRequiresHuman: the recorded park reason is the reviewer // swarm's requires_human on the current head; ReviewerFinding is what // the review found ("the reviewer marked this change high-risk"), and @@ -796,6 +802,9 @@ func decidePR(in Input) Decision { const ( RuleAdoptedFixer = "adopted-fixer" RuleAdoptedSecurityFinding = "adopted-security-finding" + // RuleAdoptedPushRefused: the hive adopted the PR but cannot push its + // branch and the author is offline, so a person pushes or closes it. + RuleAdoptedPushRefused = "adopted-push-refused" ) // decideAdoptedByHive is the adopted-in-place branch of decidePR. The hive @@ -830,6 +839,9 @@ func decideAdoptedByHive(in Input, ref string) (Decision, bool) { if len(fix) == 0 { return Decision{}, false } + if why := strings.TrimSpace(in.AdoptedPushRefused); why != "" { + return decideAdoptedPushRefused(in, ref, why, fix), true + } text := "hive's fixer: " + strings.Join(fix, ", ") + " on " + ref + "; then it merges" return Decision{ Verdict: VerdictDirection, Rule: RuleAdoptedFixer, Text: text, @@ -838,6 +850,25 @@ func decideAdoptedByHive(in Input, ref string) (Decision, bool) { }, true } +// decideAdoptedPushRefused answers an adopted PR whose branch the hive +// cannot push. A connected author can push it, so it goes back to them with +// the fix list; otherwise only a person can, so the park stays with the one +// who asked, with the reason. +func decideAdoptedPushRefused(in Input, ref, why string, fix []string) Decision { + if in.ContributorOnline || in.ReworkPickedUp { + who := in.AuthorWord() + text := who + " is connected and the hive cannot push " + ref + " (" + why + "): " + strings.Join(fix, ", ") + " on " + ref + "; then it merges" + return Decision{ + Verdict: VerdictDirection, Rule: RuleReturnToContributor, Text: text, + Rationale: "the hive adopted " + ref + " but cannot push its branch — " + why + " — and " + who + " is connected, so the fix list goes back to them", + Actions: []Action{decisionComment(text)}, + } + } + return recommendOnly(RuleAdoptedPushRefused, + "the hive adopted "+ref+" but cannot push its branch — "+why+" — so its fixer cannot carry out a direction, and "+in.OfflineWording(), + "a maintainer pushes the fix to "+ref+" ("+strings.Join(fix, ", ")+") or closes it; the hive cannot") +} + // RuleHiveSuperseder is the owner's superseder rule: "if a pr is superseded // by a pr that a hive agent creates, it should auto merge" — the only // exception being the sentinel or some other emergent problem with the PR. diff --git a/src/pkg/hiveadvisor/human_gate.go b/src/pkg/hiveadvisor/human_gate.go index c08e27226c..504282d17e 100644 --- a/src/pkg/hiveadvisor/human_gate.go +++ b/src/pkg/hiveadvisor/human_gate.go @@ -56,6 +56,7 @@ var gateReasons = map[string]gateReason{ "review_rejected": {"rejected by the hive's review", "close or rework what the hive's review rejected"}, "review_dispatch_hold": {"with the hive's review parked for a person", "read the parked hive reviews in %s"}, "review_loop_cap": {"with the hive's review and fix loop stopped", "finish the PRs whose review and fix loop stopped"}, + "adopted_push_refused": {"adopted by the hive on branches it cannot push", "push the fixes or close the adopted PRs the hive cannot push in %s"}, "stale_safety_net": {"untouched long enough that the safety net handed them to a person", "look at the long-untouched items in %s"}, "blocked_unexplained": {"labelled blocked with no blocker named", "name the blocker or lift the label"}, "pr_gate_label": {"held by a gate label", "act on the gate labels or remove them"},