From ac24e2f7cf2c83b378bae827425d11360a96952e Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sun, 1 Nov 2026 22:35:45 -0500 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20fix(automerge):=20log=20ok-t?= =?UTF-8?q?o-test=20approval=20warning=20once=20per=20PR=20head?= 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> --- changelog.d/fixed-16199.md | 1 + src/pkg/github/automerge/automerge_held_runs.go | 6 ++++-- src/pkg/github/automerge/automerge_held_runs_test.go | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 changelog.d/fixed-16199.md diff --git a/changelog.d/fixed-16199.md b/changelog.d/fixed-16199.md new file mode 100644 index 0000000000..25478d544d --- /dev/null +++ b/changelog.d/fixed-16199.md @@ -0,0 +1 @@ +The automerge sweep now logs the "install the ok-to-test workflow" approval warning once per PR head instead of every tick. diff --git a/src/pkg/github/automerge/automerge_held_runs.go b/src/pkg/github/automerge/automerge_held_runs.go index 4772482b1b..3dc0bbb3ce 100644 --- a/src/pkg/github/automerge/automerge_held_runs.go +++ b/src/pkg/github/automerge/automerge_held_runs.go @@ -224,8 +224,10 @@ func (c *Engine) workflowApprovalAttention(ctx context.Context, displayRepo, own c.postWorkflowApprovalCommand(ctx, displayRepo, owner, repo, number, headSHA) } if !firstSeen.IsZero() && headOlderThan(c.now, firstSeen, workflowApprovalGrace) { - c.warn("automerge workflow approval still required after ok-to-test grace; install the self-contained hive ok-to-test workflow", - "repo", displayRepo, "pr", number, "sha", headSHA, "held", held, "context", contextName, "command", workflowApprovalCommand) + if c.markTerminalHoldLogged(owner, repo, number, headSHA, workflowApprovalWorkflowMissingPrefix+contextName) { + c.warn("automerge workflow approval still required after ok-to-test grace; install the self-contained hive ok-to-test workflow", + "repo", displayRepo, "pr", number, "sha", headSHA, "held", held, "context", contextName, "command", workflowApprovalCommand) + } return workflowApprovalWorkflowMissingPrefix + contextName } c.info("automerge workflow approval required; posted ok-to-test command if needed", "repo", displayRepo, "pr", number, "sha", headSHA, "held", held, "context", contextName, "command", workflowApprovalCommand) diff --git a/src/pkg/github/automerge/automerge_held_runs_test.go b/src/pkg/github/automerge/automerge_held_runs_test.go index 4f0137aab0..97ca8d5e46 100644 --- a/src/pkg/github/automerge/automerge_held_runs_test.go +++ b/src/pkg/github/automerge/automerge_held_runs_test.go @@ -6,7 +6,9 @@ package automerge // and names a head whose runs were never created instead of polling it forever. import ( + "bytes" "context" + "log/slog" "net/http" "net/http/httptest" "strings" @@ -395,6 +397,8 @@ func TestTrySweepTrustedBotWorkflowApprovalMissingWorkflowAfterGrace(t *testing. c := newAutoMergeSweepClient(api.URL) c.trustedBotAuthors = func() map[string]bool { return map[string]bool{"dependabot[bot]": true} } c.now = func() time.Time { return now } + var logs bytes.Buffer + c.logger = slog.New(slog.NewTextHandler(&logs, nil)) _, reason, err := c.trySweepSelfAuthoredPR(context.Background(), "widget", "acme", "widget", 23, true) if err != nil { @@ -414,6 +418,12 @@ func TestTrySweepTrustedBotWorkflowApprovalMissingWorkflowAfterGrace(t *testing. if len(comments) != 1 || comments[0] != workflowApprovalCommandBody("sha23") { t.Fatalf("comments = %q, want one %q command with the head marker", comments, workflowApprovalCommand) } + if _, _, err = c.trySweepSelfAuthoredPR(context.Background(), "widget", "acme", "widget", 23, true); err != nil { + t.Fatalf("third tick returned error: %v", err) + } + if n := strings.Count(logs.String(), "still required after ok-to-test grace"); n != 1 { + t.Fatalf("grace warning logged %d times across repeat ticks, want once per head", n) + } } func TestTrySweepTrustedBotSentinelBlocksWorkflowApprovalAttention(t *testing.T) { From db0115f4df00eacc2a3ce4158831626bb3e8153e Mon Sep 17 00:00:00 2001 From: "hivecommons-hive[bot]" <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 03:36:37 +0000 Subject: [PATCH 2/4] changelog: fragment for #16201 Generated by changelog-fragment-guard from the PR title (#5675). Edit the wording freely, or replace this file with the no-changelog label if the change is not user-visible. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: hivecommons-hive[bot] <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-16201.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/fixed-16201.md diff --git a/changelog.d/fixed-16201.md b/changelog.d/fixed-16201.md new file mode 100644 index 0000000000..420ec814d0 --- /dev/null +++ b/changelog.d/fixed-16201.md @@ -0,0 +1 @@ +- fix(automerge): log ok-to-test approval warning once per PR head (#16201) From 145960696277ea1bcec9a625f41449cd3d7529c9 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sun, 1 Nov 2026 22:45:59 -0500 Subject: [PATCH 3/4] changelog: make the #16199 fragment an entry bullet Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-16199.md | 2 +- changelog.d/fixed-16201.md | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 changelog.d/fixed-16201.md diff --git a/changelog.d/fixed-16199.md b/changelog.d/fixed-16199.md index 25478d544d..327b7382a3 100644 --- a/changelog.d/fixed-16199.md +++ b/changelog.d/fixed-16199.md @@ -1 +1 @@ -The automerge sweep now logs the "install the ok-to-test workflow" approval warning once per PR head instead of every tick. +- The automerge sweep now logs the "install the ok-to-test workflow" approval warning once per PR head instead of every tick ([#16199](https://github.com/hivecommons/hive/issues/16199)). diff --git a/changelog.d/fixed-16201.md b/changelog.d/fixed-16201.md deleted file mode 100644 index 420ec814d0..0000000000 --- a/changelog.d/fixed-16201.md +++ /dev/null @@ -1 +0,0 @@ -- fix(automerge): log ok-to-test approval warning once per PR head (#16201) From b9a60e2d8b820d3bcb29530ac9997daca258137f Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sun, 1 Nov 2026 23:38:07 -0500 Subject: [PATCH 4/4] fix(automerge): key grace warning dedupe separately from the hold reason The ok-to-test grace warning in workflowApprovalAttention used the same terminalHoldLogged key as the hold reason it returns, so the sweep loop's once-per-head "automerge hold" line never fired for missing-workflow holds (documented in operator-reference/README.md). Use a dedicated key suffix and assert in the test that the hold reason's key is still unclaimed. 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> --- src/pkg/github/automerge/automerge_held_runs.go | 6 +++++- src/pkg/github/automerge/automerge_held_runs_test.go | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pkg/github/automerge/automerge_held_runs.go b/src/pkg/github/automerge/automerge_held_runs.go index 3dc0bbb3ce..aa0752a4cd 100644 --- a/src/pkg/github/automerge/automerge_held_runs.go +++ b/src/pkg/github/automerge/automerge_held_runs.go @@ -79,6 +79,10 @@ const ( // waiting on a person's approval. workflowRunConclusionActionRequired = "action_required" workflowApprovalWorkflowMissingPrefix = "workflow-approval-required:missing-workflow:" + // workflowApprovalGraceWarnKey keys the once-per-head grace warning in + // terminalHoldLogged separately from the hold reason itself, so the sweep + // loop's "automerge hold" line (keyed on the bare reason) still fires. + workflowApprovalGraceWarnKey = "workflow-approval-grace-warned:" // workflowApprovalUntrustedPrefix: the repository's merge bot (Prow) owns // `/ok-to-test` and only honours it from its trusted users, which a // GitHub App login never is. Posting again cannot succeed; a person must @@ -224,7 +228,7 @@ func (c *Engine) workflowApprovalAttention(ctx context.Context, displayRepo, own c.postWorkflowApprovalCommand(ctx, displayRepo, owner, repo, number, headSHA) } if !firstSeen.IsZero() && headOlderThan(c.now, firstSeen, workflowApprovalGrace) { - if c.markTerminalHoldLogged(owner, repo, number, headSHA, workflowApprovalWorkflowMissingPrefix+contextName) { + if c.markTerminalHoldLogged(owner, repo, number, headSHA, workflowApprovalGraceWarnKey+contextName) { c.warn("automerge workflow approval still required after ok-to-test grace; install the self-contained hive ok-to-test workflow", "repo", displayRepo, "pr", number, "sha", headSHA, "held", held, "context", contextName, "command", workflowApprovalCommand) } diff --git a/src/pkg/github/automerge/automerge_held_runs_test.go b/src/pkg/github/automerge/automerge_held_runs_test.go index 97ca8d5e46..85df75faf3 100644 --- a/src/pkg/github/automerge/automerge_held_runs_test.go +++ b/src/pkg/github/automerge/automerge_held_runs_test.go @@ -424,6 +424,11 @@ func TestTrySweepTrustedBotWorkflowApprovalMissingWorkflowAfterGrace(t *testing. if n := strings.Count(logs.String(), "still required after ok-to-test grace"); n != 1 { t.Fatalf("grace warning logged %d times across repeat ticks, want once per head", n) } + // The grace warning must not claim the hold reason's own dedupe key, or the + // sweep loop's once-per-head "automerge hold" line would never fire. + if !c.markTerminalHoldLogged("acme", "widget", 23, "sha23", reason) { + t.Fatalf("hold reason %q already marked logged by the grace warning; sweep loop would skip its automerge hold line", reason) + } } func TestTrySweepTrustedBotSentinelBlocksWorkflowApprovalAttention(t *testing.T) {