From 03477e7633a9502e9ab88c87b8a34ec7f9fd062d Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 21:57:58 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20tracker:=20PRs=20under=20rep?= =?UTF-8?q?air=20leave=20the=20merge=20train?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A PR being fixed (070), waiting on its author (071) or contributor (072), parked on a human decision (085), or with a red required check is not a merge-train member. The planner (mergeTrainUnderRepair) skips it; the tracker (stageTrackerTrainUnderRepair) drops it — the front included — with left_train {why, note} and a muted hover line, the survivors close ranks (size, position, front, ahead, members), and a train left with one member renders no header and no ordinal. The rebase-exhausted 085 tail stays: the train put it there. Hive's own #15405 led a header as "1st: #15405" while its chevron read "Fixing". Fixes #15615 Signed-off-by: Andrew Anderson --- ...fixed-tracker-train-under-repair-leaves.md | 1 + src/docs/api-reference/dashboard-misc.md | 2 +- src/docs/dashboard-copy-inventory.md | 1 + src/docs/dashboard-sections.md | 2 + src/pkg/dashboard/stage_tracker.go | 7 +- .../stage_tracker_merge_gate_test.go | 2 + .../dashboard/stage_tracker_merge_train.go | 175 ++++++++++++++++-- ...age_tracker_merge_train_membership_test.go | 151 +++++++++++++++ .../stage_tracker_merge_train_tag_test.go | 26 +++ .../stage_tracker_merge_train_test.go | 2 + .../dashboard/static-src/js/tracker-words.js | 16 +- src/pkg/dashboard/static/index.html | 16 +- .../github/automerge/automerge_merge_train.go | 44 +++-- .../automerge/automerge_merge_train_test.go | 45 +++++ 14 files changed, 454 insertions(+), 36 deletions(-) create mode 100644 changelog.d/fixed-tracker-train-under-repair-leaves.md create mode 100644 src/pkg/dashboard/stage_tracker_merge_train_membership_test.go diff --git a/changelog.d/fixed-tracker-train-under-repair-leaves.md b/changelog.d/fixed-tracker-train-under-repair-leaves.md new file mode 100644 index 0000000000..346aab32d7 --- /dev/null +++ b/changelog.d/fixed-tracker-train-under-repair-leaves.md @@ -0,0 +1 @@ +- Activity Monitor: a PR under repair — being fixed, waiting on its author or contributor, parked on a human decision, or with a red required check — is no longer a merge-train member. The planner skips it, the tracker drops it from the train with a muted hover note ("left the merge train while being fixed; rejoins when green"), the remaining members close ranks (count, ordinals, front), and a train left with one PR renders no header and no ordinal. Hive's own #15405 led a header as "1st: #15405" while its chevron read "Fixing" ([#15615](https://github.com/hivecommons/hive/issues/15615)). diff --git a/src/docs/api-reference/dashboard-misc.md b/src/docs/api-reference/dashboard-misc.md index 7b7911a12d..81fecb9e29 100644 --- a/src/docs/api-reference/dashboard-misc.md +++ b/src/docs/api-reference/dashboard-misc.md @@ -39,7 +39,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `GET` | `/api/budget-ignore` | Dashboard auth/session | Budget Ignore Get | `pkg/dashboard/api.go:172` | | `POST` | `/api/budget-ignore` | Owner only | Budget Ignore Set | `pkg/dashboard/api.go:173` | | `GET` | `/api/summaries` | Dashboard auth/session | Summaries | `pkg/dashboard/api.go:185` | -| `GET` | `/api/stage-tracker` | Dashboard auth/session | Stage Tracker: every open issue and pull request of the watched repos for the Hive activity monitor — actionable, held, claimed, in-progress, covered-by-PR, filtered (`needs-*`), draft and exempt-labelled items alike, each with `stage`, `stage_since`, `labels`, `created_at`, `author_kind`, `modifiers`, `claimant: {kind: hive-agent|clanker|person, login, agent, hive, since, source: claim-ledger|claim-comment|assignee|kick-history|author}` naming who holds a claimed / in-progress issue or a PR under review or rework (absent when nobody is named; mirrored onto `linked_prs[]`), (PRs) `sentinel_alert` / `sentinel_findings` / `sentinel_reason` when the sentinel flagged the PR, `decision_needed` on a row parked on a person (085 / 045 / 015, the needs-human pill; mirrored onto the issue's `linked_prs[]` entry): `{question, asked_by, since, blocker, blocker_reason, options: [{action, label, enabled, reason_if_disabled}]}` — the reviewer's own decision question when the verdict record has one, the blocker in plain words, and the applicable actions under the row context menu's action ids (`decide:delegate` first), (PRs) `lineage` on the hive's copy of an adopted PR — `{kind: adopted|superseded|rebased-by-hive, from_number, from_url, from_author, from_author_kind, to_number, to_url, at, reason}`, derived from the stage store's adoption record or the `hive/adopt-` head branch, mirrored onto the issue's `linked_prs[]` entry; absent on every other row — and (issues) `linked_prs`; items with no stage yet report stage `0` "Open"; `needs_human_labels` is the "a person must act" label set behind the monitor's Needs human facet (the same list as `/api/status.labelPresets[needs-human]`); `recently_merged` lists the PRs (`repo`, `number`, `merged_at`) whose `pr_merged` audit entry is under 30 minutes old, so a client diffing two payloads can tell a merge from a close; a PR in a conflict-aware merge train carries `merge_train` `{id, state, front, position, size, attempt, max_attempts, overlap_files, ahead, length, head_number, head_state, head_reason, head_since, eta_s, eta_at, eta_basis, late, stalled, stalled_s}` — `head_state` one of `needs-human` / `ci` / `soaking` / `ready` / `merging` / `fixing` / `unknown` with `head_reason` in plain words; `eta_s` / `eta_at` the estimated wait for this member's own merge attempt (own remaining soak + each PR ahead's remaining soak or one sweep + the next sweep tick; absent while the head waits on a person or CI), `eta_at` anchored to the member's first estimate at its position so a countdown survives polls, `eta_basis` its short reading ("2 ahead · head soaking 12m · next sweep in 40s"), `late` once now has overrun the first estimate twice over, `stalled` / `stalled_s` once the head has sat longer than `governor.merge_train_stall_warn_s` ([#15395](https://github.com/hivecommons/hive/issues/15395)); a PR the queue holds because another open PR declares the same `Fixes #N` carries no `merge_train` and a `merge_gate` of `{state: "duplicate-of:", duplicate_of, duplicate_issue}` plus the `needs-decision` modifier (the queue keeps one PR per issue: green first, then the earlier-opened); a PR GitHub reports conflicting on its own, or one at stage/072, carries no `merge_train` and is not counted in any member's `size` / `length` — the state slugs (`front`, `queued-behind`) are payload values only, the SPA renders ordinal places ("Merge queued · 1st of 2", with the train's tag when more than one train is on the page). Served from a server-side cache rebuilt at most every `dashboard.stage_tracker.cache_ttl_s` (default `governor.eval_interval_s`) from the spoke's existing snapshot — a request never calls GitHub. Carries `generated_at`, `source` (`cache` or `fresh`), `cache_ttl_s`, an `ETag` and `Cache-Control: private, max-age=`; `If-None-Match` yields 304. Each hit is recorded under REST caller `dashboard:stage-tracker` so `/api/gh-rate-limits` shows it charged nothing. | `pkg/dashboard/api.go:186` | +| `GET` | `/api/stage-tracker` | Dashboard auth/session | Stage Tracker: every open issue and pull request of the watched repos for the Hive activity monitor — actionable, held, claimed, in-progress, covered-by-PR, filtered (`needs-*`), draft and exempt-labelled items alike, each with `stage`, `stage_since`, `labels`, `created_at`, `author_kind`, `modifiers`, `claimant: {kind: hive-agent|clanker|person, login, agent, hive, since, source: claim-ledger|claim-comment|assignee|kick-history|author}` naming who holds a claimed / in-progress issue or a PR under review or rework (absent when nobody is named; mirrored onto `linked_prs[]`), (PRs) `sentinel_alert` / `sentinel_findings` / `sentinel_reason` when the sentinel flagged the PR, `decision_needed` on a row parked on a person (085 / 045 / 015, the needs-human pill; mirrored onto the issue's `linked_prs[]` entry): `{question, asked_by, since, blocker, blocker_reason, options: [{action, label, enabled, reason_if_disabled}]}` — the reviewer's own decision question when the verdict record has one, the blocker in plain words, and the applicable actions under the row context menu's action ids (`decide:delegate` first), (PRs) `lineage` on the hive's copy of an adopted PR — `{kind: adopted|superseded|rebased-by-hive, from_number, from_url, from_author, from_author_kind, to_number, to_url, at, reason}`, derived from the stage store's adoption record or the `hive/adopt-` head branch, mirrored onto the issue's `linked_prs[]` entry; absent on every other row — and (issues) `linked_prs`; items with no stage yet report stage `0` "Open"; `needs_human_labels` is the "a person must act" label set behind the monitor's Needs human facet (the same list as `/api/status.labelPresets[needs-human]`); `recently_merged` lists the PRs (`repo`, `number`, `merged_at`) whose `pr_merged` audit entry is under 30 minutes old, so a client diffing two payloads can tell a merge from a close; a PR in a conflict-aware merge train carries `merge_train` `{id, state, front, position, size, attempt, max_attempts, overlap_files, ahead, length, head_number, head_state, head_reason, head_since, eta_s, eta_at, eta_basis, late, stalled, stalled_s}` — `head_state` one of `needs-human` / `ci` / `soaking` / `ready` / `merging` / `fixing` / `unknown` with `head_reason` in plain words; `eta_s` / `eta_at` the estimated wait for this member's own merge attempt (own remaining soak + each PR ahead's remaining soak or one sweep + the next sweep tick; absent while the head waits on a person or CI), `eta_at` anchored to the member's first estimate at its position so a countdown survives polls, `eta_basis` its short reading ("2 ahead · head soaking 12m · next sweep in 40s"), `late` once now has overrun the first estimate twice over, `stalled` / `stalled_s` once the head has sat longer than `governor.merge_train_stall_warn_s` ([#15395](https://github.com/hivecommons/hive/issues/15395)); a PR the queue holds because another open PR declares the same `Fixes #N` carries no `merge_train` and a `merge_gate` of `{state: "duplicate-of:", duplicate_of, duplicate_issue}` plus the `needs-decision` modifier (the queue keeps one PR per issue: green first, then the earlier-opened); a PR GitHub reports conflicting on its own, or one under repair (stage/070, 071, 072, 085, or a red required check), carries no `merge_train` and is not counted in any member's `size` / `length` — a repaired member the view dropped carries `left_train: {why: fixing|needs-author|returned-to-contributor|needs-decision|checks-failing, note}` instead, and a train left with one member reports no `merge_train` at all — the state slugs (`front`, `queued-behind`) are payload values only, the SPA renders ordinal places ("Merge queued · 1st of 2", with the train's tag when more than one train is on the page). Served from a server-side cache rebuilt at most every `dashboard.stage_tracker.cache_ttl_s` (default `governor.eval_interval_s`) from the spoke's existing snapshot — a request never calls GitHub. Carries `generated_at`, `source` (`cache` or `fresh`), `cache_ttl_s`, an `ETag` and `Cache-Control: private, max-age=`; `If-None-Match` yields 304. Each hit is recorded under REST caller `dashboard:stage-tracker` so `/api/gh-rate-limits` shows it charged nothing. | `pkg/dashboard/api.go:186` | | `POST` | `/api/prs/{owner}/{repo}/{number}/queue-automerge` | Merger/owner role | Queue PRAuto Merge | `pkg/dashboard/api.go:187` | | `GET` | `/api/inference/models/{backend}` | Dashboard auth/session | Inference Models | `pkg/dashboard/api.go:363` | | `GET` | `/api/hive-id` | Dashboard auth/session | Hive IDGet | `pkg/dashboard/api.go:425` | diff --git a/src/docs/dashboard-copy-inventory.md b/src/docs/dashboard-copy-inventory.md index 23afa20484..c06fa10382 100644 --- a/src/docs/dashboard-copy-inventory.md +++ b/src/docs/dashboard-copy-inventory.md @@ -105,6 +105,7 @@ old name). | `STAGE_TRACKER_TRAIN_STATE_WORD` (`tracker-words.js`) | chevron label, gate pill | `front` → *Next to merge*, `queued-behind` → *In merge queue* | both *Merge queued*; the place tells them apart | `TestStageTrackerMergeTrainStateSlugsNeverLeak` | | `stageTrackerTrainWord` | chevron label | *In merge queue · 2 of 6* / *front* (leaked) | *Merge queued · 1st* / *· 2nd* / *· 3rd* … + *· ~4m* countdown | `TestStageTrackerMergeTrainOrdinalWords` | | `stageTrackerTrainOrdinalOfN` + `stageTrackerTrainTagSuffix` / `stageTrackerTrainTagTip` | chevron label, gate pill, provisional suffix, chevron hover | *Merge queued · 1st* twice over on a page with two trains (owner: "how are there 2 'merge queued 1st'?") | *Merge queued · 1st of 2*; past one train on the page *· train main.go* (overlap basename, else the head `#N`) ends the word and the hover leads *Train of 2 PRs overlapping main.go; merges after #15567.*; one train → no tag | `TestStageTrackerTrainTagOnTwoTrains` | +| `stageTrackerLeftTrainNote` + `STAGE_TRACKER_LEFT_TRAIN_NOTE` (Go: `stageTrackerLeftTrainNote`, `left_train`) | row hover | *merge train · 2 PRs · 1st: #15405* over a row whose chevron read *Fixing* (hive's own #15405, a maintainer requested changes) | the fixing row rides no train (no header, no ordinal, no rail); its hover ends *Merge train: left the merge train while being fixed; rejoins when green*; a train of one is no train | `TestStageTrackerTrainTagOnTwoTrains`, `TestStageTrackerMergeTrainUnderRepairLeaves` | | `stageTrackerOrdinal` | chevron, hover, popover | — | `1st 2nd 3rd 4th … 11th 12th 13th 21st 22nd 23rd` | same | | `stageTrackerTrainStalledWord` + `STAGE_TRACKER_TRAIN_HEAD_STALL_WORD` | chevron label (stalled train), Merge queue popover | *Merge queue stalled · head #15425 waiting for a maintainer (untrusted author) 1h21m* — painted `--yellow` on the amber active chevron, so the row read as an **empty** chevron (#15529, #15530) | rider: *Merge queue · stalled — waiting on #15425 (needs maintainer merge) · 1h21m*; head row: *Merge queue · stalled — needs maintainer merge · 1h21m*; the why comes from `head_state` (`needs-human` → *needs maintainer merge* / *needs a human decision*, `ci` → *waiting for CI*, `soaking` → *soak overran*, `ready` → *waiting for a merge sweep*, `merging` → *merge call in flight*, `fixing` → *being fixed by its author*, `unknown` → *head not in this view*); an unmapped `merge_train.state` falls back to its humanised name + place (*Waiting for front · 3rd*), never `''`; `.ham-seg.active .ham-queue-stalled` inherits the chevron's text colour | `TestStageTrackerMergeTrainStateSlugsNeverLeak` (every state × stalled × head_state × place), `TestStageTrackerMergeTrainPayloadStates` | | `stageTrackerTrainQueueTip` | chevron hover | *Behind #15253 … Estimated turn: ~25m.* / *Front of the merge queue* | *2nd of 6 in the merge queue · behind #15253 · ETA ~25m.* / *1st of 6 in the merge queue · merges next · ETA ~4m.*; *· merge sweep running* lives here only (one label per chevron, #15416) | same | diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index f0cc5fe321..3450dfb555 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -920,6 +920,8 @@ The tooltip lists the PRs ahead and the overlapping files. Waiting siblings are **Who rides.** A PR the lane leaves to a person is not a train member and never its head: an author below the lane's trust (`untrusted-author-role`, `contributor-lane:no-linked-issue`, …), the title/label human-merge rule, a human-merge path, a merge GitHub refused for review, and every other `human_merge_reason` code except the catch-all `policy`. The lane's verdict is remembered per lane and head (`noteMergeTrainOutcome`); a new head starts clean. A head the lane last saw unable to merge on its own (red required check, terminal hold, permanent refusal) stays a member but never fronts. +**PRs under repair leave the train.** A PR somebody is fixing is not a train member either: the planner (`mergeTrainUnderRepair`) skips a PR at 070 fixing, 071 needs-author, 072 returned-to-contributor or 085 needs-decision (label or stage store), and the tracker (`stageTrackerTrainUnderRepair`) drops one whose stage says so or whose `reason` is a red required check (`required-check-failing:` / `check-failing:` / `ci-red`) — hive's own #15405 once led a header as `merge train · 2 PRs · 1st: #15405` while its own chevron read *Fixing* (a maintainer had just requested changes). The dropped row carries `left_train: {why, note}` and no `merge_train`: no ordinal, no rail, and its hover ends with the one muted line *Merge train: left the merge train while being fixed; rejoins when green*. The survivors close ranks — `size`, `position`, `front`, `ahead`, `members` are recomputed, and the next in line fronts when the front itself left — and a train left with one member is no train: no header, no ordinal, the 080 row back to *Green and approved; waiting for the automerge lane to admit it*. The exception is the `rebase-exhausted` tail at 085: the train put it there, and it stays so the person who rebases it sees where it merges. Provisional members (050 / 060 with nothing red, [#15580](https://github.com/hivecommons/hive/issues/15580)) keep their slot. + **Queue position, countdown, stall** ([#15395](https://github.com/hivecommons/hive/issues/15395)). The queued chip is its place in the queue and nothing else — **Merge queued · 2nd of 6 · ~4m** — so it reads the same whether or not a merge sweep is evaluating it: the sweep is the spinning ⬡ glyph and a *Checking now…* line in the hover, never a change of words (one label per chevron), and no state slug (`queued-behind`, `front`) ever reaches the page. The hover is the place sentence — *2nd of 6 in the merge queue · behind #15253 (soaking, 12m left) · ETA ~25m (2 ahead · head soaking 12m · next pass in 40s). Hive merges one at a time, in order.*; the head's reads *1st of 6 in the merge queue · merges next · ETA ~13m.* — or, when the head is on a person or on CI, the blocker instead of a clock: *… behind #15253 (waiting for a maintainer (untrusted author)) · no estimate until #15253 moves.* Every train state — the 1st included — lights the **Merge queue** column, whatever numeric stage the lane holds the head at (the train's facts are mirrored onto a head still at 050/070; hive's own #15400 once lit CI / Review beside its 2nd-place sibling). The server adds to each member's `merge_train`: `length`, `head_number`, `head_state` (`needs-human` / `ci` / `soaking` / `ready` / `merging` / `fixing` / `unknown`), `head_reason` (plain words), `head_since`, `eta_s`, `eta_at`, `eta_basis`, `late`, `stalled`, `stalled_s`. **One PR per issue** ([#15395](https://github.com/hivecommons/hive/issues/15395)). Two open PRs declaring the same `Fixes #N` never both ride the queue (hive's own #15402 and #15407, both for #15396, once sat side by side as "waiting its turn"). Before the trains are grouped the sweep keeps one PR per closing issue — a green head (not conflicting, not blocked on a red required check) beats a red one; among equals the earlier-opened wins — and holds the other out of every train with the stage reason `merge-train:duplicate-of#:/0:0/0:`. The held row's gate reads `duplicate-of:` (`merge_gate.duplicate_of`, `merge_gate.duplicate_issue`), its chip **Duplicate of #15402 · needs a pick** with no clock, it carries no `merge_train`, and it wears `needs-decision` so both PRs sit under their issue with the hold visible. *Let hive decide* on either row takes the existing supersede path (rule `one-pr-per-issue`): on the held PR it closes it as superseded by the kept one with a credit comment, through the same write gate as every delegate close; on the kept PR it releases it and names the duplicate the queue holds (or, if the kept PR has since gone red, only recommends the fix — the queue re-picks on its next pass, so an earlier red PR yields to a later green one). diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index e82c508b63..8008598735 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -436,6 +436,11 @@ type StageTrackerItem struct { // (hivecommons/hive#15117): its position, the front, the PRs ahead and // the overlapping files. See stage_tracker_merge_train.go. MergeTrain *StageTrackerMergeTrain `json:"merge_train,omitempty"` + // LeftTrain is set on a PR the view took out of its merge train + // because it is under repair — being fixed, waiting on its author, + // parked on a decision, or red (stageTrackerTrainUnderRepair). The + // row rides no train and wears no ordinal; the hover says so. + LeftTrain *StageTrackerLeftTrain `json:"left_train,omitempty"` // BlockedOn lists the open GitHub "blocked by" dependencies ("repo#N") // of an issue the scheduler withholds from every kick until they close // (scheduler.partitionBlockedIssues). Without it a sequenced sub-issue @@ -1773,7 +1778,7 @@ func stageTrackerCaption(stage stagelabels.Stage, reason, author string, kind st if c := stageTrackerMergeTrainCaption(reason); c != "" { return c, "automerge lane" } - return joinClause("Green and approved; waiting for the automerge lane to admit it", clause), "automerge lane" + return joinClause(stageTrackerAwaitingAdmissionCaption, clause), "automerge lane" case stagelabels.NeedsDecision, stagelabels.IssueNeedsDecision: switch stageTrackerAdoptedByState(rec) { case stageTrackerAdoptedClosedTwice: diff --git a/src/pkg/dashboard/stage_tracker_merge_gate_test.go b/src/pkg/dashboard/stage_tracker_merge_gate_test.go index 827e30c56b..fbd08a3440 100644 --- a/src/pkg/dashboard/stage_tracker_merge_gate_test.go +++ b/src/pkg/dashboard/stage_tracker_merge_gate_test.go @@ -332,6 +332,8 @@ func stageTrackerTrainQueueJS(t *testing.T, html string) string { jsFunc(t, html, "stageTrackerTrainEtaWords"), jsFunc(t, html, "stageTrackerTrainEtaDetail"), jsFunc(t, html, "stageTrackerTrainQueueTip"), + jsConstLine(t, html, "STAGE_TRACKER_LEFT_TRAIN_NOTE"), + jsFunc(t, html, "stageTrackerLeftTrainNote"), jsFunc(t, html, "stageTrackerTrainLines"), }, "\n") } diff --git a/src/pkg/dashboard/stage_tracker_merge_train.go b/src/pkg/dashboard/stage_tracker_merge_train.go index 4135ec2c37..fc36c98c87 100644 --- a/src/pkg/dashboard/stage_tracker_merge_train.go +++ b/src/pkg/dashboard/stage_tracker_merge_train.go @@ -2,6 +2,7 @@ package dashboard import ( "log/slog" + "reflect" "slices" "sort" "strconv" @@ -215,10 +216,116 @@ func stageTrackerApplyDuplicateHold(it *StageTrackerItem, mt *StageTrackerMergeT } } +// 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 +// own chevron read "Fixing"). +const stageTrackerLeftTrainNote = "left the merge train while being fixed; rejoins when green" + +// stageTrackerAwaitingAdmissionCaption is the 080 row's own caption, off +// any train. +const stageTrackerAwaitingAdmissionCaption = "Green and approved; waiting for the automerge lane to admit it" + +// StageTrackerLeftTrain says why a PR the planner had ordered rides no +// train in this view: Why is the repair token (fixing, needs-author, +// returned-to-contributor, needs-decision, checks-failing) and Note the +// hover sentence. The row has no merge_train and no ordinal. +type StageTrackerLeftTrain struct { + Why string `json:"why"` + Note string `json:"note"` + // trainID and position remember the slot it held so the survivors + // can close ranks (stageTrackerMergeTrainPostPass). + trainID string + position int +} + +// stageTrackerTrainUnderRepair names why a PR at stage, with reason, is +// not a train member right now — "" when it may ride. A PR being fixed +// (070), waiting on its author (071) or contributor (072), parked on a +// human decision (085), or whose required checks are red is somebody's +// to repair first; the planner may still have ordered it, but the view +// never seats it (hivecommons/hive#15581 admits 050/060 provisionally +// only while nothing is red). +func stageTrackerTrainUnderRepair(stage int, reason string) string { + switch stage { + case stagelabels.Fixing.Number(): + return stagelabels.Fixing.Slug() + case stagelabels.NeedsAuthor.Number(): + return stagelabels.NeedsAuthor.Slug() + case stagelabels.ReturnedToContributor.Number(): + return stagelabels.ReturnedToContributor.Slug() + case stagelabels.NeedsDecision.Number(): + return stagelabels.NeedsDecision.Slug() + } + lower := strings.ToLower(strings.TrimSpace(reason)) + if strings.HasPrefix(lower, "required-check-failing:") || strings.HasPrefix(lower, "check-failing:") || lower == "ci-red" { + return "checks-failing" + } + return "" +} + +// stageTrackerLeaveMergeTrain takes a PR out of its train: the train +// record and the train's gate words go, and LeftTrain keeps why (and, +// unexported, which train and which slot) so the row can say so on hover +// and the survivors can close ranks. why "" (a train that shrank to one +// member) leaves no note — there is no train to have left. +func stageTrackerLeaveMergeTrain(it *StageTrackerItem, why string) { + if it == nil || it.MergeTrain == nil { + return + } + mt := it.MergeTrain + if it.MergeGate != nil && (it.MergeGate.State == mt.State || it.MergeGate.State == MergeGateStateTrainFront) { + it.MergeGate.State = "" + it.MergeGate.Reason = "" + if reflect.DeepEqual(*it.MergeGate, StageTrackerMergeGate{}) { + it.MergeGate = nil + } + } + it.MergeTrain = nil + // The caption the train wrote ("waiting its turn … behind #N") is + // stale now; an 080 row goes back to the gate's own words. + if it.Stage == stagelabels.AwaitingMergeAdmission.Number() && (it.Caption == stageTrackerMergeTrainCaption(it.Reason) || it.Caption == stageTrackerMergeTrainFrontCaption(mt)) { + it.Caption = stageTrackerAwaitingAdmissionCaption + } + if why != "" { + pos := mt.Position + if mt.State == MergeGateStateTrainFront { + pos = 1 + } + it.LeftTrain = &StageTrackerLeftTrain{Why: why, Note: stageTrackerLeftTrainNote, trainID: mt.ID, position: pos} + } +} + +// stageTrackerMergeTrainFrontGate words the gate of the member merging +// first: "1st in the merge queue; merges next (1st of 2, overlapping +// files: a.go)", or "merges first once it is ready" while its own stage +// is short of the gate. promoted is a member that was queued behind a +// front that just left: its queued words are stale and are replaced. +func stageTrackerMergeTrainFrontGate(front *StageTrackerItem, size int, files []string, promoted bool) { + if front.MergeGate == nil { + front.MergeGate = &StageTrackerMergeGate{} + } + if front.MergeGate.State == "" || front.MergeGate.State == MergeGateStateReady || (promoted && front.MergeGate.State == MergeGateStateQueuedBehind) { + front.MergeGate.State = MergeGateStateTrainFront + } + if front.MergeGate.Reason == "" || promoted { + next := "merges next" + if stageTrackerMergeTrainProvisional(front.Stage) { + next = "merges first once it is ready" + } + front.MergeGate.Reason = "1st in the merge queue; " + next + " (1st of " + strconv.Itoa(size) + ", overlapping files: " + strings.Join(files, ", ") + ")" + } +} + // stageTrackerMergeTrainPostPass runs over the finished items: the front // (which the lane evaluates on its normal path and so carries no train // reason) is marked from its siblings' records, and every member learns -// the PRs ahead of it. Members are matched on repo and base. +// the PRs ahead of it. Members are matched on repo and base. A member +// under repair (stageTrackerTrainUnderRepair) leaves the train first — +// the front included — the rest close ranks (size, place, front and +// ahead recomputed), and a train left with one member is no train at +// all: no header, no ordinal (hivecommons/hive#15405 led a header as +// "1st: #15405" while its own chevron read "Fixing"). func stageTrackerMergeTrainPostPass(items []StageTrackerItem, opts mergeTrainQueueOptions, mem *mergeTrainMemory) { type trainKey struct{ repo, id string } members := map[trainKey][]int{} @@ -227,14 +334,28 @@ func stageTrackerMergeTrainPostPass(items []StageTrackerItem, opts mergeTrainQue if it.MergeTrain == nil || it.Kind != "pr" { continue } + // A rebase-exhausted tail sits at 085 by the train's own doing; + // 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 != "" { + stageTrackerLeaveMergeTrain(it, why) + continue + } + } members[trainKey{it.Repo, it.MergeTrain.ID}] = append(members[trainKey{it.Repo, it.MergeTrain.ID}], i) } for key, idx := range members { sample := items[idx[0]].MergeTrain frontIdx := -1 + frontLeft := false for i := range items { it := &items[i] if it.Kind == "pr" && it.Repo == key.repo && it.Number == sample.Front && it.Stage < stageTrackerMergedStage { + if why := stageTrackerTrainUnderRepair(it.Stage, it.Reason); why != "" { + it.LeftTrain = &StageTrackerLeftTrain{Why: why, Note: stageTrackerLeftTrainNote, trainID: sample.ID, position: 1} + frontLeft = true + break + } frontIdx = i break } @@ -245,28 +366,56 @@ func stageTrackerMergeTrainPostPass(items []StageTrackerItem, opts mergeTrainQue ID: sample.ID, State: MergeGateStateTrainFront, Front: sample.Front, Position: 1, Size: sample.Size, OverlapFiles: append([]string(nil), sample.OverlapFiles...), } - if front.MergeGate == nil { - front.MergeGate = &StageTrackerMergeGate{} + stageTrackerMergeTrainFrontGate(front, sample.Size, sample.OverlapFiles, false) + if front.Stage == stagelabels.AwaitingMergeAdmission.Number() { + front.Caption = stageTrackerMergeTrainFrontCaption(sample) } - if front.MergeGate.State == "" || front.MergeGate.State == MergeGateStateReady { - front.MergeGate.State = MergeGateStateTrainFront + idx = append(idx, frontIdx) + } + // The slots the view has emptied: survivors behind them move up. + var dropped []int + for i := range items { + it := &items[i] + if it.Kind == "pr" && it.Repo == key.repo && it.MergeTrain == nil && it.LeftTrain != nil && it.LeftTrain.trainID == sample.ID { + dropped = append(dropped, it.LeftTrain.position) } - if front.MergeGate.Reason == "" { - next := "merges next" - if stageTrackerMergeTrainProvisional(front.Stage) { - next = "merges first once it is ready" + } + if len(dropped) > 0 { + if sample.Size-len(dropped) < 2 { + for _, i := range idx { + stageTrackerLeaveMergeTrain(&items[i], "") } - front.MergeGate.Reason = "1st in the merge queue; " + next + " (1st of " + strconv.Itoa(sample.Size) + ", overlapping files: " + strings.Join(sample.OverlapFiles, ", ") + ")" + continue } - if front.Stage == stagelabels.AwaitingMergeAdmission.Number() { - front.Caption = stageTrackerMergeTrainFrontCaption(sample) + for _, i := range idx { + mt := items[i].MergeTrain + moved := 0 + for _, p := range dropped { + if p > 0 && p < mt.Position { + moved++ + } + } + mt.Position -= moved + mt.Size = max(sample.Size-len(dropped), len(idx)) } - idx = append(idx, frontIdx) } // Members in merge order, so each one's Ahead is the prefix. sort.Slice(idx, func(a, b int) bool { return items[idx[a]].MergeTrain.Position < items[idx[b]].MergeTrain.Position }) + if frontLeft { + // The old front is out; the member now in slot 1 leads. + newFront := 0 + if first := &items[idx[0]]; first.MergeTrain.Position == 1 { + newFront = first.Number + first.MergeTrain.State = MergeGateStateTrainFront + stageTrackerMergeTrainFrontGate(first, first.MergeTrain.Size, first.MergeTrain.OverlapFiles, true) + frontIdx = idx[0] + } + for _, i := range idx { + items[i].MergeTrain.Front = newFront + } + } members := make([]int, 0, len(idx)) for _, i := range idx { members = append(members, items[i].Number) diff --git a/src/pkg/dashboard/stage_tracker_merge_train_membership_test.go b/src/pkg/dashboard/stage_tracker_merge_train_membership_test.go new file mode 100644 index 0000000000..39c5e85749 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_merge_train_membership_test.go @@ -0,0 +1,151 @@ +package dashboard + +import ( + "encoding/json" + "fmt" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stageengine/prstage" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// TestStageTrackerMergeTrainUnderRepairLeaves: the owner's page read +// "merge train · 2 PRs · 1st: #15405 · overlapping: operator-reference.md" +// while #15405's own chevron said "Fixing" — a maintainer had just +// requested changes. A PR under repair (070 fixing, 071 needs-author, 072 +// returned, 085 needs-decision, or red required checks) is not a train +// member: it leaves with a hover note, the survivors close ranks, and a +// train of one is no train (no header, no ordinal). +func TestStageTrackerMergeTrainUnderRepairLeaves(t *testing.T) { + now := time.Date(2026, 10, 30, 20, 0, 0, 0, time.UTC) + s, store := stageTrackerFixture(t, now) + overlap := []string{"operator-reference.md"} + queued := func(front, pos, size int) string { + return prstage.MergeTrain{State: prstage.MergeTrainStateQueuedBehind, Front: front, Position: pos, Size: size, OverlapFiles: overlap}.Reason() + } + addPR := func(n int, stage string) { + s.status.Repos[0].OpenPrs = append(s.status.Repos[0].OpenPrs, + FrontendPR{PullRequest: github.PullRequest{Number: n, Title: "Docs change", Author: "hive-app[bot]", AppAuthored: true, BaseRef: "v5", Labels: []string{stage, "author/hive"}}}) + } + // Train of 2: the front #15405 just dropped to 070 fixing. + store.Observe(stagelabels.Key("acme/console", 15405), stagelabels.Fixing, "reviewer-verdict:changes-requested") + store.Observe(stagelabels.Key("acme/console", 15410), stagelabels.AwaitingMergeAdmission, queued(15405, 2, 2)) + s.statusMu.Lock() + addPR(15405, stagelabels.Fixing.Label()) + addPR(15410, stagelabels.AwaitingMergeAdmission.Label()) + s.statusMu.Unlock() + resp := s.buildStageTracker(s.status, store, now) + + fixing := trackerItem(t, resp, "pr", 15405) + if fixing.Stage != 70 || fixing.MergeTrain != nil { + t.Fatalf("a PR being fixed rides no train: stage %d train %+v", fixing.Stage, fixing.MergeTrain) + } + if fixing.LeftTrain == nil || fixing.LeftTrain.Why != "fixing" || fixing.LeftTrain.Note != stageTrackerLeftTrainNote { + t.Fatalf("left_train = %+v", fixing.LeftTrain) + } + if fixing.MergeGate != nil && (fixing.MergeGate.State == MergeGateStateTrainFront || fixing.MergeGate.State == MergeGateStateQueuedBehind) { + t.Fatalf("the gate must not keep the train's words: %+v", fixing.MergeGate) + } + raw, err := json.Marshal(fixing) + if err != nil { + t.Fatal(err) + } + if want := `"left_train":{"why":"fixing","note":"` + stageTrackerLeftTrainNote + `"}`; !strings.Contains(string(raw), want) { + t.Fatalf("payload lacks %s:\n%s", want, raw) + } + // The lone survivor is no train: no header, no ordinal, no stale + // "behind #15405" words. + alone := trackerItem(t, resp, "pr", 15410) + if alone.MergeTrain != nil || alone.LeftTrain != nil { + t.Fatalf("a train of one is no train: train %+v left %+v", alone.MergeTrain, alone.LeftTrain) + } + if alone.MergeGate != nil && (alone.MergeGate.State == MergeGateStateQueuedBehind || strings.Contains(alone.MergeGate.Reason, "#15405")) { + t.Fatalf("survivor gate still names the train: %+v", alone.MergeGate) + } + if strings.Contains(alone.Caption, "#15405") || strings.Contains(alone.Caption, "merge train") { + t.Fatalf("survivor caption still names the train: %q", alone.Caption) + } + + // Train of 3 where the middle member is returned to its contributor: + // the two others close ranks (2nd of 2), and the member that left + // says so. + s2, store2 := stageTrackerFixture(t, now) + store2.Observe(stagelabels.Key("acme/console", 15500), stagelabels.AwaitingMergeAdmission, "") + store2.Observe(stagelabels.Key("acme/console", 15501), stagelabels.ReturnedToContributor, queued(15500, 2, 3)) + store2.Observe(stagelabels.Key("acme/console", 15502), stagelabels.AwaitingMergeAdmission, queued(15500, 3, 3)) + s2.statusMu.Lock() + for _, n := range []int{15500, 15501, 15502} { + stage := stagelabels.AwaitingMergeAdmission.Label() + if n == 15501 { + stage = stagelabels.ReturnedToContributor.Label() + } + s2.status.Repos[0].OpenPrs = append(s2.status.Repos[0].OpenPrs, + FrontendPR{PullRequest: github.PullRequest{Number: n, Title: "Docs change", Author: "hive-app[bot]", AppAuthored: true, BaseRef: "v5", Labels: []string{stage, "author/hive"}}}) + } + s2.statusMu.Unlock() + resp2 := s2.buildStageTracker(s2.status, store2, now) + returned := trackerItem(t, resp2, "pr", 15501) + if returned.MergeTrain != nil || returned.LeftTrain == nil || returned.LeftTrain.Why != "returned-to-contributor" { + t.Fatalf("returned member = train %+v left %+v", returned.MergeTrain, returned.LeftTrain) + } + front := trackerItem(t, resp2, "pr", 15500) + last := trackerItem(t, resp2, "pr", 15502) + if front.MergeTrain == nil || front.MergeTrain.Position != 1 || front.MergeTrain.Size != 2 || front.MergeTrain.State != MergeGateStateTrainFront { + t.Fatalf("front after the drop = %+v", front.MergeTrain) + } + if last.MergeTrain == nil || last.MergeTrain.Position != 2 || last.MergeTrain.Size != 2 || last.MergeTrain.Front != 15500 { + t.Fatalf("last after the drop = %+v", last.MergeTrain) + } + if fmt.Sprint(last.MergeTrain.Ahead) != "[15500]" || fmt.Sprint(last.MergeTrain.Members) != "[15500 15502]" || fmt.Sprint(front.MergeTrain.Members) != "[15500 15502]" { + t.Fatalf("ranks did not close: ahead %v members %v / %v", last.MergeTrain.Ahead, last.MergeTrain.Members, front.MergeTrain.Members) + } + + // The front itself under repair with two members still fit: the next + // in line leads and the header's "1st" follows it. + s3, store3 := stageTrackerFixture(t, now) + store3.Observe(stagelabels.Key("acme/console", 15600), stagelabels.NeedsAuthor, "required-check-failing:build-and-test") + store3.Observe(stagelabels.Key("acme/console", 15601), stagelabels.AwaitingMergeAdmission, queued(15600, 2, 3)) + store3.Observe(stagelabels.Key("acme/console", 15602), stagelabels.AwaitingMergeAdmission, queued(15600, 3, 3)) + s3.statusMu.Lock() + for _, n := range []int{15600, 15601, 15602} { + stage := stagelabels.AwaitingMergeAdmission.Label() + if n == 15600 { + stage = stagelabels.NeedsAuthor.Label() + } + s3.status.Repos[0].OpenPrs = append(s3.status.Repos[0].OpenPrs, + FrontendPR{PullRequest: github.PullRequest{Number: n, Title: "Docs change", Author: "someone", BaseRef: "v5", Labels: []string{stage, "author/human"}}}) + } + s3.statusMu.Unlock() + resp3 := s3.buildStageTracker(s3.status, store3, now) + gone := trackerItem(t, resp3, "pr", 15600) + if gone.MergeTrain != nil || gone.LeftTrain == nil || gone.LeftTrain.Why != "needs-author" { + t.Fatalf("red front = train %+v left %+v", gone.MergeTrain, gone.LeftTrain) + } + newFront := trackerItem(t, resp3, "pr", 15601) + tail := trackerItem(t, resp3, "pr", 15602) + if newFront.MergeTrain == nil || newFront.MergeTrain.State != MergeGateStateTrainFront || newFront.MergeTrain.Position != 1 || newFront.MergeTrain.Size != 2 || newFront.MergeTrain.Front != 15601 { + t.Fatalf("promoted front = %+v", newFront.MergeTrain) + } + if newFront.MergeGate == nil || newFront.MergeGate.State != MergeGateStateTrainFront || !strings.HasPrefix(newFront.MergeGate.Reason, "1st in the merge queue; merges next (1st of 2") { + t.Fatalf("promoted front gate = %+v", newFront.MergeGate) + } + if tail.MergeTrain == nil || tail.MergeTrain.Position != 2 || tail.MergeTrain.Size != 2 || tail.MergeTrain.Front != 15601 || fmt.Sprint(tail.MergeTrain.Ahead) != "[15601]" { + t.Fatalf("tail after the front left = %+v", tail.MergeTrain) + } + + // stageTrackerTrainUnderRepair names each repair, and nothing else. + for stage, want := range map[int]string{70: "fixing", 71: "needs-author", 72: "returned-to-contributor", 85: "needs-decision", 80: "", 50: "", 60: "", 95: ""} { + if got := stageTrackerTrainUnderRepair(stage, ""); got != want { + t.Errorf("underRepair(%d) = %q, want %q", stage, got, want) + } + } + if got := stageTrackerTrainUnderRepair(60, "required-check-failing:lint"); got != "checks-failing" { + t.Errorf("red checks = %q", got) + } + if got := stageTrackerTrainUnderRepair(50, "required-check-pending:lint"); got != "" { + t.Errorf("a pending check is provisional, not repair: %q", got) + } +} diff --git a/src/pkg/dashboard/stage_tracker_merge_train_tag_test.go b/src/pkg/dashboard/stage_tracker_merge_train_tag_test.go index 67685fad94..d92ab88431 100644 --- a/src/pkg/dashboard/stage_tracker_merge_train_tag_test.go +++ b/src/pkg/dashboard/stage_tracker_merge_train_tag_test.go @@ -107,5 +107,31 @@ assert.deepStrictEqual(rows.map(r => r.key), ['train:hivecommons/hive|v5#15567', assert.ok(rows[0].html.includes('class="ham-train-head ham-train-k0"'), rows[0].html); assert.ok(rows[3].html.includes('class="ham-train-head ham-train-k1"'), rows[3].html); assert.ok(rows[0].html.includes('overlapping: cmd/hive/main.go'), rows[0].html); + +// A member under repair left its train (server: merge_train gone, +// left_train set) — hive's own #15405 led a header as "1st: #15405" +// while its chevron read "Fixing". The train of two is no train: no +// header, no ordinal on the survivor; the dropped row's hover says why. +const fixing = { repo: 'hivecommons/hive', number: 15405, kind: 'pr', title: 'Docs', stage: 70, modifiers: [], reason: 'reviewer-verdict:changes-requested', + left_train: { why: 'fixing', note: STAGE_TRACKER_LEFT_TRAIN_NOTE } }; +const alone = { repo: 'hivecommons/hive', number: 15410, kind: 'pr', title: 'Docs', stage: 80, modifiers: [], merge_gate: { state: 'gate-pending', reason: 'awaiting admission', last_sweep_at: '2026-10-30T00:29:30Z' } }; +assert.strictEqual(stageTrackerTrain(fixing), null); +assert.strictEqual(stageTrackerTrainKey(fixing), ''); +assert.strictEqual(stageTrackerTrainKey(alone), ''); +assert.strictEqual(stageTrackerTrainWord(fixing), '', 'a PR that left the train has no queue word'); +assert.strictEqual(stageTrackerTrainWord(alone), '', 'a lone survivor wears no ordinal'); +assert.strictEqual(stageTrackerTrainIndex([fixing, alone]).count, 0); +const noTrain = stageTrackerTrainRows([fixing, alone], (it) => ({ key: String(it.number), html: '' })); +assert.deepStrictEqual(noTrain.map(r => r.key), ['15405', '15410'], 'no header over a train of one'); +assert.strictEqual(stageTrackerTrainRowClass(fixing, null, alone, 0), ''); +assert.strictEqual(stageTrackerLeftTrainNote(fixing), 'left the merge train while being fixed; rejoins when green'); +assert.deepStrictEqual(stageTrackerTrainLines(fixing), ['Merge train: left the merge train while being fixed; rejoins when green']); +assert.strictEqual(stageTrackerLeftTrainNote(alone), ''); +assert.deepStrictEqual(stageTrackerTrainLines(alone), []); +// A row that still rides a train never shows the left note, whatever +// an older payload says. +assert.strictEqual(stageTrackerLeftTrainNote(Object.assign({}, a2, { left_train: { why: 'fixing' } })), ''); +// No gate chip on the dropped row: nothing says "queued". +assert.strictEqual(stageTrackerMergeGateInfo(fixing, now, 1), null); `) } diff --git a/src/pkg/dashboard/stage_tracker_merge_train_test.go b/src/pkg/dashboard/stage_tracker_merge_train_test.go index 0adfb871a1..86510b83cf 100644 --- a/src/pkg/dashboard/stage_tracker_merge_train_test.go +++ b/src/pkg/dashboard/stage_tracker_merge_train_test.go @@ -254,6 +254,8 @@ func TestStageTrackerMergeTrainSPA(t *testing.T) { jsFunc(t, html, "stageTrackerTrainEtaWords"), jsFunc(t, html, "stageTrackerTrainEtaDetail"), jsFunc(t, html, "stageTrackerTrainQueueTip"), + jsConstLine(t, html, "STAGE_TRACKER_LEFT_TRAIN_NOTE"), + jsFunc(t, html, "stageTrackerLeftTrainNote"), jsFunc(t, html, "stageTrackerTrainLines"), jsFunc(t, html, "stageTrackerRowTrain"), jsFunc(t, html, "stageTrackerTrainKey"), diff --git a/src/pkg/dashboard/static-src/js/tracker-words.js b/src/pkg/dashboard/static-src/js/tracker-words.js index 397f88a6c5..098a054d60 100644 --- a/src/pkg/dashboard/static-src/js/tracker-words.js +++ b/src/pkg/dashboard/static-src/js/tracker-words.js @@ -397,10 +397,22 @@ else if (why) tip += ' · no estimate until #' + p.head + ' moves'; return tip + '.' + order; } - // Tooltip lines: the queue ahead and the overlapping files. + // The muted hover note on a PR the server took out of its merge train + // while it is under repair (left_train: {why, note} — fixing, needs + // author, needs decision, red checks). The row rides no train and + // wears no ordinal; this line is the only trace. + const STAGE_TRACKER_LEFT_TRAIN_NOTE = 'left the merge train while being fixed; rejoins when green'; + // Pure: the left-train note for a row, '' when it rides or never rode. + function stageTrackerLeftTrainNote(item) { + const lt = item && item.left_train; + if (!lt || typeof lt !== 'object' || stageTrackerTrain(item)) return ''; + return String(lt.note || STAGE_TRACKER_LEFT_TRAIN_NOTE); + } + // Tooltip lines: the queue ahead and the overlapping files — or, for a + // PR that left its train, the one muted note. function stageTrackerTrainLines(item) { const mt = stageTrackerTrain(item); - if (!mt) return []; + if (!mt) { const left = stageTrackerLeftTrainNote(item); return left ? ['Merge train: ' + left] : []; } const ahead = Array.isArray(mt.ahead) ? mt.ahead.filter(n => Number(n) > 0) : []; const files = Array.isArray(mt.overlap_files) ? mt.overlap_files.filter(Boolean) : []; const lines = ['Merge train: ' + (Number(mt.size) || 0) + ' PRs to ' + (String(mt.id || '').split('#')[0] || 'the same base') + ' touch the same files; they merge one at a time, in order' + (mt.front ? ' (1st: #' + mt.front + ')' : '')]; diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 6bd6826f9f..43ced19946 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -14712,10 +14712,22 @@

