From 8abd4a2a2629569d8474d9ca058810de838183a9 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Fri, 30 Oct 2026 12:48:14 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Merge=20train=20seats=20only?= =?UTF-8?q?=20PRs=20green=20and=20reviewed=20on=20their=20current=20head;?= =?UTF-8?q?=20regressed=20members=20are=20ejected?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Items that have not passed the review or CI is not green should not be (a) ready for merge, (b) in a merge train. The planner now seats only members whose current head is green, fully reviewed, mergeable and not held; others are candidates (overlap hint, no position, never front). A member whose head moves, CI goes pending/red, verdict is owed again or conflicts is ejected on the next evaluation and re-enters at the back when ready. Stage engine and tracker keep such PRs below 080 with a caption naming what is owed and a lineage pill. Closes #15825 Signed-off-by: Andrew Anderson --- .../fixed-15825-merge-train-ready-only.md | 1 + src/docs/hive-merge.md | 21 ++ src/pkg/dashboard/stage_tracker_build.go | 1 + .../dashboard/stage_tracker_merge_train.go | 82 ++++ .../stage_tracker_merge_train_ejected_test.go | 151 ++++++++ .../stage_tracker_merge_train_eta.go | 2 + .../stage_tracker_merge_train_overlap.go | 3 + .../stage_tracker_overlap_hint.test.js | 27 ++ .../static-src/js/tracker-words-core.js | 20 +- src/pkg/dashboard/static/index.html | 20 +- .../automerge/automerge_contributor_lane.go | 5 +- .../github/automerge/automerge_merge_train.go | 352 ++++++++++++++++-- .../automerge_merge_train_duplicate_test.go | 1 + .../automerge_merge_train_hotspot_test.go | 1 + .../automerge_merge_train_ready_test.go | 204 ++++++++++ .../automerge/automerge_merge_train_test.go | 106 ++++-- src/pkg/github/automerge/automerge_sweep.go | 11 +- src/pkg/stageengine/derive_pr_classify.go | 11 + .../stageengine/derive_pr_merge_train_test.go | 25 ++ src/pkg/stageengine/prstage/merge_train.go | 10 +- src/pkg/stagelabels/store.go | 58 +++ 21 files changed, 1058 insertions(+), 54 deletions(-) create mode 100644 changelog.d/fixed-15825-merge-train-ready-only.md create mode 100644 src/pkg/dashboard/stage_tracker_merge_train_ejected_test.go create mode 100644 src/pkg/github/automerge/automerge_merge_train_ready_test.go diff --git a/changelog.d/fixed-15825-merge-train-ready-only.md b/changelog.d/fixed-15825-merge-train-ready-only.md new file mode 100644 index 0000000000..f298dafec6 --- /dev/null +++ b/changelog.d/fixed-15825-merge-train-ready-only.md @@ -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 ([#15825](https://github.com/hivecommons/hive/issues/15825)). diff --git a/src/docs/hive-merge.md b/src/docs/hive-merge.md index f5b82f878d..7944699ec7 100644 --- a/src/docs/hive-merge.md +++ b/src/docs/hive-merge.md @@ -453,6 +453,27 @@ 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. + ### Trusted-author auto-merge `auto_merge.trusted_authors` is a third, default-off sweep tier for diff --git a/src/pkg/dashboard/stage_tracker_build.go b/src/pkg/dashboard/stage_tracker_build.go index c7e366de7b..88bb422165 100644 --- a/src/pkg/dashboard/stage_tracker_build.go +++ b/src/pkg/dashboard/stage_tracker_build.go @@ -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) diff --git a/src/pkg/dashboard/stage_tracker_merge_train.go b/src/pkg/dashboard/stage_tracker_merge_train.go index b7919f00e6..9d8ae66926 100644 --- a/src/pkg/dashboard/stage_tracker_merge_train.go +++ b/src/pkg/dashboard/stage_tracker_merge_train.go @@ -1,8 +1,10 @@ package dashboard import ( + "reflect" "slices" "strconv" + "strings" "time" "github.com/hivecommons/hive/pkg/config" @@ -176,6 +178,10 @@ func stageTrackerApplyMergeTrain(it *StageTrackerItem) { 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) @@ -247,6 +253,77 @@ func stageTrackerClaimConflictCaption(it *StageTrackerItem) string { 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:`. +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 @@ -264,6 +341,11 @@ const stageTrackerAwaitingAdmissionCaption = "Green and approved; waiting for th type StageTrackerLeftTrain struct { Why string `json:"why"` Note string `json:"note"` + // Reason is the engine's ejection token (`merge-train:ejected:`) + // 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 diff --git a/src/pkg/dashboard/stage_tracker_merge_train_ejected_test.go b/src/pkg/dashboard/stage_tracker_merge_train_ejected_test.go new file mode 100644 index 0000000000..a081f7ccbd --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_merge_train_ejected_test.go @@ -0,0 +1,151 @@ +package dashboard + +import ( + "encoding/json" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stageengine/prstage" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// The rule (hivecommons/hive#15825): items that have not passed the review +// or CI is not green should not be (a) ready for merge, (b) in a merge +// train — and "they should not be in the merge queue column". These tests +// pin the tracker column: a PR whose current head has pending CI or owed +// verdicts renders below 080 with a caption that says what is owed, the +// gray pill carrying the lineage, however it was seated before. + +func ejectedTrainFixture(t *testing.T, now time.Time) (*Server, *stagelabels.Store, func(n int, stage string, head string)) { + t.Helper() + s, store := stageTrackerFixture(t, now) + add := func(n int, stage string, head string) { + s.statusMu.Lock() + defer s.statusMu.Unlock() + s.status.Repos[0].OpenPrs = append(s.status.Repos[0].OpenPrs, + FrontendPR{PullRequest: github.PullRequest{Number: n, Title: "Docs change", Author: "contrib", BaseRef: "v5", HeadSHA: head, Labels: []string{stage, "author/contributor"}}}) + } + return s, store, add +} + +// TestStageTrackerNotGreenOrReviewedIsNotInMergeQueueColumn_CIPendingOnCurrentHead: +// the live front #15748 (approval recorded, new push at 11:50, CI +// re-running) must sit in the CI column, not ride a train, and say what +// the push owes. +func TestStageTrackerNotGreenOrReviewedIsNotInMergeQueueColumn_CIPendingOnCurrentHead(t *testing.T) { + now := time.Date(2026, 10, 30, 16, 10, 0, 0, time.UTC) + s, store, add := ejectedTrainFixture(t, now) + overlap := []string{"hive-merge.md"} + front := stagelabels.Key("acme/console", 15748) + store.Observe(front, stagelabels.AwaitingMergeAdmission, prstage.MergeTrain{State: prstage.MergeTrainStateFront, Front: 15748, Position: 1, Size: 3, OverlapFiles: overlap}.Reason()) + store.NoteActivity(front, stagelabels.Activity{Head: "aaa1111", Comments: -1, Reviews: -1}) + // New push: the lane re-stages the row to 050 with CI pending and the + // train ejects it. + store.Observe(front, stagelabels.ReviewPending, "required-check-pending:coverage") + store.NotePush(front, "bbb2222", now.Add(-3*time.Minute)) + store.NoteTrainEjected(front, "bbb2222", "head-moved", now.Add(-2*time.Minute)) + store.Observe(stagelabels.Key("acme/console", 15804), stagelabels.AwaitingMergeAdmission, prstage.MergeTrain{State: prstage.MergeTrainStateFront, Front: 15804, Position: 1, Size: 2, OverlapFiles: overlap}.Reason()) + store.Observe(stagelabels.Key("acme/console", 15812), stagelabels.AwaitingMergeAdmission, prstage.MergeTrain{State: prstage.MergeTrainStateQueuedBehind, Front: 15804, Position: 2, Size: 2, OverlapFiles: overlap}.Reason()) + add(15748, stagelabels.ReviewPending.Label(), "bbb2222") + add(15804, stagelabels.AwaitingMergeAdmission.Label(), "ccc3333") + add(15812, stagelabels.AwaitingMergeAdmission.Label(), "ddd4444") + + resp := s.buildStageTracker(s.status, store, now) + it := trackerItem(t, resp, "pr", 15748) + if it.Stage >= stagelabels.AwaitingMergeAdmission.Number() { + t.Fatalf("CI pending on the current head must not render in the merge queue column: stage %d", it.Stage) + } + if it.MergeTrain != nil { + t.Fatalf("an ejected PR rides no train: %+v", it.MergeTrain) + } + if it.LeftTrain == nil || it.LeftTrain.Why != "head-moved" || it.LeftTrain.Reason != "merge-train:ejected:head-moved" { + t.Fatalf("left_train = %+v", it.LeftTrain) + } + if it.LeftTrain.Badge != "left merge train · pushed 3m ago" { + t.Fatalf("lineage pill = %q", it.LeftTrain.Badge) + } + if !strings.Contains(it.Caption, "left the merge train") || !strings.Contains(it.Caption, "CI re-running after push") { + t.Fatalf("caption must say what the push owes: %q", it.Caption) + } + if it.MergeGate != nil && it.MergeGate.State == MergeGateStateReady { + t.Fatalf("not ready for merge: gate %+v", it.MergeGate) + } + raw, err := json.Marshal(it) + if err != nil { + t.Fatal(err) + } + for _, want := range []string{`"reason":"merge-train:ejected:head-moved"`, `"badge":"left merge train · pushed 3m ago"`} { + if !strings.Contains(string(raw), want) { + t.Fatalf("payload lacks %s:\n%s", want, raw) + } + } + // The ready members close ranks: #15804 leads a train of two. + lead := trackerItem(t, resp, "pr", 15804) + if lead.MergeTrain == nil || lead.MergeTrain.Front != 15804 || lead.MergeTrain.Size != 2 || lead.MergeTrain.State != prstage.MergeTrainStateFront { + t.Fatalf("next ready member is the front: %+v", lead.MergeTrain) + } +} + +// TestStageTrackerNotGreenOrReviewedIsNotInMergeQueueColumn_VerdictOwedOnCurrentHead: +// approval recorded for an older head, verdicts owed again for the current +// one — the Review column, with the caption naming the owed re-review. +func TestStageTrackerNotGreenOrReviewedIsNotInMergeQueueColumn_VerdictOwedOnCurrentHead(t *testing.T) { + now := time.Date(2026, 10, 30, 16, 10, 0, 0, time.UTC) + s, store, add := ejectedTrainFixture(t, now) + key := stagelabels.Key("acme/console", 15812) + store.Observe(key, stagelabels.AwaitingMergeAdmission, prstage.MergeTrain{State: prstage.MergeTrainStateQueuedBehind, Front: 15804, Position: 2, Size: 2}.Reason()) + store.NoteActivity(key, stagelabels.Activity{Head: "aaa1111", Comments: -1, Reviews: -1}) + store.Observe(key, stagelabels.ReviewPending, "contributor-lane:no-verdict") + store.NoteActivity(key, stagelabels.Activity{Head: "bbb2222", Comments: -1, Reviews: -1}) + store.NoteTrainEjected(key, "bbb2222", "verdict-owed", now.Add(-5*time.Minute)) + store.Observe(stagelabels.Key("acme/console", 15804), stagelabels.AwaitingMergeAdmission, "") + add(15812, stagelabels.ReviewPending.Label(), "bbb2222") + add(15804, stagelabels.AwaitingMergeAdmission.Label(), "ccc3333") + + resp := s.buildStageTracker(s.status, store, now) + it := trackerItem(t, resp, "pr", 15812) + if it.Stage >= stagelabels.AwaitingMergeAdmission.Number() { + t.Fatalf("verdicts owed on the current head must not render in the merge queue column: stage %d", it.Stage) + } + if it.MergeTrain != nil { + t.Fatalf("an ejected PR rides no train: %+v", it.MergeTrain) + } + if it.LeftTrain == nil || it.LeftTrain.Why != "verdict-owed" || it.LeftTrain.Reason != "merge-train:ejected:verdict-owed" || it.LeftTrain.Badge != "left merge train · 5m ago" { + t.Fatalf("left_train = %+v", it.LeftTrain) + } + if !strings.Contains(it.Caption, "left the merge train") || !strings.Contains(it.Caption, "review re-run owed") { + t.Fatalf("caption must name the owed review: %q", it.Caption) + } + // The lone survivor is no train and keeps its own 080 words. + alone := trackerItem(t, resp, "pr", 15804) + if alone.MergeTrain != nil || alone.LeftTrain != nil || alone.Stage != stagelabels.AwaitingMergeAdmission.Number() { + t.Fatalf("survivor = stage %d train %+v left %+v", alone.Stage, alone.MergeTrain, alone.LeftTrain) + } +} + +// TestStageTrackerAdmittedCandidateRidesNoTrain: a green, approved PR the +// lane found sharing files with a train holds no seat until the next plan — +// no ordinal, never the front, the overlap chip pointed at the front. +func TestStageTrackerAdmittedCandidateRidesNoTrain(t *testing.T) { + now := time.Date(2026, 10, 30, 16, 10, 0, 0, time.UTC) + s, store, add := ejectedTrainFixture(t, now) + overlap := []string{"hive-merge.md"} + store.Observe(stagelabels.Key("acme/console", 15804), stagelabels.AwaitingMergeAdmission, prstage.MergeTrain{State: prstage.MergeTrainStateFront, Front: 15804, Position: 1, Size: 1, OverlapFiles: overlap}.Reason()) + store.Observe(stagelabels.Key("acme/console", 15816), stagelabels.AwaitingMergeAdmission, prstage.MergeTrain{State: prstage.MergeTrainStateAdmitted, Front: 15804, Size: 1, OverlapFiles: overlap}.Reason()) + add(15804, stagelabels.AwaitingMergeAdmission.Label(), "ccc3333") + add(15816, stagelabels.AwaitingMergeAdmission.Label(), "eee5555") + + resp := s.buildStageTracker(s.status, store, now) + it := trackerItem(t, resp, "pr", 15816) + if it.MergeTrain != nil { + t.Fatalf("an admitted candidate holds no seat yet: %+v", it.MergeTrain) + } + if it.Overlap == nil || it.Overlap.Behind != 15804 || !strings.Contains(it.Overlap.Badge, "joins behind #15804") { + t.Fatalf("overlap = %+v", it.Overlap) + } + if !strings.Contains(it.Caption, "Green and approved") || !strings.Contains(it.Caption, "#15804") { + t.Fatalf("caption = %q", it.Caption) + } +} diff --git a/src/pkg/dashboard/stage_tracker_merge_train_eta.go b/src/pkg/dashboard/stage_tracker_merge_train_eta.go index 0e7ac13989..c80330ea2e 100644 --- a/src/pkg/dashboard/stage_tracker_merge_train_eta.go +++ b/src/pkg/dashboard/stage_tracker_merge_train_eta.go @@ -244,6 +244,8 @@ func stageTrackerMergeTrainCaption(reason string) string { return "Conflicts with " + onto + "; the hive is rebasing this PR (attempt " + strconv.Itoa(mt.Attempt) + " of " + strconv.Itoa(mt.MaxAttempts) + ")" case prstage.MergeTrainStateRebaseExhausted: return "The rebase onto " + onto + " failed " + strconv.Itoa(mt.Attempt) + " times; a maintainer rebases and merges" + case prstage.MergeTrainStateAdmitted: + return "Green and approved; takes a seat at the back of the merge train behind #" + strconv.Itoa(mt.Front) + " on the lane's next pass" default: return "Approved; waiting its turn in the merge train — " + mt.Sentence() } diff --git a/src/pkg/dashboard/stage_tracker_merge_train_overlap.go b/src/pkg/dashboard/stage_tracker_merge_train_overlap.go index 6037fe178f..f36cb4af1c 100644 --- a/src/pkg/dashboard/stage_tracker_merge_train_overlap.go +++ b/src/pkg/dashboard/stage_tracker_merge_train_overlap.go @@ -21,6 +21,9 @@ type StageTrackerOverlap struct { With []int `json:"with,omitempty"` Files []string `json:"files,omitempty"` Note string `json:"note"` + // Badge overrides the chip's words when set (an admitted candidate + // reads "joins behind #N next pass", not "when green"). + Badge string `json:"badge,omitempty"` // trainID and position remember the planner's slot so the members // that do ride can close ranks (stageTrackerMergeTrainPostPass). trainID string diff --git a/src/pkg/dashboard/stage_tracker_overlap_hint.test.js b/src/pkg/dashboard/stage_tracker_overlap_hint.test.js index a61c1d29a1..85b6dfc4e2 100644 --- a/src/pkg/dashboard/stage_tracker_overlap_hint.test.js +++ b/src/pkg/dashboard/stage_tracker_overlap_hint.test.js @@ -31,6 +31,7 @@ const src = [ fn('stageTrackerOverlap'), fn('stageTrackerOverlapBadgeText'), fn('stageTrackerOverlapTip'), + fn('stageTrackerLeftTrainBadgeText'), fn('stageTrackerOverlapBadgeHtml'), fn('stageTrackerTrainLines'), fn('stageTrackerRowTrain'), @@ -80,3 +81,29 @@ test('the hint yields to a train, a left-train note, and nothing', () => { assert.strictEqual(api.badgeText(bareFront), 'train · 1st once green'); assert.strictEqual(api.tip(bareFront), 'overlaps #2, #3 (a.go) — no member of the train is merge-ready yet; provisionally 1st, merges ahead of them if it is green first'); }); + +// hive#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 member +// the train ejected sits back in CI / Review with `left_train: {why, note, +// reason, badge}` — the gray pill carries the lineage, the hover the why — +// and an admitted candidate's chip takes the server's words. +test('an ejected member shows the lineage pill, never a train', () => { + const ejected = { repo: 'hivecommons/hive', number: 15748, kind: 'pr', stage: 50, modifiers: [], caption: 'left the merge train — new push, CI re-running after push; review re-run owed', + left_train: { why: 'head-moved', note: 'left the merge train — new push, CI re-running after push; review re-run owed', reason: 'merge-train:ejected:head-moved', badge: 'left merge train · pushed 3m ago' } }; + assert.strictEqual(api.trainKey(ejected), ''); + assert.strictEqual(api.badgeText(ejected), ''); + const badge = api.badgeHtml(ejected); + assert.match(badge, /class="ham-badge ham-badge-overlap"/); + assert.match(badge, />left merge train · pushed 3m ago { + const admitted = { repo: 'hivecommons/hive', number: 15816, kind: 'pr', stage: 80, modifiers: [], + overlap: { behind: 15804, files: ['hive-merge.md'], note: 'green and approved; takes a seat at the back of the merge train behind #15804 on the lane\'s next pass', badge: 'train · joins behind #15804 next pass' } }; + assert.strictEqual(api.badgeText(admitted), 'train · joins behind #15804 next pass'); + assert.ok(!/when green/.test(api.badgeHtml(admitted))); +}); diff --git a/src/pkg/dashboard/static-src/js/tracker-words-core.js b/src/pkg/dashboard/static-src/js/tracker-words-core.js index 061a99880d..b7e65ef04e 100644 --- a/src/pkg/dashboard/static-src/js/tracker-words-core.js +++ b/src/pkg/dashboard/static-src/js/tracker-words-core.js @@ -478,6 +478,9 @@ function stageTrackerOverlapBadgeText(item) { const o = stageTrackerOverlap(item); if (!o) return ''; + // The server may pin the words (an admitted candidate reads "joins + // behind #N next pass" — it is green already, hive#15825). + if (o.badge) return String(o.badge); if (Number(o.behind) > 0) return STAGE_TRACKER_OVERLAP_CHIP_LEAD + 'joins behind #' + Number(o.behind) + ' when green'; return STAGE_TRACKER_OVERLAP_CHIP_LEAD + '1st once green'; } @@ -493,10 +496,25 @@ const withPRs = (Array.isArray(o.with) ? o.with : []).map(Number).filter(n => n > 0); return 'overlaps ' + withPRs.map(n => '#' + n).join(', ') + paren + ' — no member of the train is merge-ready yet; provisionally 1st, merges ahead of ' + (withPRs.length > 1 ? 'them' : 'it') + ' if it is green first'; } + // Pure: the gray lineage pill for a PR the merge train ejected + // (hive#15825): `left_train.badge` ("left merge train · pushed 3m + // ago"); the hover carries the why ("left the merge train — new push, + // CI re-running after push"). '' when the row rides a train or the + // server sent no lineage. + function stageTrackerLeftTrainBadgeText(item) { + const lt = item && item.left_train; + if (!lt || typeof lt !== 'object' || stageTrackerTrain(item)) return ''; + return String(lt.badge || ''); + } // Pure: the muted badge beside the row's chips; '' without a hint. function stageTrackerOverlapBadgeHtml(item) { const text = stageTrackerOverlapBadgeText(item); - if (!text) return ''; + if (!text) { + const left = stageTrackerLeftTrainBadgeText(item); + if (!left) return ''; + const leftTip = 'Merge train: ' + stageTrackerLeftTrainNote(item); + return `${esc(left)}`; + } const tip = 'Not in the merge queue yet: ' + stageTrackerOverlapTip(item); return `${esc(text)}`; } diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 1e69e749ab..8f1ccc6150 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -15014,6 +15014,9 @@

