From a2d4ca9418296a18d7eab42c74e9bd82075c5cad Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 21:53:27 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20tracker:=20merge-failed=20chevro?= =?UTF-8?q?n=20is=20scoped=20to=20the=20head=20it=20failed=20on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A refused merge call is recorded with the head it was made on. The stage tracker demotes a refusal to prior_head_merge_failed* hover history once the PR head moves or the record regresses below 080 to wait on CI after the refusal, so the chevron reads the live stage word and never contradicts its caption (hive#15574). Fixes #15611 Signed-off-by: Andrew Anderson --- ...-15611-merge-failed-chevron-head-scoped.md | 1 + src/docs/dashboard-sections.md | 2 + src/pkg/dashboard/stage_tracker.go | 2 +- .../stage_tracker_merge_failed_stale_test.go | 135 ++++++++++++++++++ src/pkg/dashboard/stage_tracker_merge_gate.go | 57 +++++++- .../stage_tracker_merging_hold_test.go | 6 +- .../dashboard/static-src/js/tracker-row.js | 5 + .../dashboard/static-src/js/tracker-words.js | 16 +++ src/pkg/dashboard/static/index.html | 21 +++ .../automerge/automerge_contributor_lane.go | 2 +- .../automerge/automerge_merge_attempt_test.go | 6 +- src/pkg/github/automerge/automerge_sweep.go | 10 +- .../github/automerge/automerge_sweep_test.go | 2 +- src/pkg/github/merge_attempts.go | 20 ++- src/pkg/github/pullrequest.go | 2 +- 15 files changed, 268 insertions(+), 19 deletions(-) create mode 100644 changelog.d/fixed-15611-merge-failed-chevron-head-scoped.md create mode 100644 src/pkg/dashboard/stage_tracker_merge_failed_stale_test.go diff --git a/changelog.d/fixed-15611-merge-failed-chevron-head-scoped.md b/changelog.d/fixed-15611-merge-failed-chevron-head-scoped.md new file mode 100644 index 0000000000..3aef459c35 --- /dev/null +++ b/changelog.d/fixed-15611-merge-failed-chevron-head-scoped.md @@ -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)). diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index f0cc5fe321..54d9cd370f 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -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 diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index e82c508b63..7f80c30f6a 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -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" { diff --git a/src/pkg/dashboard/stage_tracker_merge_failed_stale_test.go b/src/pkg/dashboard/stage_tracker_merge_failed_stale_test.go new file mode 100644 index 0000000000..66d83a9f31 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_merge_failed_stale_test.go @@ -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, '&').replace(/ ({ 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'); +`) +} diff --git a/src/pkg/dashboard/stage_tracker_merge_gate.go b/src/pkg/dashboard/stage_tracker_merge_gate.go index 2408ecc328..bca110d8f7 100644 --- a/src/pkg/dashboard/stage_tracker_merge_gate.go +++ b/src/pkg/dashboard/stage_tracker_merge_gate.go @@ -78,6 +78,15 @@ type StageTrackerMergeGate struct { 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:", 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 @@ -175,12 +184,48 @@ func stageTrackerMergeAttemptStage(stage stagelabels.Stage, a github.MergeAttemp 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[:], 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 } @@ -194,6 +239,12 @@ func stageTrackerMergeGateAttempt(mg *StageTrackerMergeGate, a github.MergeAttem 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 diff --git a/src/pkg/dashboard/stage_tracker_merging_hold_test.go b/src/pkg/dashboard/stage_tracker_merging_hold_test.go index 485f784786..56517ce938 100644 --- a/src/pkg/dashboard/stage_tracker_merging_hold_test.go +++ b/src/pkg/dashboard/stage_tracker_merging_hold_test.go @@ -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) } @@ -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"}} { diff --git a/src/pkg/dashboard/static-src/js/tracker-row.js b/src/pkg/dashboard/static-src/js/tracker-row.js index 4180efd127..3f96011df3 100644 --- a/src/pkg/dashboard/static-src/js/tracker-row.js +++ b/src/pkg/dashboard/static-src/js/tracker-row.js @@ -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 diff --git a/src/pkg/dashboard/static-src/js/tracker-words.js b/src/pkg/dashboard/static-src/js/tracker-words.js index 397f88a6c5..57d4cadffa 100644 --- a/src/pkg/dashboard/static-src/js/tracker-words.js +++ b/src/pkg/dashboard/static-src/js/tracker-words.js @@ -1064,6 +1064,22 @@ } return { state, word, detail: STAGE_TRACKER_MERGE_REFUSAL_DETAIL[kind] || 'GitHub refused', tip: sentence + ' The lane re-evaluates it on its next pass' + (nextWords ? ' (' + nextWords + ')' : '') + '.' + lastSeen + details, cue: 'waiting', until: 0 }; } + // Pure: the hover note for a refusal that belongs to an earlier head + // (merge_gate.prior_head_merge_failed*): the PR's head moved, or the + // record fell back below 080 to wait on CI, after GitHub refused the + // merge. The chevron reads the live stage; this line is the history โ€” + // "merge attempt on previous head failed: branch protection". '' when + // there is none. Never a chevron word. + function stageTrackerPriorHeadMergeFailedNote(item) { + const mg = item && item.merge_gate; + if (!mg || (!mg.prior_head_merge_failed && !mg.prior_head_merge_failed_kind)) return ''; + const why = String(mg.prior_head_merge_failed || '').trim(); + const fallback = why && !mg.prior_head_merge_failed_kind ? stageTrackerMergeRefusalFromRaw(why) : null; + const kind = mg.prior_head_merge_failed_kind || (fallback && fallback.kind) || ''; + const detail = kind === 'checks-pending' ? 'required checks had not reported' : (STAGE_TRACKER_MERGE_REFUSAL_DETAIL[kind] || stageTrackerMergeFailedShort(why)); + const head = String(mg.prior_head_merge_failed_head || '').slice(0, 7); + return 'merge attempt on previous head' + (head ? ' ' + head : '') + ' failed: ' + detail; + } // Pure: a refusal's first line, cut to STAGE_TRACKER_MERGE_FAILED_SHORT_MAX // (tooltips and toasts; the pill detail comes from the refusal kind). function stageTrackerMergeFailedShort(why) { diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 6bd6826f9f..ddc142a11b 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -15379,6 +15379,22 @@

Where to get help

} return { state, word, detail: STAGE_TRACKER_MERGE_REFUSAL_DETAIL[kind] || 'GitHub refused', tip: sentence + ' The lane re-evaluates it on its next pass' + (nextWords ? ' (' + nextWords + ')' : '') + '.' + lastSeen + details, cue: 'waiting', until: 0 }; } + // Pure: the hover note for a refusal that belongs to an earlier head + // (merge_gate.prior_head_merge_failed*): the PR's head moved, or the + // record fell back below 080 to wait on CI, after GitHub refused the + // merge. The chevron reads the live stage; this line is the history โ€” + // "merge attempt on previous head failed: branch protection". '' when + // there is none. Never a chevron word. + function stageTrackerPriorHeadMergeFailedNote(item) { + const mg = item && item.merge_gate; + if (!mg || (!mg.prior_head_merge_failed && !mg.prior_head_merge_failed_kind)) return ''; + const why = String(mg.prior_head_merge_failed || '').trim(); + const fallback = why && !mg.prior_head_merge_failed_kind ? stageTrackerMergeRefusalFromRaw(why) : null; + const kind = mg.prior_head_merge_failed_kind || (fallback && fallback.kind) || ''; + const detail = kind === 'checks-pending' ? 'required checks had not reported' : (STAGE_TRACKER_MERGE_REFUSAL_DETAIL[kind] || stageTrackerMergeFailedShort(why)); + const head = String(mg.prior_head_merge_failed_head || '').slice(0, 7); + return 'merge attempt on previous head' + (head ? ' ' + head : '') + ' failed: ' + detail; + } // Pure: a refusal's first line, cut to STAGE_TRACKER_MERGE_FAILED_SHORT_MAX // (tooltips and toasts; the pill detail comes from the refusal kind). function stageTrackerMergeFailedShort(why) { @@ -16302,6 +16318,11 @@

