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-fixer-pushability.md
Original file line number Diff line number Diff line change
@@ -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".
2 changes: 1 addition & 1 deletion src/docs/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <instruction>` 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 <instruction>` 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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
105 changes: 105 additions & 0 deletions src/pkg/dashboard/adopted_push.go
Original file line number Diff line number Diff line change
@@ -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()
}
}
86 changes: 86 additions & 0 deletions src/pkg/dashboard/adopted_push_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
9 changes: 9 additions & 0 deletions src/pkg/dashboard/api_repo_item_decide_delegated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/dashboard/api_repo_item_decide_delegated_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
59 changes: 59 additions & 0 deletions src/pkg/dashboard/delegated_adopted_push_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
})
}
}
Loading
Loading