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-15732-already-landed-any-author.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The already-landed close now covers any author's PR, not only the hive's own: when the diff against the base is empty and a merged PR provably carries the change (the reviewer named it and it is merged, the linked issue was closed by a merged PR, or the head is contained in the base) the PR is closed as superseded with thanks instead of parking at 085 for a person; trusted authors are treated the same, and the "Let hive decide" preview gives the empty diff and the merged landing as its reason rather than the author's trust ([#15732](https://github.com/hivecommons/hive/issues/15732))
24 changes: 24 additions & 0 deletions src/docs/hive-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,30 @@ closed with the redundant-of note. Only when the verdict names no PR
*and* the compare is not empty does the PR fall through to 085 as before
([#15647](https://github.com/hivecommons/hive/pull/15647)).

**Already landed, any author.** That entry was the hive's own: #15544, a
trusted contributor's PR for #15543, was +0/βˆ’0 against `v5` because
#15545 (merged) carried the identical change, and the reviewer's "should
decide whether #15544 can be closed as a no-op now that #15545 (merged)
carries this change" still parked it at 085 for nine hours. Whether a
change is already on the base is a measurement, not a trust call, so the
already-landed entry now takes any author's PR when the evidence is
unambiguous: the diff against the current base is empty (no files, or
every file byte-identical on the base tip) **and** the landing is proven
β€” the PR the reviewer named is merged, the issue this PR closes was
closed by a merged PR, or the compare lists no commits (the head is
contained in the base). "#N (merged)" in the reviewer's words names the
landing PR like "via #N" does. The hive comments "already landed via #N
β€” closing as superseded; thank you @author", closes the PR through the
supersession-close write-back gate, and logs
`already-landed:<author_kind>` (the caption is the same "already landed
via #N β€” closing as superseded"). A trusted author is treated exactly
like anyone else. A PR with a real diff, an empty PR whose landing is not
proven, a held or `keep-open` PR, or one a person parked keeps the
reviewer's question as before. The "Let hive decide" preview for such a
PR gives the evidence as its reason β€” "diff is empty β€” the change already
landed via #N (merged)" β€” never the author's standing
([#15732](https://github.com/hivecommons/hive/issues/15732)).

## Usage

```sh
Expand Down
1 change: 1 addition & 0 deletions src/pkg/dashboard/api_repo_item_decide_delegated.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ func (s *Server) gatherDelegatedInput(ctx context.Context, repoFull string, numb
if err := s.gatherDelegatedLadderInput(ctx, repoFull, pr, &in); err != nil {
return in, err
}
in.DiffEmpty = ghpkg.PRChangedFilesClaimsEmpty(pr)
state := strings.ToLower(pr.GetMergeableState())
in.Conflicting = state == "dirty" || (pr.Mergeable != nil && !pr.GetMergeable())
green, err := delegatedHeadCIGreen(ctx, api, owner, repoName, pr, in.Conflicting, state)
Expand Down
20 changes: 20 additions & 0 deletions src/pkg/dashboard/api_repo_item_decide_delegated_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ func delegatedPlanInstruction(in delegatedecision.Input, d delegatedecision.Deci
// what decided it, otherwise the head's blockers, otherwise the first
// clause of the rule's rationale with its issue references removed.
func delegatedPlanWhy(in delegatedecision.Input, d delegatedecision.Decision) string {
if why := delegatedPlanLandedWhy(in, d); why != "" {
return why
}
var parts []string
if in.Kind == delegatedecision.KindPR && !in.TrustedAuthor && !in.HiveAuthored && d.Verdict != delegatedecision.VerdictDirection {
who := "the author"
Expand Down Expand Up @@ -280,6 +283,23 @@ func delegatedPlanWhy(in delegatedecision.Input, d delegatedecision.Decision) st
return strings.ToUpper(why[:1]) + why[1:] + "."
}

// delegatedPlanLandedWhy is the reason when a merged PR already carries
// the change (hivecommons/hive#15732): the preview for #15544 said "Close
// #15544 as superseded by #15545" and then "Author @Karibhou is untrusted
// and their clanker is offline" β€” the right action for the wrong reason.
// The evidence is the empty diff and the merged landing; the author's
// standing never enters it. Empty for any other decision.
func delegatedPlanLandedWhy(in delegatedecision.Input, d delegatedecision.Decision) string {
if d.Rule != delegatedecision.RuleAlreadyFixed || in.SupersededBy == nil || in.SupersededBy.PR <= 0 {
return ""
}
landed := "the change already landed via #" + strconv.Itoa(in.SupersededBy.PR) + " (merged)"
if in.DiffEmpty {
return "Diff is empty β€” " + landed + "."
}
return strings.ToUpper(landed[:1]) + landed[1:] + "."
}

// delegatedPlanBlockers names what keeps a head from merging, in plain
// words: "CI is red", "it conflicts with the base branch", "the sign-off
// is missing".
Expand Down
34 changes: 34 additions & 0 deletions src/pkg/dashboard/api_repo_item_decide_delegated_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,37 @@ func TestOperatorActionFromBodyRecordsChosenButton(t *testing.T) {
t.Fatalf("%+v %v", req, ok)
}
}

// TestDelegatedPlanWhyAlreadyLandedNamesTheEvidence is
// hivecommons/hive#15732: the preview for #15544 said "Close #15544 as
// superseded by #15545" and then "Author @Karibhou is untrusted and their
// clanker is offline". A close driven by an empty diff and a merged
// landing says so, and never mentions the author's standing.
func TestDelegatedPlanWhyAlreadyLandedNamesTheEvidence(t *testing.T) {
in := delegatedecision.Input{Kind: delegatedecision.KindPR, Number: 15544, Author: "Karibhou", DiffEmpty: true,
SupersededBy: &delegatedecision.MergedCloser{PR: 15545, Issue: 15543}}
d := delegatedecision.Decision{Verdict: delegatedecision.VerdictCloseSuperseded, Rule: delegatedecision.RuleAlreadyFixed,
Actions: []delegatedecision.Action{{Kind: delegatedecision.ActionCloseDuplicate, Target: 15545}}}
if why := delegatedPlanWhy(in, d); why != "Diff is empty β€” the change already landed via #15545 (merged)." {
t.Fatalf("why %q", why)
}
summary, _ := delegatedPlanWording(in, d)
if summary != "Close #15544 as superseded by #15545." {
t.Fatalf("summary %q", summary)
}
// Trusted or not, offline or not: the reason is the evidence.
in.TrustedAuthor, in.ContributorOnline = true, false
if why := delegatedPlanWhy(in, d); strings.Contains(why, "untrusted") || strings.Contains(why, "offline") {
t.Fatalf("why mentions the author's standing: %q", why)
}
// Without the empty-diff fact the landing alone is the reason.
in.DiffEmpty = false
if why := delegatedPlanWhy(in, d); why != "The change already landed via #15545 (merged)." {
t.Fatalf("why %q", why)
}
// Any other rule keeps the author's standing as the reason.
other := delegatedecision.Input{Kind: delegatedecision.KindPR, Number: 15029, Author: "Karibhou"}
if why := delegatedPlanWhy(other, delegatedecision.Decision{Rule: "contributor-offline"}); why != "Author @Karibhou is untrusted and their clanker is offline." {
t.Fatalf("why %q", why)
}
}
5 changes: 5 additions & 0 deletions src/pkg/delegatedecision/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ type Input struct {
// work (its issue is closed by that merge, or that PR declares
// `Supersedes #N`); nil when none is known (hivecommons/hive#15289).
SupersededBy *MergedCloser
// DiffEmpty: the PR's diff against its base is empty (+0/βˆ’0, no
// changed files) β€” with SupersededBy that is the already-landed case
// (hivecommons/hive#15732), and the preview says so instead of
// talking about the author's trust.
DiffEmpty bool
// AuthorTooling: what the author drives (hive / clanker / person);
// picks the words a decision uses for them (AuthorWord).
AuthorTooling AuthorTooling
Expand Down
38 changes: 31 additions & 7 deletions src/pkg/github/automerge/automerge_stage_human.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package automerge

// Human-stage routing (hivecommons/hive#12528). When a lane's opinion is
Expand Down Expand Up @@ -138,11 +138,18 @@
hiveAuthored := (pass != nil && pass.AuthorIsApp) || obs.AuthorKind == authorkind.Hive
// A person's hold is that person's decision; the rule keeps held PRs,
// so it is not asked.
if !hiveAuthored || c.gh == nil || obs.Hold != nil {
if c.gh == nil || obs.Hold != nil {
return false
}
// Another author's PR is asked only the already-landed question, and
// only when the reviewer raised it (hivecommons/hive#15732): the
// closer then proves the landing before closing. Trust changes nothing.
landedClaimed := obs.Detail.VerdictKnown && alreadyLandedClaimed(obs.Detail.Verdict)
if !hiveAuthored && !landedClaimed {
return false
}
closer, ok := c.transport.(supersededCloserTransport)
if !ok {
if !ok && hiveAuthored {
return false
}
cacheKey := key + "@" + obs.HeadSHA
Expand All @@ -160,13 +167,16 @@
c.warn("stage labels: superseded check could not read the PR", "repo", obs.Display, "pr", obs.Number, "error", err)
return false
}
if !hiveAuthored {
return c.closeEmptyDiffBeforeHumanRoute(ctx, obs, pr, false, now)
}
res, err := closer.CloseSupersededHivePRIfEligible(ctx, obs.Owner+"/"+obs.Repo, pr)
if err != nil {
c.warn("stage labels: superseded check failed", "repo", obs.Display, "pr", obs.Number, "error", err)
return false
}
if !res.Closed {
if c.closeEmptyDiffBeforeHumanRoute(ctx, obs, pr, now) {
if c.closeEmptyDiffBeforeHumanRoute(ctx, obs, pr, true, now) {
return true
}
c.debug("stage labels: hive PR kept", "repo", obs.Display, "pr", obs.Number, "verdict", res.Verdict, "reason", res.Reason)
Expand All @@ -186,6 +196,12 @@
return review.AlreadyLandedFromVerdict(v.RedundantOf, v.DecisionQuestion, v.HumanSummaries)
}

// alreadyLandedClaimed is alreadyLandedVerdict's claimed alone.
func alreadyLandedClaimed(v ContributorLaneVerdict) bool {
_, claimed := alreadyLandedVerdict(v)
return claimed
}

// alreadyLandedCloserTransport is the optional transport hook that closes
// a hive-authored PR on the reviewer's already-landed verdict
// (hgithub.Client.CloseAlreadyLandedHivePRIfEligible; hivecommons/hive#15647).
Expand All @@ -207,8 +223,11 @@
// freshness guard, files identical on the base tip count as no diff, and
// the close settles the adoption's lineage β€” the original the copy
// superseded is closed as superseded by the same landed PR, so the orphan
// recovery does not re-adopt a head the base already has.
func (c *Engine) closeEmptyDiffBeforeHumanRoute(ctx context.Context, obs stageObservation, pr *gh.PullRequest, now time.Time) bool {
// recovery does not re-adopt a head the base already has. That entry is
// open to any author (hivecommons/hive#15732); the closer proves the
// landing. hiveAuthored is false for another author's PR, which the plain
// empty-diff rule never touches.
func (c *Engine) closeEmptyDiffBeforeHumanRoute(ctx context.Context, obs stageObservation, pr *gh.PullRequest, hiveAuthored bool, now time.Time) bool {
redundantOf, claimed := 0, false
if obs.Detail.VerdictKnown {
redundantOf, claimed = alreadyLandedVerdict(obs.Detail.Verdict)
Expand All @@ -218,6 +237,11 @@
return c.closeAlreadyLandedBeforeHumanRoute(ctx, obs, pr, landedCloser, redundantOf, now)
}
}
if !hiveAuthored {
// The sweep's empty-diff rule is the hive's own; another author's
// PR closes only on the already-landed entry above.
return false
}
closer, ok := c.transport.(emptyDiffCloserTransport)
if !ok {
return false
Expand Down Expand Up @@ -254,8 +278,8 @@
return false
}
caption, _ := stagelabels.AlreadyLandedCaption(stagelabels.AlreadyLandedReason(res.RedundantOf))
c.info("stage labels: hive PR closed as already landed instead of a human decision",
"repo", obs.Display, "pr", obs.Number, "reason", stagelabels.LaneReasonAlreadyLanded, "action", res.Reason,
c.info("stage labels: PR closed as already landed instead of a human decision",
"repo", obs.Display, "pr", obs.Number, "reason", stagelabels.AlreadyLandedAuthorReason(obs.AuthorKind), "action", res.Reason,
"redundant_of", res.RedundantOf, "issues_closed", res.IssuesClosed, "supersedes", res.Supersedes, "caption", caption, "lane_reason", obs.LaneReason)
c.settleAlreadyLandedLineage(ctx, obs, pr.GetNumber(), res.RedundantOf, res.Supersedes, now)
return true
Expand Down
119 changes: 119 additions & 0 deletions src/pkg/github/automerge/automerge_stage_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2709,3 +2709,122 @@ func TestApplyStageLabelsHiveAlreadyLandedClosesInsteadOfDecision(t *testing.T)
t.Fatal("closed copy still on the store")
}
}

// TestApplyStageLabelsAnyAuthorAlreadyLandedClosesInsteadOfDecision is
// hivecommons/hive#15732: #15544 by a trusted contributor, +0/βˆ’0 against
// v5 because #15545 (merged) carried the change, parked at 085 for 9h on
// "@clubanderson should decide whether #15544 can be closed as a no-op".
// Any author's PR with an already-landed verdict goes to the closer, which
// proves the landing; it never reaches 085. The hive's own superseded rule
// is not asked for another author's PR.
func TestApplyStageLabelsAnyAuthorAlreadyLandedClosesInsteadOfDecision(t *testing.T) {
const number, landed = 15544, 15545
cases := []struct {
name string
lane string
role stagelabels.Role
login string
}{
{"contributor", stageLaneContributor, stagelabels.RoleUntrusted, "karibhou"},
{"trusted", stageLaneTrusted, stagelabels.RoleTrusted, "karibhou"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
api := &stageAPI{}
api.extra = func(w http.ResponseWriter, r *http.Request) bool {
if r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/pulls/15544" {
_ = json.NewEncoder(w).Encode(map[string]any{"number": number, "state": "open", "user": map[string]any{"login": tc.login},
"head": map[string]any{"sha": "k1", "ref": "fix"}, "base": map[string]any{"ref": "v5"}})
return true
}
return false
}
srv := newStageAPI(t, api)
defer srv.Close()
clock := &contributorLaneClock{at: time.Date(2026, 10, 20, 3, 41, 0, 0, time.UTC)}
e, _, store := newStageEngine(t, srv.URL, clock)
e.trustedAuthorPolicy = func() TrustedAuthorPolicy { return TrustedAuthorPolicy{Enabled: true} }
e.contributorLanePolicy = func() ContributorLanePolicy { return ContributorLanePolicy{} }
stage, ok := e.transport.(stageReconcilerTransport)
if !ok {
t.Fatal("engine transport provides no stage writer")
}
spy := &alreadyLandedCloserSpy{Transport: e.transport, stage: stage, result: hgithub.HiveEmptyDiffClose{Closed: true, Empty: true, RedundantOf: landed, Reason: hgithub.SupersessionActionClosedEmptyDiff}}
e.transport = spy

pr := stagePR(number)
pr.User = &gh.User{Login: gh.Ptr(tc.login)}
e.recordStage(tc.lane, "acme/widget", "acme", "widget", pr, contributorLaneReasonNoVerdict, false, nil)
e.noteStageRole("acme", "widget", number, tc.role)
e.noteStageVerdict("acme", "widget", number, ContributorLaneVerdict{Configured: true, Verdict: "requires_human", DecisionRequested: true,
DecisionQuestion: "@clubanderson should decide whether #15544 can be closed as a no-op now that #15545 (merged) carries this change"})
res, err := e.ApplyStageLabels(context.Background())
if err != nil {
t.Fatal(err)
}
if res.ClosedSuperseded != 1 {
t.Fatalf("ClosedSuperseded=%d want 1", res.ClosedSuperseded)
}
for _, batch := range api.added {
if slices.Contains(batch, "stage/085-needs-decision") {
t.Fatalf("already-landed %s PR routed to 085: added=%v", tc.name, api.added)
}
}
if !reflect.DeepEqual(spy.landedCalls, []int{number}) || !reflect.DeepEqual(spy.redundantOf, []int{landed}) {
t.Fatalf("already-landed closer calls=%v redundant_of=%v", spy.landedCalls, spy.redundantOf)
}
if len(spy.supersededCalls) != 0 {
t.Fatalf("the hive's own superseded rule asked about a %s PR: %v", tc.name, spy.supersededCalls)
}
if _, ok := store.Get(stageKey("acme", "widget", number)); ok {
t.Fatal("closed PR still on the store")
}
})
}
}

// TestApplyStageLabelsAnyAuthorAlreadyLandedKeptStillParks: when the closer
// keeps a contributor PR (a real diff, an unproven landing) the decision
// goes to a person as before.
func TestApplyStageLabelsAnyAuthorAlreadyLandedKeptStillParks(t *testing.T) {
const number = 15544
api := &stageAPI{}
api.extra = func(w http.ResponseWriter, r *http.Request) bool {
if r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/pulls/15544" {
_ = json.NewEncoder(w).Encode(map[string]any{"number": number, "state": "open", "user": map[string]any{"login": "karibhou"},
"head": map[string]any{"sha": "k1", "ref": "fix"}, "base": map[string]any{"ref": "v5"}})
return true
}
return false
}
srv := newStageAPI(t, api)
defer srv.Close()
clock := &contributorLaneClock{at: time.Date(2026, 10, 20, 3, 41, 0, 0, time.UTC)}
e, _, _ := newStageEngine(t, srv.URL, clock)
e.trustedAuthorPolicy = func() TrustedAuthorPolicy { return TrustedAuthorPolicy{Enabled: true} }
e.contributorLanePolicy = func() ContributorLanePolicy { return ContributorLanePolicy{} }
stage, _ := e.transport.(stageReconcilerTransport)
spy := &alreadyLandedCloserSpy{Transport: e.transport, stage: stage, result: hgithub.HiveEmptyDiffClose{Verdict: "keep", Reason: "has-diff"}}
e.transport = spy

pr := stagePR(number)
pr.User = &gh.User{Login: gh.Ptr("karibhou")}
e.recordStage(stageLaneContributor, "acme/widget", "acme", "widget", pr, contributorLaneReasonNoVerdict, false, nil)
e.noteStageRole("acme", "widget", number, stagelabels.RoleUntrusted)
e.noteStageVerdict("acme", "widget", number, ContributorLaneVerdict{Configured: true, Verdict: "requires_human", DecisionRequested: true,
DecisionQuestion: "@clubanderson should decide whether #15544 can be closed as a no-op now that #15545 (merged) carries this change"})
res, err := e.ApplyStageLabels(context.Background())
if err != nil {
t.Fatal(err)
}
if res.ClosedSuperseded != 0 || !reflect.DeepEqual(spy.landedCalls, []int{number}) {
t.Fatalf("ClosedSuperseded=%d landedCalls=%v", res.ClosedSuperseded, spy.landedCalls)
}
parked := false
for _, batch := range api.added {
parked = parked || slices.Contains(batch, "stage/085-needs-decision")
}
if !parked {
t.Fatalf("kept contributor PR must still reach 085: added=%v", api.added)
}
}
Loading
Loading