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-same-issue-claim-conflict-gate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Merge queue holds every open PR claiming an issue that another open PR in a different automerge lane also claims (the hive's own PR vs a trusted human's PR for one issue) until a decision is recorded β€” lane reason `merge-train:claim-conflict#<other>:<issue>`, log `same-issue claim conflict undecided: #A vs #B`, tracker chevron "held Β· duplicate of #B Β· needs decision", and a delegate plan that names the concrete PRs to keep and close instead of "all 2 PRs" (hivecommons/hive#15810).
22 changes: 22 additions & 0 deletions src/docs/hive-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,28 @@ contributor task already dispatched on it (see
[operator-reference.md Β§ Open-PR dispatch guard](operator-reference.md#open-pr-dispatch-guard-and-duplicate-fix-sweep-scanner)),
so the hive does not open the second PR in the first place.

The duplicate pick above sees one lane at a time. When the two PRs sit in
**different lanes** β€” the hive's own PR in the self lane and a trusted
human's PR in the trusted lane both closing one issue, as #15783 and
#15793 did for #15773 β€” neither lane's winner rule saw the other and both
marched toward merge. Every lane therefore also runs a **same-issue claim
gate** before its trains are grouped: a candidate whose closing issue any
other open PR of the repository also claims (`Fixes`/`Closes`/`Resolves`;
a `Refs` line is not a claim; an adoption copy and the original it
`Supersedes` are one change, not a pair) is held with lane reason
`merge-train:claim-conflict#<other>:<issue>/0:0/0:` and the log line
`same-issue claim conflict undecided: #A vs #B` β€” in every lane, so
**neither PR is admitted** while the conflict stands. The hive does not
pick: the stage engine parks the held PR at 085, the tracker chevron reads
*held Β· duplicate of #B Β· needs decision*, the row's options name the
concrete PRs (*Keep #A β€” admit it to the merge queue*, *Close #A as
superseded by #B*), and *Let hive decide* only recommends ("Hold both: #A
and #B claim issue #N. Keep #B, close #A β€” or keep #A, close #B"). A
recorded trusted decision on a PR's head (the tracker's Approve, or any
`/hive decision` on it β€” the downstream gates still judge the merge) is
what lifts the gate for that PR; closing the other ends it
([#15810](https://github.com/hivecommons/hive/issues/15810)).

### Empty-diff PRs of the hive's own

A PR of the hive's own (the App's, or an adoption it opened) whose diff
Expand Down
2 changes: 1 addition & 1 deletion src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ advanced into the merge path.
| `auto_merge.require_current_base_default` | `false` | Hive-wide default of the current-base gate for repos in neither `require_current_base` nor `skip_current_base` (Settings β†’ Features β†’ Auto-merge β†’ "Merge only on current base"). **Off** by default: the merge train already update-branches overlapping siblings, so the gate is being soaked per repo (hive's own hive first, via `require_current_base`) before any hive turns it on everywhere. When `true`, a behind head the App cannot update merges as it was tested, with one WARN per PR (`automerge current-base gate: … merging as tested`), so fork-heavy repos are not parked wholesale. |
| `auto_merge.skip_current_base` | unset | Repo list (`owner/repo`) with an explicit **off** override for the current-base gate (Settings β†’ Repos β†’ "Merge only on current base" unchecked): a green head there merges even if the base has moved, whatever `require_current_base_default` says. An explicit `require_current_base` entry wins over this list. |
| `auto_merge.merge_forward_trusted_human` | unset (off) | Repo list (`owner/repo`) where a `role/trusted` + `author/human` PR on a same-repo branch that GitHub reports as conflicting (`dirty`) gets the base merged into its head as one App-authored, signed-off merge commit via the GitHub merges API (no human commit is rewritten), then merges once CI is green on the new head. A real conflict pushes nothing and posts one `<!-- hive:merge-forward-conflict head=… -->` note naming the files both sides changed. Fork heads are never written. Attempted once per head (#13636). |
| `auto_merge.merge_train.enabled` | `true` | Conflict-aware merge train in every automerge lane (hive, trusted-author, contributor) ([#15117](https://github.com/hivecommons/hive/issues/15117)). Each sweep groups the open approved / mergeable-pending PRs of one repo+base by overlapping changed files (`GET /pulls/{n}/files`, cached per head SHA) and lets ONE front per group merge β€” ordered readiness first: a head the lane last saw at the merge gate (green, approved, soaking or waiting on a sweep) leads, one it has not evaluated since its push comes next, one still at CI / Review trails, then clean-mergeable before behind, then oldest; recomputed every pass, so a member that turns green moves up and one that turns red moves back β€” while the others wait at stage/080 with lane reason `merge-train:queued-behind#<front>:<pos>/<size>:…` (tracker pill "In merge queue Β· 3 of 4 Β· ~4m", never a human stage, never `needs-rebase` as a human flag). The moment the front merges, every sibling whose branch is merely `behind` gets `PUT /pulls/{n}/update-branch`; a `dirty` one is handed to the fixer's rebase-resolve episode (`requested_by: merge-train`, the shared two-attempt guard of [#15104](https://github.com/hivecommons/hive/pull/15104); the fixer router still requires a head the hive can push to, so a fork without maintainer edits stays on the plain `conflicting` path for a person). A head the lane last saw blocked on its own (red required check, terminal hold, permanent merge refusal) never fronts, and a group whose best member is blocked imposes no ordering (fail-open) β€” nobody waits behind a PR that is not moving. One INFO line `merge train` per order change, not per cycle. The queue carries one PR per issue: when two open PRs declare the same `Fixes #N`, the sweep keeps one (green first, then the earlier-opened) and holds the other with lane reason `merge-train:duplicate-of#<winner>:<issue>/0:0/0:` (tracker pill "Duplicate of #15402 Β· needs a pick"; *Let hive decide* supersedes, [#15395](https://github.com/hivecommons/hive/issues/15395)). `false` restores independent per-PR evaluation. A PR GitHub reports conflicting on its own, or one at stage/072 returned-to-contributor (label or stage record), is never a member nor counted in the train's size and draws no train idle comment; a conflicting PR rides only while the train itself is repairing it (its rebase requested behind a merged front, loop guard not spent) ([#15395](https://github.com/hivecommons/hive/issues/15395)). |
| `auto_merge.merge_train.enabled` | `true` | Conflict-aware merge train in every automerge lane (hive, trusted-author, contributor) ([#15117](https://github.com/hivecommons/hive/issues/15117)). Each sweep groups the open approved / mergeable-pending PRs of one repo+base by overlapping changed files (`GET /pulls/{n}/files`, cached per head SHA) and lets ONE front per group merge β€” ordered readiness first: a head the lane last saw at the merge gate (green, approved, soaking or waiting on a sweep) leads, one it has not evaluated since its push comes next, one still at CI / Review trails, then clean-mergeable before behind, then oldest; recomputed every pass, so a member that turns green moves up and one that turns red moves back β€” while the others wait at stage/080 with lane reason `merge-train:queued-behind#<front>:<pos>/<size>:…` (tracker pill "In merge queue Β· 3 of 4 Β· ~4m", never a human stage, never `needs-rebase` as a human flag). The moment the front merges, every sibling whose branch is merely `behind` gets `PUT /pulls/{n}/update-branch`; a `dirty` one is handed to the fixer's rebase-resolve episode (`requested_by: merge-train`, the shared two-attempt guard of [#15104](https://github.com/hivecommons/hive/pull/15104); the fixer router still requires a head the hive can push to, so a fork without maintainer edits stays on the plain `conflicting` path for a person). A head the lane last saw blocked on its own (red required check, terminal hold, permanent merge refusal) never fronts, and a group whose best member is blocked imposes no ordering (fail-open) β€” nobody waits behind a PR that is not moving. One INFO line `merge train` per order change, not per cycle. The queue carries one PR per issue: when two open PRs declare the same `Fixes #N`, the sweep keeps one (green first, then the earlier-opened) and holds the other with lane reason `merge-train:duplicate-of#<winner>:<issue>/0:0/0:` (tracker pill "Duplicate of #15402 Β· needs a pick"; *Let hive decide* supersedes, [#15395](https://github.com/hivecommons/hive/issues/15395)). That pick sees one lane; when the two claimants sit in different lanes (the hive's own PR and a trusted human's PR for one issue) every lane holds its candidate with lane reason `merge-train:claim-conflict#<other>:<issue>/0:0/0:` and the log line `same-issue claim conflict undecided: #A vs #B`, so neither is admitted until a decision is recorded on one head or the other PR closes β€” the PR parks at 085, the chevron reads "held Β· duplicate of #B Β· needs decision", and the row's options name the concrete PRs; the hive recommends and never picks ([#15810](https://github.com/hivecommons/hive/issues/15810)). `false` restores independent per-PR evaluation. A PR GitHub reports conflicting on its own, or one at stage/072 returned-to-contributor (label or stage record), is never a member nor counted in the train's size and draws no train idle comment; a conflicting PR rides only while the train itself is repairing it (its rebase requested behind a merged front, loop guard not spent) ([#15395](https://github.com/hivecommons/hive/issues/15395)). |
| `auto_merge.merge_train.max_rebase_attempts` | `2` | Loop guard: how many rebase-resolve requests the train makes for one PR behind one front. Past it the PR moves to stage/085 with the pill "Needs human decision Β· rebase failed twice" and the decision option "Rebase, then merge as maintainer". |
| `auto_merge.native_merge_queue.enabled` | `false` | Opt-in: once the lane's gates pass, enqueue the PR into GitHub's native merge queue (App auth only) instead of merging directly, and withdraw only Hive's own entries when the PR loses eligibility ([#15198](https://github.com/hivecommons/hive/issues/15198)). Off keeps the pre-queue behaviour everywhere, including the `merge-queue-required` park. See [native-merge-queue.md](native-merge-queue.md). |
| `auto_merge.native_merge_queue.repos` | unset (every watched repo once enabled) | `owner/repo` allow-list for the hand-off, matched case-insensitively. |
Expand Down
11 changes: 11 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 @@ -187,6 +187,17 @@ func delegatedPlanWording(in delegatedecision.Input, d delegatedecision.Decision
}
}
switch {
case d.Rule == delegatedecision.RuleSameIssueClaimConflict && in.ClaimConflictWith > 0:
other := "#" + strconv.Itoa(in.ClaimConflictWith)
issue := "the same issue"
if in.ClaimConflictIssue > 0 {
issue = "issue #" + strconv.Itoa(in.ClaimConflictIssue)
}
return "Hold both: " + ref + " and " + other + " claim " + issue + ". Keep " + other + ", close " + ref + " β€” or keep " + ref + ", close " + other + "; the hive will not pick.",
[]string{
"Neither PR merges until one of them is closed or approved.",
"Approve on a row admits that PR to the merge queue; Close as superseded on the other closes it with credit.",
}
case d.Verdict == delegatedecision.VerdictAdoptSupersede:
return "Re-open " + ref + " as hive's own PR with the same commits and merge that; close " + ref + " as superseded.",
[]string{
Expand Down
17 changes: 16 additions & 1 deletion src/pkg/dashboard/delegated_pr_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,28 @@ func (s *Server) gatherDelegatedPRContext(ctx context.Context, repo string, pr *
})
}
in.TrainDuplicateOf, in.TrainDuplicateIssue = delegatedTrainDuplicate(s.stageStoreOrShared(), repo, pr.GetNumber())
in.ClaimConflictWith, in.ClaimConflictIssue = delegatedClaimConflict(s.stageStoreOrShared(), repo, pr.GetNumber())
return nil
}

// delegatedClaimConflict reads the stage store for the cross-lane
// same-issue hold the merge queue recorded on a PR
// (hivecommons/hive#15810): the other claimant and the shared issue, 0
// when it is not held.
func delegatedClaimConflict(store *stagelabels.Store, repo string, number int) (other, issue int) {
return delegatedTrainState(store, repo, number, prstage.MergeTrainStateClaimConflict)
}

// delegatedTrainDuplicate reads the stage store for the one-PR-per-issue
// hold the merge queue recorded on a PR (hivecommons/hive#15395): the PR
// it yields to and the shared issue, 0 when it is not held.
func delegatedTrainDuplicate(store *stagelabels.Store, repo string, number int) (winner, issue int) {
return delegatedTrainState(store, repo, number, prstage.MergeTrainStateDuplicateOf)
}

// delegatedTrainState is the front and position of the merge-train reason
// recorded on a PR when its state is state, 0,0 otherwise.
func delegatedTrainState(store *stagelabels.Store, repo string, number int, state string) (int, int) {
if store == nil {
return 0, 0
}
Expand All @@ -146,7 +161,7 @@ func delegatedTrainDuplicate(store *stagelabels.Store, repo string, number int)
return 0, 0
}
mt, ok := prstage.ParseMergeTrain(rec.Reason)
if !ok || mt.State != prstage.MergeTrainStateDuplicateOf {
if !ok || mt.State != state {
return 0, 0
}
return mt.Front, mt.Position
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/dashboard/stage_tracker_build.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dashboard

import (
Expand Down Expand Up @@ -174,6 +174,9 @@
if c := stageTrackerSoakCaption(rec, now); c != "" {
it.Caption = c
}
if c := stageTrackerClaimConflictCaption(it); c != "" {
it.Caption, it.Actor = c, StageActorHuman
}
if hasRec && rec.Stage != stagelabels.None {
if at := stageTrackerNoteChangedAt(rec, now); !at.IsZero() {
it.NoteChangedAt = &at
Expand Down
87 changes: 87 additions & 0 deletions src/pkg/dashboard/stage_tracker_claim_conflict_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package dashboard

import (
"slices"
"strings"
"testing"
"time"

"github.com/hivecommons/hive/pkg/delegatedecision"
"github.com/hivecommons/hive/pkg/stageengine/prstage"
"github.com/hivecommons/hive/pkg/stagelabels"
)

// hivecommons/hive#15810: a PR the merge queue holds because an open PR in
// another lane claims the same issue reads "claim-conflict:<other>" on the
// gate, rides no train, captions "held Β· duplicate of #<other> Β· needs
// decision", and its decision options name both PRs β€” never "all N PRs".
func TestStageTrackerApplyClaimConflict(t *testing.T) {
reason := prstage.MergeTrain{State: prstage.MergeTrainStateClaimConflict, Front: 15793, Position: 15773}.Reason()
it := StageTrackerItem{Repo: "hivecommons/hive", Kind: "pr", Number: 15783, Stage: 85, BaseRef: "v5", Reason: reason}
stageTrackerApplyMergeTrain(&it)
if it.MergeTrain != nil {
t.Fatalf("a held claimant rides no train: %+v", it.MergeTrain)
}
if it.MergeGate == nil || it.MergeGate.State != "claim-conflict:15793" || it.MergeGate.DuplicateOf != 15793 || it.MergeGate.DuplicateIssue != 15773 {
t.Fatalf("gate = %+v", it.MergeGate)
}
if !slices.Contains(it.Modifiers, modNeedsDecision) {
t.Fatalf("modifiers = %v", it.Modifiers)
}
if c := stageTrackerClaimConflictCaption(&it); c != "held Β· duplicate of #15793 Β· needs decision" {
t.Fatalf("caption = %q", c)
}
d := stageTrackerDecisionNeededAt(it, nil, "", time.Now())
if d == nil || !strings.Contains(d.Question, "#15783 and #15793 both claim issue #15773") {
t.Fatalf("decision = %+v", d)
}
labels := make([]string, 0, len(d.Options))
for _, o := range d.Options {
labels = append(labels, o.Label)
}
if !slices.Contains(labels, "Keep #15783 β€” admit it to the merge queue") || !slices.Contains(labels, "Close #15783 as superseded by #15793") {
t.Fatalf("options = %v", labels)
}
for _, l := range labels {
if strings.Contains(l, "all 2") {
t.Fatalf("generic option %q", l)
}
}

// The other row β€” a plain duplicate-of hold β€” is untouched by the
// claim-conflict caption.
dup := StageTrackerItem{Kind: "pr", Number: 15407, Reason: prstage.MergeTrain{State: prstage.MergeTrainStateDuplicateOf, Front: 15402, Position: 15396}.Reason()}
stageTrackerApplyMergeTrain(&dup)
if c := stageTrackerClaimConflictCaption(&dup); c != "" {
t.Fatalf("duplicate-of caption = %q", c)
}
}

// The delegate's plan for a held claimant names the concrete PRs and the
// two ways out instead of "all 2 PRs", and only recommends.
func TestDelegatedPlanWordingClaimConflictNamesPRs(t *testing.T) {
now := time.Date(2026, 11, 3, 15, 0, 0, 0, time.UTC)
store := stagelabels.NewStore("", func() time.Time { return now })
store.Observe(stagelabels.Key("hivecommons/hive", 15783), stagelabels.NeedsDecision,
prstage.MergeTrain{State: prstage.MergeTrainStateClaimConflict, Front: 15793, Position: 15773}.Reason())
other, issue := delegatedClaimConflict(store, "hivecommons/hive", 15783)
if other != 15793 || issue != 15773 {
t.Fatalf("store read = #%d issue #%d", other, issue)
}
if w, _ := delegatedTrainDuplicate(store, "hivecommons/hive", 15783); w != 0 {
t.Fatal("a claim conflict is not the duplicate-of pick")
}

in := delegatedecision.Input{Kind: delegatedecision.KindPR, Number: 15783, HiveAuthored: true, CIGreen: true, ClaimConflictWith: other, ClaimConflictIssue: issue}
d := delegatedecision.Decide(in)
if d.Verdict != delegatedecision.VerdictRecommendOnly || d.Rule != delegatedecision.RuleSameIssueClaimConflict {
t.Fatalf("verdict %s rule %s", d.Verdict, d.Rule)
}
summary, next := delegatedPlanWording(in, d)
if summary != "Hold both: #15783 and #15793 claim issue #15773. Keep #15793, close #15783 β€” or keep #15783, close #15793; the hive will not pick." {
t.Fatalf("summary %q", summary)
}
if len(next) != 2 || strings.Contains(summary, "all 2") {
t.Fatalf("then %v", next)
}
}
2 changes: 2 additions & 0 deletions src/pkg/dashboard/stage_tracker_decision.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ func stageTrackerDecisionNeededWith(it StageTrackerItem, verdict *review.Aggrega
switch {
case it.Kind == "pr" && it.MergeTrain != nil && it.MergeTrain.State == MergeGateStateRebaseExhausted:
return decisionForMergeTrain(it, held)
case it.Kind == "pr" && it.MergeGate != nil && mergeGateClaimConflictOf(it.MergeGate.State) > 0:
return decisionForClaimConflict(it, held)
case it.Kind == "issue" && it.Blocker != nil && !it.Mirrored && (slices.Contains(it.Modifiers, modNeedsHuman) || it.Stage == stagelabels.IssueNeedsDecision.Number() || slices.Contains(it.Modifiers, modNeedsDecision)):
// A structured blocker outranks the generic park wording: the
// person is not being asked to decide, the hive is saying what it
Expand Down
Loading
Loading