Where to get help

else if (why) tip += ' · no estimate until #' + p.head + ' moves'; return tip + '.' + order; } - // Tooltip lines: the queue ahead and the overlapping files. + // The muted hover note on a PR the server took out of its merge train + // while it is under repair (left_train: {why, note} — fixing, needs + // author, needs decision, red checks). The row rides no train and + // wears no ordinal; this line is the only trace. + const STAGE_TRACKER_LEFT_TRAIN_NOTE = 'left the merge train while being fixed; rejoins when green'; + // Pure: the left-train note for a row, '' when it rides or never rode. + function stageTrackerLeftTrainNote(item) { + const lt = item && item.left_train; + if (!lt || typeof lt !== 'object' || stageTrackerTrain(item)) return ''; + return String(lt.note || STAGE_TRACKER_LEFT_TRAIN_NOTE); + } + // Tooltip lines: the queue ahead and the overlapping files — or, for a + // PR that left its train, the one muted note. function stageTrackerTrainLines(item) { const mt = stageTrackerTrain(item); - if (!mt) return []; + if (!mt) { const left = stageTrackerLeftTrainNote(item); return left ? ['Merge train: ' + left] : []; } const ahead = Array.isArray(mt.ahead) ? mt.ahead.filter(n => Number(n) > 0) : []; const files = Array.isArray(mt.overlap_files) ? mt.overlap_files.filter(Boolean) : []; const lines = ['Merge train: ' + (Number(mt.size) || 0) + ' PRs to ' + (String(mt.id || '').split('#')[0] || 'the same base') + ' touch the same files; they merge one at a time, in order' + (mt.front ? ' (1st: #' + mt.front + ')' : '')]; diff --git a/src/pkg/github/automerge/automerge_merge_train.go b/src/pkg/github/automerge/automerge_merge_train.go index e196b4f0c1..b0f40066f5 100644 --- a/src/pkg/github/automerge/automerge_merge_train.go +++ b/src/pkg/github/automerge/automerge_merge_train.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "slices" "sort" "strconv" "strings" @@ -382,8 +383,8 @@ func (c *Engine) planMergeTrains(ctx context.Context, lane, displayRepo, owner, if !mergeTrainCandidate(prefilter(pr)) { continue } - if c.mergeTrainReturnedToContributor(owner, repo, pr) { - c.mergeTrainSkipLogged(owner, repo, displayRepo, pr.GetNumber(), pr.GetHead().GetSHA(), "returned-to-contributor") + if why := c.mergeTrainUnderRepair(owner, repo, pr); why != "" { + c.mergeTrainSkipLogged(owner, repo, displayRepo, pr.GetNumber(), pr.GetHead().GetSHA(), why) continue } if c.mergeTrainHeadHumanMerge(lane, owner, repo, pr.GetNumber(), pr.GetHead().GetSHA()) { @@ -469,27 +470,36 @@ func (c *Engine) planMergeTrains(ctx context.Context, lane, displayRepo, owner, return plan } -// mergeTrainReturnedToContributor reports a PR at stage 072 -// returned-to-contributor (its label, or the stage store's record): the -// fix is the contributor's, so it never rides a train — hive's own #15307 -// (conflicting, returned) was counted "4 of 6" and drew the train's stall -// comments (hivecommons/hive#15395). -func (c *Engine) mergeTrainReturnedToContributor(owner, repo string, pr *gh.PullRequest) bool { +// mergeTrainUnderRepairStages are the stages whose PR is somebody's to +// repair before it may ride a train: 070 fixing (the hive's own fixer), +// 071 needs-author, 072 returned-to-contributor and 085 needs-decision. +var mergeTrainUnderRepairStages = []stagelabels.Stage{stagelabels.Fixing, stagelabels.NeedsAuthor, stagelabels.ReturnedToContributor, stagelabels.NeedsDecision} + +// mergeTrainUnderRepair names the repair stage a PR wears (its label, or +// the stage store's record), or "" when it may ride a train. Such a PR +// never takes a slot: hive's own #15307 (conflicting, returned) was +// counted "4 of 6" and drew the train's stall comments +// (hivecommons/hive#15395), and #15405 led a train's header as "1st" +// while a maintainer's changes-requested had it at 070 fixing. +func (c *Engine) mergeTrainUnderRepair(owner, repo string, pr *gh.PullRequest) string { if pr == nil { - return false - } - want := stagelabels.ReturnedToContributor.Label() - for _, l := range labelNames(pr.Labels) { - if strings.EqualFold(strings.TrimSpace(l), want) { - return true + return "" + } + labels := labelNames(pr.Labels) + for _, st := range mergeTrainUnderRepairStages { + want := st.Label() + for _, l := range labels { + if strings.EqualFold(strings.TrimSpace(l), want) { + return st.Slug() + } } } if store := c.stageStoreOrShared(); store != nil { - if rec, ok := store.Get(stagelabels.Key(owner+"/"+repo, pr.GetNumber())); ok && rec.Stage == stagelabels.ReturnedToContributor { - return true + if rec, ok := store.Get(stagelabels.Key(owner+"/"+repo, pr.GetNumber())); ok && slices.Contains(mergeTrainUnderRepairStages, rec.Stage) { + return rec.Stage.Slug() } } - return false + return "" } // mergeTrainConflictOutsider reports a conflicting member the train must diff --git a/src/pkg/github/automerge/automerge_merge_train_test.go b/src/pkg/github/automerge/automerge_merge_train_test.go index fa96346c91..b5cc356b67 100644 --- a/src/pkg/github/automerge/automerge_merge_train_test.go +++ b/src/pkg/github/automerge/automerge_merge_train_test.go @@ -623,3 +623,48 @@ func TestMergeTrainHumanMergeNeverMember(t *testing.T) { t.Fatal("a clean verdict re-admits the PR") } } + +// TestPlanMergeTrainsExcludesUnderRepair: hive's own #15405 led a train's +// header as "1st: #15405" while a maintainer's changes-requested had it at +// 070 fixing. A PR at 070 / 071 / 085 — by label or by the stage store — +// is somebody's to repair and takes no slot; the survivors form the train +// among themselves. +func TestPlanMergeTrainsExcludesUnderRepair(t *testing.T) { + t0 := time.Date(2026, 10, 30, 20, 0, 0, 0, time.UTC) + api := &mergeTrainAPI{ + files: map[int][]string{15405: {"operator-reference.md"}, 15406: {"operator-reference.md"}, 15407: {"operator-reference.md"}, 15408: {"operator-reference.md"}}, + state: map[int]string{15405: "clean", 15406: "clean", 15407: "clean", 15408: "clean"}, + } + srv := newMergeTrainServer(t, api) + defer srv.Close() + c, logs := newMergeTrainEngine(t, srv.URL, DefaultMergeTrainPolicy, RebaseResolverFunc(func(context.Context, RebaseRequest) error { return nil })) + c.stageStore = stagelabels.NewStore("", func() time.Time { return t0 }) + c.stageStore.Observe(stagelabels.Key("acme/widget", 15407), stagelabels.NeedsDecision, "rebase-failed-twice") + fixing := mtPR(15405, t0, "") + fixing.Labels = []*gh.Label{{Name: gh.Ptr(stagelabels.Fixing.Label())}} + 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} + plan := plan0(c, prs) + for _, n := range []int{15405, 15407, 15408} { + if plan.isSibling(n) || plan.isFront(n) { + t.Errorf("#%d is under repair and must be out of every train: %+v", n, plan.groups) + } + } + if len(plan.groups) != 0 { + t.Fatalf("only #15406 is left, and one PR is no train: %+v", plan.groups) + } + for _, want := range []string{"why=fixing", "why=needs-decision", "why=needs-author"} { + if !strings.Contains(logs.String(), want) { + t.Errorf("missing skip log %q\n%s", want, logs.String()) + } + } + // Once the fixer is done (label gone) the two clean PRs form the train + // and #15405 leads it by age. + fixing.Labels = nil + plan = plan0(c, prs) + g, ok := plan.group(15405) + if !ok || !reflect.DeepEqual(g.Order, []int{15405, 15406}) { + t.Fatalf("train = %+v", plan.groups) + } +} From 7e93f0f8eaa639e65fe701667a5c4a7f1fdf6be7 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 22:01:05 -0400 Subject: [PATCH 2/2] tracker: a survivor's gate goes back to its stage's own state The lone survivor of a train that shrank to one member reads the 080 row's own gate (ready), not an empty state. Signed-off-by: Andrew Anderson --- src/pkg/dashboard/stage_tracker_merge_train.go | 10 +++++++++- .../stage_tracker_merge_train_membership_test.go | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pkg/dashboard/stage_tracker_merge_train.go b/src/pkg/dashboard/stage_tracker_merge_train.go index fc36c98c87..aea24e3d07 100644 --- a/src/pkg/dashboard/stage_tracker_merge_train.go +++ b/src/pkg/dashboard/stage_tracker_merge_train.go @@ -275,9 +275,17 @@ func stageTrackerLeaveMergeTrain(it *StageTrackerItem, why string) { } mt := it.MergeTrain if it.MergeGate != nil && (it.MergeGate.State == mt.State || it.MergeGate.State == MergeGateStateTrainFront) { + // Back to the stage's own gate state (ready at 080, pending at + // 060); off the gate there is no gate. it.MergeGate.State = "" + switch it.Stage { + case stagelabels.Reviewed.Number(): + it.MergeGate.State = MergeGateStatePending + case stagelabels.AwaitingMergeAdmission.Number(): + it.MergeGate.State = MergeGateStateReady + } it.MergeGate.Reason = "" - if reflect.DeepEqual(*it.MergeGate, StageTrackerMergeGate{}) { + if it.MergeGate.State == "" || reflect.DeepEqual(*it.MergeGate, StageTrackerMergeGate{}) { it.MergeGate = nil } } diff --git a/src/pkg/dashboard/stage_tracker_merge_train_membership_test.go b/src/pkg/dashboard/stage_tracker_merge_train_membership_test.go index 39c5e85749..0bb94a37c4 100644 --- a/src/pkg/dashboard/stage_tracker_merge_train_membership_test.go +++ b/src/pkg/dashboard/stage_tracker_merge_train_membership_test.go @@ -62,8 +62,8 @@ func TestStageTrackerMergeTrainUnderRepairLeaves(t *testing.T) { if alone.MergeTrain != nil || alone.LeftTrain != nil { t.Fatalf("a train of one is no train: train %+v left %+v", alone.MergeTrain, alone.LeftTrain) } - if alone.MergeGate != nil && (alone.MergeGate.State == MergeGateStateQueuedBehind || strings.Contains(alone.MergeGate.Reason, "#15405")) { - t.Fatalf("survivor gate still names the train: %+v", alone.MergeGate) + if alone.MergeGate == nil || alone.MergeGate.State != MergeGateStateReady || strings.Contains(alone.MergeGate.Reason, "#15405") { + t.Fatalf("survivor gate = %+v, want the 080 row's own ready state", alone.MergeGate) } if strings.Contains(alone.Caption, "#15405") || strings.Contains(alone.Caption, "merge train") { t.Fatalf("survivor caption still names the train: %q", alone.Caption)