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-15825-merge-train-ready-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The merge train now seats only PRs whose current head is green with every required review verdict recorded, mergeable and not held; a PR short of that is a candidate without a position and never the front. A member whose head moves, whose CI goes pending or red, who owes a verdict again or who conflicts is ejected on the next evaluation (`merge train: member ejected pr=N why=…`), the next ready member fronts, and the ejected PR re-enters at the back once ready. The stage engine and the Activity Monitor keep such PRs below stage 080 — in the CI / Review column, never the Merge queue column — with a caption naming what is owed and a gray "left merge train" lineage pill. A member being rebased shows "Rebasing · attempt 1/2" in the CI / Review column; the train header counts seated members only; a seated row always names its seat rather than "Ready for auto merge · checking now", which now applies only to the PR the sweep is evaluating ([#15825](https://github.com/hivecommons/hive/issues/15825)).
27 changes: 27 additions & 0 deletions src/docs/hive-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,33 @@ merged until its checks finished. In the Activity Monitor only members at
at CI / Review keeps its chevron in its own column with a muted
"train · joins behind #N when green" note.

**Membership is ready-only** ([#15825](https://github.com/hivecommons/hive/issues/15825)).
The rule: *items that have not passed the review or CI is not green should
not be (a) ready for merge, (b) in a merge train.* A PR takes a seat only
while its **current head** is green, has every required perspective
verdict recorded, is mergeable, not conflicting and not held. A PR that
shares files with a train but is short of that is a *candidate*: the
tracker keeps the overlap note, but it holds no position and is never the
front. A member that regresses — new push (head moved), CI pending or red,
a verdict owed again, a conflict with the base — is **ejected** on the
next evaluation (one INFO line `merge train: member ejected pr=N
why=head-moved|ci-pending|ci-red|verdict-owed|conflicting`), the next
ready member fronts and merges, and the ejected PR re-enters at the back
once it is ready again. Its tracker row drops back to the CI / Review
column (never the *Merge queue* column) with a caption that says what is
owed ("left the merge train — new push, CI re-running after push") and a
gray lineage pill ("left merge train · pushed 3m ago"). Among ready
members the order is the readiness tiers above, then age. The one
exception is a member the train itself made dirty by merging the front
ahead of it: it keeps its seat (trailing every clean member) while the
resolver rebases it, so the rebase keeps its place in line. Its row still
shows in the CI / Review column while the rebase runs ("Rebasing · attempt
1/2"): the rebased head has no CI or verdicts yet. The tracker's train
header counts seated members only — a candidate or an ejected row never
adds to "merge train · N PRs" — and a seated row always reads its seat
("Merge train · 2nd of 2 · behind #15771"); "checking now" is said only
of the PR the sweep is evaluating at that moment.

### Trusted-author auto-merge

`auto_merge.trusted_authors` is a third, default-off sweep tier for
Expand Down
2 changes: 2 additions & 0 deletions src/docs/labels-and-control-signals/stage-labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ stateDiagram-v2
s060 --> s080: CI green, author side done
s080 --> s095: lane admits, soak window running
s080 --> s100: lane admits, no soak / soak already complete
s080 --> s070: current head red, changes requested or being rebased by the train (hivecommons/hive#15825; backward hop)
s080 --> s050: new push: CI and verdicts owed again on the current head (hivecommons/hive#15825; backward hop)
s095 --> s100: soak complete
s100 --> s095: pre-095 record reclassified while still soaking (not a regression)
s050 --> s070: hive PR red / changes requested
Expand Down
6 changes: 6 additions & 0 deletions src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ type StageTrackerItem struct {
// behalf: which attempt of the loop guard this is, or that the hive
// ran out and a person must resolve it.
Rebase *StageTrackerRebase `json:"rebase,omitempty"`
// ciRed is the listing's CI verdict on the current head (failure or
// named failing checks), unexported: the merge train view drops such
// a row from its train (hivecommons/hive#15825) whatever its record
// says — a header read "8 PRs" over seven seats because a red 090
// row was counted.
ciRed bool
// SentinelAlert is true on a PR the suspicious-activity sentinel flagged:
// it wears the configured alert label (sentinel.label, default
// sentinel-alert) or the review evidence bundle for its current head
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/dashboard/stage_tracker_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
if pushed {
it.Adoption = nil
}
stageTrackerApplyTrainEjection(it, rec, hasRec, now)
if login := stageTrackerWaitingOn(*it, stage); login != "" && !pushed {
it.Presence = stageTrackerPresenceFor(*it, login, stage, rec, hasRec, presence, adoptionClock, now)
it.Rework = stageTrackerReworkFor(*it, login, stage, rec, hasRec, fixWork, now)
Expand Down Expand Up @@ -363,6 +364,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
Bucket: bucket, BucketReason: bucketReason,
URL: overviewItemURL(pr.URL, pr.Repo, pr.Number, "pr", status.GitHubBaseURL)}
it.BaseRef = pr.BaseRef
it.ciRed = strings.EqualFold(pr.CIStatus, "failure") || len(pr.FailingChecks) > 0
it.AuthorKind, it.AuthorKindSource = stageTrackerAuthorKind(pr.Labels, pr.Author, pr.AppAuthored, pr.HiveAttributed)
if it.AuthorKindSource == authorKindSrcLabel {
resp.AuthorKindLabels = true
Expand Down
82 changes: 82 additions & 0 deletions src/pkg/dashboard/stage_tracker_merge_train.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dashboard

import (
"reflect"
"slices"
"strconv"
"strings"
"time"

"github.com/hivecommons/hive/pkg/config"
Expand Down Expand Up @@ -176,6 +178,10 @@
stageTrackerApplyClaimConflict(it, mt)
return
}
if mt.State == prstage.MergeTrainStateAdmitted {
stageTrackerApplyAdmittedHold(it, mt)
return
}
mt.ID = it.BaseRef + "#" + strconv.Itoa(mt.Front)
it.MergeTrain = mt
parsed, _ := prstage.ParseMergeTrain(it.Reason)
Expand Down Expand Up @@ -247,6 +253,77 @@
return prstage.ClaimConflictCaption(other)
}

// stageTrackerApplyAdmittedHold decorates a PR the lane found green and
// approved while it shares files with a train (hivecommons/hive#15825):
// it holds no seat yet — the next plan seats it at the back — so the row
// rides no train (no ordinal, never the front) and carries the overlap
// hint instead, pointed at the front it joins behind.
func stageTrackerApplyAdmittedHold(it *StageTrackerItem, mt *StageTrackerMergeTrain) {
parsed, _ := prstage.ParseMergeTrain(it.Reason)
if it.MergeGate == nil {
it.MergeGate = &StageTrackerMergeGate{}
}
it.MergeGate.State = MergeGateStateReady
it.MergeGate.Reason = parsed.Sentence()
it.MergeTrain = nil
it.Overlap = stageTrackerOverlapHint(it.Number, mt.Front, nil, mt.OverlapFiles)
it.Overlap.Note = "green and approved; takes a seat at the back of the merge train behind #" + strconv.Itoa(mt.Front) + " on the lane's next pass"
it.Overlap.Badge = "train · joins behind #" + strconv.Itoa(mt.Front) + " next pass"
}

// Ejection captions (hivecommons/hive#15825): what the merge train's
// ejection means for this row, by the engine's why token. The chevron
// caption says what is owed; the gray pill carries the lineage.
var stageTrackerEjectionCaptions = map[string]string{
"head-moved": "left the merge train — new push, CI re-running after push; review re-run owed",
"ci-pending": "left the merge train — CI re-running on this head",
"ci-red": "left the merge train — a required check is red on this head",
"verdict-owed": "left the merge train — review re-run owed for this head",
"conflicting": "left the merge train — conflicting with the base",
"under-repair": "left the merge train — being fixed; rejoins when green",
"human-merge": "left the merge train — a person merges this one",
"held": "left the merge train — held",
}

// stageTrackerEjectionReasonPrefix prefixes the LeftTrain.Reason token the
// SPA derives its words from: `merge-train:ejected:<why>`.
const stageTrackerEjectionReasonPrefix = "merge-train:ejected:"

// stageTrackerApplyTrainEjection decorates a PR the merge train ejected
// (hivecommons/hive#15825) while it sits back in the CI / Review column:
// no merge_train, a left_train that names the why and the lineage pill
// ("left merge train · pushed 3m ago"), and a caption that says what is
// owed before it rides again. A row the view already seats (the record
// is stale) or one at 080+ keeps its own words.
func stageTrackerApplyTrainEjection(it *StageTrackerItem, rec stagelabels.Record, hasRec bool, now time.Time) {
if it == nil || it.Kind != "pr" || !hasRec || it.MergeTrain != nil || it.Stage >= stagelabels.AwaitingMergeAdmission.Number() {
return
}
why, head, at, ok := rec.TrainEjected()
if !ok || (head != "" && it.Head != "" && !strings.EqualFold(head, it.Head) && why != "head-moved") {
return
}
caption := stageTrackerEjectionCaptions[why]
if caption == "" {
caption = "left the merge train — " + why
}
lineage := "left merge train"
switch {
case why == "head-moved" && !rec.LastPushAt.IsZero():
lineage += " · pushed " + shortDuration(now.Sub(rec.LastPushAt)) + " ago"
case !at.IsZero():
lineage += " · " + shortDuration(now.Sub(at)) + " ago"
}
it.LeftTrain = &StageTrackerLeftTrain{Why: why, Note: caption, Reason: stageTrackerEjectionReasonPrefix + why, Badge: lineage}
it.Caption = caption
if it.MergeGate != nil && it.MergeGate.State == MergeGateStateReady {
it.MergeGate.State = ""
if reflect.DeepEqual(*it.MergeGate, StageTrackerMergeGate{}) {
it.MergeGate = nil
}
}
}

// stageTrackerLeftTrainNote is the muted hover note on a PR the view
// dropped from its merge train while a person or the fixer has it
// (hivecommons/hive#15405 led a train header as "1st: #15405" while its
Expand All @@ -264,6 +341,11 @@
type StageTrackerLeftTrain struct {
Why string `json:"why"`
Note string `json:"note"`
// Reason is the engine's ejection token (`merge-train:ejected:<why>`)
// when the merge train itself ejected the PR (hivecommons/hive#15825);
// Badge is the gray lineage pill ("left merge train · pushed 3m ago").
Reason string `json:"reason,omitempty"`
Badge string `json:"badge,omitempty"`
// trainID and position remember the slot it held so the survivors
// can close ranks (stageTrackerMergeTrainPostPass).
trainID string
Expand Down
Loading
Loading