Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The Activity Monitor's "Merge failed" chevron is scoped to the head GitHub refused: once the PR head moves (merge-from-base, new push) or the record falls back below 080 to wait on CI after the refusal, the chevron reads the live stage word and the refusal survives only as the hover note "merge attempt on previous head failed: branch protection", so the chevron and its caption never disagree about whether a merge is failing now ([#15611](https://github.com/hivecommons/hive/issues/15611)).
2 changes: 2 additions & 0 deletions src/docs/dashboard-sections.md
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,8 @@ Every PR at the gate now carries `merge_gate: {state, reason, sweep_running, las
| any stage after the merge call drew *N of M required status checks are expected* (`merge_failed_kind: checks-pending`, `merge_failed_checks`) | **Waiting for CI** | *4 checks* | ⟳ while the sweep is on it, else 🕓 — *hive tried to merge this (automerge sweep) 1m ago before its required checks had reported — 4 required checks haven't finished. It merges once they pass.* |

A merge outcome (**Merging**, **Merge failed**, **Waiting for CI**) always lights the **Merge queue** column, whatever numeric stage the lane fell back to (hivecommons/docs#512 drew "Merge failed" in CI / Review because the PR sat at 060).

A refusal is scoped to the head it failed on. Once the PR head moves (merge-from-base, a new push) or the record falls back below 080 to wait on CI (`required-check-pending:*`) after the refusal, the chevron reads the live stage word (**CI running · build-and-test**, **Review pending**) and the refusal survives only in the hover — *merge attempt on previous head 92d4cef failed: branch protection* (`merge_gate.prior_head_merge_failed`, `prior_head_merge_failed_kind`, `prior_head_merge_failed_text`, `prior_head_merge_failed_at`, `prior_head_merge_failed_head`). The chevron and the caption never disagree about whether a merge is failing now ([#15611](https://github.com/hivecommons/hive/issues/15611); hive#15574 read "Merge failed · branch protection" over a caption waiting on CI for the new head).
| 110 | **Merged** (the ✓ cap) | — | — |

#### Merging is held for the toast's lifetime
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2128,7 +2128,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
it.StageSlug = stage.Slug()
it.StageLabel = stage.Label()
if it.Kind == "pr" {
it.MergeGate = stageTrackerMergeGateAttempt(stageTrackerMergeGate(it.Repo, it.Number, stage, rec, hasRec, sweep, now), attempt, hasAttempt)
it.MergeGate = stageTrackerMergeGateAttempt(stageTrackerMergeGate(it.Repo, it.Number, stage, rec, hasRec, sweep, now), attempt, hasAttempt, it.Head, stage, rec, hasRec)
it.Soak = stageTrackerSoakFrom(rec, hasRec, it.Head, soakWindow, now)
}
if m := trackerPRNumberRE.FindStringSubmatch(it.Reason); m != nil && it.Kind == "issue" {
Expand Down
135 changes: 135 additions & 0 deletions src/pkg/dashboard/stage_tracker_merge_failed_stale_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package dashboard

import (
"errors"
"strings"
"testing"
"time"

"github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/stagelabels"
)

// TestStageTrackerMergeFailedScopedToHead: hive#15574 read "⏱ Merge failed
// · branch protection" while its caption said the review swarm was waiting
// on CI for the new head. The sweep's merge call on the old head drew
// GitHub's refusal, the hive merged v5 in (new head), the record regressed
// 080 → 050 required-check-pending:build-and-test, and the chevron kept the
// previous head's word. A refusal is scoped to the head it failed on: once
// the head moves, or the record falls below 080 to wait on CI after the
// refusal, the chevron reads the live stage and the refusal survives only
// as prior_head_merge_failed* hover history.
func TestStageTrackerMergeFailedScopedToHead(t *testing.T) {
ended := time.Date(2026, 11, 2, 14, 0, 0, 0, time.UTC)
refused := errors.New("PUT https://api.github.com/repos/hivecommons/hive/pulls/15574/merge: 405 Pull Request is not mergeable []")
failed := github.MergeAttempt{Repo: "hivecommons/hive", Number: 15574, Path: github.PRAuditPathSweep, Head: "aaaaaaa1", StartedAt: ended.Add(-2 * time.Second), EndedAt: ended, Error: refused.Error()}
regressed := stagelabels.Record{Stage: stagelabels.ReviewPending, Reason: "required-check-pending:build-and-test", EnteredAt: ended.Add(time.Minute), RegressedFrom: stagelabels.AwaitingMergeAdmission, RegressedAt: ended.Add(time.Minute)}

// Head moved (merge-from-base → 92d4cefc): no merge-failed word.
mg := stageTrackerMergeGateAttempt(nil, failed, true, "92d4cefc", stagelabels.ReviewPending, regressed, true)
if mg == nil || mg.State == MergeGateStateMergeFailed || mg.MergeFailed != "" {
t.Fatalf("refusal on head aaaaaaa1 must not be the word on head 92d4cefc: %+v", mg)
}
if mg.PriorHeadMergeFailed != refused.Error() || mg.PriorHeadMergeFailedKind != MergeRefusalProtection || mg.PriorHeadMergeFailedHead != "aaaaaaa1" || mg.PriorHeadMergeFailedAt == nil || !mg.PriorHeadMergeFailedAt.Equal(ended) {
t.Errorf("the refusal must survive as prior-head history: %+v", mg)
}

// Same head, but the record regressed to 050 waiting on CI after the
// refusal (older attempts carry no head): still history, not the word.
sameHead := failed
sameHead.Head = ""
if mg = stageTrackerMergeGateAttempt(nil, sameHead, true, "aaaaaaa1", stagelabels.ReviewPending, regressed, true); mg == nil || mg.State == MergeGateStateMergeFailed || mg.PriorHeadMergeFailedKind != MergeRefusalProtection {
t.Errorf("050 required-check-pending after the refusal must demote it to history: %+v", mg)
}

// Control: same head, record still at 080 → the refusal is live.
live := stagelabels.Record{Stage: stagelabels.AwaitingMergeAdmission, Reason: "", EnteredAt: ended.Add(-time.Hour)}
if mg = stageTrackerMergeGateAttempt(nil, failed, true, "aaaaaaa1", stagelabels.AwaitingMergeAdmission, live, true); mg == nil || mg.State != MergeGateStateMergeFailed || mg.MergeFailedKind != MergeRefusalProtection || mg.PriorHeadMergeFailed != "" {
t.Errorf("a refusal on the current head at 080 is still the word: %+v", mg)
}
// Control: regressed to 050 before the refusal (the refusal is newer) → live.
before := regressed
before.EnteredAt, before.RegressedAt = ended.Add(-time.Minute), ended.Add(-time.Minute)
if mg = stageTrackerMergeGateAttempt(nil, sameHead, true, "aaaaaaa1", stagelabels.ReviewPending, before, true); mg == nil || mg.State != MergeGateStateMergeFailed {
t.Errorf("a refusal newer than the regression is still the word: %+v", mg)
}
// Control: regressed for a non-CI reason (a human asked for changes) → live.
changes := regressed
changes.Reason = "changes-requested"
if mg = stageTrackerMergeGateAttempt(nil, sameHead, true, "aaaaaaa1", stagelabels.ReviewPending, changes, true); mg == nil || mg.State != MergeGateStateMergeFailed {
t.Errorf("a non-CI regression does not hide the refusal: %+v", mg)
}

for reason, want := range map[string]bool{"required-check-pending:build-and-test": true, "required-check-pending": true, "check-pending": true, "changes-requested": false, "": false} {
if got := stageTrackerCIPendingReason(reason); got != want {
t.Errorf("stageTrackerCIPendingReason(%q) = %v, want %v", reason, got, want)
}
}
}

// TestStageTrackerMergeFailedScopedToHeadNode: the SPA side of hive#15574.
// A payload whose merge_gate carries only prior_head_merge_failed* (state
// empty, stage 050) draws the 050 word with no "Merge failed", and the
// hover note reads "merge attempt on previous head aaaaaaa failed: branch
// protection".
func TestStageTrackerMergeFailedScopedToHeadNode(t *testing.T) {
html := indexHTML(t)
for _, want := range []string{
`stageTrackerPriorHeadMergeFailedNote(item) : '';`,
`if (priorNote) tip += ' — ' + priorNote;`,
} {
if !strings.Contains(html, want) {
t.Errorf("index.html missing prior-head hover wiring %q", want)
}
}
runStageTrackerRowActionsScript(t, "function esc(s) { return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\"/g, '&quot;'); }\n"+
jsConstLine(t, html, "STAGE_TRACKER_TERMINAL")+"\n"+
jsConstLine(t, html, "STAGE_TRACKER_PATH")+"\n"+
jsConstLine(t, html, "STAGE_TRACKER_PR_COLUMN")+"\n"+
jsConstLine(t, html, "STAGE_TRACKER_MERGE_COLUMN")+"\n"+
jsConstLine(t, html, "STAGE_TRACKER_PRE_MERGE_SOAK")+"\n"+
jsConstLine(t, html, "STAGE_TRACKER_NEEDS_DECISION")+"\n"+
jsConstLine(t, html, "STAGE_TRACKER_ISSUE_NEEDS_DECISION")+"\n"+
jsConstLine(t, html, "STAGE_TRACKER_ISSUE_DECISION_COLUMN")+"\n"+
jsConstLine(t, html, "STAGE_TRACKER_TRIAGE_NEEDED")+"\n"+
jsConstLine(t, html, "STAGE_TRACKER_POSSIBLY_EXISTS")+"\n"+
jsConstLine(t, html, "STAGE_TRACKER_MERGE_GATE_WORD")+"\n"+
jsConstBlock(t, html, "STAGE_TRACKER_GATE_REASON_WORDS")+"\n"+
jsFunc(t, html, "stageTrackerAnchor")+"\n"+
jsFunc(t, html, "stageTrackerAgoText")+"\n"+
jsFunc(t, html, "stageTrackerSoakLeft")+"\n"+
jsFunc(t, html, "stageTrackerMergeGateStateOf")+"\n"+
jsFunc(t, html, "stageTrackerShortLeft")+"\n"+
jsFunc(t, html, "stageTrackerGateReasonText")+"\n"+
stageTrackerMergeGateInfoJS(t, html)+"\n"+
jsFunc(t, html, "stageTrackerPriorHeadMergeFailedNote")+"\n"+`
const assert = require('assert');
const now = Date.parse('2026-11-02T14:05:00Z');
const stages = [{ number: 50, label: 'stage/050-review-pending', short: 'CI / Review' }, { number: 80, label: 'stage/080-awaiting-merge', short: 'Merge gate' }];
const raw = 'PUT https://api.github.com/repos/hivecommons/hive/pulls/15574/merge: 405 Pull Request is not mergeable []';
const prior = { prior_head_merge_failed: raw, prior_head_merge_failed_kind: 'protection', prior_head_merge_failed_text: 'branch protection blocks it', prior_head_merge_failed_at: new Date(now - 300000).toISOString(), prior_head_merge_failed_head: 'aaaaaaa1deadbeef' };
const row = (mg) => ({ repo: 'hivecommons/hive', number: 15574, kind: 'pr', stage: 50, stage_label: 'stage/050-review-pending', reason: 'required-check-pending:build-and-test', modifiers: [], merge_gate: mg });