Where to get help

function stageTrackerOverlapBadgeText(item) { const o = stageTrackerOverlap(item); if (!o) return ''; + // The server may pin the words (an admitted candidate reads "joins + // behind #N next pass" — it is green already, hive#15825). + if (o.badge) return String(o.badge); if (Number(o.behind) > 0) return STAGE_TRACKER_OVERLAP_CHIP_LEAD + 'joins behind #' + Number(o.behind) + ' when green'; return STAGE_TRACKER_OVERLAP_CHIP_LEAD + '1st once green'; } @@ -15029,10 +15032,25 @@

Where to get help

const withPRs = (Array.isArray(o.with) ? o.with : []).map(Number).filter(n => n > 0); return 'overlaps ' + withPRs.map(n => '#' + n).join(', ') + paren + ' — no member of the train is merge-ready yet; provisionally 1st, merges ahead of ' + (withPRs.length > 1 ? 'them' : 'it') + ' if it is green first'; } + // Pure: the gray lineage pill for a PR the merge train ejected + // (hive#15825): `left_train.badge` ("left merge train · pushed 3m + // ago"); the hover carries the why ("left the merge train — new push, + // CI re-running after push"). '' when the row rides a train or the + // server sent no lineage. + function stageTrackerLeftTrainBadgeText(item) { + const lt = item && item.left_train; + if (!lt || typeof lt !== 'object' || stageTrackerTrain(item)) return ''; + return String(lt.badge || ''); + } // Pure: the muted badge beside the row's chips; '' without a hint. function stageTrackerOverlapBadgeHtml(item) { const text = stageTrackerOverlapBadgeText(item); - if (!text) return ''; + if (!text) { + const left = stageTrackerLeftTrainBadgeText(item); + if (!left) return ''; + const leftTip = 'Merge train: ' + stageTrackerLeftTrainNote(item); + return `${esc(left)}`; + } const tip = 'Not in the merge queue yet: ' + stageTrackerOverlapTip(item); return `${esc(text)}`; } diff --git a/src/pkg/github/automerge/automerge_contributor_lane.go b/src/pkg/github/automerge/automerge_contributor_lane.go index 43f9f32556..8b48811cc0 100644 --- a/src/pkg/github/automerge/automerge_contributor_lane.go +++ b/src/pkg/github/automerge/automerge_contributor_lane.go @@ -469,7 +469,7 @@ func (c *Engine) SweepContributorLaneAutoMerges(ctx context.Context, opts AutoMe } result.Candidates++ c.sweepClock.evaluating(displayRepo, number) - event, reason, err := c.trySweepContributorLanePR(ctx, displayRepo, owner, repoName, number, policy) + event, reason, err := c.trySweepContributorLanePR(withMergeTrainCandidateHold(ctx, c.mergeTrainCandidateReason(train, number)), displayRepo, owner, repoName, number, policy) c.sweepClock.evaluated() if err == nil { c.noteMergeTrainOutcome(stageLaneContributor, owner, repoName, number, pr.GetHead().GetSHA(), reason) @@ -1492,6 +1492,9 @@ func (c *Engine) trySweepContributorLanePR(ctx context.Context, displayRepo, own } author, headSHA, claim, verdict, method, mergeClaim := eval.author, eval.headSHA, eval.claim, eval.verdict, eval.method, eval.mergeClaim fullRepo := owner + "/" + repo + if hold := mergeTrainCandidateHold(ctx); hold != "" { + return AutoMergeSweepEvent{}, hold, nil + } if reason, err := c.tryNativeQueue(ctx, eval.pr, mergeClaim); reason != "" || err != nil { return AutoMergeSweepEvent{}, reason, err } diff --git a/src/pkg/github/automerge/automerge_merge_train.go b/src/pkg/github/automerge/automerge_merge_train.go index aae4cfdc3d..7b54f1ba22 100644 --- a/src/pkg/github/automerge/automerge_merge_train.go +++ b/src/pkg/github/automerge/automerge_merge_train.go @@ -150,6 +150,22 @@ type mergeTrainMember struct { // (hivecommons/hive#15741 at CI / Review led #15748 and #15755, both // queued at 080, and nothing merged). Readiness int + // SeatedSince is when this exact head first took a seat in a train + // (zero: not seated before this pass). Earlier seats lead, so a member + // that left the train and came back ready rides at the back + // (hivecommons/hive#15825). + SeatedSince time.Time +} + +// mergeTrainSeated reports whether a member may take a train seat: items +// that have not passed the review or CI is not green should not be (a) +// ready for merge, (b) in a merge train (hivecommons/hive#15825). Only a +// head the lane last saw ready — green on the current head, every +// required verdict recorded for it, mergeable — rides; the rest are +// candidates: they share the train's files but hold no position and never +// front it. +func mergeTrainSeated(m mergeTrainMember) bool { + return !m.Blocked && m.Readiness == mergeTrainReadinessReady } // Readiness tiers. The zero value is unknown; mergeTrainReadinessRank @@ -186,7 +202,12 @@ type mergeTrainGroup struct { Base string Order []int OverlapFiles []string - members map[int]mergeTrainMember + // Candidates share the train's files but are not ready on their + // current head (CI running, a verdict owed, blocked): no position, + // never front. They are evaluated on the lane's normal path and take a + // seat at the back once ready (hivecommons/hive#15825). + Candidates []int + members map[int]mergeTrainMember } // Front is the PR the train merges next. @@ -243,6 +264,38 @@ func mergeTrainDirty(state string) bool { return s == "dirty" || s == "conflicting" } +// mergeTrainSeatLess orders the seated members front-first: a head that +// merges trails one that does not need the train's rebase first (a +// conflict the train's own front merge caused is repaired last, after the +// ready heads behind it have merged), then the seat taken earliest leads +// (a member that came back ready re-enters at the back: zero SeatedSince +// trails), then the mergeable-state ordering of hivecommons/hive#15763, +// then age, then number. +func mergeTrainSeatLess(ms []mergeTrainMember) func(a, b int) bool { + return func(a, b int) bool { + if da, db := mergeTrainDirty(ms[a].MergeableState), mergeTrainDirty(ms[b].MergeableState); da != db { + return !da + } + sa, sb := ms[a].SeatedSince, ms[b].SeatedSince + if !sa.Equal(sb) { + if sa.IsZero() != sb.IsZero() { + return !sa.IsZero() + } + return sa.Before(sb) + } + if ra, rb := mergeTrainStateRank(ms[a].MergeableState), mergeTrainStateRank(ms[b].MergeableState); ra != rb { + return ra < rb + } + if !ms[a].CreatedAt.Equal(ms[b].CreatedAt) { + if ms[a].CreatedAt.IsZero() != ms[b].CreatedAt.IsZero() { + return !ms[a].CreatedAt.IsZero() + } + return ms[a].CreatedAt.Before(ms[b].CreatedAt) + } + return ms[a].Number < ms[b].Number + } +} + // groupMergeTrains groups members per base by overlapping files (union of // pairwise overlaps) and orders each group front-first. Groups of one are // dropped: a PR with nothing to collide with is no train. @@ -307,32 +360,33 @@ func groupMergeTrains(members []mergeTrainMember) []mergeTrainGroup { if len(ms) < 2 { continue } - sort.SliceStable(ms, func(a, b int) bool { - if ms[a].Blocked != ms[b].Blocked { - return !ms[a].Blocked - } - if ra, rb := mergeTrainReadinessRank(ms[a].Readiness), mergeTrainReadinessRank(ms[b].Readiness); ra != rb { - return ra < rb + var seated, candidates []mergeTrainMember + for _, m := range ms { + if mergeTrainSeated(m) { + seated = append(seated, m) + } else { + candidates = append(candidates, m) } - ra, rb := mergeTrainStateRank(ms[a].MergeableState), mergeTrainStateRank(ms[b].MergeableState) - if ra != rb { + } + if len(seated) == 0 { + continue + } + sort.SliceStable(seated, mergeTrainSeatLess(seated)) + sort.SliceStable(candidates, func(a, b int) bool { + if ra, rb := mergeTrainReadinessRank(candidates[a].Readiness), mergeTrainReadinessRank(candidates[b].Readiness); ra != rb { return ra < rb } - if !ms[a].CreatedAt.Equal(ms[b].CreatedAt) { - if ms[a].CreatedAt.IsZero() != ms[b].CreatedAt.IsZero() { - return !ms[a].CreatedAt.IsZero() - } - return ms[a].CreatedAt.Before(ms[b].CreatedAt) - } - return ms[a].Number < ms[b].Number + return candidates[a].Number < candidates[b].Number }) - if ms[0].Blocked { - continue - } g := mergeTrainGroup{Base: base, members: map[int]mergeTrainMember{}} count := map[string]int{} - for _, m := range ms { + for _, m := range seated { g.Order = append(g.Order, m.Number) + } + for _, m := range candidates { + g.Candidates = append(g.Candidates, m.Number) + } + for _, m := range ms { g.members[m.Number] = m seen := map[string]bool{} for _, f := range m.Files { @@ -359,6 +413,9 @@ type mergeTrainPlan struct { lane, displayRepo, owner, repo string groups []mergeTrainGroup byNumber map[int]*mergeTrainGroup + // candidates are the PRs that share a train's files but are not ready + // on their current head: they hold no seat (hivecommons/hive#15825). + candidates map[int]*mergeTrainGroup // duplicates are the PRs held out of every train this pass because // another open PR fixes the same issue (one PR per issue). duplicates map[int]mergeTrainDuplicateHold @@ -388,6 +445,62 @@ func (p *mergeTrainPlan) isFront(number int) bool { return ok && g.Front() == number } +// candidateOf returns the train number is a candidate for (shares files +// with, without a seat), if any. +func (p *mergeTrainPlan) candidateOf(number int) (*mergeTrainGroup, bool) { + if p == nil || p.candidates == nil { + return nil, false + } + g, ok := p.candidates[number] + return g, ok && g.Front() > 0 +} + +// isCandidate reports whether number shares a train's files this pass +// without a seat: the lane evaluates it, but if it turns out ready it is +// held for a seat at the back rather than merged ahead of the front. +func (p *mergeTrainPlan) isCandidate(number int) bool { + _, ok := p.candidateOf(number) + return ok +} + +// mergeTrainCandidateHoldKey is the context key under which a lane carries +// the hold reason for a train candidate (hivecommons/hive#15825): the lane +// evaluates the PR on its normal path, but a head that turns out ready is +// not merged ahead of the train's front — it is held for a seat at the +// back next pass. +type mergeTrainCandidateHoldKey struct{} + +// withMergeTrainCandidateHold marks ctx as evaluating a train candidate. +func withMergeTrainCandidateHold(ctx context.Context, reason string) context.Context { + if reason == "" { + return ctx + } + return context.WithValue(ctx, mergeTrainCandidateHoldKey{}, reason) +} + +// mergeTrainCandidateHold is the hold reason a merge point returns instead +// of merging when the lane is evaluating a train candidate; "" otherwise. +func mergeTrainCandidateHold(ctx context.Context) string { + if ctx == nil { + return "" + } + reason, _ := ctx.Value(mergeTrainCandidateHoldKey{}).(string) + return reason +} + +// mergeTrainCandidateReason is the lane reason for a candidate the lane +// found ready: `merge-train:admitted#:0/:0/0:`. The +// stage engine reads it as 080 (the PR is green and approved; its wait is +// the train's turn), and mergeTrainReadinessOf reads it as ready, so the +// next plan seats it at the back. +func (c *Engine) mergeTrainCandidateReason(plan *mergeTrainPlan, number int) string { + g, ok := plan.candidateOf(number) + if !ok { + return "" + } + return prstage.MergeTrain{State: prstage.MergeTrainStateAdmitted, Front: g.Front(), Position: 0, Size: len(g.Order), OverlapFiles: g.OverlapFiles}.Reason() +} + // mergeTrainPolicyNow reads the live policy. func (c *Engine) mergeTrainPolicyNow() MergeTrainPolicy { if c == nil || c.mergeTrainPolicy == nil { @@ -413,10 +526,11 @@ func mergeTrainCandidate(prefilterReason string) bool { // candidates share a base. Errors are logged and leave the PR out of any // train, so a failed read never blocks a merge the lane would have made. func (c *Engine) planMergeTrains(ctx context.Context, lane, displayRepo, owner, repo string, prs []*gh.PullRequest, prefilter func(*gh.PullRequest) string) *mergeTrainPlan { - plan := &mergeTrainPlan{lane: lane, displayRepo: displayRepo, owner: owner, repo: repo, byNumber: map[int]*mergeTrainGroup{}} + plan := &mergeTrainPlan{lane: lane, displayRepo: displayRepo, owner: owner, repo: repo, byNumber: map[int]*mergeTrainGroup{}, candidates: map[int]*mergeTrainGroup{}} if !c.mergeTrainPolicyNow().Enabled || c == nil || c.gh == nil { return plan } + defer c.mergeTrainSettleSeats(lane, owner, repo, displayRepo, prs, plan) prs = c.planDuplicateHolds(ctx, plan, lane, owner, repo, displayRepo, prs, prefilter) perBase := map[string][]*gh.PullRequest{} for _, pr := range prs { @@ -506,12 +620,21 @@ func (c *Engine) planMergeTrains(ctx context.Context, lane, displayRepo, owner, m.Number = 0 } } + for i := range members { + m := &members[i] + if seat, ok := c.mergeTrainSeatFor(lane, owner, repo, m.Number); ok && seat.sha == m.HeadSHA { + m.SeatedSince = seat.since + } + } plan.groups = groupMergeTrains(members) for i := range plan.groups { g := &plan.groups[i] for _, n := range g.Order { plan.byNumber[n] = g } + for _, n := range g.Candidates { + plan.candidates[n] = g + } c.logMergeTrainTransition(displayRepo, lane, *g) } return plan @@ -867,16 +990,177 @@ type mergeTrainState struct { // mergeTrainVerdicts remembers, per lane and PR, the last head whose // verdict keeps it from fronting (or riding) a train. mergeTrainVerdicts map[string]mergeTrainVerdict + // mergeTrainSeats remembers, per lane and PR, the head that holds a + // train seat and since when (hivecommons/hive#15825): the seat orders + // the train (earliest first) and its loss is the ejection the log and + // the stage store report. + mergeTrainSeats map[string]mergeTrainSeat + // mergeTrainNow is the planner's clock (tests inject one). + mergeTrainNow func() time.Time +} + +// mergeTrainSeat is one PR's train seat: the head seated and since when. +type mergeTrainSeat struct { + sha string + since time.Time +} + +// Ejection reasons: why a seated member left the train +// (hivecommons/hive#15825). Logged once per ejection and recorded on the +// stage store so the tracker row says what happened. +const ( + mergeTrainEjectHeadMoved = "head-moved" + mergeTrainEjectCIPending = "ci-pending" + mergeTrainEjectCIRed = "ci-red" + mergeTrainEjectVerdictOwed = "verdict-owed" + mergeTrainEjectConflicting = "conflicting" + mergeTrainEjectUnderRepair = "under-repair" + mergeTrainEjectHumanMerge = "human-merge" + mergeTrainEjectHeld = "held" +) + +func (c *Engine) mergeTrainClock() time.Time { + if c != nil && c.mergeTrainNow != nil { + return c.mergeTrainNow() + } + return time.Now() +} + +func (c *Engine) mergeTrainSeatFor(lane, owner, repo string, number int) (mergeTrainSeat, bool) { + if c == nil { + return mergeTrainSeat{}, false + } + c.mergeTrainMu.Lock() + defer c.mergeTrainMu.Unlock() + seat, ok := c.mergeTrainSeats[mergeTrainVerdictKey(lane, owner, repo, number)] + return seat, ok +} + +// mergeTrainSettleSeats reconciles the seat memory with this pass's plan: +// every seated member keeps (or takes) its seat at its current head; a +// PR that held a seat and is open but not seated now is ejected — once, +// at INFO, with the why — and the stage store is told so the row reads +// "left the merge train — new push, CI re-running" while it sits back in +// the CI / Review column. A seat whose PR is gone (merged, closed) is +// forgotten silently. +func (c *Engine) mergeTrainSettleSeats(lane, owner, repo, displayRepo string, prs []*gh.PullRequest, plan *mergeTrainPlan) { + if c == nil || plan == nil { + return + } + now := c.mergeTrainClock() + open := map[int]*gh.PullRequest{} + for _, pr := range prs { + if pr != nil && pr.GetNumber() > 0 { + open[pr.GetNumber()] = pr + } + } + store := c.stageStoreOrShared() + type ejection struct { + number int + sha string + why string + } + var ejected []ejection + var seatedNow []int + c.mergeTrainMu.Lock() + if c.mergeTrainSeats == nil { + c.mergeTrainSeats = map[string]mergeTrainSeat{} + } + prefix := mergeTrainVerdictKey(lane, owner, repo, 0) + prefix = prefix[:strings.LastIndex(prefix, "#")+1] + for key, seat := range c.mergeTrainSeats { + if !strings.HasPrefix(key, prefix) { + continue + } + number, err := strconv.Atoi(strings.TrimPrefix(key, prefix)) + if err != nil || number <= 0 { + delete(c.mergeTrainSeats, key) + continue + } + if g, ok := plan.group(number); ok && g.Position(number) > 0 { + continue + } + delete(c.mergeTrainSeats, key) + pr, isOpen := open[number] + if !isOpen { + continue + } + sha := pr.GetHead().GetSHA() + if why := c.mergeTrainEjectWhyLocked(lane, owner, repo, number, sha, seat, pr, plan); why != "" { + ejected = append(ejected, ejection{number: number, sha: sha, why: why}) + } + } + for n, g := range plan.byNumber { + if g.Position(n) == 0 { + continue + } + key := mergeTrainVerdictKey(lane, owner, repo, n) + sha := g.members[n].HeadSHA + if seat, ok := c.mergeTrainSeats[key]; !ok || seat.sha != sha { + c.mergeTrainSeats[key] = mergeTrainSeat{sha: sha, since: now} + } + seatedNow = append(seatedNow, n) + } + c.mergeTrainMu.Unlock() + sort.Slice(ejected, func(a, b int) bool { return ejected[a].number < ejected[b].number }) + for _, e := range ejected { + c.info("merge train: member ejected", "repo", displayRepo, "pr", e.number, "why", e.why, "lane", lane) + if store != nil { + store.NoteTrainEjected(stagelabels.Key(owner+"/"+repo, e.number), e.sha, e.why, now) + } + } + if store != nil { + for _, n := range seatedNow { + store.ClearTrainEjected(stagelabels.Key(owner+"/"+repo, n)) + } + } +} + +// mergeTrainEjectWhyLocked names why a seated PR lost its seat; the +// caller holds mergeTrainMu. "" means no ejection worth reporting: the +// train itself dissolved (the front merged and one PR remains), so the PR +// simply merges on its own. +func (c *Engine) mergeTrainEjectWhyLocked(lane, owner, repo string, number int, sha string, seat mergeTrainSeat, pr *gh.PullRequest, plan *mergeTrainPlan) string { + switch { + case sha != seat.sha: + return mergeTrainEjectHeadMoved + case mergeTrainDirty(pr.GetMergeableState()): + return mergeTrainEjectConflicting + } + if v, ok := c.mergeTrainVerdicts[mergeTrainVerdictKey(lane, owner, repo, number)]; ok && v.sha == sha { + switch { + case v.humanMerge: + return mergeTrainEjectHumanMerge + case v.blocked: + return mergeTrainEjectCIRed + case classifyCIReason(v.reason) == ciReasonPending: + return mergeTrainEjectCIPending + case v.readiness == mergeTrainReadinessUnready: + return mergeTrainEjectVerdictOwed + } + } + if c.mergeTrainUnderRepair(owner, repo, pr) != "" { + return mergeTrainEjectUnderRepair + } + if _, candidate := plan.candidates[number]; candidate { + return mergeTrainEjectVerdictOwed + } + if len(plan.groups) == 0 { + return "" + } + return mergeTrainEjectHeld } // mergeTrainVerdict is the remembered lane verdict for one head: Blocked // heads never front; HumanMerge heads are not train members at all; -// Readiness orders the members that do ride (mergeTrainReadiness*). +// Readiness orders the members that do ride (mergeTrainReadiness*); +// reason is the verdict itself, so an ejection can say "ci-pending". type mergeTrainVerdict struct { sha string blocked bool humanMerge bool readiness int + reason string } // mergeTrainBlockingReason reports whether a lane's verdict means the head @@ -896,6 +1180,9 @@ func mergeTrainBlockingReason(reason string) bool { // review gate still waiting is unready; any other reason says nothing // about readiness (unknown). func mergeTrainReadinessOf(reason string) int { + if mt, ok := prstage.ParseMergeTrain(reason); ok && mt.State == prstage.MergeTrainStateAdmitted { + return mergeTrainReadinessReady + } switch { case reason == "", strings.HasPrefix(reason, prstage.ContributorLaneReasonSoaking), stageengine.MergeQueueReason(reason): @@ -938,7 +1225,7 @@ func (c *Engine) noteMergeTrainOutcome(lane, owner, repo string, number int, sha return } key := mergeTrainVerdictKey(lane, owner, repo, number) - v := mergeTrainVerdict{sha: sha, blocked: mergeTrainBlockingReason(reason), humanMerge: mergeTrainHumanMergeReason(reason), readiness: mergeTrainReadinessOf(reason)} + v := mergeTrainVerdict{sha: sha, blocked: mergeTrainBlockingReason(reason), humanMerge: mergeTrainHumanMergeReason(reason), readiness: mergeTrainReadinessOf(reason), reason: reason} c.mergeTrainMu.Lock() defer c.mergeTrainMu.Unlock() if (!v.humanMerge && !v.blocked && v.readiness == mergeTrainReadinessUnknown) || strings.TrimSpace(sha) == "" { @@ -978,6 +1265,12 @@ func (c *Engine) mergeTrainHeadReadiness(lane, owner, repo string, number int, s if v, ok := c.mergeTrainVerdictFor(lane, owner, repo, number, sha); ok { return v.readiness } + if seat, ok := c.mergeTrainSeatFor(lane, owner, repo, number); ok && seat.sha != sha { + // The head moved since the train seated it: CI and the verdicts + // are owed again, whatever the stage record still says + // (hivecommons/hive#15825). + return mergeTrainReadinessUnknown + } store := c.stageStoreOrShared() if store == nil { return mergeTrainReadinessUnknown @@ -989,6 +1282,19 @@ func (c *Engine) mergeTrainHeadReadiness(lane, owner, repo string, number int, s if _, parked := prstage.ParseMergeTrain(rec.Reason); parked { return mergeTrainReadinessUnknown } + if rec.TrainEjectedWhy != "" && strings.EqualFold(rec.TrainEjectedHead, sha) { + // Ejected at this very head: only the lane's own verdict on it + // (above) re-admits it. + return mergeTrainReadinessUnknown + } + if rec.ActivityHead != "" && !strings.EqualFold(rec.ActivityHead, sha) { + // The record describes an earlier head: a push since then owes + // CI and the verdicts again (hivecommons/hive#15825). + return mergeTrainReadinessUnknown + } + if rec.LastPushSha != "" && !strings.EqualFold(rec.LastPushSha, sha) { + return mergeTrainReadinessUnknown + } if rec.Stage.Number() >= stagelabels.AwaitingMergeAdmission.Number() { return mergeTrainReadinessReady } diff --git a/src/pkg/github/automerge/automerge_merge_train_duplicate_test.go b/src/pkg/github/automerge/automerge_merge_train_duplicate_test.go index 3f5f9901b7..f141a5e23f 100644 --- a/src/pkg/github/automerge/automerge_merge_train_duplicate_test.go +++ b/src/pkg/github/automerge/automerge_merge_train_duplicate_test.go @@ -136,6 +136,7 @@ func TestPlanMergeTrainsHoldsSameIssueDuplicate(t *testing.T) { withBody(mtPR(15407, t0.Add(time.Hour), ""), "Fixes #15396"), withBody(mtPR(15410, t0.Add(2*time.Hour), ""), "Fixes #15399"), } + mtReady(c, "self", prs...) plan := c.planMergeTrains(context.Background(), "self", "acme/widget", "acme", "widget", prs, func(*gh.PullRequest) string { return "" }) h, held := plan.duplicateOf(15407) if !held || h.Winner != 15402 || h.Issue != 15396 { diff --git a/src/pkg/github/automerge/automerge_merge_train_hotspot_test.go b/src/pkg/github/automerge/automerge_merge_train_hotspot_test.go index b8b40fc83c..4c45e165a4 100644 --- a/src/pkg/github/automerge/automerge_merge_train_hotspot_test.go +++ b/src/pkg/github/automerge/automerge_merge_train_hotspot_test.go @@ -51,6 +51,7 @@ func TestMergeTrainFeedsHotspotRecorder(t *testing.T) { rec := &recordedHotspot{} c.hotspotRecorder = rec prs := []*gh.PullRequest{mtPR(20, t0, ""), mtPR(21, t0.Add(time.Minute), ""), mtPR(22, t0.Add(2*time.Minute), "")} + mtReady(c, "self", prs...) plan := c.planMergeTrains(context.Background(), "self", "acme/widget", "acme", "widget", prs, func(*gh.PullRequest) string { return "" }) if !plan.isFront(20) { t.Fatalf("front = %v", plan.groups) diff --git a/src/pkg/github/automerge/automerge_merge_train_ready_test.go b/src/pkg/github/automerge/automerge_merge_train_ready_test.go new file mode 100644 index 0000000000..15a93b05b5 --- /dev/null +++ b/src/pkg/github/automerge/automerge_merge_train_ready_test.go @@ -0,0 +1,204 @@ +package automerge + +import ( + "context" + "strings" + "testing" + "time" + + gh "github.com/google/go-github/v72/github" + + "github.com/hivecommons/hive/pkg/stageengine/prstage" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// hivecommons/hive#15825: items that have not passed the review or CI is +// not green should not be (a) ready for merge, (b) in a merge train. + +// TestMergeTrainNotGreenOrReviewedIsNotMember: a PR at CI (check pending) +// or at Review (verdict owed), and one the lane has not judged at all, +// share the train's files but take no seat — no position, never front. +func TestMergeTrainNotGreenOrReviewedIsNotMember(t *testing.T) { + t0 := time.Date(2026, 10, 30, 16, 0, 0, 0, time.UTC) + api := &mergeTrainAPI{ + files: map[int][]string{15748: {"a.go"}, 15804: {"a.go"}, 15812: {"a.go"}, 15816: {"a.go"}}, + state: map[int]string{15748: "clean", 15804: "clean", 15812: "clean", 15816: "clean"}, + } + srv := newMergeTrainServer(t, api) + defer srv.Close() + c, logs := newMergeTrainEngine(t, srv.URL, DefaultMergeTrainPolicy, nil) + ciPending, ready, verdictOwed, fresh := mtPR(15748, t0, ""), mtPR(15804, t0.Add(time.Minute), ""), mtPR(15812, t0.Add(2*time.Minute), ""), mtPR(15816, t0.Add(3*time.Minute), "") + c.noteMergeTrainOutcome("self", "acme", "widget", 15748, "sha15748", "required-check-pending:coverage") + c.noteMergeTrainOutcome("self", "acme", "widget", 15804, "sha15804", "") + c.noteMergeTrainOutcome("self", "acme", "widget", 15812, "sha15812", prstage.ContributorLaneReasonNoVerdict) + prs := []*gh.PullRequest{ciPending, ready, verdictOwed, fresh} + plan := plan0(c, prs) + if !plan.isFront(15804) { + t.Fatalf("the only green, reviewed head fronts: %+v", plan.groups) + } + for _, n := range []int{15748, 15812, 15816} { + if plan.isFront(n) || plan.isSibling(n) { + t.Errorf("#%d is not green / reviewed on its head and must hold no seat: %+v", n, plan.groups) + } + if !plan.isCandidate(n) { + t.Errorf("#%d shares the train's files and is a candidate", n) + } + if g, _ := plan.candidateOf(n); g.Position(n) != 0 { + t.Errorf("#%d position = %d, want none", n, g.Position(n)) + } + } + if g, _ := plan.group(15804); len(g.Order) != 1 || len(g.Candidates) != 3 { + t.Fatalf("order = %v candidates = %v", g.Order, g.Candidates) + } + if strings.Contains(logs.String(), "member ejected") { + t.Fatalf("nobody held a seat; nothing to eject:\n%s", logs.String()) + } + // A candidate the lane finds ready is held for a seat, not merged + // ahead of the front; the hold reads as ready next pass. + reason := c.mergeTrainCandidateReason(plan, 15816) + mt, ok := prstage.ParseMergeTrain(reason) + if !ok || mt.State != prstage.MergeTrainStateAdmitted || mt.Front != 15804 || mt.Position != 0 || mt.Size != 1 { + t.Fatalf("candidate reason = %q (%+v)", reason, mt) + } + if got := mergeTrainCandidateHold(withMergeTrainCandidateHold(context.Background(), reason)); got != reason { + t.Fatalf("hold from ctx = %q, want %q", got, reason) + } + if mergeTrainCandidateHold(context.Background()) != "" || c.mergeTrainCandidateReason(plan, 15804) != "" { + t.Fatal("a seated member or a plain context carries no hold") + } + if mergeTrainReadinessOf(reason) != mergeTrainReadinessReady { + t.Fatal("an admitted candidate reads as ready for the next plan") + } + c.noteMergeTrainOutcome("self", "acme", "widget", 15816, "sha15816", reason) + if plan := plan0(c, prs); !plan.isFront(15804) || !plan.isSibling(15816) { + t.Fatalf("the admitted candidate takes the seat behind the front: %+v", plan.groups) + } +} + +// TestMergeTrainFrontEjectedOnHeadMoved: the front receives a push; CI +// restarts and the verdicts are owed again. On the next evaluation it is +// ejected (logged once, recorded on the stage store) and the next ready +// member fronts. +func TestMergeTrainFrontEjectedOnHeadMoved(t *testing.T) { + t0 := time.Date(2026, 10, 30, 16, 0, 0, 0, time.UTC) + api := &mergeTrainAPI{ + files: map[int][]string{15748: {"a.go"}, 15757: {"a.go"}, 15804: {"a.go"}}, + state: map[int]string{15748: "clean", 15757: "clean", 15804: "clean"}, + heads: map[int]string{}, + } + srv := newMergeTrainServer(t, api) + defer srv.Close() + c, logs := newMergeTrainEngine(t, srv.URL, DefaultMergeTrainPolicy, nil) + now := t0 + c.mergeTrainNow = func() time.Time { return now } + c.stageStore = stagelabels.NewStore("", func() time.Time { return now }) + for _, n := range []int{15748, 15757, 15804} { + c.stageStore.Observe(stagelabels.Key("acme/widget", n), stagelabels.AwaitingMergeAdmission, "") + } + prs := []*gh.PullRequest{mtPR(15748, t0, ""), mtPR(15757, t0.Add(time.Minute), ""), mtPR(15804, t0.Add(2*time.Minute), "")} + mtReady(c, "self", prs...) + if plan := plan0(c, prs); !plan.isFront(15748) || !plan.isSibling(15757) || !plan.isSibling(15804) { + t.Fatalf("initial train: %+v", plan.groups) + } + // The push: a new head the lane has not judged. + now = now.Add(5 * time.Minute) + api.mu.Lock() + api.heads[15748] = "sha15748b" + api.mu.Unlock() + prs[0].Head.SHA = gh.Ptr("sha15748b") + plan := plan0(c, prs) + if plan.isFront(15748) || plan.isSibling(15748) { + t.Fatalf("a pushed front holds no seat: %+v", plan.groups) + } + if !plan.isFront(15757) || !plan.isSibling(15804) || !plan.isCandidate(15748) { + t.Fatalf("the next ready member fronts, the pushed one is a candidate: %+v", plan.groups) + } + want := "msg=\"merge train: member ejected\" repo=acme/widget pr=15748 why=head-moved lane=self" + if n := strings.Count(logs.String(), "member ejected"); n != 1 || !strings.Contains(logs.String(), want) { + t.Fatalf("ejection logged %d times, want once as %q:\n%s", n, want, logs.String()) + } + rec, _ := c.stageStore.Get(stagelabels.Key("acme/widget", 15748)) + if why, head, at, ok := rec.TrainEjected(); !ok || why != mergeTrainEjectHeadMoved || head != "sha15748b" || !at.Equal(now) { + t.Fatalf("store ejection = %q %q %v %v", why, head, at, ok) + } + // The same pass again: no second line. + plan0(c, prs) + if n := strings.Count(logs.String(), "member ejected"); n != 1 { + t.Fatalf("ejection logged %d times, want once", n) + } + // CI still running on the new head: still out, no new ejection. + c.noteMergeTrainOutcome("self", "acme", "widget", 15748, "sha15748b", "check-pending") + if plan := plan0(c, prs); plan.isFront(15748) || plan.isSibling(15748) || !plan.isFront(15757) { + t.Fatalf("CI pending on the new head: still a candidate: %+v", plan.groups) + } + if n := strings.Count(logs.String(), "member ejected"); n != 1 { + t.Fatalf("ejection logged %d times, want once", n) + } +} + +// TestMergeTrainEjectedReentersAtBack: the ejected PR turns green and +// reviewed again and takes the seat at the back, behind the members that +// kept theirs; its ejection record clears. +func TestMergeTrainEjectedReentersAtBack(t *testing.T) { + t0 := time.Date(2026, 10, 30, 16, 0, 0, 0, time.UTC) + api := &mergeTrainAPI{ + files: map[int][]string{15748: {"a.go"}, 15757: {"a.go"}, 15804: {"a.go"}}, + state: map[int]string{15748: "clean", 15757: "clean", 15804: "clean"}, + heads: map[int]string{}, + } + srv := newMergeTrainServer(t, api) + defer srv.Close() + c, _ := newMergeTrainEngine(t, srv.URL, DefaultMergeTrainPolicy, nil) + now := t0 + c.mergeTrainNow = func() time.Time { return now } + c.stageStore = stagelabels.NewStore("", func() time.Time { return now }) + for _, n := range []int{15748, 15757, 15804} { + c.stageStore.Observe(stagelabels.Key("acme/widget", n), stagelabels.AwaitingMergeAdmission, "") + } + prs := []*gh.PullRequest{mtPR(15748, t0, ""), mtPR(15757, t0.Add(time.Minute), ""), mtPR(15804, t0.Add(2*time.Minute), "")} + mtReady(c, "self", prs...) + plan0(c, prs) + now = now.Add(5 * time.Minute) + api.mu.Lock() + api.heads[15748] = "sha15748b" + api.mu.Unlock() + prs[0].Head.SHA = gh.Ptr("sha15748b") + c.noteMergeTrainOutcome("self", "acme", "widget", 15748, "sha15748b", "check-pending") + if plan := plan0(c, prs); !plan.isCandidate(15748) { + t.Fatalf("pushed front is a candidate: %+v", plan.groups) + } + // Green and reviewed again on the new head: the lane would merge it, + // but it is a candidate of the train — held, then seated at the back. + now = now.Add(10 * time.Minute) + plan := plan0(c, prs) + c.noteMergeTrainOutcome("self", "acme", "widget", 15748, "sha15748b", c.mergeTrainCandidateReason(plan, 15748)) + plan = plan0(c, prs) + g, ok := plan.group(15748) + if !ok || g.Front() != 15757 || g.Position(15804) != 2 || g.Position(15748) != 3 { + t.Fatalf("re-entry order = %v, want [15757 15804 15748]", plan.groups) + } + rec, _ := c.stageStore.Get(stagelabels.Key("acme/widget", 15748)) + if _, _, _, ejected := rec.TrainEjected(); ejected { + t.Fatal("a seated member carries no ejection") + } + // Age alone never beats a seat: #15748 is the oldest and still last. + if g.Order[0] != 15757 { + t.Fatalf("front = %d, want 15757", g.Order[0]) + } +} + +// TestMergeTrainHeadReadinessIgnoresStaleStage: the stage store's 080 for +// an earlier head says nothing about the pushed one. +func TestMergeTrainHeadReadinessIgnoresStaleStage(t *testing.T) { + c := &Engine{} + c.stageStore = stagelabels.NewStore("", time.Now) + key := stagelabels.Key("acme/widget", 7) + c.stageStore.Observe(key, stagelabels.AwaitingMergeAdmission, "") + c.stageStore.NoteActivity(key, stagelabels.Activity{Head: "old", Comments: -1, Reviews: -1}) + if got := c.mergeTrainHeadReadiness("self", "acme", "widget", 7, "old"); got != mergeTrainReadinessReady { + t.Fatalf("readiness at the recorded head = %d, want ready", got) + } + if got := c.mergeTrainHeadReadiness("self", "acme", "widget", 7, "new"); got != mergeTrainReadinessUnknown { + t.Fatalf("readiness at a pushed head = %d, want unknown", got) + } +} diff --git a/src/pkg/github/automerge/automerge_merge_train_test.go b/src/pkg/github/automerge/automerge_merge_train_test.go index ce05815aca..dd68e91a19 100644 --- a/src/pkg/github/automerge/automerge_merge_train_test.go +++ b/src/pkg/github/automerge/automerge_merge_train_test.go @@ -20,17 +20,20 @@ import ( "github.com/hivecommons/hive/pkg/stagelabels" ) +// mtMember is a ready member (green, reviewed on its head): the only kind +// that takes a seat (hivecommons/hive#15825). func mtMember(n int, state string, created time.Time, files ...string) mergeTrainMember { - return mergeTrainMember{Number: n, Base: "v5", HeadSHA: "sha" + strconv.Itoa(n), Files: files, CreatedAt: created, MergeableState: state} + return mergeTrainMember{Number: n, Base: "v5", HeadSHA: "sha" + strconv.Itoa(n), Files: files, CreatedAt: created, MergeableState: state, Readiness: mergeTrainReadinessReady} } func TestGroupMergeTrains(t *testing.T) { t0 := time.Date(2026, 10, 20, 9, 0, 0, 0, time.UTC) cases := []struct { - name string - members []mergeTrainMember - want [][]int - overlap []string + name string + members []mergeTrainMember + want [][]int + candidates [][]int + overlap []string }{ { name: "disjoint files form no train", @@ -88,13 +91,14 @@ func TestGroupMergeTrains(t *testing.T) { overlap: []string{"a.go"}, }, { - name: "a mergeable head fronts over an older blocked one", + name: "a blocked head is a candidate, not a member; the mergeable one fronts alone", members: []mergeTrainMember{ blocked(mtMember(1, "clean", t0, "x.go")), mtMember(2, "clean", t0.Add(time.Minute), "x.go"), }, - want: [][]int{{2, 1}}, - overlap: []string{"x.go"}, + want: [][]int{{2}}, + candidates: [][]int{{1}}, + overlap: []string{"x.go"}, }, { name: "every member blocked holds nobody back (fail-open)", @@ -105,40 +109,62 @@ func TestGroupMergeTrains(t *testing.T) { }, { // hivecommons/hive#15741 at CI / Review led #15748 and #15755, - // both green at 080, and nothing merged. - name: "ready members lead an older one still at CI / Review", + // both green at 080, and nothing merged. Items that have not + // passed the review or CI is not green should not be in a + // merge train (hivecommons/hive#15825): #15741 is a candidate. + name: "not green or reviewed is not a member: ready members ride, the one at CI / Review is a candidate", members: []mergeTrainMember{ readiness(mtMember(15741, "clean", t0, "x.go"), mergeTrainReadinessUnready), readiness(mtMember(15748, "clean", t0.Add(time.Minute), "x.go"), mergeTrainReadinessReady), readiness(mtMember(15755, "clean", t0.Add(2*time.Minute), "x.go"), mergeTrainReadinessReady), }, - want: [][]int{{15748, 15755, 15741}}, - overlap: []string{"x.go"}, + want: [][]int{{15748, 15755}}, + candidates: [][]int{{15741}}, + overlap: []string{"x.go"}, }, { - name: "an unevaluated head leads an unready one, ready beats both; readiness outranks mergeable state", + name: "an unevaluated head is a candidate too; only the ready head rides", members: []mergeTrainMember{ readiness(mtMember(1, "clean", t0, "x.go"), mergeTrainReadinessUnready), readiness(mtMember(2, "behind", t0.Add(time.Minute), "x.go"), mergeTrainReadinessReady), - mtMember(3, "clean", t0.Add(2*time.Minute), "x.go"), + readiness(mtMember(3, "clean", t0.Add(2*time.Minute), "x.go"), mergeTrainReadinessUnknown), }, - want: [][]int{{2, 3, 1}}, - overlap: []string{"x.go"}, + want: [][]int{{2}}, + candidates: [][]int{{3, 1}}, + overlap: []string{"x.go"}, }, { - name: "all unready keeps the age tiebreak (a provisional front)", + name: "all unready forms no train (nobody is ready to front it)", members: []mergeTrainMember{ readiness(mtMember(2, "clean", t0.Add(time.Minute), "x.go"), mergeTrainReadinessUnready), readiness(mtMember(1, "clean", t0, "x.go"), mergeTrainReadinessUnready), }, - want: [][]int{{1, 2}}, - overlap: []string{"x.go"}, }, { - name: "a blocked head trails even a ready-tier sort", + name: "a blocked head never rides even when ready-tier", members: []mergeTrainMember{ blocked(readiness(mtMember(1, "clean", t0, "x.go"), mergeTrainReadinessReady)), - readiness(mtMember(2, "clean", t0.Add(time.Minute), "x.go"), mergeTrainReadinessUnready), + readiness(mtMember(2, "clean", t0.Add(time.Minute), "x.go"), mergeTrainReadinessReady), + }, + want: [][]int{{2}}, + candidates: [][]int{{1}}, + overlap: []string{"x.go"}, + }, + { + name: "the earliest seat leads; a member back from ejection re-enters at the back", + members: []mergeTrainMember{ + seated(mtMember(1, "clean", t0, "x.go"), time.Time{}), + seated(mtMember(2, "clean", t0.Add(time.Minute), "x.go"), t0.Add(10*time.Minute)), + seated(mtMember(3, "clean", t0.Add(2*time.Minute), "x.go"), t0.Add(5*time.Minute)), + }, + want: [][]int{{3, 2, 1}}, + overlap: []string{"x.go"}, + }, + { + name: "a conflict the train is repairing trails every head that merges as is", + members: []mergeTrainMember{ + seated(mtMember(1, "dirty", t0, "x.go"), t0), + seated(mtMember(2, "clean", t0.Add(time.Minute), "x.go"), t0.Add(time.Minute)), }, want: [][]int{{2, 1}}, overlap: []string{"x.go"}, @@ -147,13 +173,19 @@ func TestGroupMergeTrains(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { groups := groupMergeTrains(tc.members) - var got [][]int + var got, cands [][]int for _, g := range groups { got = append(got, g.Order) + if len(g.Candidates) > 0 { + cands = append(cands, g.Candidates) + } } if !reflect.DeepEqual(got, tc.want) { t.Fatalf("orders = %v, want %v", got, tc.want) } + if !reflect.DeepEqual(cands, tc.candidates) { + t.Fatalf("candidates = %v, want %v", cands, tc.candidates) + } if len(groups) == 1 && !reflect.DeepEqual(groups[0].OverlapFiles, tc.overlap) { t.Fatalf("overlap = %v, want %v", groups[0].OverlapFiles, tc.overlap) } @@ -247,6 +279,7 @@ func TestPlanMergeTrainsSiblingsAndFront(t *testing.T) { c, logs := newMergeTrainEngine(t, srv.URL, DefaultMergeTrainPolicy, nil) // The list API carries no mergeable state; the planner reads it. prs := []*gh.PullRequest{mtPR(13, t0, ""), mtPR(11, t0.Add(time.Minute), ""), mtPR(10, t0.Add(2*time.Minute), ""), mtPR(12, t0.Add(3*time.Minute), ""), mtPR(14, t0.Add(4*time.Minute), "")} + mtReady(c, "self", prs...) prefilter := func(pr *gh.PullRequest) string { if pr.GetNumber() == 11 { return "label:needs-rebase" // admitted: a merely-behind head is what the train updates @@ -349,6 +382,7 @@ func TestMergeTrainAfterFrontMergeBehindAndDirty(t *testing.T) { }) c, _ := newMergeTrainEngine(t, srv.URL, DefaultMergeTrainPolicy, resolver) prs := []*gh.PullRequest{mtPR(20, t0, ""), mtPR(21, t0.Add(time.Minute), ""), mtPR(22, t0.Add(2*time.Minute), ""), mtPR(23, t0.Add(3*time.Minute), "")} + mtReady(c, "self", prs...) plan := c.planMergeTrains(context.Background(), "self", "acme/widget", "acme", "widget", prs, func(*gh.PullRequest) string { return "" }) if !plan.isFront(20) { t.Fatalf("front = %v", plan.groups) @@ -397,6 +431,7 @@ func TestMergeTrainFrontRebaseLoopGuard(t *testing.T) { }) c, logs := newMergeTrainEngine(t, srv.URL, MergeTrainPolicy{Enabled: true, MaxRebaseAttempts: 2}, resolver) prs := []*gh.PullRequest{mtPR(30, t0, ""), mtPR(31, t0.Add(time.Minute), "")} + mtReady(c, "self", prs...) // Two heads that arrived conflicting on their own are nobody's train: // the planner carries neither (hivecommons/hive#15395, #15307). if plan := plan0(c, prs); plan.isFront(30) || plan.isSibling(31) || len(plan.groups) != 0 { @@ -468,6 +503,7 @@ func TestPlanMergeTrainsExcludesReturnedAndConflicting(t *testing.T) { returned := mtPR(15430, t0.Add(2*time.Minute), "") returned.Labels = []*gh.Label{{Name: gh.Ptr(stagelabels.ReturnedToContributor.Label())}} prs := []*gh.PullRequest{mtPR(15424, t0, ""), mtPR(15307, t0.Add(time.Minute), ""), returned, mtPR(15431, t0.Add(3*time.Minute), "")} + mtReady(c, "self", prs...) plan := plan0(c, prs) for _, n := range []int{15307, 15430, 15431} { if plan.isSibling(n) || plan.isFront(n) { @@ -509,6 +545,7 @@ func TestMergeTrainFrontNoResolverFallsThroughOnce(t *testing.T) { defer srv.Close() c, logs := newMergeTrainEngine(t, srv.URL, DefaultMergeTrainPolicy, nil) prs := []*gh.PullRequest{mtPR(40, t0, ""), mtPR(41, t0.Add(time.Minute), "")} + mtReady(c, "self", prs...) // Without a resolver no dirty head is under repair, so two conflicting // heads are no train at all and the lane's conflicting path takes them. for i := 0; i < 2; i++ { @@ -575,6 +612,19 @@ func readiness(m mergeTrainMember, tier int) mergeTrainMember { return m } +// mtReady records the lane's "would merge" verdict for each PR's current +// head (sha): the readiness a seat requires (hivecommons/hive#15825). +func mtReady(c *Engine, lane string, prs ...*gh.PullRequest) { + for _, pr := range prs { + c.noteMergeTrainOutcome(lane, "acme", "widget", pr.GetNumber(), pr.GetHead().GetSHA(), "") + } +} + +func seated(m mergeTrainMember, since time.Time) mergeTrainMember { + m.SeatedSince = since + return m +} + // TestMergeTrainReadinessMemory: the lane's verdict on a head sets its // readiness tier for the next plan — a soak or merge-queue wait is ready, // CI pending or a review wait is unready, a new head forgets — and a PR @@ -714,6 +764,7 @@ func TestMergeTrainHumanMergeNeverMember(t *testing.T) { defer srv.Close() c, _ := newMergeTrainEngine(t, srv.URL, DefaultMergeTrainPolicy, nil) prs := []*gh.PullRequest{mtPR(60, t0, "clean"), mtPR(61, t0.Add(time.Minute), "clean"), mtPR(62, t0.Add(2*time.Minute), "clean")} + mtReady(c, "self", prs...) // The oldest, cleanest PR is an untrusted author's: the lane said so. c.noteMergeTrainOutcome("self", "acme", "widget", 60, "sha60", prstage.ContributorLaneReasonNoLinkedIssue) plan := plan0(c, prs) @@ -725,14 +776,18 @@ func TestMergeTrainHumanMergeNeverMember(t *testing.T) { } // The same verdict from another lane does not touch this lane's train. c2, _ := newMergeTrainEngine(t, srv.URL, DefaultMergeTrainPolicy, nil) + mtReady(c2, "self", prs...) c2.noteMergeTrainOutcome("trusted", "acme", "widget", 60, "sha60", "untrusted-author-role") if plan := plan0(c2, prs); !plan.isFront(60) { t.Fatal("another lane's verdict must not evict the member from this lane's train") } - // A new head starts clean: the lane re-judges it. + // A clean verdict re-admits the PR — at the back: #61 and #62 hold + // the earlier seats (hivecommons/hive#15825). c.noteMergeTrainOutcome("self", "acme", "widget", 60, "sha60", "") - if plan := plan0(c, prs); !plan.isFront(60) { - t.Fatal("a clean verdict re-admits the PR") + if plan := plan0(c, prs); !plan.isFront(61) || !plan.isSibling(60) { + t.Fatalf("a clean verdict re-admits the PR behind the seated members: %+v", plan.groups) + } else if g, _ := plan.group(60); g.Position(60) != 3 { + t.Fatalf("re-admitted PR position = %d, want 3 (the back)", g.Position(60)) } } @@ -757,6 +812,7 @@ func TestPlanMergeTrainsExcludesUnderRepair(t *testing.T) { needsAuthor := mtPR(15408, t0.Add(3*time.Minute), "") needsAuthor.Labels = []*gh.Label{{Name: gh.Ptr(stagelabels.NeedsAuthor.Label())}} prs := []*gh.PullRequest{fixing, mtPR(15406, t0.Add(time.Minute), ""), mtPR(15407, t0.Add(2*time.Minute), ""), needsAuthor} + mtReady(c, "self", prs...) plan := plan0(c, prs) for _, n := range []int{15405, 15407, 15408} { if plan.isSibling(n) || plan.isFront(n) { diff --git a/src/pkg/github/automerge/automerge_sweep.go b/src/pkg/github/automerge/automerge_sweep.go index 1502bc2c98..f924124ebd 100644 --- a/src/pkg/github/automerge/automerge_sweep.go +++ b/src/pkg/github/automerge/automerge_sweep.go @@ -1271,7 +1271,7 @@ func (c *Engine) SweepSelfAuthoredAutoMerges(ctx context.Context, opts AutoMerge result.Candidates++ repoCandidates++ c.sweepClock.evaluating(repo, number) - event, reason, err := c.trySweepSelfAuthoredPR(ctx, repo, owner, repoName, number, branchUpdateAttempts < selfAuthoredSweepMaxBranchUpdates) + event, reason, err := c.trySweepSelfAuthoredPR(withMergeTrainCandidateHold(ctx, c.mergeTrainCandidateReason(train, number)), repo, owner, repoName, number, branchUpdateAttempts < selfAuthoredSweepMaxBranchUpdates) c.sweepClock.evaluated() if event.BranchUpdated || reason == "updated-branch" || reason == "update-branch" { branchUpdateAttempts++ @@ -1466,7 +1466,7 @@ func (c *Engine) SweepTrustedAuthorAutoMerges(ctx context.Context, opts AutoMerg } result.Candidates++ c.sweepClock.evaluating(displayRepo, number) - event, reason, err := c.trySweepTrustedAuthorPR(ctx, displayRepo, owner, repoName, number, policy) + event, reason, err := c.trySweepTrustedAuthorPR(withMergeTrainCandidateHold(ctx, c.mergeTrainCandidateReason(train, number)), displayRepo, owner, repoName, number, policy) c.sweepClock.evaluated() if err == nil { c.noteMergeTrainOutcome(stageLaneTrusted, owner, repoName, number, pr.GetHead().GetSHA(), reason) @@ -2076,6 +2076,10 @@ func (c *Engine) trySweepSelfAuthoredPR(ctx context.Context, displayRepo, owner, return AutoMergeSweepEvent{}, reviewReason, nil } + if hold := mergeTrainCandidateHold(ctx); hold != "" { + return AutoMergeSweepEvent{}, hold, nil + } + // Queue-enabled bases use GitHub's native queue after the same gates. // Other bases retain the direct merge and remembered refusal handling. if reason, err := c.tryNativeQueue(ctx, current, mergeClaim); reason != "" || err != nil { @@ -2534,6 +2538,9 @@ func (c *Engine) trySweepTrustedAuthorPR(ctx context.Context, displayRepo, owner if reviewReason := c.mergeReviewGate(ctx, displayRepo, owner, repo, stageLaneTrusted, number, current, headSHA, priorApprover, priorChecked); reviewReason != "" { return AutoMergeSweepEvent{}, reviewReason, nil } + if hold := mergeTrainCandidateHold(ctx); hold != "" { + return AutoMergeSweepEvent{}, hold, nil + } if reason, err := c.tryNativeQueue(ctx, current, mergeClaim); reason != "" || err != nil { return AutoMergeSweepEvent{}, reason, err } diff --git a/src/pkg/stageengine/derive_pr_classify.go b/src/pkg/stageengine/derive_pr_classify.go index 8577097f00..5676a85a51 100644 --- a/src/pkg/stageengine/derive_pr_classify.go +++ b/src/pkg/stageengine/derive_pr_classify.go @@ -396,6 +396,17 @@ func ClassifyStage(o stageObservation) stageVerdict { // the App's own — as superseded, never "waiting its turn". return stageVerdict{Stage: fixing, Rank: stageRankOwned} } + // Items that have not passed the review or CI is not green should + // not be (a) ready for merge, (b) in a merge train + // (hivecommons/hive#15825): the train seats only heads the lane + // found green and reviewed, and a seat never outranks what this + // head's own evidence says. + if VerdictBlocks(o.Detail) { + return stageVerdict{Stage: fixing, Rank: stageRankOwned, Reason: StageVerdictReason(o.Detail)} + } + if name := o.Detail.RedCheck(o.HeadSHA); name != "" { + return stageVerdict{Stage: fixing, Rank: stageRankOwned, Reason: stageReasonOptionalCheckFailing + name} + } return WithHumanApprovalReason(stageVerdict{Stage: stagelabels.AwaitingMergeAdmission, Rank: stageRankOwned}, humanApprovalReason) } if rank := stageAdmissionReasons[reason]; rank != stageRankNone { diff --git a/src/pkg/stageengine/derive_pr_merge_train_test.go b/src/pkg/stageengine/derive_pr_merge_train_test.go index 265460041d..ccc2960f82 100644 --- a/src/pkg/stageengine/derive_pr_merge_train_test.go +++ b/src/pkg/stageengine/derive_pr_merge_train_test.go @@ -57,3 +57,28 @@ func TestClassifyStageMergeTrainDuplicateParksWithAuthor(t *testing.T) { } } } + +// hivecommons/hive#15825: 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 +// train reason never lifts a head whose own evidence is red or whose +// reviewer asked for changes to 080; the admitted hold (green, reviewed, +// waiting for a seat) is 080. +func TestClassifyStageMergeTrainNotGreenOrReviewedIsNotMergeQueue(t *testing.T) { + parked := prstage.MergeTrain{State: prstage.MergeTrainStateQueuedBehind, Front: 15748, Position: 3, Size: 4}.Reason() + red := ClassifyStage(stageObservation{Lane: stageLaneSelf, Reason: parked, HeadSHA: goldenHead, + Detail: stageDetail{RedChecks: []string{"coverage"}, RedChecksHead: goldenHead}}) + if red.Stage != stagelabels.Fixing || red.Reason != stageReasonOptionalCheckFailing+"coverage" { + t.Fatalf("red check under a train reason classified as %+v, want 070 with the check named", red) + } + changes := ClassifyStage(stageObservation{Lane: stageLaneSelf, Reason: parked, HeadSHA: goldenHead, + Detail: stageDetail{VerdictKnown: true, Verdict: prstage.ReviewVerdict{Verdict: "changes_requested"}}}) + if changes.Stage != stagelabels.Fixing || changes.Reason == "" { + t.Fatalf("changes requested under a train reason classified as %+v, want 070", changes) + } + admitted := prstage.MergeTrain{State: prstage.MergeTrainStateAdmitted, Front: 15748, Position: 0, Size: 2}.Reason() + v := ClassifyStage(stageObservation{Lane: stageLaneContributor, Reason: admitted, HeadSHA: goldenHead, + Detail: stageDetail{VerdictKnown: true, Verdict: prstage.ReviewVerdict{Approved: true}}}) + if v.Stage != stagelabels.AwaitingMergeAdmission || v.Human { + t.Fatalf("admitted candidate classified as %+v, want 080", v) + } +} diff --git a/src/pkg/stageengine/prstage/merge_train.go b/src/pkg/stageengine/prstage/merge_train.go index e948959893..110abb3d56 100644 --- a/src/pkg/stageengine/prstage/merge_train.go +++ b/src/pkg/stageengine/prstage/merge_train.go @@ -49,7 +49,13 @@ const ( // claimant, Position the issue. Unlike DuplicateOf the queue picked // nobody: the PR parks at 085 until a person or the delegate decides. MergeTrainStateClaimConflict = "claim-conflict" - MergeTrainReasonMaxFiles = 4 + // MergeTrainStateAdmitted: the PR shares files with a train and the + // lane just found it ready (green, approved, mergeable); it is held + // for a seat at the back of the train on the next pass rather than + // merged ahead of the front (hivecommons/hive#15825). Position is 0; + // Size is the train's current size. + MergeTrainStateAdmitted = "admitted" + MergeTrainReasonMaxFiles = 4 ) // MergeTrain is the decoded form of a merge-train reason. @@ -203,6 +209,8 @@ func (m MergeTrain) Sentence() string { return "1st in the merge queue, still conflicting after " + strconv.Itoa(m.MaxAttempts) + " rebase attempts; a person decides (" + slot + files + ")" case MergeTrainStateFront: return "1st in the merge queue; merges next (" + slot + files + ")" + case MergeTrainStateAdmitted: + return "green and approved; joins the merge train behind #" + strconv.Itoa(m.Front) + " on the next pass (" + strconv.Itoa(m.Size) + " ahead" + files + ")" case MergeTrainStateDuplicateOf: issue := "" if m.Position > 0 { diff --git a/src/pkg/stagelabels/store.go b/src/pkg/stagelabels/store.go index 9b8db788d9..bbf72d05bc 100644 --- a/src/pkg/stagelabels/store.go +++ b/src/pkg/stagelabels/store.go @@ -344,6 +344,15 @@ type Record struct { // is not evidence that a park lifted (hivecommons/hive#15541 rows read // "PR in progress" while the record said 085). LabelsSuppressed bool `json:"labels_suppressed,omitempty"` + // TrainEjectedWhy / TrainEjectedHead / TrainEjectedAt record the merge + // train's last ejection of this PR (hivecommons/hive#15825): the head + // it was ejected at, why (head-moved, ci-pending, ci-red, + // verdict-owed, conflicting, …) and when. The tracker's gray pill + // carries the lineage ("left merge train · pushed 3m ago") while the + // row sits back in the CI / Review column; re-admission clears it. + TrainEjectedWhy string `json:"train_ejected_why,omitempty"` + TrainEjectedHead string `json:"train_ejected_head,omitempty"` + TrainEjectedAt time.Time `json:"train_ejected_at,omitempty"` } // Activity is what the reconciler observed this cycle that a person (or @@ -864,6 +873,55 @@ func (s *Store) NotePush(key, sha string, at time.Time) bool { return true } +// NoteTrainEjected records that the merge train ejected an existing +// record's PR at head for why (hivecommons/hive#15825). A zero or future +// instant reads as now. +func (s *Store) NoteTrainEjected(key, head, why string, now time.Time) { + why = strings.TrimSpace(why) + if why == "" { + s.ClearTrainEjected(key) + return + } + s.mu.Lock() + defer s.mu.Unlock() + r, ok := s.items[key] + if !ok { + return + } + at := now + if clock := s.now(); at.IsZero() || at.After(clock) { + at = clock + } + if r.TrainEjectedWhy == why && r.TrainEjectedHead == head { + return + } + r.TrainEjectedWhy, r.TrainEjectedHead, r.TrainEjectedAt = why, strings.TrimSpace(head), at + s.items[key] = r + s.dirty = true +} + +// ClearTrainEjected forgets a record's merge-train ejection: the PR rides +// a train again, or merged. +func (s *Store) ClearTrainEjected(key string) { + s.mu.Lock() + defer s.mu.Unlock() + r, ok := s.items[key] + if !ok || (r.TrainEjectedWhy == "" && r.TrainEjectedHead == "" && r.TrainEjectedAt.IsZero()) { + return + } + r.TrainEjectedWhy, r.TrainEjectedHead, r.TrainEjectedAt = "", "", time.Time{} + s.items[key] = r + s.dirty = true +} + +// TrainEjected reports the recorded merge-train ejection. +func (r Record) TrainEjected() (why, head string, at time.Time, ok bool) { + if r.TrainEjectedWhy == "" { + return "", "", time.Time{}, false + } + return r.TrainEjectedWhy, r.TrainEjectedHead, r.TrainEjectedAt, true +} + // PushedSinceWaiting reports whether a push landed after the current // waiting-on-push state began: the ball is back with the hive even if the // sweep has not re-staged the item yet. From 0c9487902b878f325644140cd02adae27d6f40eb Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Fri, 30 Oct 2026 14:04:46 -0400 Subject: [PATCH 2/2] fix: rebasing rides no seat; train size counts seats; seat words over checking-now MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - stage engine files a rebasing train member at 070 (its new head owes CI and verdicts); transition diagram gains 080->070 / 080->050 edges - tracker: red-check rows hold no seat and are not counted in size; riders are renumbered (gate reason, caption) to the train that rides; a lone 080 rider under a pending front keeps its seat words instead of 'Ready for auto merge · checking now' - sweep clock marks only the PR being evaluated as 'checking now' - SPA chevron word shows 'Rebasing · attempt n/m' below the merge queue hivecommons/hive#15825 Signed-off-by: Andrew Anderson --- .../fixed-15825-merge-train-ready-only.md | 2 +- src/docs/hive-merge.md | 8 +- .../stage-labels.md | 2 + src/pkg/dashboard/stage_tracker.go | 6 + src/pkg/dashboard/stage_tracker_build.go | 1 + .../stage_tracker_merge_train_ejected_test.go | 48 +++++++ .../stage_tracker_merge_train_overlap_test.go | 18 ++- .../stage_tracker_merge_train_postpass.go | 131 +++++++++++++++++- .../stage_tracker_merge_train_test.go | 52 ++++--- .../dashboard/static-src/js/tracker-row.js | 4 + src/pkg/dashboard/static/index.html | 4 + src/pkg/stageengine/derive_pr_classify.go | 5 + .../stageengine/derive_pr_merge_train_test.go | 4 +- src/pkg/stageengine/transition_table.go | 2 + src/pkg/stageengine/transition_table_test.go | 6 +- 15 files changed, 264 insertions(+), 29 deletions(-) diff --git a/changelog.d/fixed-15825-merge-train-ready-only.md b/changelog.d/fixed-15825-merge-train-ready-only.md index f298dafec6..2293b72dc8 100644 --- a/changelog.d/fixed-15825-merge-train-ready-only.md +++ b/changelog.d/fixed-15825-merge-train-ready-only.md @@ -1 +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 ([#15825](https://github.com/hivecommons/hive/issues/15825)). +- 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)). diff --git a/src/docs/hive-merge.md b/src/docs/hive-merge.md index 7944699ec7..de75260387 100644 --- a/src/docs/hive-merge.md +++ b/src/docs/hive-merge.md @@ -472,7 +472,13 @@ 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. +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 diff --git a/src/docs/labels-and-control-signals/stage-labels.md b/src/docs/labels-and-control-signals/stage-labels.md index f5716df41a..5250872bc0 100644 --- a/src/docs/labels-and-control-signals/stage-labels.md +++ b/src/docs/labels-and-control-signals/stage-labels.md @@ -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 diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index d16c1fe4e3..b7e029cc97 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -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 diff --git a/src/pkg/dashboard/stage_tracker_build.go b/src/pkg/dashboard/stage_tracker_build.go index 88bb422165..eb15a0dedc 100644 --- a/src/pkg/dashboard/stage_tracker_build.go +++ b/src/pkg/dashboard/stage_tracker_build.go @@ -364,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 diff --git a/src/pkg/dashboard/stage_tracker_merge_train_ejected_test.go b/src/pkg/dashboard/stage_tracker_merge_train_ejected_test.go index a081f7ccbd..ec4e076e48 100644 --- a/src/pkg/dashboard/stage_tracker_merge_train_ejected_test.go +++ b/src/pkg/dashboard/stage_tracker_merge_train_ejected_test.go @@ -149,3 +149,51 @@ func TestStageTrackerAdmittedCandidateRidesNoTrain(t *testing.T) { t.Fatalf("caption = %q", it.Caption) } } + +// TestStageTrackerNotGreenOrReviewedIsNotInMergeQueueColumn_RedCheckRiderUnseated: +// the live header read "merge train · 8 PRs" over seven seats — the eighth +// was a red-check row at 090. A member whose current head has a failing +// check holds no seat and is not counted in the train's size. +func TestStageTrackerNotGreenOrReviewedIsNotInMergeQueueColumn_RedCheckRiderUnseated(t *testing.T) { + now := time.Date(2026, 10, 30, 17, 0, 0, 0, time.UTC) + s, store := stageTrackerFixture(t, now) + overlap := []string{"tracker-row.js"} + for i, n := range []int{15771, 15834, 15831} { + st := prstage.MergeTrainStateQueuedBehind + if i == 0 { + st = prstage.MergeTrainStateFront + } + stage := stagelabels.AwaitingMergeAdmission + if n == 15831 { + stage = stagelabels.ReadyForHumanMerge + } + store.Observe(stagelabels.Key("acme/console", n), stage, prstage.MergeTrain{State: st, Front: 15771, Position: i + 1, Size: 3, OverlapFiles: overlap}.Reason()) + pr := github.PullRequest{Number: n, Title: "Tracker", Author: "hive-app[bot]", AppAuthored: true, BaseRef: "v5", Labels: []string{stage.Label(), "author/hive"}} + if n == 15831 { + pr.CIStatus = "failure" + pr.FailingChecks = []string{"build-and-test"} + } + s.statusMu.Lock() + s.status.Repos[0].OpenPrs = append(s.status.Repos[0].OpenPrs, FrontendPR{PullRequest: pr}) + s.statusMu.Unlock() + } + resp := s.buildStageTracker(s.status, store, now) + red := trackerItem(t, resp, "pr", 15831) + if red.MergeTrain != nil { + t.Fatalf("a red-check row holds no seat: %+v", red.MergeTrain) + } + if red.LeftTrain == nil || red.LeftTrain.Why != "checks-failing" { + t.Fatalf("red row lineage = %+v", red.LeftTrain) + } + front := trackerItem(t, resp, "pr", 15771) + rider := trackerItem(t, resp, "pr", 15834) + if front.MergeTrain == nil || front.MergeTrain.Size != 2 || rider.MergeTrain == nil || rider.MergeTrain.Size != 2 || rider.MergeTrain.Position != 2 { + t.Fatalf("size counts seated members only: front=%+v rider=%+v", front.MergeTrain, rider.MergeTrain) + } + if got := front.MergeTrain.Members; len(got) != 2 || got[0] != 15771 || got[1] != 15834 { + t.Fatalf("members = %v", got) + } + if !strings.Contains(rider.MergeGate.Reason, "behind #15771 in merge train (2nd of 2") || !strings.Contains(rider.Caption, "behind #15771") { + t.Fatalf("rider words = gate %q caption %q", rider.MergeGate.Reason, rider.Caption) + } +} diff --git a/src/pkg/dashboard/stage_tracker_merge_train_overlap_test.go b/src/pkg/dashboard/stage_tracker_merge_train_overlap_test.go index ce18e2eae2..dc96ab4ba9 100644 --- a/src/pkg/dashboard/stage_tracker_merge_train_overlap_test.go +++ b/src/pkg/dashboard/stage_tracker_merge_train_overlap_test.go @@ -111,9 +111,10 @@ func TestStageTrackerMergeTrainCountsOnlyMergeQueueMembers(t *testing.T) { } // Two overlapping PRs, the planner's front still at 050 and the sibling -// at 080: no train (one merge-queue member is no train), the 080 row -// back to its own caption, the 050 row with the hint — naming the 080 -// row as the PR it joins behind: the lane merges the ready one first. +// at 080: no train object (one merge-queue member is no train), but the +// 080 row keeps its seat words — "behind #15577 (2nd of 2)" — rather than +// "Ready for auto merge · checking now" (hivecommons/hive#15825), and the +// 050 row's hint says it leads once green, naming the rider waiting on it. func TestStageTrackerMergeTrainPendingFrontLeavesLoneRider(t *testing.T) { now := time.Date(2026, 10, 30, 0, 0, 0, 0, time.UTC) s, store := stageTrackerFixture(t, now) @@ -132,14 +133,17 @@ func TestStageTrackerMergeTrainPendingFrontLeavesLoneRider(t *testing.T) { if front.MergeTrain != nil || rider.MergeTrain != nil { t.Fatalf("no train of one: front=%+v rider=%+v", front.MergeTrain, rider.MergeTrain) } - if front.Overlap == nil || front.Overlap.Behind != 15578 || len(front.Overlap.With) != 1 || front.Overlap.With[0] != 15578 { + if front.Overlap == nil || front.Overlap.Behind != 0 || len(front.Overlap.With) != 1 || front.Overlap.With[0] != 15578 || front.Overlap.Badge != "train · 1st once green" { t.Errorf("front overlap = %+v", front.Overlap) } - if want := "overlaps #15578 (tracker-words.js) — joins the merge train behind it when green"; front.Overlap.Note != want { + if want := "1st in the merge train; #15578 waits behind it until this head is green (tracker-words.js)"; front.Overlap.Note != want { t.Errorf("front note = %q, want %q", front.Overlap.Note, want) } - if rider.Overlap != nil || rider.Caption != stageTrackerAwaitingAdmissionCaption { - t.Errorf("080 rider: overlap=%+v caption=%q", rider.Overlap, rider.Caption) + if rider.MergeGate == nil || rider.MergeGate.State != MergeGateStateQueuedBehind || rider.MergeGate.SweepRunning || !strings.Contains(rider.MergeGate.Reason, "behind #15577 in merge train (2nd of 2") { + t.Errorf("080 rider gate = %+v", rider.MergeGate) + } + if rider.Caption == stageTrackerAwaitingAdmissionCaption || !strings.Contains(rider.Caption, "waiting its turn in the merge train — behind #15577") { + t.Errorf("080 rider caption = %q", rider.Caption) } } diff --git a/src/pkg/dashboard/stage_tracker_merge_train_postpass.go b/src/pkg/dashboard/stage_tracker_merge_train_postpass.go index b14ab4b974..da03f2a08c 100644 --- a/src/pkg/dashboard/stage_tracker_merge_train_postpass.go +++ b/src/pkg/dashboard/stage_tracker_merge_train_postpass.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "github.com/hivecommons/hive/pkg/stageengine/prstage" "github.com/hivecommons/hive/pkg/stagelabels" ) @@ -86,7 +87,18 @@ func stageTrackerMergeTrainPostPass(items []StageTrackerItem, opts mergeTrainQue // it stays so the person who rebases it sees where it merges. if it.MergeTrain.State != MergeGateStateRebaseExhausted { if why := stageTrackerTrainUnderRepair(it.Stage, it.Reason); why != "" { + rebasing := it.MergeTrain.State == MergeGateStateRebasing stageTrackerLeaveMergeTrain(it, why) + if rebasing { + stageTrackerApplyTrainRebasing(it) + } + continue + } + if it.ciRed { + // Items that have not passed the review or CI is not + // green should not be in a merge train (#15825): the + // listing's red verdict outranks a seat the record kept. + stageTrackerLeaveMergeTrain(it, "checks-failing") continue } if stageTrackerBelowMergeQueue(it.Stage) { @@ -102,6 +114,9 @@ func stageTrackerMergeTrainPostPass(items []StageTrackerItem, opts mergeTrainQue if why := stageTrackerTrainUnderRepair(front.Stage, front.Reason); why != "" { front.LeftTrain = &StageTrackerLeftTrain{Why: why, Note: stageTrackerLeftTrainNote, trainID: sample.ID, position: 1} frontLeft = true + } else if front.ciRed { + front.LeftTrain = &StageTrackerLeftTrain{Why: "checks-failing", Note: stageTrackerLeftTrainNote, trainID: sample.ID, position: 1} + frontLeft = true } else if stageTrackerBelowMergeQueue(front.Stage) { front.Overlap = stageTrackerOverlapHint(front.Number, sample.Front, roster(front.Number), sample.OverlapFiles) front.Overlap.trainID, front.Overlap.position = sample.ID, 1 @@ -155,7 +170,7 @@ func stageTrackerMergeTrainPostPass(items []StageTrackerItem, opts mergeTrainQue if len(dropped) > 0 { if sample.Size-len(dropped) < 2 { for _, i := range idx { - stageTrackerLeaveMergeTrain(&items[i], "") + stageTrackerKeepSeatWordsOrLeave(&items[i], items) } continue } @@ -197,6 +212,13 @@ func stageTrackerMergeTrainPostPass(items []StageTrackerItem, opts mergeTrainQue items[i].MergeTrain.Front = newFront } } + // A rider's gate and caption counted the planner's slot, size + // and front; say the seat it holds in the train that rides. + for _, i := range idx { + if items[i].MergeTrain.State == MergeGateStateQueuedBehind { + stageTrackerMergeTrainRiderWords(&items[i]) + } + } members := make([]int, 0, len(idx)) for _, i := range idx { members = append(members, items[i].Number) @@ -330,3 +352,110 @@ func stageTrackerSoakLeftOf(it *StageTrackerItem, now time.Time) time.Duration { } return 0 } + +// stageTrackerKeepSeatWordsOrLeave handles the one rider left when the +// view seats fewer than two of a train's members. Its train record is +// stale when its planner front is under repair or red — the engine +// ejects such a front on its next pass (hivecommons/hive#15825) — so the +// row goes back to the gate's own words. But while the record still +// holds a live seat behind a front the view merely draws below the +// merge queue (its 080 record lagging the engine's evaluation), the row +// keeps the seat's words — "behind #15771 (tracker-row.js)" — never +// "Ready for auto merge · checking now" (hive's own #15834 read so for +// twenty minutes): the gate carries the seat and the front's hint says +// it leads. No merge_train rides, so no header counts a train of one. +func stageTrackerKeepSeatWordsOrLeave(it *StageTrackerItem, items []StageTrackerItem) { + if it == nil || it.MergeTrain == nil { + return + } + mt := it.MergeTrain + parsed, ok := prstage.ParseMergeTrain(it.Reason) + seated := ok && parsed.State == prstage.MergeTrainStateQueuedBehind && parsed.Front > 0 && parsed.Front != it.Number && it.Stage == stagelabels.AwaitingMergeAdmission.Number() + var front *StageTrackerItem + if seated { + for i := range items { + f := &items[i] + if f.Kind == "pr" && f.Repo == it.Repo && f.Number == parsed.Front && f.Stage < stageTrackerMergedStage { + front = f + break + } + } + } + if front == nil || !stageTrackerBelowMergeQueue(front.Stage) || front.ciRed || stageTrackerTrainUnderRepair(front.Stage, front.Reason) != "" { + stageTrackerLeaveMergeTrain(it, "") + return + } + it.MergeTrain = nil + if it.MergeGate == nil { + it.MergeGate = &StageTrackerMergeGate{} + } + it.MergeGate.State = MergeGateStateQueuedBehind + it.MergeGate.Reason = parsed.Sentence() + it.MergeGate.SweepRunning = false + it.Caption = stageTrackerMergeTrainCaption(it.Reason) + if front.Overlap != nil { + front.Overlap.Behind = 0 + front.Overlap.With = []int{it.Number} + front.Overlap.Badge = "train · 1st once green" + front.Overlap.Note = "1st in the merge train; #" + strconv.Itoa(it.Number) + " waits behind it until this head is green" + stageTrackerOverlapFilesParen(mt.OverlapFiles) + } +} + +func stageTrackerOverlapFilesParen(files []string) string { + if len(files) == 0 { + return "" + } + return " (" + strings.Join(files, ", ") + ")" +} + +// stageTrackerApplyTrainRebasing words a member the train is rebasing +// (hivecommons/hive#15825). The head the hive pushes has no CI and no +// verdicts yet, so the stage engine files it at 070 and the row sits in +// the CI / Review column — never the Merge queue column — with its +// chevron reading "Rebasing · attempt 1/2" (the rebase pill the fixer's +// own episodes use) and a left-train note that says it rejoins when green. +func stageTrackerApplyTrainRebasing(it *StageTrackerItem) { + mt, ok := prstage.ParseMergeTrain(it.Reason) + if !ok || mt.State != prstage.MergeTrainStateRebasing { + return + } + attempt, max := mt.Attempt, mt.MaxAttempts + if attempt < 1 { + attempt = 1 + } + if max < attempt { + max = attempt + } + if it.Rebase == nil { + it.Rebase = &StageTrackerRebase{Attempt: attempt, Max: max, Text: "Rebasing · attempt " + strconv.Itoa(attempt) + "/" + strconv.Itoa(max)} + } + onto := "the base" + if mt.Front > 0 { + onto = "the merged front #" + strconv.Itoa(mt.Front) + } + note := "left the merge train while the hive rebases it onto " + onto + " (attempt " + strconv.Itoa(attempt) + " of " + strconv.Itoa(max) + "); the rebased head gets CI and review, then rejoins at the back" + if it.LeftTrain == nil { + it.LeftTrain = &StageTrackerLeftTrain{} + } + it.LeftTrain.Why, it.LeftTrain.Note, it.LeftTrain.Reason = "rebasing", note, stageTrackerEjectionReasonPrefix+"rebasing" + it.LeftTrain.Badge = "left merge train · rebasing " + strconv.Itoa(attempt) + "/" + strconv.Itoa(max) + it.Caption = stageTrackerMergeTrainCaption(it.Reason) +} + +// stageTrackerMergeTrainRiderWords rewrites a queued-behind rider's gate +// reason and caption from its live seat (position, size, front) so a +// member seated 3rd of 4 by the planner whose neighbour left the ride +// reads 2nd of 3 behind the new front — never the planner's stale count. +func stageTrackerMergeTrainRiderWords(it *StageTrackerItem) { + mt := it.MergeTrain + if mt == nil || it.MergeGate == nil { + return + } + live := prstage.MergeTrain{State: prstage.MergeTrainStateQueuedBehind, Front: mt.Front, Position: mt.Position, Size: mt.Size, OverlapFiles: mt.OverlapFiles} + if it.MergeGate.State == MergeGateStateQueuedBehind { + it.MergeGate.Reason = live.Sentence() + } + if strings.HasPrefix(it.Caption, "Approved; waiting its turn in the merge train") { + it.Caption = stageTrackerMergeTrainCaption(live.Reason()) + } +} diff --git a/src/pkg/dashboard/stage_tracker_merge_train_test.go b/src/pkg/dashboard/stage_tracker_merge_train_test.go index 010e7b1c9c..1c6b554697 100644 --- a/src/pkg/dashboard/stage_tracker_merge_train_test.go +++ b/src/pkg/dashboard/stage_tracker_merge_train_test.go @@ -28,7 +28,9 @@ func TestStageTrackerMergeTrainPayload(t *testing.T) { } store.Observe(stagelabels.Key("acme/console", 15074), stagelabels.AwaitingMergeAdmission, "") store.Observe(stagelabels.Key("acme/console", 15085), stagelabels.AwaitingMergeAdmission, queued(2)) - store.Observe(stagelabels.Key("acme/console", 15087), stagelabels.AwaitingMergeAdmission, prstage.MergeTrain{State: prstage.MergeTrainStateRebasing, Front: 15074, Position: 3, Size: 4, Attempt: 1, MaxAttempts: 2, OverlapFiles: overlap}.Reason()) + // hivecommons/hive#15825: the stage engine files a member the train is + // rebasing at 070 — its pushed head has no CI or verdicts yet. + store.Observe(stagelabels.Key("acme/console", 15087), stagelabels.Fixing, prstage.MergeTrain{State: prstage.MergeTrainStateRebasing, Front: 15074, Position: 3, Size: 4, Attempt: 1, MaxAttempts: 2, OverlapFiles: overlap}.Reason()) store.Observe(stagelabels.Key("acme/console", 15097), stagelabels.NeedsDecision, prstage.MergeTrain{State: prstage.MergeTrainStateRebaseExhausted, Front: 15074, Position: 4, Size: 4, Attempt: 2, MaxAttempts: 2, OverlapFiles: overlap}.Reason()) s.statusMu.Lock() for _, n := range []int{15074, 15085, 15087, 15097} { @@ -36,6 +38,9 @@ func TestStageTrackerMergeTrainPayload(t *testing.T) { if n == 15097 { stage = "stage/085-needs-decision" } + if n == 15087 { + stage = "stage/070-fixing" + } labels := []string{stage, "author/hive"} if n != 15074 { labels = append(labels, "needs-rebase") @@ -47,10 +52,10 @@ func TestStageTrackerMergeTrainPayload(t *testing.T) { resp := s.buildStageTracker(s.status, store, now) front := trackerItem(t, resp, "pr", 15074) - if front.MergeTrain == nil || front.MergeTrain.State != MergeGateStateTrainFront || front.MergeTrain.Position != 1 || front.MergeTrain.Size != 4 || front.MergeTrain.ID != "v5#15074" { + if front.MergeTrain == nil || front.MergeTrain.State != MergeGateStateTrainFront || front.MergeTrain.Position != 1 || front.MergeTrain.Size != 3 || front.MergeTrain.ID != "v5#15074" { t.Fatalf("front merge_train = %+v", front.MergeTrain) } - if front.MergeGate == nil || front.MergeGate.State != MergeGateStateTrainFront || !strings.Contains(front.Caption, "1st in a merge queue of 4 PRs") { + if front.MergeGate == nil || front.MergeGate.State != MergeGateStateTrainFront || !strings.Contains(front.Caption, "1st in a merge queue of 3 PRs") { t.Fatalf("front gate %+v caption %q", front.MergeGate, front.Caption) } if hasMod(front, modNeedsRebase) || len(front.MergeTrain.Ahead) != 0 { @@ -61,7 +66,7 @@ func TestStageTrackerMergeTrainPayload(t *testing.T) { if sib.Stage != 80 || sib.MergeTrain == nil || sib.MergeTrain.State != MergeGateStateQueuedBehind || sib.MergeTrain.Position != 2 || sib.MergeTrain.Front != 15074 { t.Fatalf("sibling = stage %d train %+v", sib.Stage, sib.MergeTrain) } - if sib.MergeGate == nil || sib.MergeGate.State != "queued-behind" || sib.MergeGate.Reason != "behind #15074 in merge train (2nd of 4, overlapping files: stage_tracker.go, index.html)" { + if sib.MergeGate == nil || sib.MergeGate.State != "queued-behind" || sib.MergeGate.Reason != "behind #15074 in merge train (2nd of 3, overlapping files: stage_tracker.go, index.html)" { t.Fatalf("sibling merge_gate = %+v", sib.MergeGate) } if hasMod(sib, modNeedsRebase) || hasMod(sib, modNeedsHuman) || !hasStale(sib, modNeedsRebase) { @@ -77,17 +82,19 @@ func TestStageTrackerMergeTrainPayload(t *testing.T) { t.Fatalf("a queued sibling owes no decision: %+v", sib.DecisionNeeded) } + // The member being rebased rides no train and sits in the CI / Review + // column with the rebase pill as its chevron word (hivecommons/hive#15825). rebasing := trackerItem(t, resp, "pr", 15087) - if rebasing.MergeTrain.State != MergeGateStateRebasing || rebasing.MergeTrain.Attempt != 1 || rebasing.MergeTrain.MaxAttempts != 2 || !strings.Contains(rebasing.Caption, "rebasing this PR (attempt 1 of 2)") { - t.Fatalf("rebasing = %+v caption %q", rebasing.MergeTrain, rebasing.Caption) + if rebasing.Stage != 70 || rebasing.MergeTrain != nil || !strings.Contains(rebasing.Caption, "rebasing this PR (attempt 1 of 2)") { + t.Fatalf("rebasing = stage %d train %+v caption %q", rebasing.Stage, rebasing.MergeTrain, rebasing.Caption) } - if got := rebasing.MergeTrain.Ahead; len(got) != 2 || got[0] != 15074 || got[1] != 15085 { - t.Fatalf("rebasing ahead = %v", got) + if rebasing.Rebase == nil || rebasing.Rebase.Text != "Rebasing · attempt 1/2" || rebasing.LeftTrain == nil || rebasing.LeftTrain.Why != "rebasing" || rebasing.LeftTrain.Reason != "merge-train:ejected:rebasing" { + t.Fatalf("rebasing pill %+v left %+v", rebasing.Rebase, rebasing.LeftTrain) } // Every member carries the whole roster in merge order, so a view that // draws only some of them can name the rest in the train header. - for _, it := range []StageTrackerItem{front, sib, rebasing} { - if got := it.MergeTrain.Members; fmt.Sprint(got) != fmt.Sprint([]int{15074, 15085, 15087, 15097}) { + for _, it := range []StageTrackerItem{front, sib} { + if got := it.MergeTrain.Members; fmt.Sprint(got) != fmt.Sprint([]int{15074, 15085, 15097}) { t.Fatalf("#%d members = %v", it.Number, got) } } @@ -114,8 +121,8 @@ func TestStageTrackerMergeTrainPayload(t *testing.T) { if err != nil { t.Fatal(err) } - for _, want := range []string{`"merge_gate":{"state":"queued-behind","reason":"behind #15074 in merge train (2nd of 4, overlapping files: stage_tracker.go, index.html)"`, - `"merge_train":{"id":"v5#15074","state":"queued-behind","front":15074,"position":2,"size":4,"overlap_files":["stage_tracker.go","index.html"],"ahead":[15074],"members":[15074,15085,15087,15097],"length":4,"head_number":15074,"head_state":"ready","head_reason":"approved and green; merges on hive's next pass","head_since":"2026-10-27T14:00:00Z","eta_s":300,"eta_at":"2026-10-27T14:05:00Z","eta_basis":"1 ahead"}`} { + for _, want := range []string{`"merge_gate":{"state":"queued-behind","reason":"behind #15074 in merge train (2nd of 3, overlapping files: stage_tracker.go, index.html)"`, + `"merge_train":{"id":"v5#15074","state":"queued-behind","front":15074,"position":2,"size":3,"overlap_files":["stage_tracker.go","index.html"],"ahead":[15074],"members":[15074,15085,15097],"length":3,"head_number":15074,"head_state":"ready","head_reason":"approved and green; merges on hive's next pass","head_since":"2026-10-27T14:00:00Z","eta_s":300,"eta_at":"2026-10-27T14:05:00Z","eta_basis":"1 ahead"}`} { if !strings.Contains(string(raw), want) { t.Fatalf("payload lacks %s:\n%s", want, raw) } @@ -124,12 +131,23 @@ func TestStageTrackerMergeTrainPayload(t *testing.T) { if plain := trackerItem(t, resp, "pr", 102); plain.MergeTrain != nil { t.Fatalf("PR 102 is not in a train: %+v", plain.MergeTrain) } - // A dirty front the train is rebasing carries its own reason and is not - // re-marked. - store.Observe(stagelabels.Key("acme/console", 15074), stagelabels.AwaitingMergeAdmission, prstage.MergeTrain{State: prstage.MergeTrainStateRebasing, Front: 15074, Position: 1, Size: 4, Attempt: 1, MaxAttempts: 2, OverlapFiles: overlap}.Reason()) + // A dirty front the train is rebasing (filed at 070 by the stage + // engine) leaves the train too; the rest close ranks behind #15085. + store.Observe(stagelabels.Key("acme/console", 15074), stagelabels.Fixing, prstage.MergeTrain{State: prstage.MergeTrainStateRebasing, Front: 15074, Position: 1, Size: 4, Attempt: 1, MaxAttempts: 2, OverlapFiles: overlap}.Reason()) + s.statusMu.Lock() + for i, raw := range s.status.Repos[0].OpenPrs { + if fp, ok := raw.(FrontendPR); ok && fp.Number == 15074 { + fp.Labels = []string{"stage/070-fixing", "author/hive"} + s.status.Repos[0].OpenPrs[i] = fp + } + } + s.statusMu.Unlock() resp = s.buildStageTracker(s.status, store, now) - if f := trackerItem(t, resp, "pr", 15074); f.MergeTrain.State != MergeGateStateRebasing || f.MergeTrain.Position != 1 { - t.Fatalf("rebasing front = %+v", f.MergeTrain) + if f := trackerItem(t, resp, "pr", 15074); f.Stage != 70 || f.MergeTrain != nil || f.Rebase == nil || f.Rebase.Text != "Rebasing · attempt 1/2" { + t.Fatalf("rebasing front = stage %d train %+v rebase %+v", f.Stage, f.MergeTrain, f.Rebase) + } + if n := trackerItem(t, resp, "pr", 15085); n.MergeTrain == nil || n.MergeTrain.State != MergeGateStateTrainFront || n.MergeTrain.Size != 2 { + t.Fatalf("new front = %+v", n.MergeTrain) } } diff --git a/src/pkg/dashboard/static-src/js/tracker-row.js b/src/pkg/dashboard/static-src/js/tracker-row.js index 74d8377c4d..2934e6eece 100644 --- a/src/pkg/dashboard/static-src/js/tracker-row.js +++ b/src/pkg/dashboard/static-src/js/tracker-row.js @@ -83,6 +83,10 @@ let word = state === 'active' && STAGE_TRACKER_ACTIVE_WORD[cur] ? STAGE_TRACKER_ACTIVE_WORD[cur] : (st.short || st.label || String(n)); // A merge-train member's word is its place in the train (#15117). if (state === 'active' && !detour && n > 0 && typeof stageTrackerTrainWord === 'function') { const tw = stageTrackerTrainWord(item, trains); if (tw) word = tw; } + // A PR the hive is rebasing (the train's or the fixer's episode) + // reads "Rebasing · attempt 1/2" in the CI / Review column it sits + // in (hive#15825) — its head has no CI yet, so no merge-queue word. + if (state === 'active' && !detour && n > 0 && n < 80 && item.rebase && item.rebase.text && !(typeof stageTrackerTrain === 'function' && stageTrackerTrain(item))) word = String(item.rebase.text); const mods = Array.isArray(item.modifiers) ? item.modifiers : []; const openHold = n === 0 && state === 'active' && mods.indexOf('hold') >= 0; // hold is a human instruction, so it wins over blocked when both are present. diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 8f1ccc6150..ae917bd227 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -16537,6 +16537,10 @@

