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
1 change: 1 addition & 0 deletions changelog.d/fixed-16405.md
Original file line number Diff line number Diff line change
@@ -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)).
41 changes: 41 additions & 0 deletions src/pkg/github/automerge/automerge_stage_human_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/pkg/stagelabels/human.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}
Expand Down
9 changes: 8 additions & 1 deletion src/pkg/stagelabels/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down
Loading