From a275958d831288533d0f0934a70afc5151348580 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 04:20:19 -0500 Subject: [PATCH] fix(automerge): key the 085 entry comment on the decision, not the observing lane Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-16405.md | 1 + .../automerge/automerge_stage_human_test.go | 41 +++++++++++++++++++ src/pkg/stagelabels/human.go | 6 ++- src/pkg/stagelabels/store.go | 9 +++- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 changelog.d/fixed-16405.md diff --git a/changelog.d/fixed-16405.md b/changelog.d/fixed-16405.md new file mode 100644 index 0000000000..49009c7fca --- /dev/null +++ b/changelog.d/fixed-16405.md @@ -0,0 +1 @@ +- The `stage/085-needs-decision` entry comment is no longer posted again on the same head when a different automerge lane observes the PR; maintainers get one explanation per decision ([#16405](https://github.com/hivecommons/hive/issues/16405)). diff --git a/src/pkg/github/automerge/automerge_stage_human_test.go b/src/pkg/github/automerge/automerge_stage_human_test.go index f5ae34e3a5..d8bb8128e1 100644 --- a/src/pkg/github/automerge/automerge_stage_human_test.go +++ b/src/pkg/github/automerge/automerge_stage_human_test.go @@ -627,6 +627,47 @@ func TestDecisionEntryRepostsWhenCauseChanges(t *testing.T) { } } +// TestDecisionEntryNotRepostedWhenObservingLaneFlaps: one requires_human +// verdict on one head reaches 085 through the contributor lane's verdict +// hand-off on one sweep and the trusted lane's trust hand-off on the next. +// The lane-rule consequence bullet only the first adds is presentation, not +// cause: the maintainer is owed one explanation, not one per observing lane +// (hivecommons/hive#16405). +func TestDecisionEntryNotRepostedWhenObservingLaneFlaps(t *testing.T) { + api, closeAPI := seededStageAPI(t) + defer closeAPI() + clock := &contributorLaneClock{at: time.Date(2026, 11, 3, 12, 0, 0, 0, time.UTC)} + verdict := &ContributorLaneVerdict{Configured: true, Verdict: "requires_human"} + e, store := humanStageEngine(t, api.url, clock, verdict, 0) + ctx := context.Background() + sweep := func(lane, reason string, labels ...string) { + t.Helper() + pr := stagePR(9, labels...) + pr.Body = gh.Ptr("Fixes the widget.\n\n— hive: backend=pi model=gpt-6\n") + e.recordStage(lane, "acme/widget", "acme", "widget", pr, reason, false, nil) + if lane == stageLaneContributor { + e.noteStageVerdict("acme", "widget", 9, *verdict) + } + e.noteStageRole("acme", "widget", 9, stagelabels.RoleContributor) + if _, err := e.ApplyStageLabels(ctx); err != nil { + t.Fatal(err) + } + if got := stageOf(t, store, 9); got != stagelabels.NeedsDecision { + t.Fatalf("%s lane: stage=%v want 085", lane, got) + } + } + + api.reset() + sweep(stageLaneContributor, stageReasonVerdictRequiresHuman, "role/contributor", "author/clanker", "stage/050-review-pending") + sweep(stageLaneTrusted, "untrusted-author-role", "role/contributor", "author/clanker", "stage/085-needs-decision") + if len(api.comments) != 1 || !strings.HasPrefix(api.comments[0], stagelabels.DecisionCommentMarker) { + t.Fatalf("085 entry comment reposted on the same head when the observing lane changed: %q", api.comments) + } + if rec, _ := store.Get(stageKey("acme", "widget", 9)); len(rec.EntryCommentedCauses) != 1 || rec.EntryCommentedHead != "sha" { + t.Fatalf("one decision recorded as several causes: %+v", rec) + } +} + // Admission skips carry no CI state in their reasons, // so the human route's check digest decides whether the 050 head waits on // the hive (hivecommons/hive#15009, #15164): running checks do, a settled head with diff --git a/src/pkg/stagelabels/human.go b/src/pkg/stagelabels/human.go index 027399872b..67d071c50d 100644 --- a/src/pkg/stagelabels/human.go +++ b/src/pkg/stagelabels/human.go @@ -363,6 +363,10 @@ func ParseFixerExhausted(reason string) (attempts int, ok bool) { return n, true } +// decisionConsequenceReason is the 085 bullet for a lane rule that names no +// specific cause; EntryCause leaves it out of the dedup digest. +const decisionConsequenceReason = "the automerge lane will not merge this unattended" + // RouteHuman decides which stage a lane's "a human must act" resolves to. func RouteHuman(e Evidence) Route { fixing := FixingStageFor(e.SelfAuthored, e.AuthorKind) @@ -500,7 +504,7 @@ func RouteHuman(e Evidence) Route { if e.Cause == CauseDecision && strings.TrimSpace(e.CauseReason) != "" && !manualMergeApproved { decide = append(decide, e.CauseReason) } else if e.Cause == CauseDecision && len(e.ForkGuard) == 0 && !manualMergeApproved { - decide = append(decide, "the automerge lane will not merge this unattended") + decide = append(decide, decisionConsequenceReason) } if len(decide) > 0 { return Route{Stage: NeedsDecision, Reasons: decide, Summary: summary, Head: e.Head, SelfAuthored: e.SelfAuthored, Verdict: e.Verdict, HumanApprover: approver, Hold: e.Hold} diff --git a/src/pkg/stagelabels/store.go b/src/pkg/stagelabels/store.go index 29a6bd9703..e0bd43cfc1 100644 --- a/src/pkg/stagelabels/store.go +++ b/src/pkg/stagelabels/store.go @@ -1183,11 +1183,18 @@ func (s *Store) MarkEntryCommentedCause(key, head, cause string) { // EntryCause digests an entry comment's reasons (the bullet list, not the // evidence summary whose soak clock ticks) so two comments that would tell -// the maintainer the same thing compare equal. +// the maintainer the same thing compare equal. The lane-rule consequence +// bullet is presentation, not cause: RouteHuman adds it only when the +// observing lane handed off at 085, so a PR two lanes observe alternately +// would otherwise digest the same decision twice on one head +// (hivecommons/hive#16405). It still counts when it is the only bullet. func EntryCause(reasons []string) string { if len(reasons) == 0 { return "" } + if kept := slices.DeleteFunc(slices.Clone(reasons), func(r string) bool { return r == decisionConsequenceReason }); len(kept) > 0 { + reasons = kept + } sum := sha256.Sum256([]byte(strings.Join(reasons, "\n"))) return hex.EncodeToString(sum[:8]) }