From 5e0c526c97e3a4b4f342d8989b9d360bca6b4b1f Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 17:57:22 -0400 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20fix:=20exclude=20relay-refus?= =?UTF-8?q?ed=20contributor=20PRs=20from=20merge-eligible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-merge-eligible-lane-gate.md | 1 + src/cmd/hive/main.go | 2 + src/cmd/hive/merge_eligibility.go | 48 +++++++++++++++ src/cmd/hive/merge_eligible_lane_gate_test.go | 60 +++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 changelog.d/fixed-merge-eligible-lane-gate.md create mode 100644 src/cmd/hive/merge_eligible_lane_gate_test.go diff --git a/changelog.d/fixed-merge-eligible-lane-gate.md b/changelog.d/fixed-merge-eligible-lane-gate.md new file mode 100644 index 0000000000..7c9eee3de6 --- /dev/null +++ b/changelog.d/fixed-merge-eligible-lane-gate.md @@ -0,0 +1 @@ +The merge-eligible list no longer includes contributor PRs the merge relay's contributor-lane policy refuses (for example newcomer-tier authors), so agents stop wasting a hive-merge attempt on them every kick. diff --git a/src/cmd/hive/main.go b/src/cmd/hive/main.go index 4bdb162700..0f5c542e79 100644 --- a/src/cmd/hive/main.go +++ b/src/cmd/hive/main.go @@ -2571,6 +2571,8 @@ func (b *boot) bootAgentsWith(deps bootAgentsDeps) { return b.cfg != nil && b.cfg.AutoMerge.MergeForwardTrustedHumanFor(repo) } b.requestRelays = newRequestRelaySupervisor(b.ctx, func(ctx context.Context, client *github.Client) <-chan struct{} { + laneGate := relayLanePolicyGate(autoMergeOpts)(client) + setMergeEligibleLaneGate(laneGate) relaysDone := deps.startRequestRelays(ctx, client, requestRelays{ prOpen: b.agentMgr.AuthorizePROpen, holdLabel: holdLabel, diff --git a/src/cmd/hive/merge_eligibility.go b/src/cmd/hive/merge_eligibility.go index 72117450ca..f11309723f 100644 --- a/src/cmd/hive/merge_eligibility.go +++ b/src/cmd/hive/merge_eligibility.go @@ -1,11 +1,13 @@ package main import ( + "context" "encoding/json" "fmt" "log/slog" "os" "strings" + "sync" "time" "github.com/hivecommons/hive/pkg/config" @@ -392,6 +394,46 @@ func relayLanePolicyGate(opts automerge.Options) func(*github.Client) github.Mer } } +var ( + mergeEligibleLaneGateMu sync.RWMutex + mergeEligibleLaneGate github.MergeRequestPolicyGate +) + +// setMergeEligibleLaneGate installs the lane-policy gate the merge relay +// uses so the merge-eligible classifier asks the same question. +func setMergeEligibleLaneGate(g github.MergeRequestPolicyGate) { + mergeEligibleLaneGateMu.Lock() + mergeEligibleLaneGate = g + mergeEligibleLaneGateMu.Unlock() +} + +// relayLaneRefusal returns the contributor-lane refusal the merge relay would +// give for pr, or "" when the relay would let it through. A PR the relay +// refuses must not be listed merge-eligible: hive-merge on it is a wasted +// attempt every kick, and the contributor lane merges it itself when ready. +// It reuses the relay's gate (automerge.Engine.RelayMergeRefusal) rather than +// restating the rule. Hive-authored PRs bypass the lane, and an unreadable +// gate leaves the PR listed — the relay still re-checks it at merge time. +func relayLaneRefusal(pr github.PullRequest, fullRepo string, logger *slog.Logger) string { + mergeEligibleLaneGateMu.RLock() + gate := mergeEligibleLaneGate + mergeEligibleLaneGateMu.RUnlock() + if gate == nil || hiveAuthoredPR(pr) { + return "" + } + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + refusal, err := gate(ctx, fullRepo, pr.Number, pr.HeadSHA) + if err != nil { + logger.Warn("merge-eligible lane gate could not evaluate PR; leaving it listed", "repo", fullRepo, "number", pr.Number, "error", err) + return "" + } + if refusal != "" { + logger.Info("excluding PR from merge-eligible: contributor lane refuses the merge relay", "repo", fullRepo, "number", pr.Number, "refusal", refusal) + } + return refusal +} + // mergeableJSON renders a tri-state mergeability verdict for the // merge-eligible.json marker, mapping the unknown zero value to an explicit // "unknown" rather than an empty string. @@ -1037,6 +1079,12 @@ func writeMergeEligible(actionable *github.ActionableResult, hold github.HoldRes adopted := adoptedInPlace(fullRepo, pr.Number) prGates.adopted = adopted bucket, verdict, intentReason := classifyMergeEligibility(pr, held, fullRepo, prGates) + if bucket == mergeBucketEligible { + if refusal := relayLaneRefusal(pr, fullRepo, logger); refusal != "" { + bucket = mergeBucketSkip + verdict = github.MergeVerdict{State: github.MergeVerdictOutstanding, Reason: refusal} + } + } verdicts[github.MergeVerdictKey(pr)] = verdict if intentReason != "" { iv := intentVerdicts[fmt.Sprintf("%s/%d", fullRepo, pr.Number)] diff --git a/src/cmd/hive/merge_eligible_lane_gate_test.go b/src/cmd/hive/merge_eligible_lane_gate_test.go new file mode 100644 index 0000000000..95b7d3308c --- /dev/null +++ b/src/cmd/hive/merge_eligible_lane_gate_test.go @@ -0,0 +1,60 @@ +package main + +import ( + "context" + "encoding/json" + "os" + "path/filepath" + "testing" + + "github.com/hivecommons/hive/pkg/github" +) + +// A PR the merge relay's contributor-lane gate refuses (a newcomer-tier +// author) must not be listed merge-eligible: hive-merge on it is refused +// every kick. +func TestWriteMergeEligible_ExcludesPRsTheRelayLaneRefuses(t *testing.T) { + origMerge, origFail := mergeEligiblePath, ciFailingPath + dir := t.TempDir() + mergeEligiblePath = filepath.Join(dir, "merge-eligible.json") + ciFailingPath = filepath.Join(dir, "ci-failing.json") + t.Cleanup(func() { + mergeEligiblePath = origMerge + ciFailingPath = origFail + setMergeEligibleLaneGate(nil) + }) + setMergeEligibleLaneGate(func(_ context.Context, _ string, number int, _ string) (string, error) { + if number == 15086 { + return "contributor-lane policy refuses the merge relay for @Karibhou's PR: contributor-lane:claim-tier-untrusted (author tier \"newcomer\", require_tiers merger, trusted)", nil + } + return "", nil + }) + + green := func(number int, author string) github.PullRequest { + return github.PullRequest{Repo: "hive", Number: number, Author: author, CIStatus: "success", Mergeable: github.MergeableYes, HeadSHA: "cafe"} + } + actionable := &github.ActionableResult{PRs: github.PRResult{Items: []github.PullRequest{ + green(15086, "Karibhou"), + green(15087, "trusted-human"), + }}} + verdicts := writeMergeEligible(actionable, github.HoldResult{}, "hivecommons", nil, false, nil, false, nil, nil, nil, discardLogger()) + + data, err := os.ReadFile(mergeEligiblePath) + if err != nil { + t.Fatal(err) + } + var out struct { + Eligible []struct { + Number int `json:"number"` + } `json:"merge_eligible"` + } + if err := json.Unmarshal(data, &out); err != nil { + t.Fatal(err) + } + if len(out.Eligible) != 1 || out.Eligible[0].Number != 15087 { + t.Fatalf("merge_eligible = %+v, want only #15087", out.Eligible) + } + if v := verdicts[github.MergeVerdictKey(actionable.PRs.Items[0])]; v.State == github.MergeVerdictEligible { + t.Fatalf("refused PR verdict = %+v, want not eligible", v) + } +} From c2fc2f8c066e0b072302de496a4c934067f5c33d Mon Sep 17 00:00:00 2001 From: "hivecommons-hive[bot]" <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:59:01 +0000 Subject: [PATCH 2/3] changelog: fragment for #15129 Generated by changelog-fragment-guard from the PR title (#5675). Edit the wording freely, or replace this file with the no-changelog label if the change is not user-visible. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: hivecommons-hive[bot] <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-15129.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/fixed-15129.md diff --git a/changelog.d/fixed-15129.md b/changelog.d/fixed-15129.md new file mode 100644 index 0000000000..8a57ef302d --- /dev/null +++ b/changelog.d/fixed-15129.md @@ -0,0 +1 @@ +- fix: exclude relay-refused contributor PRs from merge-eligible (#15129) From 53ce6bf01c6dc2bf610d4cd75aa1efde18b8ee90 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 18:45:00 -0400 Subject: [PATCH 3/3] changelog: fold fragments into one bullet entry for #15129 The guard requires a fragment to start with a '- ' bullet; the prose-only fixed-merge-eligible-lane-gate.md failed it. Merge both fragments into changelog.d/fixed-15129.md. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-15129.md | 2 +- changelog.d/fixed-merge-eligible-lane-gate.md | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 changelog.d/fixed-merge-eligible-lane-gate.md diff --git a/changelog.d/fixed-15129.md b/changelog.d/fixed-15129.md index 8a57ef302d..b1eab3eb65 100644 --- a/changelog.d/fixed-15129.md +++ b/changelog.d/fixed-15129.md @@ -1 +1 @@ -- fix: exclude relay-refused contributor PRs from merge-eligible (#15129) +- The merge-eligible list no longer includes contributor PRs the merge relay's contributor-lane policy refuses (for example newcomer-tier authors), so agents stop wasting a `hive merge` attempt on them every kick ([#15093](https://github.com/hivecommons/hive/issues/15093), [#15129](https://github.com/hivecommons/hive/pull/15129)). diff --git a/changelog.d/fixed-merge-eligible-lane-gate.md b/changelog.d/fixed-merge-eligible-lane-gate.md deleted file mode 100644 index 7c9eee3de6..0000000000 --- a/changelog.d/fixed-merge-eligible-lane-gate.md +++ /dev/null @@ -1 +0,0 @@ -The merge-eligible list no longer includes contributor PRs the merge relay's contributor-lane policy refuses (for example newcomer-tier authors), so agents stop wasting a hive-merge attempt on them every kick.