// Record with merge_failed at head A + regression to 050 on head B: the
// gate carries no state, so no gate word (the chevron reads the 050 word)
// and the row stays in CI / Review rather than lighting the Merge gate.
assert.strictEqual(stageTrackerMergeGateStateOf(row(prior)), '', 'no live gate state at 050');
assert.strictEqual(stageTrackerMergeGateInfo(row(prior), now), null, 'no "Merge failed" word from a prior-head refusal');
assert.strictEqual(stageTrackerAnchor(50, stages, 'pr', row(prior)), 50, 'stays in CI / Review');

// The hover keeps the history, in plain words with the short head.
const note = stageTrackerPriorHeadMergeFailedNote(row(prior));
assert.strictEqual(note, 'merge attempt on previous head aaaaaaa failed: branch protection');
assert.ok(!/http|api\.github\.com/.test(note), note);
// Raw-only payload (no kind): the SPA classifies the text itself.
assert.strictEqual(stageTrackerPriorHeadMergeFailedNote(row({ prior_head_merge_failed: raw })), 'merge attempt on previous head failed: branch protection');
assert.strictEqual(stageTrackerPriorHeadMergeFailedNote(row({ prior_head_merge_failed: '405 1 of 3 required status checks are expected.' })), 'merge attempt on previous head failed: required checks had not reported');
// Nothing to say without a prior refusal.
assert.strictEqual(stageTrackerPriorHeadMergeFailedNote(row({ state: 'gate-pending' })), '');
assert.strictEqual(stageTrackerPriorHeadMergeFailedNote({}), '');

