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/changed-hive-superseding-automerge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Hive-authored superseding PRs (`Supersedes #N`, opened by the hive App) now auto-merge with no operator decision: a reviewer `requires_human` — security-sensitive included — is routed to the fixer instead of parking at `stage/085`, and only an unacknowledged sentinel finding, a hold, exhausted fix attempts, red CI after fixes or an unresolvable base conflict park it, each named in the 085 caption. New knob `auto_merge.hive_superseding.auto_merge` (default `true`).
25 changes: 13 additions & 12 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

import (
Expand Down Expand Up @@ -2049,18 +2049,19 @@
// its open-PR set and run on webhook events instead of listing /pulls.
forgeOpenPRs := b.forgeStateOpenPRs()
autoMergeOpts := automerge.Options{
Logger: b.logger,
MergerAuthorizer: trustedMergerFunc(b.cfg),
HumanChangeRequests: review.DefaultHumanChangeRequests(),
TrustedAuthorizer: trustedAuthorFunc(b.cfg),
TrustedAuthorPolicy: trustedAuthorPolicyFunc(b.cfg),
ContributorLanePolicy: contributorLanePolicyFunc(b.cfg),
ContributorLaneVerdict: contributorLaneVerdictFunc(b.cfg, b.logger),
ContributorRegistryTier: contributorRegistryTierFunc(),
StageLabelPolicy: stageLabelPolicyFunc(b.cfg),
StageEngine: stageEngineOptions(b.cfg, b.logger),
SentinelLabel: func() string { return b.cfg.Sentinel.LabelOrDefault() },
SweepTrigger: b.sweepTrigger,
Logger: b.logger,
MergerAuthorizer: trustedMergerFunc(b.cfg),
HumanChangeRequests: review.DefaultHumanChangeRequests(),
TrustedAuthorizer: trustedAuthorFunc(b.cfg),
TrustedAuthorPolicy: trustedAuthorPolicyFunc(b.cfg),
ContributorLanePolicy: contributorLanePolicyFunc(b.cfg),
ContributorLaneVerdict: contributorLaneVerdictFunc(b.cfg, b.logger),
ContributorRegistryTier: contributorRegistryTierFunc(),
StageLabelPolicy: stageLabelPolicyFunc(b.cfg),
StageEngine: stageEngineOptions(b.cfg, b.logger),
SentinelLabel: func() string { return b.cfg.Sentinel.LabelOrDefault() },
HiveSupersedingAutoMerge: func() bool { return b.cfg.AutoMerge.HiveSuperseding.AutoMergeEnabled() },
SweepTrigger: b.sweepTrigger,
}
if forgeOpenPRs != nil {
autoMergeOpts.OpenPRs = forgeOpenPRs
Expand Down
12 changes: 8 additions & 4 deletions src/cmd/hive/main_sweeps.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ func runAutoMergeSweepIfDue(ctx context.Context, ghClient *github.Client, cfg *c
}
if cfg != nil {
opts.SentinelLabel = func() string { return cfg.Sentinel.LabelOrDefault() }
opts.HiveSupersedingAutoMerge = func() bool { return cfg.AutoMerge.HiveSuperseding.AutoMergeEnabled() }
if set, ok := cfg.AutoMerge.RequiredCheckSet(); ok {
opts.RequiredChecks = set
}
Expand Down Expand Up @@ -2651,10 +2652,13 @@ func refreshReviewVerdicts(cfg *config.Config, logger *slog.Logger) {
MaxPerspectivesPerPR: cfg.Review.MaxPerspectivesPerPR,
Perspectives: reviewPerspectiveSet(cfg, logger),
SelfAuthoredDecisionPolicy: cfg.Review.EffectiveSelfAuthoredDecisionPolicy(),
SensitivePaths: cfg.Security.SensitivePaths,
ModelStamps: reviewModelStamps(logger),
ExpectedHeads: cfg.ExpectedReviewHeads(),
MissingHeads: reviewMissingHeads(),
// Owner rule: the hive's superseding copies auto-merge; their
// reviewer findings go to the fixer, not to a person.
HiveSupersedingAutoMergeOff: !cfg.AutoMerge.HiveSuperseding.AutoMergeEnabled(),
SensitivePaths: cfg.Security.SensitivePaths,
ModelStamps: reviewModelStamps(logger),
ExpectedHeads: cfg.ExpectedReviewHeads(),
MissingHeads: reviewMissingHeads(),
}, time.Now().UTC())
if err != nil {
if !os.IsNotExist(err) {
Expand Down
55 changes: 55 additions & 0 deletions src/docs/hive-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,61 @@ recorded trusted decision on a PR's head (the tracker's Approve, or any
what lifts the gate for that PR; closing the other ends it
([#15810](https://github.com/hivecommons/hive/issues/15810)).

### Hive-authored superseding PRs auto-merge

Owner rule (@clubanderson): *"if a pr is superseded by a pr that a hive
agent creates, it should auto merge"* — *"the only exception would be if
this is sentinel or some other emergent problem with the pr."*

A **hive superseding PR** is a PR the hive App itself authored
(`@hivecommons-hive[bot]`) whose body declares `Supersedes #N` — the PR a
takeover, close-first adoption or re-author lead opens to carry a
contributor's or bot's change. `github.IsHiveSupersedingPR` /
`github.HiveSupersedingPR` detect it; `PullRequest.Supersedes` carries the
number. Twice in one morning such PRs (#15649, #15646) parked at
`stage/085-needs-decision` on a reviewer's security-sensitive
`requires_human` and the owner had to click approve for work the hive had
already decided to carry. Under this rule they do not:

- **Reviewer findings go to the fixer.** On a hive superseding PR the
aggregate (`review.hiveSupersedingFixRoute`) turns a `requires_human` —
a risk-class decision question, a security-sensitive finding, an
unresolved escalation — into `changes_requested` with the reason
`hive-authored superseding PR: reviewer requires_human routed to the fixer; auto-merges once CI and review are clean`; the fixer
addresses it and the swarm re-reviews, exactly like any other finding.
A `reject` is not converted: it is an emergent problem with the PR. The
stage engine captions the head *"hive-authored superseding PR —
auto-merging once CI/review are clean"* (lane reason
`hive-superseder:fixer`) rather than "needs your decision", and the
reviewer prompts say so (`hiveSupersedingGuidance`).
- **Green and clean merges with no decision.** Once CI is green and the
review has no open findings the PR follows the hive-authored admission
path (`stage/080` → merge). The superseded PR is closed as superseded by
the existing writeback (`Superseded by #N`) once it merges, as before.
- **The only exceptions are the hard stops**, computed in one place
(`automerge.hiveSupersederHardStop`) and named in the 085 caption
(`hive-superseder-hard-stop:<token>`):
- `sentinel-unacknowledged` — the sentinel label is on and nobody has
acknowledged its finding (`sentinel_acknowledged` in the review
evidence bundle; an acknowledged sentinel, as on #15650, is not a
stop);
- `hold` — a `hold` / decision-class label or a repo/global hold;
- `fix-attempts-exhausted` — the fixer spent its cycle cap on the
reviewer's findings; reported as `ci-red-after-fixes` when CI is
still red, `base-conflict-unresolved` when the head still conflicts;
- `base-conflict-unresolved` — the hive's rebase-resolve episode
already failed twice.

A pending check, a first conflict or an ordinary reviewer finding is
never a stop. The tracker row reads *"The hive's superseding PR would
auto-merge (owner rule), but <stop>"*, and *Let hive decide* answers
recommend-only, naming the stop (`delegatedecision.RuleHiveSuperseder`);
without a stop it releases the PR under the same rule.

`auto_merge.hive_superseding.auto_merge: false` turns the rule off and
restores the previous behaviour (a `requires_human` parks the superseding
PR at 085 like any hive-authored PR).

### Empty-diff PRs of the hive's own

A PR of the hive's own (the App's, or an adoption it opened) whose diff
Expand Down
1 change: 1 addition & 0 deletions src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ advanced into the merge path.
| `auto_merge.native_merge_queue.repos` | unset (every watched repo once enabled) | `owner/repo` allow-list for the hand-off, matched case-insensitively. |
| `auto_merge.native_merge_queue.skip_current_base_gate` | `false` | Explicitly lets a queue-enabled base bypass the `auto_merge.require_current_base` gate and the `behind` update-branch, because the merge group re-tests the merged result and a pushed head drops the PR from the queue. Off keeps both gates in force on queue bases. |
| `auto_merge.native_merge_queue.probe_ttl` | `30m` | How long one base branch's `isMergeQueueEnabled` GraphQL answer is cached before re-reading. |
| `auto_merge.hive_superseding.auto_merge` | `true` | Owner rule: a PR the hive App itself opened to supersede another PR (`Supersedes #N` in its body — takeover, close-first adoption, re-author) auto-merges with no operator decision. A reviewer `requires_human`, security-sensitive included, is routed to the fixer as `changes_requested` instead of parking at `stage/085`; the head merges through the hive-authored lane once CI and review are clean. The only stops are an unacknowledged sentinel finding, a hold, exhausted fix attempts (CI still red / base still conflicting), or a conflict the hive already failed to rebase twice — each named in the 085 caption as `hive-superseder-hard-stop:<reason>`. `false` restores the old park. See [hive-merge.md](hive-merge.md#hive-authored-superseding-prs-auto-merge). |
| `auto_merge.squash_only` | unset (no repo) | Repo list (`owner/repo`) whose branch policy forbids merge commits. Elsewhere, a `role/trusted` PR whose head mixes the contributor's commits with App-linked, App-signed ones (the hive's own in-place adoption fixes), every commit self-signed, is labelled `merge-method/merge` and merged with a merge commit instead of parking at `stage/085` as `adoption-stalled:hive-signoff-attribution`; a listed repo keeps squash-only policy and re-homes an in-place adoption to an App-authored superseder instead (#13975). |
| `auto_merge.credit_issue_authors` | `true` | Append `Co-authored-by: <login> <id+login@users.noreply.github.com>` for the human authors of the issues a PR closes (`Fixes|Closes|Resolves #N`) to the squash (or merge) commit message on every hive-performed merge, so reporters land on the contributor graph when an external clanker fixed their issue. Bots, the PR author and logins already credited on the branch are skipped; the logins are recorded as `issue_authors=` on the merge audit entry and in review evidence. One cached `GET /issues/{n}` per newly referenced issue. `false` leaves GitHub's default squash message untouched (#14581). |
| `auto_merge.bot_takeover.enabled` | `true` | When `github-actions[bot]` is in `auto_merge.trusted_bot_authors`, re-author its same-repo PRs whose required `pull_request` checks can never run (the bot opened them with a workflow `GITHUB_TOKEN`). After the head is older than both `min_head_age` and 30 minutes with no `pull_request` run, the App pushes the same change as one signed-off commit to `hive/takeover-<n>`, opens a PR with the original title/body plus `Supersedes #<n>`, comments `Superseded by #N` on the bot PR and closes it. One attempt per bot head SHA. See [hive-merge.md](hive-merge.md#github-actionsbot-pr-takeover). |
Expand Down
2 changes: 2 additions & 0 deletions src/docs/review-swarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ Aggregation rules are deterministic:
6. Every delivered perspective approving while some the PR is owed have not reported yields `incomplete`: not merge-eligible, not a human hold, with a reason naming the missing perspectives (`review coverage incomplete: missing docs-currency`). An incomplete head stays in the dispatcher: only the missing perspectives are re-asked (under `pending_ttl` / `max_redispatch`), never the ones whose reports already exist. The exception is a head that already holds a settled non-approve verdict (`requires_human`, `changes_requested` or `reject`): an incomplete re-review of the same head does not replace it. The artifact keeps the prior decision, its findings or question and its `recorded_at`, so the dispatcher never sees `incomplete` for that head — a `requires_human` head keeps taking the human-hold path and stays at 085, and a `changes_requested` or `reject` head stays on the fix path (rather than dropping back to 050 to re-ask the missing perspectives) until a complete replacement review lands. When the stale entries expire under `pending_ttl`, the whole perspective set is asked again for that head, not just the missing ones (hivecommons/hive#12878). Before this state existed a reviewer kick that died after its peers had reported left the head on a `requires_human` hold that no re-dispatch could clear (hivecommons/hive#12045).
7. Any other non-unanimous result requires human review.

One exception to rules 2–3: on a **hive superseding PR** (the App's own PR declaring `Supersedes #N`, `PerspectiveReport.hive_superseding`) a `requires_human` — security-sensitive included — becomes `changes_requested` and enters the fix cycle, because the owner's rule is that such PRs auto-merge with no operator decision; only the fix cap, a `reject`, or the stage engine's hard stops (sentinel, hold, red CI, unresolvable conflict) hand it to a person. `auto_merge.hive_superseding.auto_merge: false` turns this off. See [hive-merge.md](hive-merge.md#hive-authored-superseding-prs-auto-merge).

Out-of-scope findings alone are normalized to an approving perspective for aggregation and confidence. They remain in the structured record, but they never lower the verdict or the 0–5 confidence score for the PR.

The default human threshold is `high`. Review-triggered fix cycles use the same cap value as the escalation re-engagement circuit breaker (`escalation.MaxReEngagements`) so bot loops remain bounded.
Expand Down
2 changes: 1 addition & 1 deletion src/docs/scale-envelope.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ones to:
2. **Truncation must preserve the prioritization signal, not cut an arbitrary slice.**
This holds today and is easy to assume backwards:
- Issues are sorted by actionable rank tier, then **oldest first** within each tier before any cap is applied
(`RankActionableIssues`, `src/pkg/github/client.go:4936-4946`, descending `AgeMinutes` within each tier).
(`RankActionableIssues`, `src/pkg/github/client.go:4942-4952`, descending `AgeMinutes` within each tier).
- PRs are sorted by **review class then oldest-first within class**
(`SortPullRequestsForReview`, `src/pkg/github/review_priority.go:334`;
fixes → refactors/docs → tests).
Expand Down
17 changes: 17 additions & 0 deletions src/pkg/config/automerge_merge_train_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,20 @@ func TestMergeTrainAutoMergeConfigDefaults(t *testing.T) {
})
}
}

func TestHiveSupersedingAutoMergeEnabledDefaultsOn(t *testing.T) {
on, off := true, false
for _, tc := range []struct {
name string
cfg HiveSupersedingAutoMergeConfig
want bool
}{
{"default", HiveSupersedingAutoMergeConfig{}, true},
{"explicit on", HiveSupersedingAutoMergeConfig{AutoMerge: &on}, true},
{"explicit off", HiveSupersedingAutoMergeConfig{AutoMerge: &off}, false},
} {
if got := tc.cfg.AutoMergeEnabled(); got != tc.want {
t.Fatalf("%s: AutoMergeEnabled = %v want %v", tc.name, got, tc.want)
}
}
}
24 changes: 24 additions & 0 deletions src/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8336,6 +8336,10 @@ type AutoMergeConfig struct {
// opt-in per repo: a hive that never sets it keeps the pre-queue
// behaviour, including the `merge-queue-required` park.
NativeMergeQueue NativeMergeQueueAutoMergeConfig `yaml:"native_merge_queue,omitempty" json:"native_merge_queue,omitempty"`
// HiveSuperseding is the owner's rule for the hive's own superseding
// copies of other PRs (@clubanderson: "if a pr is superseded by a pr
// that a hive agent creates, it should auto merge"). Default ON.
HiveSuperseding HiveSupersedingAutoMergeConfig `yaml:"hive_superseding,omitempty" json:"hive_superseding,omitempty"`
}

// NativeMergeQueueAutoMergeConfig is auto_merge.native_merge_queue.*.
Expand Down Expand Up @@ -8389,6 +8393,26 @@ func (n NativeMergeQueueAutoMergeConfig) EffectiveProbeTTL() time.Duration {
return n.ProbeTTL
}

// HiveSupersedingAutoMergeConfig is auto_merge.hive_superseding.*.
type HiveSupersedingAutoMergeConfig struct {
// AutoMerge: a PR the hive App authored that declares "Supersedes #N"
// auto-merges with no operator decision. A reviewer's requires_human
// — a risk-class question or a security-sensitive finding included —
// is routed to the fixer and re-reviewed like any other finding; the
// PR parks at stage 085 only for a sentinel finding nobody has
// acknowledged or an emergent hard-stop (fix attempts exhausted, a
// hold, CI red after fixes, an unresolvable base conflict). nil/unset
// means ON; `auto_merge: false` restores the ordinary hive-authored
// routing, where such findings wait for a person.
AutoMerge *bool `yaml:"auto_merge,omitempty" json:"auto_merge,omitempty"`
}

// AutoMergeEnabled reports the auto_merge.hive_superseding.auto_merge
// switch; unset is on.
func (h HiveSupersedingAutoMergeConfig) AutoMergeEnabled() bool {
return h.AutoMerge == nil || *h.AutoMerge
}

// MergeTrainAutoMergeConfig is auto_merge.merge_train.*.
type MergeTrainAutoMergeConfig struct {
// Enabled turns the train on. nil/unset means ON; `enabled: false`
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/config/testdata/agent_runtime_golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@
"contributor_lane": {},
"contributor_tier": {},
"merge_train": {},
"native_merge_queue": {}
"native_merge_queue": {},
"hive_superseding": {}
},
"decisions": {
"delegate": {}
Expand Down
9 changes: 9 additions & 0 deletions src/pkg/dashboard/api.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dashboard

import (
Expand Down Expand Up @@ -884,6 +884,15 @@
return s.deps.Config.Sentinel.LabelOrDefault()
}

// hiveSupersedingAutoMerge is the live hive-superseding auto-merge switch
// (config.HiveSupersedingAutoMergeConfig; nil config = on).
func (s *Server) hiveSupersedingAutoMerge() bool {
if s == nil || s.deps == nil || s.deps.Config == nil {
return true
}
return s.deps.Config.AutoMerge.HiveSuperseding.AutoMergeEnabled()
}

func (s *Server) handleHistory(w http.ResponseWriter, r *http.Request) {
evalHistoryResponse(w, r, s.historyPayload())
}
Expand Down
4 changes: 4 additions & 0 deletions src/pkg/dashboard/api_repo_item_decide_delegated.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,10 @@ func (s *Server) gatherDelegatedInput(ctx context.Context, repoFull string, numb
}
in.SentinelReason = strings.TrimSpace(req.SentinelReason)
lowerReason := strings.ToLower(reason)
if in.Kind == delegatedecision.KindPR && in.HiveAuthored && s.hiveSupersedingAutoMerge() {
in.HiveSuperseding = ghpkg.HiveSupersedingPR(true, in.Body)
in.HiveSupersederHardStop = stagelabels.HiveSupersederHardStopReason(reason)
}
in.AdoptionStalled = strings.HasPrefix(lowerReason, stagelabels.LaneReasonAdoptionStalledPrefix)
if in.Kind == delegatedecision.KindPR && !in.HiveAuthored {
in.AdoptionGraceElapsed = s.delegatedAdoptionGraceElapsed(repoFull, number)
Expand Down
1 change: 1 addition & 0 deletions src/pkg/dashboard/settings_parity_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ auto_merge.native_merge_queue.enabled # native merge queue hand-off opt-in (#151
auto_merge.native_merge_queue.probe_ttl # merge-queue probe cache TTL (#15198); yaml-only
auto_merge.native_merge_queue.repos[] # native merge queue per-repo allow-list (#15198); yaml-only
auto_merge.native_merge_queue.skip_current_base_gate # explicit current-base bypass on queue bases (#15198); yaml-only
auto_merge.hive_superseding.auto_merge # hive-authored superseding PRs auto-merge without an operator decision; yaml-only
auto_merge.no_ci_ok[] # TODO #11854
auto_merge.repos.<key>.required_checks[] # TODO #11854
auto_merge.require_current_base[] # current-base gate per-repo "on" override, written by the Repos tab (#15335)
Expand Down
19 changes: 19 additions & 0 deletions src/pkg/dashboard/stage_tracker_decision_hive_superseder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dashboard

import (
"strings"
"testing"

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

// The hive's superseding PR parked by its one exception class: the tracker
// names the stop rather than "needs your decision".
func TestDecisionForPRHiveSupersederHardStopNamesReason(t *testing.T) {
it := StageTrackerItem{Repo: "hivecommons/hive", Number: 15649, Kind: "pr", Stage: 85, Head: "abc1234",
Reason: stagelabels.LaneReasonHiveSupersederHardStopPrefix + stagelabels.HiveSupersederHardStopSentinel}
d := decisionForPR(it, nil, "", false)
if d.AskedBy != decisionAskedByLane || !strings.Contains(d.Question, "would auto-merge") || !strings.Contains(d.Question, stagelabels.HiveSupersederHardStopProse(stagelabels.HiveSupersederHardStopSentinel)) {
t.Fatalf("decision = %+v", d)
}
}
Loading
Loading