Skip to content
Closed
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
5 changes: 4 additions & 1 deletion .github/workflows/v2-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,10 @@ jobs:
needs: required-context-scope
if: ${{ always() && (needs.required-context-scope.result != 'success' || needs.required-context-scope.outputs.run-ci == 'true') }}
runs-on: ubuntu-latest
timeout-minutes: 10
# This builds the full runtime image, like the docker matrix above. Allow
# the same budget for cold builds and slow backend package downloads so
# the job can reach the overlayfs assertions (exec itself is capped at 90s).
timeout-minutes: 45
# No `needs: build-and-test` — see the note above the `docker` job.
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down
1 change: 1 addition & 0 deletions changelog.d/fixed-14816-decision-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Preserve maintainer decision intent: approval commands retain rationale, edited non-closing issue references stay non-closing, same-head approvals release metadata-only fixes, and trusted contributor change requests return to the author.
14 changes: 11 additions & 3 deletions src/docs/maintainer-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,21 @@ The whole comment after `/hive decision` is the instruction — numbered points
on the lines below the command are kept and quoted verbatim — and the
decision on the current head outranks the swarm's decision-requested verdict
on that head, so the stage moves in the same pass as the acknowledgement
rather than waiting on a re-review. A bare `/hive decision approve` (nothing
beyond the approval word) is recorded as your answer to the swarm's question
instead: no fix is kicked, requires_human is released for that head and the
rather than waiting on a re-review. A `/hive decision` starting with `approve`,
`approved`, `lgtm`, or `yes` is recorded as approval; the rest of the comment
is retained as its rationale. To request changes, start with the instruction
(e.g. `/hive decision change the PR body to Refs #123`). No fix is kicked
for an approval, requires_human is released for that head and the
PR follows the normal merge path. An acknowledged decision whose record did
not survive a pod restart is rebuilt from the comment thread; a decision
answered for an older head is left alone
([#14679](https://github.com/hivecommons/hive/issues/14679)).
The sweep also reads `/hive decision` at `stage/070-fixing`: approve the
current head after a body or metadata fix to release a standing request without
pushing a cosmetic commit. A later trusted GitHub APPROVED review on the same
head also supersedes the recorded request; an older approval does not.
Issue-link repair preserves edited `Refs` bodies and PRs with a recorded
decision, so it cannot restore auto-close over the owner's direction.
The 085 entry comment names both actions. The commenter must hold `write` or better on the
repo *and* be in the hive's trusted-merger set (the bar a human approval
already meets). `/hive decision` on a PR the hive did **not** open, or `/hive
Expand Down
6 changes: 6 additions & 0 deletions src/pkg/github/automerge/automerge_contributor_lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,12 @@ func (c *Engine) evaluateContributorLanePR(ctx context.Context, displayRepo, own
eval.verdict = verdict
approver, humanApproved := c.trustedHumanApprovalForRequiresHuman(ctx, owner, repo, number, headSHA, verdict)
c.noteStageVerdict(owner, repo, number, verdict)
// A trusted head-scoped change request answers the swarm's question
// even when admission or a requires_human verdict would return early.
if rv, ok := c.latestTrustedHumanChangesRequested(ctx, owner, repo, number, headSHA); ok {
c.noteStageHumanChangeRequest(owner, repo, number, headSHA, hgithub.SafeGetLogin(rv.GetUser()))
return eval, contributorLaneReasonChangesRequested, nil
}
if claim.Reason != "" {
// Neither this hive's registry nor an App-authored marker vouches
// for the author, so GitHub's association is the only evidence left;
Expand Down
30 changes: 30 additions & 0 deletions src/pkg/github/automerge/automerge_contributor_lane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import (
"time"

gh "github.com/google/go-github/v72/github"
"github.com/hivecommons/hive/pkg/authorkind"
hgithub "github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/intent"
"github.com/hivecommons/hive/pkg/stagelabels"
)

const (
Expand Down Expand Up @@ -1660,3 +1662,31 @@ func TestContributorLaneAssociationTrusted(t *testing.T) {
t.Fatal("nil PR must not be trusted")
}
}

func TestContributorTrustedChangeRequestAnswersRequiresHuman(t *testing.T) {
fx := validContributorFixture()
fx.reviews = []map[string]any{humanReview(1, "clubanderson", "CHANGES_REQUESTED", "sha7", "please fix the metadata")}
api := newContributorLaneAPI(t, &fx)
defer api.Close()
policy := defaultContributorLanePolicy()
clock := &contributorLaneClock{at: time.Date(2026, 10, 28, 3, 0, 0, 0, time.UTC)}
engine := newContributorLaneEngine(api.URL, policy, clock, Options{
ContributorLaneVerdict: func(string, int, string) ContributorLaneVerdict {
return ContributorLaneVerdict{Configured: true, Verdict: "requires_human", DecisionRequested: true}
},
})
engine.SetMergerAuthorizer(func(login string) bool { return login == "clubanderson" })
engine.stageTracker = NewStageTracker()
engine.stageLabelPolicy = func() StageLabelPolicy { return StageLabelPolicy{Enabled: true} }
_, reason, err := engine.trySweepContributorLanePR(context.Background(), "widget", "acme", "widget", 7, policy)
if err != nil || reason != contributorLaneReasonChangesRequested || fx.merges != 0 {
t.Fatalf("reason=%s err=%v merges=%d", reason, err, fx.merges)
}
detail := engine.stageTracker.details[stageKey("acme", "widget", 7)]
// Production observations include the author kind; the lane alone does
// not distinguish an automated contributor (072) from a human (071).
o := stageObservation{AuthorKind: authorkind.Clanker, Lane: stageLaneContributor, HeadSHA: "sha7", Reason: reason, Detail: detail}
if v := classifyStage(o); v.Stage != stagelabels.ReturnedToContributor {
t.Fatalf("stage=%+v, want returned to contributor", v)
}
}
41 changes: 32 additions & 9 deletions src/pkg/github/automerge/automerge_human_changes_requested.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package automerge

import (
Expand All @@ -20,6 +20,12 @@
// already pushed past it, and the new head goes through the normal swarm
// re-review rather than another kick.
func (c *Engine) latestTrustedHumanChangesRequested(ctx context.Context, owner, repo string, number int, head string) (*gh.PullRequestReview, bool) {
return c.latestTrustedHumanReview(ctx, owner, repo, number, head, "CHANGES_REQUESTED")
}

// latestTrustedHumanReview reads all pages before selecting an opinion. An
// older approval must never shadow a later change request or dismissal.
func (c *Engine) latestTrustedHumanReview(ctx context.Context, owner, repo string, number int, head, state string) (*gh.PullRequestReview, bool) {
if c == nil || c.gh == nil || strings.TrimSpace(head) == "" {
return nil, false
}
Expand Down Expand Up @@ -54,7 +60,7 @@
c.noteStageReviews(owner, repo, number, seen)
var found *gh.PullRequestReview
for login, rv := range latest {
if !strings.EqualFold(rv.GetState(), "CHANGES_REQUESTED") || strings.TrimSpace(rv.GetCommitID()) != strings.TrimSpace(head) {
if !strings.EqualFold(rv.GetState(), state) || strings.TrimSpace(rv.GetCommitID()) != strings.TrimSpace(head) {
continue
}
if c.isHiveAppReviewAuthor(rv) || strings.HasSuffix(login, "[bot]") {
Expand Down Expand Up @@ -92,6 +98,22 @@
if !found || standing.IsApproval() {
return false
}
// A later trusted approval on this same head can acknowledge a body-
// only fix. Persist it so the planner also stops scheduling a fix.
if approval, approved := c.latestTrustedHumanReview(ctx, owner, repo, number, head, "APPROVED"); approved && approval.GetSubmittedAt().After(standing.RecordedAt) {
req := review.HumanChangeRequest{
Repo: owner + "/" + repo, Number: number, HeadSHA: head,
Source: review.HumanChangeRequestSourceReview, SourceID: approval.GetID(),
Actor: hgithub.SafeGetLogin(approval.GetUser()), Body: approval.GetBody(), URL: approval.GetHTMLURL(),
Kind: review.HumanChangeRequestKindApprove, RecordedAt: approval.GetSubmittedAt().Time,
}
if err := c.humanChangeRequests.Record(req); err == nil {
c.noteStageTrustedHumanApproval(owner, repo, number, head, req.Actor)
return false
} else {
c.warn("could not record approval clearing human change request", "pr", number, "error", err)
}
}
c.noteStageHumanChangeRequest(owner, repo, number, head, standing.Actor)
return true
}
Expand All @@ -100,14 +122,15 @@
return true
}
req := review.HumanChangeRequest{
Repo: owner + "/" + repo,
Number: number,
HeadSHA: strings.TrimSpace(head),
Source: review.HumanChangeRequestSourceReview,
SourceID: rv.GetID(),
Actor: strings.TrimSpace(hgithub.SafeGetLogin(rv.GetUser())),
Body: rv.GetBody(),
URL: rv.GetHTMLURL(),
Repo: owner + "/" + repo,
Number: number,
HeadSHA: strings.TrimSpace(head),
Source: review.HumanChangeRequestSourceReview,
SourceID: rv.GetID(),
Actor: strings.TrimSpace(hgithub.SafeGetLogin(rv.GetUser())),
Body: rv.GetBody(),
URL: rv.GetHTMLURL(),
RecordedAt: rv.GetSubmittedAt().Time,
}
if existing, found := c.humanChangeRequests.For(req.Repo, number, req.HeadSHA); found && existing.Source == req.Source && existing.SourceID == req.SourceID {
return true
Expand Down
51 changes: 51 additions & 0 deletions src/pkg/github/automerge/automerge_human_changes_requested_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"strings"
"testing"
"time"

"github.com/hivecommons/hive/pkg/review"
"github.com/hivecommons/hive/pkg/stagelabels"
Expand Down Expand Up @@ -228,3 +229,53 @@ func TestTrySweepSelfAuthoredPRRecordedDecisionNotesStageAndApprovalReleases(t *
})
}
}

func TestHumanChangeRequestClearedByLaterApprovalWithoutNewHead(t *testing.T) {
for _, tc := range []struct {
name, login, head, state, submitted string
wantHeld bool
}{
{"later trusted approval", "bob", "sha7", "APPROVED", "2026-10-28T02:00:00Z", false},
{"old approval", "bob", "sha7", "APPROVED", "2026-10-28T00:00:00Z", true},
{"approval on another head", "bob", "sha6", "APPROVED", "2026-10-28T02:00:00Z", true},
{"untrusted approval", "mallory", "sha7", "APPROVED", "2026-10-28T02:00:00Z", true},
{"still requesting changes", "bob", "sha7", "CHANGES_REQUESTED", "2026-10-28T02:00:00Z", true},
} {
t.Run(tc.name, func(t *testing.T) {
rv := humanReview(2, tc.login, tc.state, tc.head, "metadata fix checked")
rv["submitted_at"] = tc.submitted
api := newSelfSweepGuardAPI(t, selfSweepFixture{reviews: []map[string]any{rv}})
defer api.Close()
c := newAutoMergeSweepClient(api.URL)
store := review.NewHumanChangeRequests("")
c.humanChangeRequests = store
at, err := time.Parse(time.RFC3339, "2026-10-28T01:00:00Z")
if err != nil {
t.Fatal(err)
}
if err := store.Record(review.HumanChangeRequest{Repo: "acme/widget", Number: 7, HeadSHA: "sha7", Source: review.HumanChangeRequestSourceDecision, SourceID: 99, Actor: "bob", Body: "edit body", RecordedAt: at}); err != nil {
t.Fatal(err)
}
for i := 0; i < 2; i++ {
if held := c.humanChangesRequestedForHead(context.Background(), "acme", "widget", 7, "sha7"); held != tc.wantHeld {
t.Fatalf("held=%v, want %v", held, tc.wantHeld)
}
if scheduled := review.HumanChangeRequestFor(store, "acme/widget", 7, "sha7") != nil; scheduled != tc.wantHeld {
t.Fatalf("planner still schedules=%v, want %v", scheduled, tc.wantHeld)
}
}
})
}
}

func TestTrustedHumanApprovalUsesLatestOpinion(t *testing.T) {
api := newSelfSweepGuardAPI(t, selfSweepFixture{reviews: []map[string]any{
humanReview(1, "bob", "APPROVED", "sha7", ""),
humanReview(2, "bob", "CHANGES_REQUESTED", "sha7", "please fix"),
}})
defer api.Close()
c := newAutoMergeSweepClient(api.URL)
if login, ok := c.latestTrustedHumanApproval(context.Background(), "acme", "widget", 7, "sha7"); ok {
t.Fatalf("obsolete approval from %s accepted", login)
}
}
40 changes: 5 additions & 35 deletions src/pkg/github/automerge/automerge_review_gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,43 +312,13 @@ func reviewGateRecordLane(lane string) string {
}

func (c *Engine) latestTrustedHumanApproval(ctx context.Context, owner, repo string, number int, head string) (string, bool) {
if c == nil || c.gh == nil {
rv, ok := c.latestTrustedHumanReview(ctx, owner, repo, number, head, "APPROVED")
if !ok {
return "", false
}
if ctx == nil {
ctx = context.Background()
}
opts := &gh.ListOptions{PerPage: 100}
var seen []*gh.PullRequestReview
for {
reviews, resp, err := c.gh.PullRequests.ListReviews(ctx, owner, repo, number, opts)
if err != nil {
c.warn("automerge review gate could not read PR reviews for human approval", "owner", owner, "repo", repo, "pr", number, "error", err)
return "", false
}
seen = append(seen, reviews...)
for _, review := range reviews {
if !strings.EqualFold(review.GetState(), "APPROVED") || strings.TrimSpace(review.GetCommitID()) != head {
continue
}
login := strings.TrimSpace(hgithub.SafeGetLogin(review.GetUser()))
if login == "" || c.isHiveAppReviewAuthor(review) || strings.HasSuffix(strings.ToLower(login), "[bot]") {
continue
}
trusted, configured := c.isTrustedMerger(login)
if configured && trusted {
c.noteStageReviews(owner, repo, number, seen)
c.noteStageTrustedHumanApproval(owner, repo, number, head, login)
return login, true
}
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
c.noteStageReviews(owner, repo, number, seen)
return "", false
login := strings.TrimSpace(hgithub.SafeGetLogin(rv.GetUser()))
c.noteStageTrustedHumanApproval(owner, repo, number, head, login)
return login, true
}

func (c *Engine) trustedHumanApprovalForRequiresHuman(ctx context.Context, owner, repo string, number int, head string, verdict ContributorLaneVerdict) (string, bool) {
Expand Down
22 changes: 13 additions & 9 deletions src/pkg/github/issue_unpark_command.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package github

import (
Expand Down Expand Up @@ -99,11 +99,15 @@
Text string
}

// BareApproval reports whether a `/hive decision` carries nothing beyond an
// approval word — the owner answered "yes" without an instruction to act on.
func (c unparkCommand) BareApproval() bool {
switch strings.ToLower(strings.TrimSpace(c.Text)) {
case "approve", "approved", "approve.", "approved.", "lgtm", "yes":
// Approval reports whether the first word explicitly approves the head.
// The remaining text is retained as the approval rationale.
func (c unparkCommand) Approval() bool {
words := strings.Fields(c.DecisionText())
if len(words) == 0 {
return false
}
switch strings.ToLower(strings.TrimRight(words[0], ".:")) {
case "approve", "approved", "lgtm", "yes":
return true
}
return false
Expand Down Expand Up @@ -155,7 +159,7 @@
LabelApprovalAudit func(IssueLabelApprovalEvent)
// HumanChangeRequests receives `/hive decision <text>` left by a trusted
// maintainer on a hive-authored PR parked at stage/085-needs-decision
// (hivecommons/hive#13041); the review planner turns it into a fix kick.
// or stage/070-fixing; the review planner turns instructions into a fix kick.
// nil means the sweep answers the PR but cannot route the decision.
HumanChangeRequests review.HumanChangeRequestStore
// TrustedMerger is the automerge lane's merger trust test. A PR-side
Expand All @@ -179,7 +183,7 @@
Actor string
Decision string
// Mode is "changes_requested" (the decision carries an instruction)
// or "approve" (a bare `/hive decision approve`).
// or "approve" (an approval word followed by optional rationale).
Mode string
CommentURL string
}
Expand Down Expand Up @@ -311,9 +315,9 @@
}
}
// Otherwise PRs take one command only — `/hive decision`
// while parked at 085 (hivecommons/hive#13041) — and never a
// while at 085 or 070 — and never a
// notice.
if !labelPresent(labels, PRNeedsDecisionStageLabel) {
if !labelPresent(labels, PRNeedsDecisionStageLabel) && !labelPresent(labels, stagelabels.Fixing.Label()) {
continue
}
result.Seen++
Expand Down
11 changes: 5 additions & 6 deletions src/pkg/github/issue_unpark_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1243,16 +1243,15 @@ func TestSweepClosedIssueStageLabelsCap(t *testing.T) {
}

// hivecommons/hive#14679 (seen on #14628): the owner's `/hive decision
// approve` followed by numbered instructions must reach the author agent
// whole, and a bare approve must read as an approval, not an instruction.
// approve` followed by rationale retains the whole text and reads as approval.
func TestParseUnparkCommandKeepsDecisionTextAfterFirstLine(t *testing.T) {
body := "/hive decision approve\r\n\r\nPlease do the following before merging:\r\n\r\n1. Change `Closes #14605` to `Refs #14605`.\n2. Keep #14605 open.\n3. Merge on green.\n"
cmd, ok := parseUnparkCommand(body)
if !ok || cmd.Kind != unparkCommandDecision || cmd.Decision != "approve" {
t.Fatalf("parseUnparkCommand = %+v, %v", cmd, ok)
}
if cmd.BareApproval() {
t.Fatalf("approve with instructions read as a bare approval: %q", cmd.Text)
if !cmd.Approval() {
t.Fatalf("approve with rationale did not read as approval: %q", cmd.Text)
}
for _, want := range []string{"approve\n\n", "1. Change `Closes #14605` to `Refs #14605`.", "2. Keep #14605 open.", "3. Merge on green."} {
if !strings.Contains(cmd.DecisionText(), want) {
Expand All @@ -1261,12 +1260,12 @@ func TestParseUnparkCommandKeepsDecisionTextAfterFirstLine(t *testing.T) {
}
for _, bare := range []string{"/hive decision approve", "/hive decision Approved\n", "/hive decision approve.\n\n"} {
cmd, ok := parseUnparkCommand(bare)
if !ok || !cmd.BareApproval() || cmd.DecisionText() == "" {
if !ok || !cmd.Approval() || cmd.DecisionText() == "" {
t.Fatalf("parseUnparkCommand(%q) = %+v, %v; want a bare approval", bare, cmd, ok)
}
}
single, _ := parseUnparkCommand("/hive decision keep 10 stable tags")
if single.DecisionText() != "keep 10 stable tags" || single.BareApproval() {
if single.DecisionText() != "keep 10 stable tags" || single.Approval() {
t.Fatalf("single-line decision = %+v", single)
}
}
Loading
Loading