// A live refusal on the current head still reads "Merge failed".
const liveInfo = stageTrackerMergeGateInfo(row({ state: 'merge-failed', merge_failed: raw, merge_failed_kind: 'protection', merge_failed_text: 'branch protection blocks it', merge_failed_at: new Date(now - 9000).toISOString(), sweep_running: false }), now);
assert.strictEqual(liveInfo.word + ' · ' + liveInfo.detail, 'Merge failed · branch protection');
`)
}
57 changes: 54 additions & 3 deletions src/pkg/dashboard/stage_tracker_merge_gate.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dashboard

import (
Expand Down Expand Up @@ -78,6 +78,15 @@
MergeFailedKind string `json:"merge_failed_kind,omitempty"`
MergeFailedText string `json:"merge_failed_text,omitempty"`
MergeFailedChecks int `json:"merge_failed_checks,omitempty"`
// PriorHeadMergeFailed* keep a refusal that no longer describes the
// row: the merge call was on an earlier head (the PR's head moved, or
// the record regressed below 080 to wait on CI again). The chevron
// reads the live stage; the hover keeps the refusal as history.
PriorHeadMergeFailed string `json:"prior_head_merge_failed,omitempty"`
PriorHeadMergeFailedKind string `json:"prior_head_merge_failed_kind,omitempty"`
PriorHeadMergeFailedText string `json:"prior_head_merge_failed_text,omitempty"`
PriorHeadMergeFailedAt *time.Time `json:"prior_head_merge_failed_at,omitempty"`
PriorHeadMergeFailedHead string `json:"prior_head_merge_failed_head,omitempty"`
// DuplicateOf / DuplicateIssue: for State "duplicate-of:<n>", the open
// PR the merge queue kept for the same issue and that issue
// (hivecommons/hive#15395); the row waits for a person or the
Expand Down Expand Up @@ -175,12 +184,48 @@
return stage
}

// stageTrackerMergeAttemptStale reports whether a refused merge attempt
// no longer describes the PR: it was aimed at a head other than the
// current one (merge-from-base, new push), or the stage record has since
// regressed below 080 to wait on CI again (the hive merged base into the
// branch after GitHub refused the old head). The chevron then reads the
// live stage and the refusal becomes hover history; chevron and caption
// never disagree about whether a merge is failing right now.
func stageTrackerMergeAttemptStale(a github.MergeAttempt, head string, stage stagelabels.Stage, rec stagelabels.Record, hasRec bool) bool {
if !a.Failed() {
return false
}
if a.Head != "" && head != "" && !strings.EqualFold(a.Head, head) {
return true
}
if !hasRec || stage == stagelabels.None || stage.Number() >= stagelabels.AwaitingMergeAdmission.Number() {
return false
}
if !stageTrackerCIPendingReason(rec.Reason) {
return false
}
return rec.EnteredAt.After(a.EndedAt) || (rec.Regressed() && rec.RegressedAt.After(a.EndedAt))
}

// stageTrackerCIPendingReason reports whether a stage reason token says
// the row waits on CI: required-check-pending[:<name>], check-pending,
// status-pending and the other pending CI states.
func stageTrackerCIPendingReason(reason string) bool {
lower := strings.ToLower(strings.TrimSpace(reason))
if strings.HasPrefix(lower, "required-check-pending") {
return true
}
words, ok := stageTrackerCIStateWords(lower)
return ok && words == "CI running"
}

// stageTrackerMergeGateAttempt folds a merge attempt into the gate
// narration: a live or just-successful attempt sets merging + since; a
// refused one sets merge-failed with the reason (even off the gate, so
// a 090 row whose maintainer merge GitHub refused says so). nil without
// an attempt.
func stageTrackerMergeGateAttempt(mg *StageTrackerMergeGate, a github.MergeAttempt, ok bool) *StageTrackerMergeGate {
// a 090 row whose maintainer merge GitHub refused says so). A refusal on
// a previous head (stageTrackerMergeAttemptStale) is kept only as
// PriorHeadMergeFailed* history. nil without an attempt.
func stageTrackerMergeGateAttempt(mg *StageTrackerMergeGate, a github.MergeAttempt, ok bool, head string, stage stagelabels.Stage, rec stagelabels.Record, hasRec bool) *StageTrackerMergeGate {
if !ok {
return mg
}
Expand All @@ -194,6 +239,12 @@
mg.MergingSince = &since
mg.MergePath = a.Path
mg.SoakUntil, mg.SoakRemainingSeconds, mg.NextSweepAt = nil, 0, nil
case stageTrackerMergeAttemptStale(a, head, stage, rec, hasRec):
mg.PriorHeadMergeFailed = a.Error
mg.PriorHeadMergeFailedKind, mg.PriorHeadMergeFailedText, _ = stageTrackerMergeRefusal(a.Error)
at := a.EndedAt
mg.PriorHeadMergeFailedAt = &at
mg.PriorHeadMergeFailedHead = a.Head
case a.Failed():
mg.State = MergeGateStateMergeFailed
mg.MergingSince = &since
Expand Down
6 changes: 3 additions & 3 deletions src/pkg/dashboard/stage_tracker_merging_hold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ func TestStageTrackerMergeAttemptInPayload(t *testing.T) {
// into the gate narration.
func TestStageTrackerMergeGateAttemptOverlay(t *testing.T) {
now := time.Date(2026, 10, 28, 21, 31, 0, 0, time.UTC)
if mg := stageTrackerMergeGateAttempt(nil, github.MergeAttempt{}, false); mg != nil {
if mg := stageTrackerMergeGateAttempt(nil, github.MergeAttempt{}, false, "", stagelabels.None, stagelabels.Record{}, false); mg != nil {
t.Errorf("no attempt, no gate: %+v", mg)
}
live := github.MergeAttempt{Repo: "a/b", Number: 1, StartedAt: now, Path: github.PRAuditPathRelay}
soak := now.Add(time.Minute)
mg := stageTrackerMergeGateAttempt(&StageTrackerMergeGate{State: MergeGateStateSoaking, SoakUntil: &soak, SoakRemainingSeconds: 60, NextSweepAt: &soak}, live, true)
mg := stageTrackerMergeGateAttempt(&StageTrackerMergeGate{State: MergeGateStateSoaking, SoakUntil: &soak, SoakRemainingSeconds: 60, NextSweepAt: &soak}, live, true, "", stagelabels.PreMergeSoak, stagelabels.Record{}, false)
if mg.State != MergeGateStateMerging || mg.MergingSince == nil || mg.SoakUntil != nil || mg.SoakRemainingSeconds != 0 || mg.NextSweepAt != nil || mg.MergePath != github.PRAuditPathRelay {
t.Errorf("live attempt over soaking: %+v", mg)
}
Expand All @@ -86,7 +86,7 @@ func TestStageTrackerMergeGateAttemptOverlay(t *testing.T) {
if st := stageTrackerMergeAttemptStage(stagelabels.ReadyForHumanMerge, failed, true); st != stagelabels.ReadyForHumanMerge {
t.Errorf("failed attempt must keep the stage, got %v", st)
}
if mg = stageTrackerMergeGateAttempt(nil, failed, true); mg == nil || mg.State != MergeGateStateMergeFailed || mg.MergeFailed != "422 boom" || mg.MergeFailedAt == nil {
if mg = stageTrackerMergeGateAttempt(nil, failed, true, "", stagelabels.None, stagelabels.Record{}, false); mg == nil || mg.State != MergeGateStateMergeFailed || mg.MergeFailed != "422 boom" || mg.MergeFailedAt == nil {
t.Errorf("failed attempt off the gate: %+v", mg)
}
for _, c := range []struct{ path, want string }{{github.PRAuditPathDashboard, "dashboard"}, {github.PRAuditPathRelay, "relay"}, {github.PRAuditPathForge, "forge"}, {github.PRAuditPathSweep, "automerge lane"}, {"", "automerge lane"}} {
Expand Down
5 changes: 5 additions & 0 deletions src/pkg/dashboard/static-src/js/tracker-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@
// Why a person merges a 090 PR leads its tooltip (hivecommons/hive#14658).
// The reason is the whole story; the stage description would only repeat it (hivecommons/hive#15394).
else if (curStage === STAGE_TRACKER_READY_FOR_HUMAN_MERGE && item.human_merge_reason_text) tip = ((sg.detour && sg.detour.text) || sg.label) + ' — ' + String(item.human_merge_reason_text).trim();
// A refusal on an earlier head is history, not the word: the
// chevron reads the live stage and the hover keeps "merge attempt
// on previous head failed: branch protection".
const priorNote = !sg.cap && typeof stageTrackerPriorHeadMergeFailedNote === 'function' ? stageTrackerPriorHeadMergeFailedNote(item) : '';
if (priorNote) tip += ' — ' + priorNote;
if (actorTip && !sg.cap) tip += actorTip;
if (claimant && !sg.cap) tip += ' · ' + stageTrackerClaimantLine(claimant, nowMs);
// The sentinel's reason leads the lane tooltip so the security
Expand Down
Loading
Loading