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-decision-answered-verdict.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- A recorded `/hive decision` (or trusted CHANGES_REQUESTED review) on a PR head is now folded into the reviewer verdict for that head as a durable, head-scoped answer, so the stage-label reconciler's verdict route treats the `requires_human` / decision-requested verdict as **answered** on every tick and after a restart: instructions route to `070-fixing` with reason `contributor-lane:decision-answered`, a bare approve clears the hold, and only a new head with a fresh `requires_human` verdict asks again. Ends the 070↔085 flap seen on hive#14628, where the fix planner or a maintainer moved the PR to 070 and the next reconcile tick put it back ([#14679](https://github.com/hivecommons/hive/issues/14679)).
1 change: 1 addition & 0 deletions src/docs/labels-and-control-signals.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ used to admit the PR:
| CI pending, verdict approve | `060-reviewed` |
| CI green, verdict approve, no modifier, yet the lane stopped on a reason no stage claims or tripped on a transient error (`review-state-check`, …) | `080-awaiting-merge-admission` (weak opinion: any lane's definite stage wins) |
| a posted reviewer decision question (`decision_requested`) on a conflicting / not-mergeable / changes-requested head | `085-needs-decision`, reason `contributor-lane:decision-requested` — no fixer is kicked for such a head, and a conflict is moot if the answer is to close it ([#14607](https://github.com/hivecommons/hive/issues/14607)) |
| a trusted maintainer answered that question on the same head — `/hive decision <instruction>` or a CHANGES_REQUESTED review (recorded in `review-human-change-requests.json`, head-scoped) | `070-fixing`, reason `contributor-lane:decision-answered`: the answer is folded into the reviewer verdict for that head on every tick and after a restart, so the stage never re-derives 085 from the stale `requires_human` verdict. A bare `/hive decision approve` instead clears the hold like a trusted Approve review. A new head draws a new verdict with no answer and asks again ([#14679](https://github.com/hivecommons/hive/issues/14679)) |
| CI red (`check-failing:*`, `required-check-failing:*`, `status-*`), `conflicting`, `not-mergeable`, `changes-requested`, verdict changes_requested/reject, `needs-rebase` present | `070-fixing` (self-authored lane or `author/hive`) / `071-needs-author` (`author/human`) / `072-returned-to-contributor` (`author/clanker`) — see [Stage 07x by author kind](#stage-07x-by-author-kind). A head whose App-linked commits carry a `Signed-off-by` the squash would misattribute to the PR author (`hive-signoff-attribution`) follows the same split: the branch owner is the only one who can rewrite them. |
| `contributor-lane:soaking(...)` — and no red check on the head | `095-pre-merge-soak` |
| `head-changed-since-eval`, `merge-failed`, `merge-queue-required` (the base branch's ruleset only accepts merges through GitHub's merge queue, so the direct REST merge is refused; logged as a skip rather than a merge error, [#14018](https://github.com/hivecommons/hive/issues/14018); the self-authored sweep then skips the direct merge on that base for 30 minutes and logs the skip once per PR head, [#14068](https://github.com/hivecommons/hive/issues/14068); the trusted-author, queued and contributor-lane sweeps skip it the same way), `required-checks-expected`, `behind`, `updated-branch`, `behind-update-budget-exhausted` (a behind self-authored PR the sweep did not update only because this tick's branch-update budget was spent; retried next tick, waits on the hive, [#12607](https://github.com/hivecommons/hive/issues/12607)), `release-hold*` — and no red check on the head | `100-merge-queue` |
Expand Down
19 changes: 18 additions & 1 deletion src/pkg/github/automerge/automerge_contributor_lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import (
hgithub "github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/intent"
"github.com/hivecommons/hive/pkg/issueclaim"
"github.com/hivecommons/hive/pkg/review"
"github.com/hivecommons/hive/pkg/stageengine/prstage"
"github.com/hivecommons/hive/pkg/stagelabels"
)
Expand Down Expand Up @@ -1130,7 +1131,23 @@ func (c *Engine) contributorLaneVerdictFor(fullRepo string, number int, headSHA
if c == nil || c.contributorLaneVerdict == nil {
return ContributorLaneVerdict{}
}
return normalizeContributorLaneVerdict(c.contributorLaneVerdict(fullRepo, number, headSHA))
return c.withRecordedDecision(fullRepo, number, headSHA, normalizeContributorLaneVerdict(c.contributorLaneVerdict(fullRepo, number, headSHA)))
}

// withRecordedDecision folds the trusted human's recorded decision on
// headSHA (review-human-change-requests.json) into the reviewer verdict, so
// a requires_human / decision-requested verdict the person already answered
// reads as answered on every tick and after every restart — never back to
// 085 until a new head draws a new verdict (hivecommons/hive#14679).
func (c *Engine) withRecordedDecision(fullRepo string, number int, headSHA string, v ContributorLaneVerdict) ContributorLaneVerdict {
if c == nil || c.humanChangeRequests == nil {
return v
}
req, ok := review.DecisionAnswerFor(c.humanChangeRequests, fullRepo, number, headSHA)
if !ok {
return v
}
return v.WithDecisionAnswer(strings.ToLower(req.Actor), headSHA, req.Directive())
}

// contributorLaneEval is what the contributor lane established about one PR
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/github/automerge/automerge_contributor_nudge.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package automerge

import (
Expand Down Expand Up @@ -110,6 +110,9 @@
case r == autoMergeReasonHumanChangesRequested:
asks = append(asks, "a maintainer requested changes; the hive is pushing the fix")
human = true
case r == stageReasonDecisionAnswered:
asks = append(asks, "a maintainer answered the decision question with an instruction; the hive is pushing the fix")
human = true
case r == contributorLaneReasonChangesRequested, r == stagelabels.LaneReasonChangesRequested:
asks = append(asks, "the review swarm requested changes")
case r == "conflicting" || r == "not-mergeable" || r == "label:needs-rebase":
Expand Down
95 changes: 95 additions & 0 deletions src/pkg/github/automerge/automerge_decision_answered_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package automerge

import (
"testing"

"github.com/hivecommons/hive/pkg/review"
"github.com/hivecommons/hive/pkg/stagelabels"
)

// hivecommons/hive#14679 (the 070↔085 flap on #14628): the reconcile tick
// re-derived 085 from the persisted decision-requested verdict because no
// lane had noted the owner's answer that cycle. The pass now folds the
// durable decision record into every observation's verdict before
// classification, so the tick yields 070 decision-answered — whatever the
// lanes reported and however the PR reached 070 (planner, manual label) —
// and a new head with a fresh requires_human verdict parks again.
func TestFoldRecordedDecisionAnswersVerdictRoute(t *testing.T) {
const head, newHead = "3b4a2b5510feb333579520508478acd0bc1b2ccc", "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"
asked := ContributorLaneVerdict{Configured: true, Verdict: "requires_human", DecisionRequested: true, HiveAuthoredKnown: true, HiveAuthored: true}
store := review.NewHumanChangeRequests("")
if err := store.Record(review.HumanChangeRequest{Repo: "hivecommons/hive", Number: 14628, HeadSHA: head, Source: review.HumanChangeRequestSourceDecision, SourceID: 6450262272, Actor: "clubanderson", Body: "approve\n1. Change `Closes #14605` to `Refs #14605`."}); err != nil {
t.Fatal(err)
}
c := &Engine{humanChangeRequests: store}

for _, tc := range []struct {
name string
head string
labels []string
wantStage stagelabels.Stage
wantReason string
}{
{name: "tick after the decision → 070 decision-answered", head: head, wantStage: stagelabels.Fixing, wantReason: stageReasonDecisionAnswered},
{name: "manual 070 is not reverted", head: head, labels: []string{stagelabels.Fixing.Label()}, wantStage: stagelabels.Fixing, wantReason: stageReasonDecisionAnswered},
{name: "new head, fresh requires_human → 085", head: newHead, wantStage: stagelabels.NeedsDecision, wantReason: stageReasonDecisionRequested},
} {
t.Run(tc.name, func(t *testing.T) {
list := []stageObservation{
{Lane: stageLaneSelf, Owner: "hivecommons", Repo: "hive", Number: 14628, HeadSHA: tc.head, Labels: tc.labels, Reason: contributorLaneReasonNoVerdict, Detail: stageDetail{VerdictKnown: true, Verdict: asked}},
{Lane: stageLaneContributor, Owner: "hivecommons", Repo: "hive", Number: 14628, HeadSHA: tc.head, Labels: tc.labels, Reason: contributorLaneReasonAppAuthored, Detail: stageDetail{VerdictKnown: true, Verdict: asked}},
}
c.foldRecordedDecision(list)
got, _, obs := resolveStage(list)
if got.Stage != tc.wantStage || got.Reason != tc.wantReason {
t.Fatalf("stage=%s reason=%q (lane %s), want %s %q", got.Stage, got.Reason, obs.Lane, tc.wantStage, tc.wantReason)
}
add, remove := stagelabels.Plan(tc.labels, stagelabels.Desired{Stage: got.Stage})
if len(tc.labels) > 0 && (hasStageLabel(remove, stagelabels.Fixing.Label()) || hasStageLabel(add, stagelabels.NeedsDecision.Label())) {
t.Fatalf("manual 070 would be rewritten: add=%v remove=%v", add, remove)
}
})
}
}

// The lanes' own verdict lookup carries the same answer, so the review gate
// and the stage tracker never see an unanswered decision-requested verdict
// for a head the owner already answered; a bare approve reads as approve.
func TestContributorLaneVerdictForCarriesRecordedDecision(t *testing.T) {
const head = "3b4a2b5510feb333579520508478acd0bc1b2ccc"
asked := ContributorLaneVerdict{Configured: true, Verdict: "requires_human", DecisionRequested: true}
for _, tc := range []struct {
name, kind, wantDirective string
}{
{name: "instruction", kind: review.HumanChangeRequestKindChanges, wantDirective: review.DecisionDirectiveChanges},
{name: "bare approve", kind: review.HumanChangeRequestKindApprove, wantDirective: review.DecisionDirectiveApprove},
} {
t.Run(tc.name, func(t *testing.T) {
store := review.NewHumanChangeRequests("")
if err := store.Record(review.HumanChangeRequest{Repo: "hivecommons/hive", Number: 14628, HeadSHA: head, Source: review.HumanChangeRequestSourceDecision, SourceID: 1, Actor: "ClubAnderson", Body: "approve", Kind: tc.kind}); err != nil {
t.Fatal(err)
}
c := &Engine{humanChangeRequests: store, contributorLaneVerdict: func(string, int, string) ContributorLaneVerdict { return asked }}
v := c.contributorLaneVerdictFor("hivecommons/hive", 14628, head)
if !v.DecisionAnswered || v.DecisionAnsweredBy != "clubanderson" || v.DecisionAnsweredHead != head || v.DecisionDirective != tc.wantDirective {
t.Fatalf("verdict = %+v", v)
}
if other := c.contributorLaneVerdictFor("hivecommons/hive", 14628, "0ther"); other.DecisionAnswered {
t.Fatalf("answer leaked onto another head: %+v", other)
}
o := stageObservation{Lane: stageLaneSelf, HeadSHA: head, Reason: contributorLaneReasonNoVerdict, Detail: stageDetail{VerdictKnown: true, Verdict: v}}
if got := classifyStage(o); got.Stage == stagelabels.NeedsDecision {
t.Fatalf("classified as %+v, want the question answered", got)
}
})
}
}

func hasStageLabel(list []string, want string) bool {
for _, l := range list {
if l == want {
return true
}
}
return false
}
31 changes: 30 additions & 1 deletion src/pkg/github/automerge/automerge_stage_labels.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package automerge

// Stage labels (hivecommons/hive#12429). Each automerge lane already computes
Expand Down Expand Up @@ -31,6 +31,7 @@
"github.com/hivecommons/hive/pkg/authorkind"
"github.com/hivecommons/hive/pkg/delegatedecision"
hgithub "github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/review"
"github.com/hivecommons/hive/pkg/stageengine"
"github.com/hivecommons/hive/pkg/stageengine/prstage"
"github.com/hivecommons/hive/pkg/stagelabels"
Expand Down Expand Up @@ -462,6 +463,32 @@
})
}

// foldRecordedDecision stamps the trusted human's recorded decision on each
// observation's head into its verdict before classification. The lanes note
// the same answer when they reach it, but a lane that skips early (the
// contributor lane on an app-authored PR, a lane stopped at CI) never does,
// and the stage pass must not re-derive 085 from the stale decision-requested
// verdict in that case — that was the 070↔085 flap on hive#14628
// (hivecommons/hive#14679). Reads the durable store, so it holds across
// restarts and across the drain that clears the tracker's details.
func (c *Engine) foldRecordedDecision(list []stageObservation) {
if c == nil || c.humanChangeRequests == nil {
return
}
for i := range list {
o := &list[i]
if o.HeadSHA == "" || (o.Detail.VerdictKnown && o.Detail.Verdict.DecisionAnswered && o.Detail.Verdict.DecisionAnsweredHead == o.HeadSHA) {
continue
}
req, ok := review.DecisionAnswerFor(c.humanChangeRequests, o.Owner+"/"+o.Repo, o.Number, o.HeadSHA)
if !ok {
continue
}
o.Detail.Verdict = o.Detail.Verdict.WithDecisionAnswer(strings.ToLower(req.Actor), o.HeadSHA, req.Directive())
o.Detail = normalizeStageDetail(o.Detail)
}
}

// noteStageRole records the author's admission tier as the lane computed
// it. Lanes disagree by design (the contributor lane reports "untrusted"
// for a maintainer with no registry profile), so tiers merge by precedence
Expand Down Expand Up @@ -615,6 +642,7 @@
ciReasonRed = stageengine.CIReasonRed
stageReasonVerdictRequiresHuman = stageengine.StageReasonVerdictRequiresHuman
stageReasonDecisionRequested = stageengine.StageReasonDecisionRequested
stageReasonDecisionAnswered = stageengine.StageReasonDecisionAnswered
)

func classifyCIReason(reason string) ciReasonKind { return stageengine.ClassifyCIReason(reason) }
Expand Down Expand Up @@ -743,6 +771,7 @@
continue
}
result.Items++
c.foldRecordedDecision(list)
verdict, role, obs := resolveStage(list)
key := stageKey(obs.Owner, obs.Repo, obs.Number)
if verdict.Rank == stageRankNone {
Expand Down Expand Up @@ -949,7 +978,7 @@
if obs.Detail.VerdictKnown {
rawVerdict := obs.Detail.Verdict
normalizedVerdict := normalizeContributorLaneVerdict(rawVerdict)
c.info("stage labels: reviewer verdict route", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "lane", obs.Lane, "raw_verdict", rawVerdict.Verdict, "normalized_verdict", normalizedVerdict.Verdict, "decision_requested", normalizedVerdict.DecisionRequested, "stage", verdict.Stage.String(), "reason", obs.Reason)
c.info("stage labels: reviewer verdict route", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "lane", obs.Lane, "raw_verdict", rawVerdict.Verdict, "normalized_verdict", normalizedVerdict.Verdict, "decision_requested", normalizedVerdict.DecisionRequested, "decision_answered", normalizedVerdict.DecisionAnswered && normalizedVerdict.DecisionAnsweredHead == obs.HeadSHA, "decision_by", normalizedVerdict.DecisionAnsweredBy, "decision_directive", normalizedVerdict.DecisionDirective, "stage", verdict.Stage.String(), "reason", obs.Reason)
}
add, remove := stagelabels.Plan(obs.Labels, want)
if len(add)+len(remove) > 0 {
Expand Down
34 changes: 34 additions & 0 deletions src/pkg/review/human_change_request.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package review

import (
Expand Down Expand Up @@ -75,6 +75,23 @@
return r.Kind == HumanChangeRequestKindApprove
}

// Decision directives: what a recorded `/hive decision` told the hive to do
// with the head it names. They ride on the reviewer verdict for that head
// (prstage.ReviewVerdict.DecisionDirective) so every stage derivation reads
// the requires_human / decision-requested question as answered.
const (
DecisionDirectiveApprove = "approve"
DecisionDirectiveChanges = "changes_requested"
)

// Directive is the decision directive the request carries.
func (r HumanChangeRequest) Directive() string {
if r.IsApproval() {
return DecisionDirectiveApprove
}
return DecisionDirectiveChanges
}

// HumanChangeRequestStore records maintainer change requests and answers
// which one, if any, stands against a PR head. Implementations are safe for
// concurrent use: the automerge sweep records while the planner reads.
Expand Down Expand Up @@ -252,6 +269,23 @@
return &req
}

// DecisionAnswerFor returns the newest recorded trusted-human decision —
// instruction or bare approval, from a review or a `/hive decision` — that
// stands against pr's exact head. It is the durable, head-scoped fact that a
// reviewer verdict asking for a person on that head has been ANSWERED
// (hivecommons/hive#14679): a newer head carries no answer until someone
// gives one.
func DecisionAnswerFor(store HumanChangeRequestStore, repo string, number int, head string) (HumanChangeRequest, bool) {
if store == nil || strings.TrimSpace(head) == "" {
return HumanChangeRequest{}, false
}
req, ok := store.For(repo, number, strings.TrimSpace(head))
if !ok || strings.TrimSpace(req.Actor) == "" {
return HumanChangeRequest{}, false
}
return req, true
}

// HumanApprovalFor returns the bare `/hive decision approve` standing
// against pr's head, if the newest recorded decision on that head is one.
func HumanApprovalFor(store HumanChangeRequestStore, repo string, number int, head string) *HumanChangeRequest {
Expand Down
30 changes: 30 additions & 0 deletions src/pkg/review/human_change_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,33 @@ func TestHumanChangeRequestApprovalKindIsNotAFixRequest(t *testing.T) {
t.Fatalf("superseded approval still standing: %+v", got)
}
}

// The fix kick carries every line of the decision, not just the first:
// the numbered instructions under `/hive decision approve` on hive#14628
// are the whole scope of the fix (hivecommons/hive#14679).
func TestHumanChangeRequestPromptSectionCarriesEveryDecisionLine(t *testing.T) {
req := liveCaseRequest()
req.Source, req.Body = HumanChangeRequestSourceDecision, "approve\n1. Change `Closes #14605` to `Refs #14605`.\n2. Keep #14605 open.\n3. Merge on green."
got := humanChangeRequestPromptSection(req)
for _, want := range []string{"> approve\n", "> 1. Change `Closes #14605` to `Refs #14605`.\n", "> 2. Keep #14605 open.\n", "> 3. Merge on green.\n", "via /hive decision"} {
if !strings.Contains(got, want) {
t.Fatalf("prompt section missing %q:\n%s", want, got)
}
}
if req.Directive() != DecisionDirectiveChanges {
t.Fatalf("directive = %q", req.Directive())
}
if _, ok := DecisionAnswerFor(nil, liveCaseRepo, liveCaseNumber, liveCaseHead); ok {
t.Fatal("nil store answered")
}
store := NewHumanChangeRequests("")
if err := store.Record(req); err != nil {
t.Fatal(err)
}
if got, ok := DecisionAnswerFor(store, liveCaseRepo, liveCaseNumber, liveCaseHead); !ok || got.Actor != req.Actor || got.Directive() != DecisionDirectiveChanges {
t.Fatalf("DecisionAnswerFor = %+v ok=%v", got, ok)
}
if _, ok := DecisionAnswerFor(store, liveCaseRepo, liveCaseNumber, "0ther"); ok {
t.Fatal("answer leaked onto another head")
}
}
Loading
Loading