diff --git a/changelog.d/fixed-14604.md b/changelog.d/fixed-14604.md new file mode 100644 index 0000000000..830d22e31c --- /dev/null +++ b/changelog.d/fixed-14604.md @@ -0,0 +1 @@ +- A hive PR's pending fix now expires after 2h without a new head and is retried, and a posted decision request lands the PR in needs-decision instead of 070-fixing when it conflicts (#14604, #14607) diff --git a/src/docs/labels-and-control-signals.md b/src/docs/labels-and-control-signals.md index 575f591f4e..fbb04efc19 100644 --- a/src/docs/labels-and-control-signals.md +++ b/src/docs/labels-and-control-signals.md @@ -456,6 +456,7 @@ used to admit the PR: | `contributor-lane:no-verdict`, `review-gate:no-review-bundle`, `review-gate:awaiting-review-approval`, CI pending with no verdict | `050-review-pending` | | 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)) | | 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` | @@ -782,7 +783,9 @@ does not bump itself. in-place `stage/074-adopted-by-hive` contributor branch — is not waiting for a maintainer `/lgtm` or `/approve`. A review verdict of `changes_requested` keeps an adopted PR in the fixer's work list every cycle until a new head - lands. Existing pending fix rows are replaced with the next bounded attempt; + lands. Existing pending fix rows are replaced with the next bounded attempt + (adopted PRs at once; any other hive-owned PR once the row is older than + `PendingFixTTL`, default 2h, with the head unchanged); once the attempt cap is exhausted the PR is visibly parked for a human at 085 with reason `fix-attempts-exhausted`, not left silent. - **Cleared at once on any activity.** The next cycle that sees a new head, diff --git a/src/pkg/review/dispatch.go b/src/pkg/review/dispatch.go index cfa87691eb..5788e16028 100644 --- a/src/pkg/review/dispatch.go +++ b/src/pkg/review/dispatch.go @@ -37,6 +37,11 @@ const ( // pending reviews expire before the planner stops re-kicking and hands // the PR to a human (review.max_redispatch). DefaultMaxRedispatch = 3 + // DefaultPendingFixTTL is how long a dispatched fix may sit without a new + // head before its pending row expires and the next bounded attempt is + // dispatched. A fixer turn that never pushes leaves no signal, so without + // an expiry the row excluded the PR forever (hivecommons/hive#14604). + DefaultPendingFixTTL = 2 * time.Hour // HoldReasonDispatchExhausted prefixes the requires_human reason recorded // when a head's reviews expired DefaultMaxRedispatch times. HoldReasonDispatchExhausted = "review-dispatch-exhausted" @@ -218,6 +223,11 @@ type DispatchOptions struct { // before the PR is held for a human instead of re-kicked. Zero means // DefaultMaxRedispatch. MaxRedispatch int + // PendingFixTTL is how long a pending fix row stays authoritative with + // no new head before the next bounded attempt replaces it. Zero means + // DefaultPendingFixTTL; negative disables expiry. Attempts are capped by + // escalation.MaxReEngagements. + PendingFixTTL time.Duration // HeadMaxRetries caps how many times one review head's expired review of a // perspective is re-sent (review.head_max_retries). Zero means // MaxRedispatch. @@ -1178,7 +1188,7 @@ func (p *DispatchPlan) dispatchFix(pr PullRequest, agg Aggregate, opts DispatchO idx := fixIndex(p.State.Fixes, pr.Repo, pr.Number, pr.HeadSHA) pendingAttempts := 0 if idx >= 0 { - if !adoptedHiveOwnedFix(pr, opts) { + if !adoptedHiveOwnedFix(pr, opts) && !pendingFixExpired(p.State.Fixes[idx], opts, now) { p.recordFixExclusion(pr, FixDispatchExcludedPending, p.State.Fixes[idx].Attempts) return } @@ -1209,6 +1219,19 @@ func (p *DispatchPlan) dispatchFix(pr PullRequest, agg Aggregate, opts DispatchO p.State.Fixes = append(p.State.Fixes, PendingFix{Repo: pr.Repo, Number: pr.Number, HeadSHA: pr.HeadSHA, Agent: agent, Attempts: attempts, Dispatched: now}) } +// pendingFixExpired reports whether a pending fix outlived PendingFixTTL with +// no head change. A row with no dispatched_at has no measurable age. +func pendingFixExpired(f PendingFix, opts DispatchOptions, now time.Time) bool { + ttl := opts.PendingFixTTL + if ttl < 0 || f.Dispatched.IsZero() { + return false + } + if ttl == 0 { + ttl = DefaultPendingFixTTL + } + return now.Sub(f.Dispatched) >= ttl +} + func adoptedHiveOwnedFix(pr PullRequest, opts DispatchOptions) bool { return hasLabelFold(pr.Labels, stagelabels.AdoptedByHive.Label()) && hiveAuthored(pr, opts) } diff --git a/src/pkg/review/human_change_request_test.go b/src/pkg/review/human_change_request_test.go index 0fffde0015..cddc9c6bae 100644 --- a/src/pkg/review/human_change_request_test.go +++ b/src/pkg/review/human_change_request_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/hivecommons/hive/pkg/escalation" "github.com/hivecommons/hive/pkg/outputschema" ) @@ -209,3 +210,44 @@ func TestBuildFixPromptQuotesMaintainerInstructionVerbatim(t *testing.T) { t.Fatalf("prompt lacks the instruction framing or the swarm findings:\n%s", got) } } + +// TestPlanDispatchPendingFixExpires covers #14604: a pending fix whose head +// never moved is replaced by the next bounded attempt after PendingFixTTL. +func TestPlanDispatchPendingFixExpires(t *testing.T) { + dispatched := time.Date(2026, 10, 9, 17, 29, 0, 0, time.UTC) + pr := liveCasePR() + req := liveCaseRequest() + pr.HumanChangeRequest = &req + opts := humanRequestOpts() + for _, tc := range []struct { + name string + age time.Duration + ttl time.Duration + attempts int + wantKicks int + wantExcl string + }{ + {name: "fresh", age: time.Hour, attempts: 1, wantExcl: FixDispatchExcludedPending}, + {name: "expired", age: 3 * time.Hour, attempts: 1, wantKicks: 1}, + {name: "custom ttl", age: 10 * time.Minute, ttl: 5 * time.Minute, attempts: 1, wantKicks: 1}, + {name: "expiry disabled", age: 48 * time.Hour, ttl: -1, attempts: 1, wantExcl: FixDispatchExcludedPending}, + {name: "expired at cap", age: 3 * time.Hour, attempts: escalation.MaxReEngagements, wantExcl: FixDispatchExcludedAttemptsExhausted}, + } { + t.Run(tc.name, func(t *testing.T) { + o := opts + o.Now = dispatched.Add(tc.age) + o.PendingFixTTL = tc.ttl + state := DispatchState{Fixes: []PendingFix{{Repo: liveCaseRepo, Number: liveCaseNumber, HeadSHA: liveCaseHead, Agent: "scanner", Attempts: tc.attempts, Dispatched: dispatched}}} + plan := PlanDispatch([]PullRequest{pr}, Artifact{Items: []Aggregate{liveCaseAggregate()}}, state, o) + if len(plan.FixKicks) != tc.wantKicks { + t.Fatalf("fix kicks = %+v, want %d", plan.FixKicks, tc.wantKicks) + } + if tc.wantExcl != "" && (len(plan.FixExclusions) != 1 || plan.FixExclusions[0].Reason != tc.wantExcl) { + t.Fatalf("exclusions = %+v, want %s", plan.FixExclusions, tc.wantExcl) + } + if tc.wantKicks == 1 && plan.State.Fixes[len(plan.State.Fixes)-1].Attempts != tc.attempts+1 { + t.Fatalf("pending fixes = %+v, want attempts %d", plan.State.Fixes, tc.attempts+1) + } + }) + } +} diff --git a/src/pkg/stageengine/derive_pr_classify.go b/src/pkg/stageengine/derive_pr_classify.go index 489c5741f5..21dcfd0c43 100644 --- a/src/pkg/stageengine/derive_pr_classify.go +++ b/src/pkg/stageengine/derive_pr_classify.go @@ -330,6 +330,14 @@ func ClassifyStage(o stageObservation) stageVerdict { } return stageVerdict{Stage: stagelabels.NeedsDecision, Rank: stageRankOwned, Human: true} } + if o.Detail.VerdictKnown && o.Detail.Verdict.DecisionRequested { + // A posted decision question outranks mergeability: no fixer is kicked + // for a decision-requested head, and a conflict is moot if the answer + // is to close it (hivecommons/hive#14607). + if v, ok := RequiresHumanStage(o, stageRankOwned); ok { + return v + } + } if stageFixingReasons[reason] || strings.HasPrefix(reason, "label:") && strings.Contains(reason, "rebase") { return stageVerdict{Stage: fixing, Rank: stageRankOwned} } diff --git a/src/pkg/stageengine/derive_pr_handoff_test.go b/src/pkg/stageengine/derive_pr_handoff_test.go index 804b3e643f..5ed5abd9ba 100644 --- a/src/pkg/stageengine/derive_pr_handoff_test.go +++ b/src/pkg/stageengine/derive_pr_handoff_test.go @@ -42,3 +42,19 @@ func TestResolveStageAppAuthoredHandoffsAttributeToSelfLane(t *testing.T) { t.Fatalf("attributed to lane %q, want %q", obs.Lane, stageLaneSelf) } } + +// hivecommons/hive#14607: a posted decision question must not be masked by a +// conflicting lane reason that no fixer is kicked for. +func TestClassifyStageDecisionRequestedOutranksConflict(t *testing.T) { + detail := stageDetail{VerdictKnown: true, Verdict: ContributorLaneVerdict{Configured: true, Verdict: "requires_human", DecisionRequested: true}} + for _, reason := range []string{"conflicting", "not-mergeable", "changes-requested"} { + v := ClassifyStage(stageObservation{Lane: stageLaneSelf, Reason: reason, HeadSHA: goldenHead, Detail: detail}) + if v.Stage != stagelabels.NeedsDecision || !v.Human || v.Reason != StageReasonDecisionRequested { + t.Fatalf("%q classified as %+v, want needs-decision with %s", reason, v, StageReasonDecisionRequested) + } + } + plain := stageDetail{VerdictKnown: true, Verdict: ContributorLaneVerdict{Configured: true, Verdict: "requires_human"}} + if v := ClassifyStage(stageObservation{Lane: stageLaneSelf, Reason: "conflicting", HeadSHA: goldenHead, Detail: plain}); v.Stage != FixingStage(stageObservation{Lane: stageLaneSelf}) { + t.Fatalf("conflicting without a decision request classified as %+v, want fixing", v) + } +}