Where to get help

// 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 diff --git a/src/pkg/github/automerge/automerge_contributor_lane.go b/src/pkg/github/automerge/automerge_contributor_lane.go index ea0da01c12..f78a190dc9 100644 --- a/src/pkg/github/automerge/automerge_contributor_lane.go +++ b/src/pkg/github/automerge/automerge_contributor_lane.go @@ -1483,7 +1483,7 @@ func (c *Engine) trySweepContributorLanePR(ctx context.Context, displayRepo, own mergeMessage, mergeOpts := c.mergeOptions(ctx, owner, repo, eval.pr, headSHA, method) var mergeResult *gh.PullRequestMergeResult - mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, func(ctx context.Context) (effects.Result, error) { + mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, headSHA, func(ctx context.Context) (effects.Result, error) { var apiErr error mergeResult, _, apiErr = c.gh.PullRequests.Merge(ctx, owner, repo, number, mergeMessage, mergeOpts) if apiErr != nil { diff --git a/src/pkg/github/automerge/automerge_merge_attempt_test.go b/src/pkg/github/automerge/automerge_merge_attempt_test.go index 84179b755d..773a344882 100644 --- a/src/pkg/github/automerge/automerge_merge_attempt_test.go +++ b/src/pkg/github/automerge/automerge_merge_attempt_test.go @@ -19,7 +19,7 @@ func TestExecuteMergeEffectRecordsMergeAttempt(t *testing.T) { var during hgithub.MergeAttempt var seen bool - out, err := engine.executeMergeEffect(context.Background(), claim, "acme", "widget", 41, func(context.Context) (effects.Result, error) { + out, err := engine.executeMergeEffect(context.Background(), claim, "acme", "widget", 41, "", func(context.Context) (effects.Result, error) { during, seen = hgithub.MergeAttemptFor("acme/widget", 41) return effects.Result{Provenance: "merge-sha"}, nil }) @@ -35,7 +35,7 @@ func TestExecuteMergeEffectRecordsMergeAttempt(t *testing.T) { } // A refusal ends the attempt with its words. - _, err = engine.executeMergeEffect(context.Background(), claim, "acme", "widget", 42, func(context.Context) (effects.Result, error) { + _, err = engine.executeMergeEffect(context.Background(), claim, "acme", "widget", 42, "", func(context.Context) (effects.Result, error) { return effects.Result{}, errors.New("405 Pull Request is not mergeable") }) if err == nil { @@ -45,7 +45,7 @@ func TestExecuteMergeEffectRecordsMergeAttempt(t *testing.T) { t.Fatalf("refused attempt: %+v", a) } // A call that returns without a merge SHA did not merge. - if _, err = engine.executeMergeEffect(context.Background(), claim, "acme", "widget", 43, func(context.Context) (effects.Result, error) { + if _, err = engine.executeMergeEffect(context.Background(), claim, "acme", "widget", 43, "", func(context.Context) (effects.Result, error) { return effects.Result{}, nil }); err != nil { t.Fatal(err) diff --git a/src/pkg/github/automerge/automerge_sweep.go b/src/pkg/github/automerge/automerge_sweep.go index e51c3317cb..79337749b1 100644 --- a/src/pkg/github/automerge/automerge_sweep.go +++ b/src/pkg/github/automerge/automerge_sweep.go @@ -2021,7 +2021,7 @@ func (c *Engine) trySweepSelfAuthoredPR(ctx context.Context, displayRepo, owner, mergeMessage, mergeOpts := c.mergeOptions(ctx, owner, repo, current, evaluatedHeadSHA, method) var mergeResult *gh.PullRequestMergeResult - mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, func(ctx context.Context) (effects.Result, error) { + mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, evaluatedHeadSHA, func(ctx context.Context) (effects.Result, error) { var apiErr error mergeResult, _, apiErr = c.gh.PullRequests.Merge(ctx, owner, repo, number, mergeMessage, mergeOpts) if apiErr != nil { @@ -2425,7 +2425,7 @@ func (c *Engine) trySweepTrustedAuthorPR(ctx context.Context, displayRepo, owner mergeMessage, mergeOpts := c.mergeOptions(ctx, owner, repo, current, headSHA, method) var mergeResult *gh.PullRequestMergeResult - mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, func(ctx context.Context) (effects.Result, error) { + mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, headSHA, func(ctx context.Context) (effects.Result, error) { var apiErr error mergeResult, _, apiErr = c.gh.PullRequests.Merge(ctx, owner, repo, number, mergeMessage, mergeOpts) if apiErr != nil { @@ -2779,7 +2779,7 @@ func (c *Engine) trySweepQueuedPR(ctx context.Context, displayRepo, owner, repo mergeMessage, mergeOpts := c.mergeOptions(ctx, owner, repo, pr, headSHA, method) var mergeResult *gh.PullRequestMergeResult - mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, func(ctx context.Context) (effects.Result, error) { + mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, headSHA, func(ctx context.Context) (effects.Result, error) { var apiErr error mergeResult, _, apiErr = c.gh.PullRequests.Merge(ctx, owner, repo, number, mergeMessage, mergeOpts) if apiErr != nil { @@ -3195,9 +3195,9 @@ func mergeAPIErrorNotApplied(err error) error { // executeMergeEffect runs the merge call through the mutation boundary and // brackets it with a merge attempt (hivecommons/hive#15245) so the tracker // shows "Merging" for the call's duration and a refusal's reason after. -func (c *Engine) executeMergeEffect(ctx context.Context, claim effects.Claim, owner, repo string, number int, merge func(context.Context) (effects.Result, error)) (effects.Result, error) { +func (c *Engine) executeMergeEffect(ctx context.Context, claim effects.Claim, owner, repo string, number int, head string, merge func(context.Context) (effects.Result, error)) (effects.Result, error) { slug := owner + "/" + repo - hgithub.BeginMergeAttempt(slug, number, hgithub.PRAuditPathSweep) + hgithub.BeginMergeAttemptOnHead(slug, number, hgithub.PRAuditPathSweep, head) out, err := c.executeMergeEffectOnce(ctx, claim, owner, repo, number, merge) switch { case err != nil: diff --git a/src/pkg/github/automerge/automerge_sweep_test.go b/src/pkg/github/automerge/automerge_sweep_test.go index 11eff6e4fb..1b146488ee 100644 --- a/src/pkg/github/automerge/automerge_sweep_test.go +++ b/src/pkg/github/automerge/automerge_sweep_test.go @@ -425,7 +425,7 @@ func TestExecuteMergeEffectReconcilesUnknownOpenPRBeforeRetry(t *testing.T) { Actor: "automerge", Inputs: map[string]string{"method": "squash", "expect_sha": "head", "lane": "self-authored"}, } - out, err := engine.executeMergeEffect(context.Background(), claim, "acme", "widget", 7, func(context.Context) (effects.Result, error) { + out, err := engine.executeMergeEffect(context.Background(), claim, "acme", "widget", 7, "", func(context.Context) (effects.Result, error) { return effects.Result{Provenance: "merge-sha"}, nil }) if err != nil { diff --git a/src/pkg/github/merge_attempts.go b/src/pkg/github/merge_attempts.go index cf53127c72..c0e743cc93 100644 --- a/src/pkg/github/merge_attempts.go +++ b/src/pkg/github/merge_attempts.go @@ -31,6 +31,12 @@ type MergeAttempt struct { Merged bool `json:"merged,omitempty"` // Error is the refusal, in words, when the attempt ended unmerged. Error string `json:"error,omitempty"` + // Head is the head SHA the merge call targeted ("" when the caller did + // not know it). A refusal belongs to that head: once the PR's head + // moves (merge-from-base, new push) the tracker drops the "Merge + // failed" word and keeps the refusal as history + // (hivecommons/hive#15245 follow-up). + Head string `json:"head,omitempty"` } // InFlight reports whether the merge call has not returned yet. @@ -78,13 +84,19 @@ func (m *MergeAttempts) SetOnChange(fn func()) { // Begin records that a merge of repo#number is being attempted now by // path, replacing any earlier attempt on the PR. func (m *MergeAttempts) Begin(repo string, number int, path string) { + m.BeginOnHead(repo, number, path, "") +} + +// BeginOnHead is Begin for a merge call aimed at head (the PR head SHA +// the caller verified or asked GitHub to expect). +func (m *MergeAttempts) BeginOnHead(repo string, number int, path, head string) { if m == nil || number <= 0 || strings.TrimSpace(repo) == "" { return } m.mu.Lock() now := m.now() m.purgeLocked(now) - m.items[mergeAttemptKey(repo, number)] = MergeAttempt{Repo: strings.TrimSpace(repo), Number: number, Path: path, StartedAt: now} + m.items[mergeAttemptKey(repo, number)] = MergeAttempt{Repo: strings.TrimSpace(repo), Number: number, Path: path, StartedAt: now, Head: strings.TrimSpace(head)} fn := m.onChange m.mu.Unlock() if fn != nil { @@ -171,6 +183,12 @@ func BeginMergeAttempt(repo string, number int, path string) { defaultMergeAttempts.Begin(repo, number, path) } +// BeginMergeAttemptOnHead is BeginMergeAttempt with the head SHA the merge +// call targets. +func BeginMergeAttemptOnHead(repo string, number int, path, head string) { + defaultMergeAttempts.BeginOnHead(repo, number, path, head) +} + func EndMergeAttempt(repo string, number int, merged bool, err error) { defaultMergeAttempts.End(repo, number, merged, err) } diff --git a/src/pkg/github/pullrequest.go b/src/pkg/github/pullrequest.go index bff3bbb5c5..a695161f99 100644 --- a/src/pkg/github/pullrequest.go +++ b/src/pkg/github/pullrequest.go @@ -473,7 +473,7 @@ func (c *Client) MergePRVia(ctx context.Context, repo string, number int, mergeM } // The tracker's "Merging" state (hivecommons/hive#15245) spans exactly // the merge call, whichever caller issued it. - BeginMergeAttempt(owner+"/"+repo, number, auditPath) + BeginMergeAttemptOnHead(owner+"/"+repo, number, auditPath, expectSHA) out, err := effects.Execute(ctx, boundary, claim, merge) if errors.Is(err, effects.ErrNeedsReconciliation) { out, err = c.reconcileMerge(ctx, boundary, claim, owner, repo, number, merge, err)