From b89a144371f7255a64ff1239d0f46d8ffb4e300f Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 12:23:45 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20honour=20requiredChec?= =?UTF-8?q?ksExpected=20memory=20on=20the=20queued=20merge=20lane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- .../fixed-15419-queued-required-checks.md | 1 + src/pkg/github/automerge/automerge_sweep.go | 3 ++ .../github/automerge/automerge_sweep_test.go | 40 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 changelog.d/fixed-15419-queued-required-checks.md diff --git a/changelog.d/fixed-15419-queued-required-checks.md b/changelog.d/fixed-15419-queued-required-checks.md new file mode 100644 index 0000000000..ba3618141a --- /dev/null +++ b/changelog.d/fixed-15419-queued-required-checks.md @@ -0,0 +1 @@ +- The queued auto-merge lane now remembers GitHub's "required status checks are expected" merge refusal per head, like the other lanes, instead of re-PUTting the merge every sweep pass and logging a false merge-failed ([#15419](https://github.com/hivecommons/hive/issues/15419)). diff --git a/src/pkg/github/automerge/automerge_sweep.go b/src/pkg/github/automerge/automerge_sweep.go index 97221e28b1..ff323aa8b5 100644 --- a/src/pkg/github/automerge/automerge_sweep.go +++ b/src/pkg/github/automerge/automerge_sweep.go @@ -2694,6 +2694,9 @@ func (c *Engine) trySweepQueuedPR(ctx context.Context, displayRepo, owner, repo return effects.Result{Provenance: mergeResult.GetSHA()}, nil }) if err != nil { + if c.requiredChecksExpected(attempt, err) { + return AutoMergeSweepEvent{}, autoMergeReasonChecksExpected, nil + } if refused := c.refusedMerge(attempt, err); refused != "" { return AutoMergeSweepEvent{}, refused, nil } diff --git a/src/pkg/github/automerge/automerge_sweep_test.go b/src/pkg/github/automerge/automerge_sweep_test.go index 6ceb5875ce..ce9fe8c9e8 100644 --- a/src/pkg/github/automerge/automerge_sweep_test.go +++ b/src/pkg/github/automerge/automerge_sweep_test.go @@ -1046,6 +1046,46 @@ func TestTrySweepQueuedPRMergeError(t *testing.T) { } } +func TestTrySweepQueuedPRRequiredChecksExpectedIsRemembered(t *testing.T) { + var merges int + api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch { + case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/pulls/7": + json.NewEncoder(w).Encode(map[string]any{ + "number": 7, "state": "open", "mergeable_state": "clean", "mergeable": true, + "user": map[string]string{"login": "alice"}, + "head": map[string]string{"sha": "sha7"}, + "labels": []map[string]string{{"name": hgithub.AutoMergeQueuedLabel}}, + }) + case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/pulls/7/reviews": + json.NewEncoder(w).Encode([]map[string]any{{"state": "APPROVED", "body": "Approved by @bob for Hive auto-merge on green CI.", "commit_id": "sha7", "user": map[string]string{"login": testHiveAppBotLogin}}}) + case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/commits/sha7/status": + json.NewEncoder(w).Encode(map[string]any{"state": "success", "total_count": 1, "statuses": []map[string]string{{"context": "ci/build", "state": "success"}}}) + case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/commits/sha7/check-runs": + json.NewEncoder(w).Encode(map[string]any{"total_count": 1, "check_runs": []map[string]string{{"name": "build", "status": "completed", "conclusion": "success"}}}) + case r.Method == http.MethodPut && r.URL.Path == "/repos/acme/widget/pulls/7/merge": + merges++ + w.WriteHeader(http.StatusMethodNotAllowed) + json.NewEncoder(w).Encode(map[string]string{"message": "4 of 4 required status checks are expected."}) + default: + t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path) + } + })) + defer api.Close() + c := newAutoMergeSweepClient(api.URL) + _, reason, err := c.trySweepQueuedPR(context.Background(), "widget", "acme", "widget", 7, hgithub.AutoMergeQueuedLabel) + if err != nil || reason != autoMergeReasonChecksExpected { + t.Fatalf("trySweepQueuedPR reason=%q err=%v, want %q without error", reason, err, autoMergeReasonChecksExpected) + } + attempt := mergeAttempt{owner: "acme", repo: "widget", number: 7, head: "sha7", state: "blocked"} + if !c.checksExpectedKnown(attempt, c.clock()) { + t.Fatalf("required-checks-expected refusal was not remembered for the queued head") + } + if merges != 1 { + t.Fatalf("merges = %d, want 1", merges) + } +} + func TestLatestHiveQueueApprovalDoesNotTrustBodyWhenReviewerIsNotApp(t *testing.T) { var logs bytes.Buffer api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { From 528ef1d6889c836f4054ec5282ea2cac06e4a569 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 12:52:36 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20re-arm=20requiredChec?= =?UTF-8?q?ksExpected=20memory=20on=20mergeable=5Fstate=20change,=20not=20?= =?UTF-8?q?only=20off=20"blocked"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit checksExpectedKnown only honoured the memory while GitHub reported the head "blocked", but the queued lane only reaches the merge call for a head GitHub already calls mergeable, so the stored refusal was deleted on sight and the merge re-PUT every pass. Re-arm on a change from the stored state (as the review key does) so the memory applies on every lane. The queued-lane test now runs two passes and asserts a single merge call via knownMergeRefusal; the self-authored lane's "check-pending" literal uses the shared constant. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- .../automerge/automerge_merge_refusal.go | 21 ++++++++++------ .../automerge/automerge_merge_refusal_test.go | 5 ++-- src/pkg/github/automerge/automerge_sweep.go | 2 +- .../github/automerge/automerge_sweep_test.go | 25 +++++++++++++------ 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/pkg/github/automerge/automerge_merge_refusal.go b/src/pkg/github/automerge/automerge_merge_refusal.go index 194b39a215..4ca3bb932a 100644 --- a/src/pkg/github/automerge/automerge_merge_refusal.go +++ b/src/pkg/github/automerge/automerge_merge_refusal.go @@ -106,11 +106,14 @@ const autoMergeReasonChecksExpected = "check-pending" // requiredChecksExpected reports whether err is GitHub's 405 "N of M // required status checks are expected" and, when it is, remembers the head -// so knownMergeRefusal skips the merge call on the following passes while -// GitHub still reports the PR blocked (hivecommons/docs#512: the sweep put -// /merge on every pass, each refusal lighting "Merge failed" on the tracker -// for a PR whose checks had simply not started). A check run completing -// flips mergeable_state off "blocked", which re-arms the call. +// and the mergeable_state it was refused in so knownMergeRefusal skips the +// merge call on the following passes while GitHub still reports that state +// (hivecommons/docs#512: the sweep put /merge on every pass, each refusal +// lighting "Merge failed" on the tracker for a PR whose checks had simply +// not started). A check run reporting moves mergeable_state (blocked → +// clean, or clean → unstable/blocked when GitHub had called the head clean +// before its required checks were even created, hivecommons/hive#15419), +// which re-arms the call, as does a new head or the recheck window. func (c *Engine) requiredChecksExpected(a mergeAttempt, err error) bool { if !requiredChecksExpectedMergeError(err) { return false @@ -123,13 +126,17 @@ func (c *Engine) requiredChecksExpected(a mergeAttempt, err error) bool { } // checksExpectedKnown reports whether the head of a is remembered as -// waiting on required checks and GitHub still reports it blocked. +// waiting on required checks and GitHub still reports the mergeable_state +// it was refused in. It does not require that state to be "blocked": the +// queued lane only reaches the merge call for a head GitHub already calls +// mergeable, so a "blocked"-only memory was never consulted there and the +// merge was re-PUT every pass (hivecommons/hive#15419). func (c *Engine) checksExpectedKnown(a mergeAttempt, now time.Time) bool { r, ok := c.mergeRefusals[mergeRefusalChecksKey(a)] if !ok { return false } - if now.Sub(r.at) >= mergeRefusalRecheck || !strings.EqualFold(r.head, strings.TrimSpace(a.head)) || comparableMergeableState(a.state) != "blocked" { + if now.Sub(r.at) >= mergeRefusalRecheck || !strings.EqualFold(r.head, strings.TrimSpace(a.head)) || comparableMergeableState(a.state) != r.state { delete(c.mergeRefusals, mergeRefusalChecksKey(a)) return false } diff --git a/src/pkg/github/automerge/automerge_merge_refusal_test.go b/src/pkg/github/automerge/automerge_merge_refusal_test.go index fe2c3bceb3..2df7121902 100644 --- a/src/pkg/github/automerge/automerge_merge_refusal_test.go +++ b/src/pkg/github/automerge/automerge_merge_refusal_test.go @@ -218,8 +218,9 @@ func TestContributorLanePermanentMergeRefusalOneMergeCall(t *testing.T) { // TestRequiredChecksExpectedRemembered: GitHub's 405 "N of M required status // checks are expected" (hivecommons/docs#512, 2026-10-29) is remembered per // head, and the next pass skips the merge call as check-pending while the -// PR is still blocked — a new head, an unblocked state or the recheck -// window re-arms it; other errors are not remembered. +// PR still reports the mergeable_state it was refused in — a new head, a +// changed state or the recheck window re-arms it; other errors are not +// remembered. func TestRequiredChecksExpectedRemembered(t *testing.T) { expected := &gh.ErrorResponse{Response: &http.Response{StatusCode: http.StatusMethodNotAllowed}, Message: "4 of 4 required status checks are expected."} base := mergeAttempt{owner: "hivecommons", repo: "docs", base: "main", number: 512, head: "sha512", state: "blocked", method: "squash"} diff --git a/src/pkg/github/automerge/automerge_sweep.go b/src/pkg/github/automerge/automerge_sweep.go index ff323aa8b5..ebaa56ae74 100644 --- a/src/pkg/github/automerge/automerge_sweep.go +++ b/src/pkg/github/automerge/automerge_sweep.go @@ -1950,7 +1950,7 @@ func (c *Engine) trySweepSelfAuthoredPR(ctx context.Context, displayRepo, owner, if err != nil { if c.requiredChecksExpected(attempt, err) { if !branchUpdateAllowed { - return AutoMergeSweepEvent{}, "check-pending", nil + return AutoMergeSweepEvent{}, autoMergeReasonChecksExpected, nil } return c.updateBranchAndSkip(ctx, displayRepo, owner, repo, number, evaluatedHeadSHA, "required-checks-expected", c.isForkPR(pr)) } diff --git a/src/pkg/github/automerge/automerge_sweep_test.go b/src/pkg/github/automerge/automerge_sweep_test.go index ce9fe8c9e8..11eff6e4fb 100644 --- a/src/pkg/github/automerge/automerge_sweep_test.go +++ b/src/pkg/github/automerge/automerge_sweep_test.go @@ -1073,16 +1073,25 @@ func TestTrySweepQueuedPRRequiredChecksExpectedIsRemembered(t *testing.T) { })) defer api.Close() c := newAutoMergeSweepClient(api.URL) - _, reason, err := c.trySweepQueuedPR(context.Background(), "widget", "acme", "widget", 7, hgithub.AutoMergeQueuedLabel) - if err != nil || reason != autoMergeReasonChecksExpected { - t.Fatalf("trySweepQueuedPR reason=%q err=%v, want %q without error", reason, err, autoMergeReasonChecksExpected) - } - attempt := mergeAttempt{owner: "acme", repo: "widget", number: 7, head: "sha7", state: "blocked"} - if !c.checksExpectedKnown(attempt, c.clock()) { - t.Fatalf("required-checks-expected refusal was not remembered for the queued head") + // Two passes against the same head: the first is refused and remembered, + // the second must skip the merge call on the memory alone. + for pass := 1; pass <= 2; pass++ { + _, reason, err := c.trySweepQueuedPR(context.Background(), "widget", "acme", "widget", 7, hgithub.AutoMergeQueuedLabel) + if err != nil || reason != autoMergeReasonChecksExpected { + t.Fatalf("pass %d: trySweepQueuedPR reason=%q err=%v, want %q without error", pass, reason, err, autoMergeReasonChecksExpected) + } } if merges != 1 { - t.Fatalf("merges = %d, want 1", merges) + t.Fatalf("merges = %d, want 1 (the remembered refusal must not be re-PUT)", merges) + } + attempt := mergeAttempt{owner: "acme", repo: "widget", number: 7, head: "sha7", state: "clean"} + if got := c.knownMergeRefusal(attempt); got != autoMergeReasonChecksExpected { + t.Fatalf("knownMergeRefusal = %q, want %q for the queued head", got, autoMergeReasonChecksExpected) + } + // A check reporting moves mergeable_state, which re-arms the merge call. + attempt.state = "unstable" + if got := c.knownMergeRefusal(attempt); got != "" { + t.Fatalf("knownMergeRefusal = %q after mergeable_state changed, want re-armed", got) } }