Where to get help

let word = state === 'active' && STAGE_TRACKER_ACTIVE_WORD[cur] ? STAGE_TRACKER_ACTIVE_WORD[cur] : (st.short || st.label || String(n)); // A merge-train member's word is its place in the train (#15117). if (state === 'active' && !detour && n > 0 && typeof stageTrackerTrainWord === 'function') { const tw = stageTrackerTrainWord(item, trains); if (tw) word = tw; } + // A PR the hive is rebasing (the train's or the fixer's episode) + // reads "Rebasing · attempt 1/2" in the CI / Review column it sits + // in (hive#15825) — its head has no CI yet, so no merge-queue word. + if (state === 'active' && !detour && n > 0 && n < 80 && item.rebase && item.rebase.text && !(typeof stageTrackerTrain === 'function' && stageTrackerTrain(item))) word = String(item.rebase.text); const mods = Array.isArray(item.modifiers) ? item.modifiers : []; const openHold = n === 0 && state === 'active' && mods.indexOf('hold') >= 0; // hold is a human instruction, so it wins over blocked when both are present. diff --git a/src/pkg/stageengine/derive_pr_classify.go b/src/pkg/stageengine/derive_pr_classify.go index 5676a85a51..64ea4cc90f 100644 --- a/src/pkg/stageengine/derive_pr_classify.go +++ b/src/pkg/stageengine/derive_pr_classify.go @@ -407,6 +407,11 @@ func ClassifyStage(o stageObservation) stageVerdict { if name := o.Detail.RedCheck(o.HeadSHA); name != "" { return stageVerdict{Stage: fixing, Rank: stageRankOwned, Reason: stageReasonOptionalCheckFailing + name} } + if train.State == prstage.MergeTrainStateRebasing { + // The hive is rebasing it: the head it pushes has no CI and no + // verdicts yet, so it is being fixed (070), not merge-queued. + return stageVerdict{Stage: stagelabels.Fixing, Rank: stageRankOwned} + } return WithHumanApprovalReason(stageVerdict{Stage: stagelabels.AwaitingMergeAdmission, Rank: stageRankOwned}, humanApprovalReason) } if rank := stageAdmissionReasons[reason]; rank != stageRankNone { diff --git a/src/pkg/stageengine/derive_pr_merge_train_test.go b/src/pkg/stageengine/derive_pr_merge_train_test.go index ccc2960f82..adbd70cbdd 100644 --- a/src/pkg/stageengine/derive_pr_merge_train_test.go +++ b/src/pkg/stageengine/derive_pr_merge_train_test.go @@ -22,7 +22,9 @@ func TestClassifyStageMergeTrainReasons(t *testing.T) { human bool }{ {"queued-behind", prstage.MergeTrain{State: prstage.MergeTrainStateQueuedBehind, Front: 15074, Position: 3, Size: 4, OverlapFiles: files}.Reason(), stagelabels.AwaitingMergeAdmission, false}, - {"rebasing", prstage.MergeTrain{State: prstage.MergeTrainStateRebasing, Front: 15074, Position: 2, Size: 4, Attempt: 1, MaxAttempts: 2, OverlapFiles: files}.Reason(), stagelabels.AwaitingMergeAdmission, false}, + // hivecommons/hive#15825: a head the train is rebasing has no + // CI and no verdicts yet — being fixed, never merge-queued. + {"rebasing", prstage.MergeTrain{State: prstage.MergeTrainStateRebasing, Front: 15074, Position: 2, Size: 4, Attempt: 1, MaxAttempts: 2, OverlapFiles: files}.Reason(), stagelabels.Fixing, false}, {"exhausted", prstage.MergeTrain{State: prstage.MergeTrainStateRebaseExhausted, Front: 15074, Position: 2, Size: 4, Attempt: 2, MaxAttempts: 2, OverlapFiles: files}.Reason(), stagelabels.NeedsDecision, true}, // hivecommons/hive#15810: an undecided same-issue claim across // lanes is a person's call, not a turn in the queue. diff --git a/src/pkg/stageengine/transition_table.go b/src/pkg/stageengine/transition_table.go index 887fd41f39..1d3ae868d8 100644 --- a/src/pkg/stageengine/transition_table.go +++ b/src/pkg/stageengine/transition_table.go @@ -35,6 +35,8 @@ var diagramEdges = map[Edge]bool{ {stagelabels.Reviewed, stagelabels.AwaitingMergeAdmission}: true, // CI green, author side done {stagelabels.AwaitingMergeAdmission, stagelabels.PreMergeSoak}: true, // lane admits, soak window running {stagelabels.AwaitingMergeAdmission, stagelabels.MergeQueue}: true, // lane admits, no soak / soak already complete + {stagelabels.AwaitingMergeAdmission, stagelabels.Fixing}: true, // current head red, changes requested or being rebased by the train (hivecommons/hive#15825; backward hop) + {stagelabels.AwaitingMergeAdmission, stagelabels.ReviewPending}: true, // new push: CI and verdicts owed again on the current head (hivecommons/hive#15825; backward hop) {stagelabels.PreMergeSoak, stagelabels.MergeQueue}: true, // soak complete {stagelabels.MergeQueue, stagelabels.PreMergeSoak}: true, // pre-095 record reclassified while still soaking (not a regression) {stagelabels.ReviewPending, stagelabels.Fixing}: true, // hive PR red / changes requested diff --git a/src/pkg/stageengine/transition_table_test.go b/src/pkg/stageengine/transition_table_test.go index 592db19645..aca7db7604 100644 --- a/src/pkg/stageengine/transition_table_test.go +++ b/src/pkg/stageengine/transition_table_test.go @@ -134,7 +134,11 @@ func TestExpectedRules(t *testing.T) { // 045 never regresses (IsRegression) and every backward hop among // 010–040 is now drawn, so a park release is a non-regression hop. {"park released to a held claim, not drawn", stagelabels.IssueItem, stagelabels.IssueNeedsDecision, stagelabels.Claimed, true}, - {"undrawn regression (pr)", stagelabels.PRItem, stagelabels.AwaitingMergeAdmission, stagelabels.ReviewPending, false}, + {"undrawn regression (pr)", stagelabels.PRItem, stagelabels.PreMergeSoak, stagelabels.Reviewed, false}, + // hivecommons/hive#15825: a merge-queued head that is pushed or + // turns red / rebasing falls back to CI / Review, drawn. + {"merge-queued head pushed, drawn", stagelabels.PRItem, stagelabels.AwaitingMergeAdmission, stagelabels.ReviewPending, true}, + {"merge-queued head rebased by the train, drawn", stagelabels.PRItem, stagelabels.AwaitingMergeAdmission, stagelabels.Fixing, true}, {"pr stage on an issue", stagelabels.IssueItem, stagelabels.Actionable, stagelabels.ReviewPending, false}, {"issue stage on a pr", stagelabels.PRItem, stagelabels.Claimed, stagelabels.ReviewPending, false}, }