diff --git a/changelog.d/fixed-human-author-pr-never-adopted.md b/changelog.d/fixed-human-author-pr-never-adopted.md new file mode 100644 index 0000000000..78050b44c2 --- /dev/null +++ b/changelog.d/fixed-human-author-pr-never-adopted.md @@ -0,0 +1 @@ +- A PR a person pushed themselves — an owner or maintainer in `dashboard.authorized_users`, or any `author/human` PR — is never adopted by the hive ([#15202](https://github.com/hivecommons/hive/issues/15202)). The contributor-lane "contributor offline" rule now applies only to clanker and registered-contributor PRs; a `requires_human` or changes-requested verdict on a human-authored PR routes to 071 Needs author and tells the author what the reviewer asked (or that the branch conflicts and needs their rebase) instead of parking at 085; and "Let hive decide" on such a PR can only approve-admit a reviewed, green head, return it to its author with the reviewer's question or the fix, or hold. The adoption path itself — the engine's `adoption/supersede` label handler, the delegate executor and the 090 "ready for human merge" decider from #15181 — refuses a person's PR with a logged reason that the stage tracker row shows as "not adopted: the hive asks them, not adopts". Folded from #15191: a DCO-less clanker head at 090 adopts in supersede mode rather than waiting on a person. diff --git a/src/cmd/hive/merge_eligibility.go b/src/cmd/hive/merge_eligibility.go index 778b3d6078..a6c5872a48 100644 --- a/src/cmd/hive/merge_eligibility.go +++ b/src/cmd/hive/merge_eligibility.go @@ -125,6 +125,7 @@ func stageLabelPolicyFunc(cfg *config.Config) func() automerge.StageLabelPolicy HiveID: cfg.HiveID, AuthorKindLabels: cfg.Governor.Labels.Author.Names(), RelayKnown: contributorRelayKnown, + OwnerAuthor: dashboardOwnerLogin(cfg), SharedCIIncident: stageSharedCIIncident, BaseBranchRed: stageBaseBranchRed, ForkGuard: stageForkGuard, @@ -134,6 +135,24 @@ func stageLabelPolicyFunc(cfg *config.Config) func() automerge.StageLabelPolicy } } +// dashboardOwnerLogin answers StageLabelPolicy.OwnerAuthor from +// dashboard.authorized_users: an owner's PR is a person's, never adopted +// (hivecommons/hive#15202). +func dashboardOwnerLogin(cfg *config.Config) func(login string) bool { + return func(login string) bool { + login = strings.TrimSpace(strings.TrimPrefix(login, "@")) + if login == "" || cfg == nil { + return false + } + for _, entry := range cfg.Dashboard.AuthorizedUsers { + if name, _ := dashboard.AuthorizedUserEntry(entry); strings.EqualFold(name, login) { + return true + } + } + return false + } +} + // contributorRelayKnown answers authorkind's weakest author/clanker signal: // the login has a contributor profile on this hive, i.e. runs a relay that // targets it. It only decides a PR whose body carries no hive marker. diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated.go b/src/pkg/dashboard/api_repo_item_decide_delegated.go index 68f467a819..191c081a89 100644 --- a/src/pkg/dashboard/api_repo_item_decide_delegated.go +++ b/src/pkg/dashboard/api_repo_item_decide_delegated.go @@ -806,6 +806,9 @@ func (s *Server) executeDelegatedDecision(ctx context.Context, in delegatedecisi if in.Kind != delegatedecision.KindPR || in.HiveAuthored { return notes, fmt.Errorf("supersede adoption requires a contributor PR") } + if in.PersonAuthored() { + return notes, fmt.Errorf("a person pushed %s#%d themselves (@%s); the hive asks the author instead of adopting it", repoFull, number, in.Author) + } if !s.stageAdoptionEnabled() { // The engine only consumes the request label with adoption // on; queuing it would be a silent no-op with a stale label. diff --git a/src/pkg/dashboard/delegated_decision_human_merge.go b/src/pkg/dashboard/delegated_decision_human_merge.go index 3fbf335242..309c87d899 100644 --- a/src/pkg/dashboard/delegated_decision_human_merge.go +++ b/src/pkg/dashboard/delegated_decision_human_merge.go @@ -118,6 +118,7 @@ const ( delegatedHumanMergeAdoptCIRedRule = "human-merge-adopt-ci-red" delegatedHumanMergeAdoptRebaseRule = "human-merge-adopt-conflicting" delegatedHumanMergeAdoptReviewRule = "human-merge-adopt-review" + delegatedHumanMergeAdoptDCORule = "human-merge-adopt-dco" ) // delegatedHumanMergeDecidedPath is the chosen path and its reason for a @@ -133,6 +134,10 @@ func delegatedHumanMergeDecidedPath(rule string) string { return "adopt · conflicting, needs rebase" case delegatedHumanMergeAdoptReviewRule: return "adopt · review not passed" + case delegatedHumanMergeAdoptDCORule: + return "adopt · DCO sign-off missing" + case delegatedecision.RuleReturnToAuthor: + return "return to author · a person pushed this PR; the hive asked them, not adopted it" } return "" } @@ -174,6 +179,14 @@ func (s *Server) delegatedHumanMergeDecision(in delegatedecision.Input, req dele } ref := "#" + strconv.Itoa(in.Number) adopt := func(rule, why string) (delegatedecision.Decision, []string, bool) { + if in.PersonAuthored() { + // A person pushed this PR: it is theirs to fix, never the + // hive's to adopt (hivecommons/hive#15202). + if d, ok := delegatedecision.ReturnToAuthor(in); ok { + return d, []string{"hive decided: return to author · " + why}, true + } + return delegatedecision.Decision{}, nil, false + } if !s.stageAdoptionEnabled() { return delegatedecision.Decision{}, nil, false } @@ -189,6 +202,8 @@ func (s *Server) delegatedHumanMergeDecision(in delegatedecision.Input, req dele switch { case in.Conflicting: return adopt(delegatedHumanMergeAdoptRebaseRule, "the branch conflicts with the base and needs a rebase") + case in.DCOMissing: + return adopt(delegatedHumanMergeAdoptDCORule, "the DCO sign-off is missing from its commits") case !in.CIGreen: return adopt(delegatedHumanMergeAdoptCIRedRule, "CI is not green on its head") case !s.delegatedHumanMergeReviewPassed(in): diff --git a/src/pkg/dashboard/delegated_decision_human_merge_test.go b/src/pkg/dashboard/delegated_decision_human_merge_test.go index 64546865b5..7e65c373b5 100644 --- a/src/pkg/dashboard/delegated_decision_human_merge_test.go +++ b/src/pkg/dashboard/delegated_decision_human_merge_test.go @@ -114,3 +114,63 @@ func TestDelegatedDecisionUntrustedReadyForHumanMergeDecides(t *testing.T) { }) } } + +// hivecommons/hive#15202: a person's 090 PR (owner or author/human) is never +// adopted. A conflicting, red or unsigned head is returned to its author with +// the fix spelled out; a clean head is still approved; and a DCO-less clanker +// head still adopts (the one branch folded from hivecommons/hive#15191). +func TestDelegatedHumanMergeDecisionPersonAuthoredNeverAdopts(t *testing.T) { + srv := newDelegatedServer(t, &repoItemDecisionMock{}) + srv.deps.Config.Governor.Labels.Stage.Adoption.Enabled = boolPtr(true) + base := delegatedecision.Input{ + Repo: "testorg/testrepo", Number: 15157, Kind: delegatedecision.KindPR, Author: "clubanderson", + Labels: []string{stagelabels.ReadyForHumanMerge.Label(), "role/newcomer"}, CIGreen: true, + } + req := delegatedDecisionRequest{Type: "pr", Reason: "contributor-lane:author-association"} + cases := []struct { + name string + mutate func(in *delegatedecision.Input) + wantRule string + wantNote string + wantText string + }{ + {name: "owner conflicting returns to author", mutate: func(in *delegatedecision.Input) { in.OwnerAuthor = true; in.Conflicting = true }, + wantRule: delegatedecision.RuleReturnToAuthor, wantNote: "hive decided: return to author · the branch conflicts with the base and needs a rebase", + wantText: "@clubanderson: rebase onto the base branch on #15157; then it merges"}, + {name: "author/human red CI returns to author", mutate: func(in *delegatedecision.Input) { in.HumanAuthor = true; in.CIGreen = false }, + wantRule: delegatedecision.RuleReturnToAuthor, wantNote: "hive decided: return to author · CI is not green on its head", + wantText: "make CI green"}, + {name: "owner DCO missing returns to author", mutate: func(in *delegatedecision.Input) { in.OwnerAuthor = true; in.DCOMissing = true }, + wantRule: delegatedecision.RuleReturnToAuthor, wantNote: "hive decided: return to author · the DCO sign-off is missing from its commits", + wantText: "add the DCO sign-off"}, + {name: "owner clean head approves", mutate: func(in *delegatedecision.Input) { in.OwnerAuthor = true }, + wantRule: delegatedHumanMergeApproveRule, wantNote: "hive decided: approve · review passed, CI green"}, + {name: "clanker DCO missing adopts", mutate: func(in *delegatedecision.Input) { in.DCOMissing = true }, + wantRule: delegatedHumanMergeAdoptDCORule, wantNote: "hive decided: adopt · DCO sign-off missing"}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + in := base + in.Labels = append([]string(nil), base.Labels...) + tc.mutate(&in) + d, notes, ok := srv.delegatedHumanMergeDecision(in, req, "writer", true) + if !ok || d.Rule != tc.wantRule { + t.Fatalf("ok=%v decision=%+v, want rule %q", ok, d, tc.wantRule) + } + if len(notes) != 1 || notes[0] != tc.wantNote { + t.Fatalf("notes = %q, want %q", notes, tc.wantNote) + } + if tc.wantText != "" && !strings.Contains(d.Text, tc.wantText) { + t.Fatalf("text = %q, want it to contain %q", d.Text, tc.wantText) + } + for _, a := range d.Actions { + if in.PersonAuthored() && a.Kind == delegatedecision.ActionAdoptSupersede { + t.Fatalf("a person's PR must never carry an adopt action: %+v", d) + } + } + if d.Rule == delegatedHumanMergeAdoptDCORule && d.Verdict != delegatedecision.VerdictAdoptSupersede { + t.Fatalf("clanker DCO-less head should adopt: %+v", d) + } + }) + } +} diff --git a/src/pkg/dashboard/delegated_pr_context.go b/src/pkg/dashboard/delegated_pr_context.go index 74895d8177..fa4bd9991b 100644 --- a/src/pkg/dashboard/delegated_pr_context.go +++ b/src/pkg/dashboard/delegated_pr_context.go @@ -71,7 +71,11 @@ func delegatedCompetingNumbers(items []StageTrackerItem, repo string, pr *gh.Pul func (s *Server) gatherDelegatedPRContext(ctx context.Context, repo string, pr *gh.PullRequest, in *delegatedecision.Input) error { owner, name, _ := strings.Cut(repo, "/") now := time.Now().UTC() - if !in.HiveAuthored { + in.HumanAuthor = s.delegatedHumanAuthor(in.Labels) + in.OwnerAuthor = s.isAuthorizedUserLogin(in.Author) + // A person's PR is never a contributor with an expected connected hive; + // "offline" has no meaning for it (hivecommons/hive#15202). + if !in.HiveAuthored && !in.PersonAuthored() { window := config.DefaultPresenceWindow if s.deps.Config != nil { window = s.deps.Config.Governor.Labels.Stage.EffectivePresenceWindow() @@ -132,6 +136,50 @@ type delegatedActivity struct { // Only the author's own activity proves presence: bot nudges and other people's // reviews must not keep an absent contributor online. Read every page before // declaring absence; API failures abort gathering rather than authorizing adoption. +// delegatedHumanAuthor reads the author-kind label (author/human by default, +// renamed via governor.labels.author) from the PR's labels. hive beats +// clanker beats human when labels disagree, as in pkg/authorkind. +func (s *Server) delegatedHumanAuthor(labels []string) bool { + human, clanker, hive := authorKindLabelPfx+authorKindHuman, authorKindLabelPfx+authorKindClanker, authorKindLabelPfx+authorKindHive + if s != nil && s.deps != nil && s.deps.Config != nil { + a := s.deps.Config.Governor.Labels.Author + if strings.TrimSpace(a.Human) != "" { + human = a.Human + } + if strings.TrimSpace(a.Clanker) != "" { + clanker = a.Clanker + } + if strings.TrimSpace(a.Hive) != "" { + hive = a.Hive + } + } + isHuman := false + for _, l := range labels { + switch l = strings.TrimSpace(l); { + case strings.EqualFold(l, hive), strings.EqualFold(l, clanker): + return false + case strings.EqualFold(l, human): + isHuman = true + } + } + return isHuman +} + +// isAuthorizedUserLogin: login is one of this hive's dashboard.authorized_users. +func (s *Server) isAuthorizedUserLogin(login string) bool { + login = strings.TrimSpace(strings.TrimPrefix(login, "@")) + if login == "" || s == nil || s.deps == nil || s.deps.Config == nil { + return false + } + for _, entry := range s.deps.Config.Dashboard.AuthorizedUsers { + name, _ := dashboardAuthorizedUserEntry(entry) + if name != "" && strings.EqualFold(name, login) { + return true + } + } + return false +} + func (s *Server) delegatedContributorOnline(ctx context.Context, owner, repo string, pr *gh.PullRequest, cutoff time.Time) (bool, error) { author := pr.GetUser().GetLogin() // Unknown identity is not evidence of absence. diff --git a/src/pkg/dashboard/server.go b/src/pkg/dashboard/server.go index 795c2cff67..a190bb60f0 100644 --- a/src/pkg/dashboard/server.go +++ b/src/pkg/dashboard/server.go @@ -2229,6 +2229,12 @@ func (s *Server) configuredOwnerUser() string { return "" } +// AuthorizedUserEntry splits a dashboard.authorized_users entry +// ("login" or "login:role") into its login and role. +func AuthorizedUserEntry(entry string) (name, role string) { + return dashboardAuthorizedUserEntry(entry) +} + func dashboardAuthorizedUserEntry(entry string) (name, role string) { entry = strings.TrimSpace(entry) if idx := strings.LastIndex(entry, ":"); idx >= 0 { diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 9f679586f4..204aa897c0 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -1902,8 +1902,11 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto stageTrackerApplyMergeTrain(it) it.Caption, it.Actor = stageTrackerCaption(stage, it.Reason, it.Author, it.Kind, it.Mirrored, rec, hasRec, it.LinkedPR, it.Head) // Adoption is clanker-only (a human's PR is never adopted), so a - // human-authored 072 row keeps its plain caption. - if stage == stagelabels.ReturnedToContributor && it.Kind == "pr" && it.AuthorKind != authorKindHuman { + // human-authored 072 row keeps its plain caption. The one exception + // is a person's PR the engine was asked to adopt and refused + // (hivecommons/hive#15202): that row says "not adopted" wherever it sits. + personRefused := hasRec && it.Kind == "pr" && rec.AdoptionBlocked(it.Head) == stagelabels.AdoptBlockedAuthorPerson + if personRefused || (stage == stagelabels.ReturnedToContributor && it.Kind == "pr" && it.AuthorKind != authorKindHuman) { if it.Adoption = stageTrackerAdoption(*it, rec, hasRec, presence, maintainerPolicy, now); it.Adoption != nil { it.Caption = stageTrackerAdoptionCaption(it.Caption, it.Adoption) } diff --git a/src/pkg/dashboard/stage_tracker_adoption.go b/src/pkg/dashboard/stage_tracker_adoption.go index a6198caf5c..ef1a798c17 100644 --- a/src/pkg/dashboard/stage_tracker_adoption.go +++ b/src/pkg/dashboard/stage_tracker_adoption.go @@ -101,7 +101,21 @@ func (s *Server) stageTrackerMaintainerPolicy() string { // when the row was never nudged at its current head (nothing to adopt // yet) or is already adopted. func stageTrackerAdoption(it StageTrackerItem, rec stagelabels.Record, hasRec bool, presence func(login string) (automerge.ContributorPresence, bool), policy string, now time.Time) *StageTrackerAdoption { - if it.Kind != "pr" || !hasRec || rec.NudgeCount == 0 || rec.NudgeStart().IsZero() { + if it.Kind != "pr" || !hasRec { + return nil + } + if rec.AdoptionBlocked(it.Head) == stagelabels.AdoptBlockedAuthorPerson { + // A person's PR was asked to be adopted and refused: say so on the + // row even though no nudge clock ever ran (hivecommons/hive#15202). + out := &StageTrackerAdoption{Author: it.Author, Policy: policy, Due: true, BlockedBy: stagelabels.AdoptBlockedAuthorPerson} + if !rec.AdoptBlockedAt.IsZero() { + since := rec.AdoptBlockedAt + out.Since = &since + } + out.Text = stageTrackerAdoptionText(it.Author, *out, now) + return out + } + if rec.NudgeCount == 0 || rec.NudgeStart().IsZero() { return nil } if it.Head != "" && rec.NudgeHead != "" && rec.NudgeHead != it.Head { @@ -148,6 +162,9 @@ func stageTrackerAdoptionText(author string, a StageTrackerAdoption, now time.Ti if author != "" { who = "@" + author } + if a.BlockedBy == stagelabels.AdoptBlockedAuthorPerson { + return who + " pushed this PR themselves — not adopted: the hive asks them, not adopts" + } var facts []string if a.AuthorMaintainer { facts = append(facts, "maintainer") diff --git a/src/pkg/dashboard/stage_tracker_adoption_test.go b/src/pkg/dashboard/stage_tracker_adoption_test.go index 7103a6b88b..f2883bb38c 100644 --- a/src/pkg/dashboard/stage_tracker_adoption_test.go +++ b/src/pkg/dashboard/stage_tracker_adoption_test.go @@ -338,3 +338,41 @@ func TestStageTrackerAdoptionEndpointShape(t *testing.T) { t.Fatalf("endpoint body lacks adoption: %s", rr.Body.String()) } } + +// hivecommons/hive#15202: an owner's / author-human PR the engine refused to +// adopt says so on its row, with no Adopt offer and no nudge clock needed. +func TestStageTrackerAdoptionPersonAuthoredSaysNotAdopted(t *testing.T) { + now := time.Date(2026, 10, 28, 20, 30, 0, 0, time.UTC) + s := newTestServer() + store := stagelabels.NewStore("", func() time.Time { return now }) + s.stageStore = store + s.deps = &Dependencies{Config: &config.Config{}} + key := stagelabels.Key("hivecommons/hive", 15157) + store.Observe(key, stagelabels.NeedsDecision, "contributor-lane:decision-requested") + store.NoteAdoptionBlocked(key, "cafe", stagelabels.AdoptBlockedAuthorPerson, now.Add(-2*time.Minute)) + status := minimalPayload() + status.HiveID = "hive" + status.Repos = []FrontendRepo{{ + Name: "hive", Full: "hivecommons/hive", + OpenPrs: []any{FrontendPR{PullRequest: github.PullRequest{Number: 15157, Title: "Owner change", Author: "clubanderson", HeadSHA: "cafe", Labels: []string{"stage/085-needs-decision", "author/human", "role/trusted"}}}}, + }} + s.UpdateStatus(status) + it := trackerItem(t, s.buildStageTracker(status, store, now), "pr", 15157) + a := it.Adoption + if a == nil || !a.Due || a.BlockedBy != stagelabels.AdoptBlockedAuthorPerson || a.Action != "" { + t.Fatalf("adoption = %+v", a) + } + if a.Text != "@clubanderson pushed this PR themselves — not adopted: the hive asks them, not adopts" { + t.Fatalf("text = %q", a.Text) + } + if !strings.Contains(it.Caption, "not adopted") { + t.Fatalf("caption = %q", it.Caption) + } + if d := it.DecisionNeeded; d != nil { + for _, o := range d.Options { + if o.Action == decisionActionAdopt { + t.Fatalf("adopt offered on a person's PR: %+v", d) + } + } + } +} diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 5769af7e25..d0bc446b3c 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -17394,6 +17394,7 @@

All labels

"reporter-trust": {"kind": "rule", "plain": "the hold on an unknown reporter is cleared because the fix is sound", "detail": "The PR was held until the reporter's trust was known; its fix is green and mergeable, so the hold is cleared."}, "request_changes": {"kind": "reason", "plain": "a reviewer asked for changes; a new commit is needed", "detail": "A reviewer asked for changes on this branch. Approving cannot override that: only a new commit, or a maintainer merging by hand, moves it."}, "requires_human": {"kind": "reason", "plain": "marked needs-human; a person must remove the label", "detail": "The item is marked needs-human: automated fixes ran out or a person flagged it. The hive waits until the label is removed."}, + "return-to-author": {"kind": "rule", "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."}, "review-backlog": {"kind": "rule", "plain": "the PR closed without merging, so the issue stays open", "detail": "The fixing PR closed unmerged; the issue stays open and is re-triaged rather than auto-closed."}, "reviewer-verdict:request_changes": {"kind": "reason", "plain": "a reviewer asked for changes; a new commit is needed", "detail": "A reviewer asked for changes on this branch. Approving cannot override that: only a new commit, or a maintainer merging by hand, moves it."}, "self-decision-read-as-changes": {"kind": "reason", "plain": "hive's own decision comment was read as a reviewer asking for changes", "detail": "The merge gate read the hive's own `/hive decision` comment as a reviewer asking for changes, so the decision blocked the PR it meant to advance (hivecommons/hive#14822). A new commit or a maintainer merge clears it."}, diff --git a/src/pkg/delegatedecision/decision_glossary.go b/src/pkg/delegatedecision/decision_glossary.go index 7fc24f0044..a8c5defe33 100644 --- a/src/pkg/delegatedecision/decision_glossary.go +++ b/src/pkg/delegatedecision/decision_glossary.go @@ -84,6 +84,8 @@ var glossary = []GlossaryEntry{ Detail: "An older issue already tracks the same work; one thread keeps it moving."}, {Slug: "fix-then-merge", Kind: GlossaryRule, Plain: "the branch isn't mergeable yet", Detail: "The branch cannot merge as it is (conflicts, red CI or a missing sign-off); the hive told the author agent exactly what to fix."}, + {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", Detail: "This needs a secret, token or organization permission that only the hive owner holds; the hive cannot do it for you.", Aliases: []string{"owner_only"}}, {Slug: "prefer-contributor", Kind: GlossaryRule, Plain: "a contributor's PR and a hive PR do the same work", diff --git a/src/pkg/delegatedecision/decision_glossary_test.go b/src/pkg/delegatedecision/decision_glossary_test.go index 6701abd9c3..f13eff31ab 100644 --- a/src/pkg/delegatedecision/decision_glossary_test.go +++ b/src/pkg/delegatedecision/decision_glossary_test.go @@ -20,6 +20,7 @@ func TestGlossaryCoversEveryRuleSlug(t *testing.T) { regexp.MustCompile(`\b(?:recommendOnly|approveIssue|releasePR)\("([a-z0-9-]+)"`), regexp.MustCompile(`\bruleDefault[A-Za-z]+\s*=\s*"([a-z0-9-]+)"`), regexp.MustCompile(`\bRuleLLM\s*=\s*"([a-z0-9-]+)"`), + regexp.MustCompile(`\bRuleReturnToAuthor\s*=\s*"([a-z0-9-]+)"`), } found := map[string]bool{} for _, file := range []string{"policy.go", "llm.go"} { diff --git a/src/pkg/delegatedecision/llm.go b/src/pkg/delegatedecision/llm.go index 46fcc0b356..c7d6315694 100644 --- a/src/pkg/delegatedecision/llm.go +++ b/src/pkg/delegatedecision/llm.go @@ -413,7 +413,7 @@ const ( // goes through ApplyRails. A runner or validation error falls back to the // rules' reversible default and is returned for the caller to note. func RunWithLLM(ctx context.Context, in Input, c LLMContext, runner TurnRunner) (Decision, LLMOutcome, error) { - rails := Rails{Held: hasLabel(in.Labels, LabelHold)} + rails := Rails{Held: hasLabel(in.Labels, LabelHold), PersonAuthored: in.PersonAuthored()} rules := Decide(in) if runner == nil || rails.Held || !IsReversibleDefault(rules) { return ApplyRails(rules, rails), LLMNotConsulted, nil diff --git a/src/pkg/delegatedecision/person_author_test.go b/src/pkg/delegatedecision/person_author_test.go new file mode 100644 index 0000000000..6410db3c05 --- /dev/null +++ b/src/pkg/delegatedecision/person_author_test.go @@ -0,0 +1,101 @@ +package delegatedecision + +import ( + "strings" + "testing" +) + +// hivecommons/hive#15202: a PR pushed by a person (author/human label or one +// of this hive's owners) is never a "contributor" with an offline hive. The +// delegate hands it back to that person by name and never adopts it. +func TestDecidePRPersonAuthoredNeverAdopted(t *testing.T) { + base := Input{Kind: KindPR, Number: 15157, Title: "Fix the tracker", Author: "clubanderson", ContributorOnline: false} + cases := []struct { + name string + in Input + verdict Verdict + rule string + wantText []string + noAdopt bool + }{ + { + name: "human author offline conflicting → return to author, not adopt", + in: with(base, func(i *Input) { i.HumanAuthor = true; i.Conflicting = true; i.CIGreen = true }), + verdict: VerdictDirection, rule: RuleReturnToAuthor, + wantText: []string{"@clubanderson", "rebase onto the base branch", "#15157"}, + noAdopt: true, + }, + { + name: "owner author offline red CI → return to author", + in: with(base, func(i *Input) { i.OwnerAuthor = true; i.CIGreen = false }), + verdict: VerdictDirection, rule: RuleReturnToAuthor, + wantText: []string{"@clubanderson", "make CI green"}, + noAdopt: true, + }, + { + name: "human author offline, adoption stalled, green → approves (never adopts)", + in: with(base, func(i *Input) { i.HumanAuthor = true; i.AdoptionStalled = true; i.CIGreen = true; i.Small = true }), + verdict: VerdictApprove, rule: "small-low-risk", + noAdopt: true, + }, + { + name: "human author green with an open reviewer question → relays the question", + in: with(base, func(i *Input) { i.HumanAuthor = true; i.CIGreen = true; i.Question = "is the retry bounded?" }), + verdict: VerdictDirection, rule: RuleReturnToAuthor, + wantText: []string{"@clubanderson, the reviewer asked: is the retry bounded?"}, + noAdopt: true, + }, + { + name: "clanker author offline conflicting still adopts", + in: with(base, func(i *Input) { i.Conflicting = true; i.CIGreen = true }), + verdict: VerdictAdoptSupersede, rule: "contributor-offline", + }, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + d := Run(tc.in) + if d.Verdict != tc.verdict || d.Rule != tc.rule { + t.Fatalf("got %s/%s want %s/%s (%+v)", d.Verdict, d.Rule, tc.verdict, tc.rule, d) + } + for _, w := range tc.wantText { + if !strings.Contains(d.Text, w) { + t.Errorf("text %q lacks %q", d.Text, w) + } + } + for _, a := range d.Actions { + if tc.noAdopt && a.Kind == ActionAdoptSupersede { + t.Errorf("person-authored PR must never be adopted: %+v", d) + } + } + }) + } +} + +// The rail holds even when a rule (or an LLM) asked for adoption outright. +func TestApplyRailsRefusesAdoptSupersedeForPersonAuthored(t *testing.T) { + d := Decision{Verdict: VerdictAdoptSupersede, Rule: "contributor-offline", Text: "supersede now", + Actions: []Action{decisionComment("supersede now"), {Kind: ActionAdoptSupersede}}} + out := ApplyRails(d, Rails{PersonAuthored: true}) + for _, a := range out.Actions { + if a.Kind == ActionAdoptSupersede { + t.Fatalf("adopt-supersede survived the person-authored rail: %+v", out) + } + } + found := false + for _, r := range out.Refusals { + if r == RefusalAdoptPersonAuthored { + found = true + } + } + if !found { + t.Fatalf("refusal missing: %+v", out.Refusals) + } + if out.Verdict != VerdictAdoptSupersede || len(out.Actions) != 1 || out.Actions[0].Kind != ActionCommentDecision { + t.Fatalf("expected the decision comment to survive alone: %+v", out) + } + if plain := RulePlain(RuleReturnToAuthor); plain == "" { + t.Fatal("return-to-author needs a glossary entry") + } +} + +func with(in Input, f func(*Input)) Input { f(&in); return in } diff --git a/src/pkg/delegatedecision/policy.go b/src/pkg/delegatedecision/policy.go index 3196e35929..254ef418a7 100644 --- a/src/pkg/delegatedecision/policy.go +++ b/src/pkg/delegatedecision/policy.go @@ -178,6 +178,12 @@ type Input struct { // ContributorOnline: the author is reachable (relay heartbeat / recent // activity); false for an external author who went quiet. ContributorOnline bool + // HumanAuthor: the PR carries the author/human label — a person pushed + // it themselves. OwnerAuthor: the author is one of this hive's owners + // (dashboard.authorized_users). Neither has a hive that can be "offline", + // and the delegate never adopts their work (hivecommons/hive#15202). + HumanAuthor bool + OwnerAuthor bool // DuplicateOf is the older issue this one duplicates (0 = none known). DuplicateOf int // Overlaps lists issues that overlap without duplicating. @@ -469,7 +475,14 @@ func decidePR(in Input) Decision { return d } } - if !in.HiveAuthored && !in.ContributorOnline && in.WorkflowPath && (in.AdoptionStalled || in.AdoptionGraceElapsed || in.Conflicting || !in.CIGreen || in.DCOMissing) { + // A person pushed this PR themselves (an owner, or author/human): + // it is theirs to fix, never the hive's to adopt (hivecommons/hive#15202). + if in.PersonAuthored() { + if d, ok := decideReturnToAuthor(in, ref); ok { + return d + } + } + if !in.HiveAuthored && !in.PersonAuthored() && !in.ContributorOnline && in.WorkflowPath && (in.AdoptionStalled || in.AdoptionGraceElapsed || in.Conflicting || !in.CIGreen || in.DCOMissing) { // The adoption engine refuses to publish a contributor's workflow // edits from the App (contributor-lane:workflow-path), so an // adopt-supersede here is decided and never executed @@ -478,7 +491,7 @@ func decidePR(in Input) Decision { return recommendOnly(RuleCapabilityGap, "the PR edits .github/workflows and the hive's GitHub App lacks the `workflows` permission, so the adoption fence refuses to supersede it; deciding to adopt cannot take effect", "grant the App the `workflows` permission and re-run the decision, or have a person rebase and merge "+ref+" on GitHub, or close it as superseded") } - if !in.HiveAuthored && in.Kind == KindPR && in.AdoptionGraceElapsed { + if !in.HiveAuthored && !in.PersonAuthored() && in.Kind == KindPR && in.AdoptionGraceElapsed { text := "adopt now: the offline grace on " + ref + " has already elapsed; adopt in supersede mode at once, preserving the author's commits and sign-off" return Decision{ Verdict: VerdictAdoptSupersede, Rule: RuleAdoptNow, Text: text, @@ -486,7 +499,7 @@ func decidePR(in Input) Decision { Actions: []Action{decisionComment(text), {Kind: ActionAdoptSupersede}}, } } - if !in.HiveAuthored && !in.ContributorOnline && (in.AdoptionStalled || in.Conflicting || !in.CIGreen || in.DCOMissing) { + if !in.HiveAuthored && !in.PersonAuthored() && !in.ContributorOnline && (in.AdoptionStalled || in.Conflicting || !in.CIGreen || in.DCOMissing) { text := "supersede now: adopt " + ref + " in supersede mode, preserving the author's commits and sign-off; do not wait for the grace deadline" return Decision{ Verdict: VerdictAdoptSupersede, Rule: "contributor-offline", Text: text, @@ -547,6 +560,60 @@ func decideCompeting(in Input, ref string) (Decision, bool) { return Decision{}, false } +// PersonAuthored: a human or one of this hive's owners pushed the PR +// themselves. Such a PR is never a "contributor" with an expected connected +// hive, so the contributor-offline rule and adoption do not apply to it. +func (in Input) PersonAuthored() bool { return in.HumanAuthor || in.OwnerAuthor } + +// RuleReturnToAuthor hands a person's PR back to that person with the exact +// fix list and the reviewer's question, instead of adopting it. +const RuleReturnToAuthor = "return-to-author" + +// decideReturnToAuthor is the person-authored branch of decidePR: a head that +// is not mergeable, or a reviewer question still open, goes back to the +// author by name. A green, mergeable head with no open question falls +// through to the ordinary approve rules. +// ReturnToAuthor is decideReturnToAuthor for callers outside the policy +// (the 090 human-merge decider): the person's PR goes back to them with +// the fix list and the reviewer's question; ok=false when nothing is owed. +func ReturnToAuthor(in Input) (Decision, bool) { + return decideReturnToAuthor(in, "#"+strconv.Itoa(in.Number)) +} + +func decideReturnToAuthor(in Input, ref string) (Decision, bool) { + var fix []string + if in.Conflicting { + fix = append(fix, "rebase onto the base branch") + } + if in.DCOMissing { + fix = append(fix, "add the DCO sign-off") + } + if !in.CIGreen { + fix = append(fix, "make CI green without widening scope") + } + question := strings.TrimSpace(in.Question) + if len(fix) == 0 && question == "" { + return Decision{}, false + } + who := "the author" + if a := strings.TrimSpace(in.Author); a != "" { + who = "@" + strings.TrimPrefix(a, "@") + } + var parts []string + if len(fix) > 0 { + parts = append(parts, who+": "+strings.Join(fix, ", ")+" on "+ref+"; then it merges") + } + if question != "" { + parts = append(parts, who+", the reviewer asked: "+question) + } + text := strings.Join(parts, " — ") + return Decision{ + Verdict: VerdictDirection, Rule: RuleReturnToAuthor, Text: text, + Rationale: "a person pushed this PR themselves, so the hive asks that person instead of adopting the work (hivecommons/hive#15202)", + Actions: []Action{decisionComment(text)}, + }, true +} + func releasePR(rule, text, rationale string) Decision { return Decision{ Verdict: VerdictApprove, Rule: rule, Text: text, Rationale: rationale, @@ -566,8 +633,15 @@ type Rails struct { Held bool // AllowedActions overrides the allowed set (nil = AllowedActions). AllowedActions []ActionKind + // PersonAuthored: a human or owner pushed the PR; adopt-supersede is + // refused whatever the rule chose (hivecommons/hive#15202). + PersonAuthored bool } +// RefusalAdoptPersonAuthored is the refusal ApplyRails records when a rule +// asked to adopt a person's PR. +const RefusalAdoptPersonAuthored = "adopt-supersede: a person pushed this PR themselves; the hive asks the author instead of adopting it" + // ApplyRails enforces the safety rails on a decision: a held item is refused // outright; actions outside the allowed set are dropped with a refusal; a // hold label is never removed; a decision whose every action was dropped @@ -599,6 +673,10 @@ func ApplyRails(d Decision, r Rails) Decision { out.Refusals = append(out.Refusals, "labels-remove hold: the delegate never lifts a hold") continue } + if a.Kind == ActionAdoptSupersede && r.PersonAuthored { + out.Refusals = append(out.Refusals, RefusalAdoptPersonAuthored) + continue + } out.Actions = append(out.Actions, a) } if len(out.Actions) == 0 { @@ -611,7 +689,7 @@ func ApplyRails(d Decision, r Rails) Decision { // Run is Decide followed by ApplyRails with the hold rail read from the labels. func Run(in Input) Decision { - return ApplyRails(Decide(in), Rails{Held: hasLabel(in.Labels, LabelHold)}) + return ApplyRails(Decide(in), Rails{Held: hasLabel(in.Labels, LabelHold), PersonAuthored: in.PersonAuthored()}) } // CommentBody renders the comment the delegate posts for a decision: the diff --git a/src/pkg/github/automerge/automerge_contributor_adopt.go b/src/pkg/github/automerge/automerge_contributor_adopt.go index 6773ba9c40..c710fdbb3c 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopt.go +++ b/src/pkg/github/automerge/automerge_contributor_adopt.go @@ -11,6 +11,7 @@ import ( "time" gh "github.com/google/go-github/v72/github" + "github.com/hivecommons/hive/pkg/authorkind" "github.com/hivecommons/hive/pkg/config" "github.com/hivecommons/hive/pkg/delegatedecision" "github.com/hivecommons/hive/pkg/effects" @@ -640,6 +641,15 @@ func (c *Engine) adoptContributorPR(ctx context.Context, store *stagelabels.Stor c.info("stage labels: adoption due but blocked by label", "repo", obs.Display, "pr", obs.Number, "label", l) return 0, nil } + if personAuthored(obs, policy) { + // A person's own PR (hivecommons/hive#15202): no contributor hive + // can be offline for it, and neither an operator request nor a + // forced adoption changes who should fix it. Recorded so the + // tracker row says why. + store.NoteAdoptionBlocked(key, obs.HeadSHA, stagelabels.AdoptBlockedAuthorPerson, now) + c.info("stage labels: adoption refused, a person pushed this PR themselves; asking the author instead", "repo", obs.Display, "pr", obs.Number, "author", obs.Author, "head", obs.HeadSHA, "author_kind", obs.AuthorKind.String(), "reason", reason, "requested", requested, "forced", forced) + return 0, nil + } if forced { c.info("stage labels: operator forced adoption; maintainer policy, admission and presence bypassed", "repo", obs.Display, "pr", obs.Number, "author", obs.Author, "by", forcedBy, "online", presence.Online, "policy", policy.maintainerPolicy()) } else if c.adoptionRefusedByAdmission(store, key, obs, requested, now) { @@ -757,6 +767,11 @@ func (c *Engine) refuseSelfAuthoredSupersede(ctx context.Context, store *stagela // attempt between the two snapshots: MarkAdopted stamps head/by/at before // any write, so a changed adoption record means this head was tried. func delegatedAdoptionAttempted(before, after stagelabels.Record) bool { + // A person-authored refusal is terminal for the request, not a + // deferral: the label must not re-ask every sweep (hivecommons/hive#15202). + if after.AdoptBlockedBy == stagelabels.AdoptBlockedAuthorPerson && after.AdoptBlockedHead != "" { + return true + } return after.AdoptedHead != before.AdoptedHead || after.AdoptedBy != before.AdoptedBy || !after.AdoptedAt.Equal(before.AdoptedAt) || @@ -1380,6 +1395,16 @@ func (c *Engine) authorMaintainsRepo(ctx context.Context, obs stageObservation, return maintainer, nil } +// personAuthored: the PR was pushed by a person — author/human, or one of +// this hive's owners — rather than by a clanker or a registered contributor +// relay. Such a PR is never adopted (hivecommons/hive#15202). +func personAuthored(obs stageObservation, policy StageLabelPolicy) bool { + if obs.AuthorKind == authorkind.Human { + return true + } + return policy.OwnerAuthor != nil && obs.Author != "" && policy.OwnerAuthor(obs.Author) +} + // maintainerPolicy resolves the policy's maintainer rule ("" = adopt). func (p StageLabelPolicy) maintainerPolicy() string { switch strings.ToLower(strings.TrimSpace(p.AdoptionMaintainerPolicy)) { diff --git a/src/pkg/github/automerge/automerge_contributor_adopt_test.go b/src/pkg/github/automerge/automerge_contributor_adopt_test.go index a5c4498062..4771a4c8ba 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopt_test.go +++ b/src/pkg/github/automerge/automerge_contributor_adopt_test.go @@ -2719,3 +2719,44 @@ func TestAdoptionSupersedeConflictCommentListsFiles(t *testing.T) { t.Fatal("empty file list rendered") } } + +// hivecommons/hive#15202: an owner's / author-human PR parked at 085 with a +// delegated `adoption/supersede` request is never adopted. The refusal is +// recorded on the tracker row, the request label is consumed (one attempt, +// not a standing order) and the PR never reaches 074. +func TestDelegatedSupersedeRefusesPersonAuthoredPR(t *testing.T) { + cases := []struct { + name string + labels []string + human bool + owner func(string) bool + }{ + {name: "author/human label", labels: []string{"stage/085-needs-decision", "author/human", delegatedecision.LabelAdoptSupersede}, human: true}, + {name: "hive owner whose hive opened the PR", labels: []string{"stage/085-needs-decision", delegatedecision.LabelAdoptSupersede}, + owner: func(login string) bool { return login == "mallory" }}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + policy := adoptPolicy() + policy.OwnerAuthor = tc.owner + h, done := newAdoptHarness(t, ContributorNudgeOutcome{}, policy) + defer done() + pr := adoptPR(7, "aaa", tc.labels...) + if tc.human { + // No relay trailer: a person pushed it from their own machine. + pr.Body = gh.Ptr("Fixes the widget.\n\nCloses #12\n") + } + h.observe(pr, contributorLaneReasonNoReviewer) + if len(h.adopt.pulls) != 0 || len(h.adopt.refs) != 0 || strings.Contains(strings.Join(h.addedLabels(), " "), "stage/074") { + t.Fatalf("adopted a person's PR: pulls=%v refs=%v added=%v", h.adopt.pulls, h.adopt.refs, h.api.added) + } + rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) + if rec.AdoptionBlocked("aaa") != stagelabels.AdoptBlockedAuthorPerson { + t.Fatalf("refusal not recorded for the tracker: %+v", rec) + } + if !slices.Contains(h.api.removed, delegatedecision.LabelAdoptSupersede) { + t.Fatalf("request label kept after a terminal refusal: removed=%v", h.api.removed) + } + }) + } +} diff --git a/src/pkg/github/automerge/automerge_contributor_nudge.go b/src/pkg/github/automerge/automerge_contributor_nudge.go index 90f1639e32..57cebd2b9e 100644 --- a/src/pkg/github/automerge/automerge_contributor_nudge.go +++ b/src/pkg/github/automerge/automerge_contributor_nudge.go @@ -115,6 +115,10 @@ func nudgeDiagnosis(reason string, d stageDetail) (checks, asks []string, human human = true case r == contributorLaneReasonChangesRequested, r == stagelabels.LaneReasonChangesRequested: asks = append(asks, "the review swarm requested changes") + case r == stagelabels.LaneReasonReviewerQuestion: + // A person's PR routed to them on requires_human + // (hivecommons/hive#15202); the route carries the question itself. + asks = append(asks, "the review swarm returned `requires_human`: it has a question for you, not a fix for the hive") case r == "conflicting" || r == "not-mergeable" || r == "label:needs-rebase": asks = append(asks, "the branch conflicts with the base and needs a rebase") case r == autoMergeReasonForkNotEditable: @@ -176,6 +180,13 @@ func nudgeDiagnosisRouted(reason string, d stageDetail, route *stagelabels.Route seenAsk[a] = true asks = append(asks, a) } + case strings.HasPrefix(r, "reviewer question: "), strings.HasPrefix(r, "reviewer summary: "): + // A person's PR at 071 on a requires_human verdict: the + // reviewer's question is theirs to answer (hivecommons/hive#15202). + if a := "the reviewer asked you: " + strings.TrimSpace(r[strings.Index(r, ": ")+2:]); !seenAsk[a] { + seenAsk[a] = true + asks = append(asks, a) + } } } return checks, asks, human diff --git a/src/pkg/github/automerge/automerge_stage_human.go b/src/pkg/github/automerge/automerge_stage_human.go index 0ad09c201f..e2881641a1 100644 --- a/src/pkg/github/automerge/automerge_stage_human.go +++ b/src/pkg/github/automerge/automerge_stage_human.go @@ -15,6 +15,7 @@ import ( "time" gh "github.com/google/go-github/v72/github" + "github.com/hivecommons/hive/pkg/authorkind" hgithub "github.com/hivecommons/hive/pkg/github" "github.com/hivecommons/hive/pkg/oktotest" "github.com/hivecommons/hive/pkg/stagelabels" @@ -83,6 +84,16 @@ func humanVerdict(v ContributorLaneVerdict) stagelabels.VerdictState { // cleanly. var humanConflictReasons = map[string]bool{"conflicting": true, "not-mergeable": true, "label:needs-rebase": true} +// humanConflict reports a head that does not merge cleanly. The stage reason +// is what classifyStage chose; for a hive or clanker PR a decision-requested +// verdict outranks the conflict (hivecommons/hive#14607). A person's own PR +// is different: the conflict is theirs to fix, so the lane's own reason +// (kept in LaneReason) still counts (hivecommons/hive#15202). +func humanConflict(obs stageObservation) bool { + return humanConflictReasons[obs.Reason] || hasLabelFold(obs.Labels, "needs-rebase") || + obs.AuthorKind == authorkind.Human && humanConflictReasons[obs.LaneReason] +} + // humanEvidence gathers the Evidence for one human-routed observation. func (c *Engine) humanEvidence(ctx context.Context, tracker *StageTracker, key string, obs stageObservation, cause stagelabels.HumanCause, now time.Time) stagelabels.Evidence { contributorVerdict := normalizeContributorLaneVerdict(c.contributorLaneVerdictFor(obs.Owner+"/"+obs.Repo, obs.Number, obs.HeadSHA)) @@ -90,7 +101,7 @@ func (c *Engine) humanEvidence(ctx context.Context, tracker *StageTracker, key s e := stagelabels.Evidence{ Head: obs.HeadSHA, Verdict: humanVerdict(contributorVerdict), - Conflict: humanConflictReasons[obs.Reason] || hasLabelFold(obs.Labels, "needs-rebase"), + Conflict: humanConflict(obs), Holds: stagelabels.Holds(obs.Labels), Hold: obs.Hold, Cause: cause, diff --git a/src/pkg/github/automerge/automerge_stage_human_test.go b/src/pkg/github/automerge/automerge_stage_human_test.go index e8bb21e8ce..9083bfbc5b 100644 --- a/src/pkg/github/automerge/automerge_stage_human_test.go +++ b/src/pkg/github/automerge/automerge_stage_human_test.go @@ -313,7 +313,11 @@ func TestRequiresHumanLandsAt085WithEntryComment(t *testing.T) { sweep := func(labels ...string) { t.Helper() api.reset() - e.recordStage(stageLaneContributor, "acme/widget", "acme", "widget", stagePR(13, labels...), contributorLaneReasonNoVerdict, false, nil) + // A clanker PR (attribution trailer): a person's requires_human + // routes to 071 instead (hivecommons/hive#15202). + pr := stagePR(13, labels...) + pr.Body = gh.Ptr("Fixes the widget.\n\n— hive: backend=pi model=gpt-6\n") + e.recordStage(stageLaneContributor, "acme/widget", "acme", "widget", pr, contributorLaneReasonNoVerdict, false, nil) e.noteStageVerdict("acme", "widget", 13, *verdict) e.noteStageRole("acme", "widget", 13, stagelabels.RoleContributor) if _, err := e.ApplyStageLabels(ctx); err != nil { @@ -328,7 +332,7 @@ func TestRequiresHumanLandsAt085WithEntryComment(t *testing.T) { t.Fatal("verdict reason must not be rendered twice in the 085 comment") } - sweep("role/contributor", "author/human", "stage/050-review-pending") + sweep("role/contributor", "author/clanker", "stage/050-review-pending") if got := stageOf(t, store, 13); got != stagelabels.NeedsDecision { t.Fatalf("stage=%v want 085", got) } @@ -346,7 +350,7 @@ func TestRequiresHumanLandsAt085WithEntryComment(t *testing.T) { } // Same state again: no second entry comment, no writes. - sweep("role/contributor", "author/human", "stage/085-needs-decision") + sweep("role/contributor", "author/clanker", "stage/085-needs-decision") if len(api.comments) != 0 || api.writes() != 0 { t.Fatalf("085 dedupe: comments=%q writes=%d", api.comments, api.writes()) } @@ -366,6 +370,7 @@ func TestEntryCommentOncePerStageAndHead(t *testing.T) { api.reset() pr := stagePR(13, labels...) pr.Head.SHA = gh.Ptr(head) + pr.Body = gh.Ptr("Fixes the widget.\n\n— hive: backend=pi model=gpt-6\n") e.recordStage(stageLaneContributor, "acme/widget", "acme", "widget", pr, contributorLaneReasonNoVerdict, false, nil) e.noteStageVerdict("acme", "widget", 13, *verdict) e.noteStageRole("acme", "widget", 13, stagelabels.RoleContributor) @@ -411,7 +416,9 @@ func TestDecisionRequestedLandsAt085WithQuestion(t *testing.T) { e, store := humanStageEngine(t, api.url, clock, verdict, 0) ctx := context.Background() - e.recordStage(stageLaneContributor, "acme/widget", "acme", "widget", stagePR(17, "role/contributor", "author/human", "stage/050-review-pending"), contributorLaneReasonNoVerdict, false, nil) + pr := stagePR(17, "role/contributor", "author/human", "stage/050-review-pending") + pr.Body = gh.Ptr("Fixes the widget.\n\n— hive: backend=pi model=gpt-6\n") + e.recordStage(stageLaneContributor, "acme/widget", "acme", "widget", pr, contributorLaneReasonNoVerdict, false, nil) e.noteStageVerdict("acme", "widget", 17, *verdict) e.noteStageRole("acme", "widget", 17, stagelabels.RoleContributor) if _, err := e.ApplyStageLabels(ctx); err != nil { @@ -441,7 +448,9 @@ func TestRequiresHumanLandsAt085WithSummary(t *testing.T) { e, store := humanStageEngine(t, api.url, clock, verdict, 0) ctx := context.Background() - e.recordStage(stageLaneContributor, "acme/widget", "acme", "widget", stagePR(17, "author/contributor", "stage/050-review-pending"), contributorLaneReasonNoVerdict, false, nil) + pr := stagePR(17, "author/contributor", "stage/050-review-pending") + pr.Body = gh.Ptr("Fixes the widget.\n\n— hive: backend=pi model=gpt-6\n") + e.recordStage(stageLaneContributor, "acme/widget", "acme", "widget", pr, contributorLaneReasonNoVerdict, false, nil) e.noteStageVerdict("acme", "widget", 17, *verdict) if _, err := e.ApplyStageLabels(ctx); err != nil { t.Fatal(err) @@ -455,6 +464,77 @@ func TestRequiresHumanLandsAt085WithSummary(t *testing.T) { } } +// TestRequiresHumanOnPersonPRRoutesToAuthor: a requires_human verdict on a +// PR a person pushed themselves is the author's question to answer, not a +// maintainer's decision (hivecommons/hive#15202). It lands at 071, the +// author is told what the reviewer asked whatever their role, and nothing +// ever queues adoption. A hive-authored PR has nobody to ask and keeps 085. +func TestRequiresHumanOnPersonPRRoutesToAuthor(t *testing.T) { + api, closeAPI := seededStageAPI(t) + defer closeAPI() + clock := &contributorLaneClock{at: time.Date(2026, 10, 28, 20, 24, 0, 0, time.UTC)} + verdict := &ContributorLaneVerdict{ + Configured: true, + Verdict: "requires_human", + DecisionRequested: true, + DecisionQuestion: "should this groundwork land before its consumer?", + } + e, store := humanStageEngine(t, api.url, clock, verdict, 0) + ctx := context.Background() + sweep := func(number int, role stagelabels.Role, labels ...string) { + t.Helper() + api.reset() + pr := stagePR(number, labels...) + pr.User = &gh.User{Login: gh.Ptr("clubanderson")} + if number == 23 { + pr.User = &gh.User{Login: gh.Ptr(testHiveAppBotLogin)} + } + e.recordStage(stageLaneContributor, "acme/widget", "acme", "widget", pr, contributorLaneReasonNoVerdict, false, nil) + e.noteStageVerdict("acme", "widget", number, *verdict) + e.noteStageRole("acme", "widget", number, role) + if _, err := e.ApplyStageLabels(ctx); err != nil { + t.Fatal(err) + } + } + + sweep(21, stagelabels.RoleContributor, "role/contributor", "author/human", "stage/050-review-pending") + if got := stageOf(t, store, 21); got != stagelabels.NeedsAuthor { + t.Fatalf("stage=%v want 071", got) + } + if !reflect.DeepEqual(api.added, [][]string{{"stage/071-needs-author"}}) { + t.Fatalf("added=%v", api.added) + } + if rec, _ := store.Get(stageKey("acme", "widget", 21)); rec.Reason != stagelabels.LaneReasonReviewerQuestion { + t.Fatalf("recorded reason = %q", rec.Reason) + } + if len(api.comments) != 1 || !strings.HasPrefix(api.comments[0], "