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-adoption-stall-fixer-queue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- An adopted PR waiting unattempted in the fixer queue no longer runs the stage/074 stall clock toward a needs-decision park; the wait is capped at four dwells and does not apply when the fixer is unavailable (#15036).
22 changes: 22 additions & 0 deletions src/cmd/hive/merge_eligibility.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

import (
Expand Down Expand Up @@ -906,6 +906,26 @@
return owner, ""
}

// markAdoptedFixerQueued records that an adopted PR sits in the fixer queue
// so the 074 dwell can wait for a fixer that has not reached it
// (hivecommons/hive#15036). An unavailable fixer is not recorded: its rows
// must still escalate at the dwell.
func markAdoptedFixerQueued(repo string, number int, head, agent string, cfg *config.Config) {
if head == "" || !fixerAvailable(agent, cfg) {
return
}
stagelabels.Shared().MarkFixerQueued(stagelabels.Key(repo, number), head)
}

func fixerAvailable(agent string, cfg *config.Config) bool {
if cfg == nil {
return true
}
base := cfg.BaseAgentName(agent)
ac, ok := cfg.Agents[base]
return ok && !ac.Paused && cfg.HasAnyCadence(base) && !allConfiguredCadencesPaused(cfg, base)
}

func allConfiguredCadencesPaused(cfg *config.Config, agent string) bool {
if cfg == nil {
return false
Expand Down Expand Up @@ -1217,6 +1237,7 @@
row.ReroutedFrom = reroutedFrom
row.DeferredIncident = pr.SharedCIIncident
if adopted {
markAdoptedFixerQueued(fullRepo, pr.Number, pr.HeadSHA, agent, cfg)
logger.Info("adopted PR routed to fixer", "repo", fullRepo, "number", pr.Number, "work", "rebase", "mergeable_state", pr.MergeableState, "fixer", agent, "sentinel_alert", row.SentinelAlert)
}
failing = append(failing, row)
Expand All @@ -1234,6 +1255,7 @@
row.DeferredIncident = pr.SharedCIIncident
row.DeferredExternal = pr.ExternalCIDeferred
if adopted {
markAdoptedFixerQueued(fullRepo, pr.Number, pr.HeadSHA, agent, cfg)
logger.Info("adopted PR routed to fixer", "repo", fullRepo, "number", pr.Number, "work", "fix-ci", "failing_checks", pr.FailingChecks, "fixer", agent, "sentinel_alert", row.SentinelAlert)
}
failing = append(failing, row)
Expand Down
2 changes: 1 addition & 1 deletion src/docs/labels-and-control-signals.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ referenced it) a lone `stage/050-review-pending`
| `stage/070-fixing` | PR | hive-owned repair: App/taken-over PR red, changes requested (by the swarm, or by a trusted human's **changes requested** review / `/hive decision <text>` on the current head — reason `human-changes-requested`, which also kicks the author agent with the text verbatim, [#13041](https://github.com/hivecommons/hive/issues/13041)) or needs-rebase, **or** a non-App PR whose red head was caused by a hive-pushed commit that must be removed/re-homed; a hive agent is reworking it | 2h |
| `stage/071-needs-author` | PR | human-authored PR (`author/human`): CI red / changes requested / conflicting; the hive posted its diagnosis, the author must act. No nudge, no adoption — the person pushes or comments | 24h |
| `stage/072-returned-to-contributor` | PR | clanker PR (`author/clanker`, relay or external hive): CI red / changes requested / conflicting; the hive posted its diagnosis, the ball is in the contributor hive's court. (Briefly spelled `stage/072-needs-author` by [#12713](https://github.com/hivecommons/hive/pull/12713); the engine renames that label back in place) | 24h |
| `stage/074-adopted-by-hive` | PR | the author (a clanker) was unavailable — relay offline, never registered, or silent past the grace (see below); the hive took the PR over: in place on the PR's own branch when it may push there (the scanner's red-PR fix kick rebases and fixes it), otherwise via `hive/adopt-<n>` and a superseding App PR that keeps the author's commits (the original closes automatically when the superseder merges). Adoption is an **ownership** state, not a CI state: the PR reads 074 for as long as the hive owns it — through its fixes going pending, green, reviewed or red again (074 outranks 050/060/070/071/072) — and leaves 074 only at the merge gate (080/085/090/100), when the adoption is released, or to 085 `adoption-stalled:<reason>` when the head sat unchanged past the dwell with CI idle and a real blocker the hive cannot push past — a red optional check alone never counts, and the escalation releases back to 074 as soon as the reason clears (an in-place adoption with a blocking review finding re-homes to `hive/adopt-<n>` first instead; one with a squash-unsafe hive commit elects a merge commit on a `role/trusted` PR — `merge-method/merge` label, lane continues — and otherwise immediately re-homes to an App-authored superseder (`signoff-rehome`), preserving commits and sign-offs while changing squash attribution; loss of push access re-homes immediately, and idle rebase work re-homes after the dwell). For in-place adoption, a changed head must be linked to the App bot by GitHub commit metadata (the stage store only remembers heads that already passed that check); otherwise the hive treats it as a contributor push and hands the PR back (072 if red, else the normal path). Forgeable git author/committer names and emails never keep 074. A PR whose author holds **admin** or **maintain** on the repository is never adopted or re-homed (one cached permission read per repo and author per 10 minutes; a failed read is not cached and defers: no adoption, and an existing adoption is neither released nor re-homed until the read succeeds), and an adoption of such an author is released on the next pass, closing a still-open hive superseder with a note first. A fork PR is never superseded or re-homed into the base repository (that would run unreviewed fork code with the repository's trusted CI). So a fork PR is adopted only in place, when the hive can push to the fork's branch; one it cannot push to is not adopted at all. It stays at `072` with its author's nudge and queued `fix-pr` task, and parks at `085` as `adoption-stalled:fork-rehome-refused` only after the `072` dwell (24h) since the nudge on that head. An in-place fork adoption that can no longer be finished on the fork's branch parks there at once. | 3h |
| `stage/074-adopted-by-hive` | PR | the author (a clanker) was unavailable — relay offline, never registered, or silent past the grace (see below); the hive took the PR over: in place on the PR's own branch when it may push there (the scanner's red-PR fix kick rebases and fixes it), otherwise via `hive/adopt-<n>` and a superseding App PR that keeps the author's commits (the original closes automatically when the superseder merges). Adoption is an **ownership** state, not a CI state: the PR reads 074 for as long as the hive owns it — through its fixes going pending, green, reviewed or red again (074 outranks 050/060/070/071/072) — and leaves 074 only at the merge gate (080/085/090/100), when the adoption is released, or to 085 `adoption-stalled:<reason>` when the head sat unchanged past the dwell with CI idle and a real blocker the hive cannot push past — a red optional check alone never counts, the dwell waits while the fixer queue lists the head and no fixer kick has carried it yet (capped at four dwells; not applied when the fixer is unavailable), and the escalation releases back to 074 as soon as the reason clears (an in-place adoption with a blocking review finding re-homes to `hive/adopt-<n>` first instead; one with a squash-unsafe hive commit elects a merge commit on a `role/trusted` PR — `merge-method/merge` label, lane continues — and otherwise immediately re-homes to an App-authored superseder (`signoff-rehome`), preserving commits and sign-offs while changing squash attribution; loss of push access re-homes immediately, and idle rebase work re-homes after the dwell). For in-place adoption, a changed head must be linked to the App bot by GitHub commit metadata (the stage store only remembers heads that already passed that check); otherwise the hive treats it as a contributor push and hands the PR back (072 if red, else the normal path). Forgeable git author/committer names and emails never keep 074. A PR whose author holds **admin** or **maintain** on the repository is never adopted or re-homed (one cached permission read per repo and author per 10 minutes; a failed read is not cached and defers: no adoption, and an existing adoption is neither released nor re-homed until the read succeeds), and an adoption of such an author is released on the next pass, closing a still-open hive superseder with a note first. A fork PR is never superseded or re-homed into the base repository (that would run unreviewed fork code with the repository's trusted CI). So a fork PR is adopted only in place, when the hive can push to the fork's branch; one it cannot push to is not adopted at all. It stays at `072` with its author's nudge and queued `fix-pr` task, and parks at `085` as `adoption-stalled:fork-rehome-refused` only after the `072` dwell (24h) since the nudge on that head. An in-place fork adoption that can no longer be finished on the fork's branch parks there at once. | 3h |
| `stage/080-awaiting-merge-admission` | PR | nothing left for the author: CI green (no red check on the head, required or not), verdict approve, no modifiers — and the automerge lane has not admitted it yet (prefilter not evaluated for this head, labels not synced, lane tripped). A stall here means a lane problem, so the hive also posts one `<!-- hive:stage-stalled -->` comment with the lane's last skip reason | 30m |
| `stage/085-needs-decision` | PR | **PR-only** since the owner decision of 2026-10-17 (issues park at `stage/045-needs-decision`; before that this stage carried both, [#12683](https://github.com/hivecommons/hive/issues/12683)). A person owes a **decision**, not a merge: a `requires_human` swarm verdict (reason `reviewer-verdict:requires_human`), `sentinel-alert`, `hold` / `do-not-merge*` / `needs-decision` modifier, no reviewer configured, GitHub workflow approval is required for a trusted same-repo bot/App/clanker PR (`workflow-approval-required:<ctx>`); Hive has posted `/ok-to-test` and is waiting for the repo-local `hive-ok-to-test` workflow or a maintainer, or a human-only lane rule unrelated to trust (workflow-path edits, tests removed, human-merge path, reporter-trust hold), or an open issue the PR closes is held or parked (`linked-issue:hold:#N:<label>` / `linked-issue:needs-decision:#N:<label>`), or GitHub refused to update the branch from its base because the base changed `.github/workflows/` and the App lacks the workflows permission (`workflow-permission`: a person merges or rebases the base in and pushes, or grants the App Workflows: write). A trusted human's normal GitHub **Approve** review on the exact current head clears a `requires_human` verdict for any author kind/lane and records `reviewer-verdict:requires_human:human-approved@<login>`; a new head invalidates it. The same approval also clears the merge-lane review gate over any non-approved swarm outcome, a perspective's `changes_requested` included (the `review_evaluated` audit line records `human_approver` and `overrode`); without it, `changes_requested` / `reject` still require fixes or manual merge. Under `review.self_authored_decision_policy: resolve`, a Hive-authored PR's reviewer decision question parks here only when it matches a named risk class (`review.DecisionRiskClasses`: permissions/credentials, security, sensitive paths, data loss/irreversible, merge/trust policy, external side effects, licensing/legal, unverifiable) or carries `<!-- hive-decision-risk: high -->`; any other question is resolved by policy and recorded as an advisory reason on the approving aggregate. Hive-authored non-risk incomplete-fix reviews with concrete remediation are normalized to `changes_requested` at verdict load/aggregation time and by the stage-label detail selector, even when the finding was marked high severity; duplicate summary/changelog intent-alignment cleanup with a concrete trim/reword fix is included. Those PRs go to `stage/070-fixing`, not here. On a hive-authored PR the trusted human can also answer with a **changes requested** review on the head, or `/hive decision <what to change>`, which moves the PR to `stage/070-fixing` and kicks the author agent with the text verbatim ([#13041](https://github.com/hivecommons/hive/issues/13041)); `/hive decision` on a PR the hive did not open gets one reply naming the review-side equivalents. One `<!-- hive:stage-needs-decision -->` comment on entry names what is owed and, per lane, what clears it ([#13087](https://github.com/hivecommons/hive/issues/13087)): for a hive-authored `requires_human` park the two actions — approve the head (review or `/hive approve` reply after the verdict) to merge as-is, or request changes and the hive pushes the fix; for any other `requires_human` park a trusted merger's approval by review or `/hive approve` reply; for a hold / sentinel park the label a person must remove; for a linked-issue park the issue and the label to remove from it; and for a manual-merge-only lane rule that a maintainer must merge by hand, which no approval overrides. A `workflow-path` fence the owner's approval releases ([#14664](https://github.com/hivecommons/hive/issues/14664)) is not such a rule: the comment reads "Needs a decision, not a merge" and asks for a trusted merger's GitHub **Approve** review (or a dashboard `/hive decision approve`) on the current head — a `/hive approve` reply does not release the fence — and still lists the sentinel alert and hold labels a person must clear (projectbluefin/testsuite#1037) | none |
| `stage/090-ready-for-human-merge` | PR | the hive would merge this itself but trust/role blocks it: reviewer verdict approve at the **current** head, required checks green (tide excluded), DCO yes, no sentinel alert, no conflicts, soak elapsed, no hold — and the only remaining lane reason is the author's tier/role. A maintainer's `/lgtm` `/approve` is the only missing step. One `<!-- hive:stage-ready-for-human-merge -->` comment on entry carries the evidence. Always read with the `role/*` and `author/*` labels. (Was `stage/090-needs-human` before [#12528](https://github.com/hivecommons/hive/issues/12528); the engine renames the GitHub label in place) | none |
Expand Down
47 changes: 47 additions & 0 deletions src/pkg/github/automerge/automerge_adoption_escape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,3 +838,50 @@ func TestAdoptionEscalationHoldsAgainstErroredLane(t *testing.T) {
t.Fatalf("escalation churned: added=%v removed=%v comments=%v", h.api.added, h.api.removed, h.api.comments)
}
}

// A queued, unattempted adopted head does not run the 074 clock
// (hivecommons/hive#15036).
func TestAdoptionStaleWaitsForFixerQueue(t *testing.T) {
policy := adoptPolicy()
start := time.Date(2026, 10, 28, 11, 0, 0, 0, time.UTC)
obs := stageObservation{HeadSHA: "aaa", Reason: "label:needs-rebase", LaneReason: "label:needs-rebase", Labels: []string{"needs-rebase"}}
base := stagelabels.Record{AdoptedHead: "aaa", AdoptMode: stagelabels.AdoptModeInPlace, AdoptedAt: start, AdoptedHeadAt: start}
queued := func(seen time.Time) stagelabels.Record {
r := base
r.FixerQueuedHead, r.FixerQueuedSeenAt = "aaa", seen
return r
}
attempted := func(at time.Time) stagelabels.Record {
r := queued(at)
r.FixerAttemptedHead, r.FixerAttemptedAt = "aaa", at
return r
}
tests := []struct {
name string
rec stagelabels.Record
at time.Time
want bool
}{
{"no queue record behaves as today", base, start.Add(adoptedDwell), true},
{"queued and unattempted past the dwell waits", queued(start.Add(adoptedDwell)), start.Add(adoptedDwell + time.Minute), false},
{"attempted 1h ago is not stale", attempted(start.Add(2 * adoptedDwell)), start.Add(2*adoptedDwell + time.Hour), false},
{"attempted 4h ago is stale", attempted(start.Add(adoptedDwell)), start.Add(adoptedDwell + 4*time.Hour), true},
{"queue no longer listing the row (fixer unavailable) is stale at the dwell", queued(start.Add(time.Hour)), start.Add(adoptedDwell), true},
{"past the hard cap while queued is stale", queued(start.Add(4*adoptedDwell - time.Minute)), start.Add(4 * adoptedDwell), true},
{"queue entry for another head does not pause", func() stagelabels.Record {
r := queued(start.Add(adoptedDwell))
r.FixerQueuedHead = "bbb"
return r
}(), start.Add(adoptedDwell + time.Minute), true},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if got := adoptionStale(obs, tc.rec, policy, tc.at); got != tc.want {
t.Fatalf("adoptionStale=%v, want %v", got, tc.want)
}
if got := inPlaceRehomeReason(obs, tc.rec, policy, tc.at); got != "" && !tc.want {
t.Fatalf("inPlaceRehomeReason=%q while waiting on the fixer queue", got)
}
})
}
}
15 changes: 14 additions & 1 deletion src/pkg/github/automerge/automerge_contributor_adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -1506,9 +1506,22 @@ func adoptionStale(obs stageObservation, rec stagelabels.Record, policy StageLab
// sat yet under that plan.
return false
}
return now.Sub(since) >= stagelabels.Dwell(stagelabels.AdoptedByHive, policy.Dwell)
dwell := stagelabels.Dwell(stagelabels.AdoptedByHive, policy.Dwell)
if attempted := rec.FixerAttemptedSince(obs.HeadSHA); attempted.After(since) {
// The fixer reached the head: the dwell is the fixer's time to act.
since = attempted
} else if rec.FixerQueuedUnattempted(obs.HeadSHA, now) && now.Sub(since) < dwell*adoptionQueuedDwellCap {
// Waiting in the fixer queue is not the adopter sitting idle
// (hivecommons/hive#15036); the cap keeps a dead fixer escalating.
return false
}
return now.Sub(since) >= dwell
}

// adoptionQueuedDwellCap bounds, in 074 dwells from the head clock, how long a
// queued but unattempted row pauses adoptionStale.
const adoptionQueuedDwellCap = 4

// adoptedHeadSignoffUnfixable reports a head whose App sign-off cannot
// survive a squash attributed to the contributor. Re-home it without
// rewriting commits: the superseding PR is App-authored, so the App's own
Expand Down
12 changes: 12 additions & 0 deletions src/pkg/scheduler/policy_overlays.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package scheduler

import (
Expand All @@ -8,6 +8,7 @@

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

const (
Expand Down Expand Up @@ -199,6 +200,15 @@
return appendKickSection(message, section)
}

// markAdoptedFixerAttempt records that a fixer kick carried an adopted row, so
// the 074 stall clock stops waiting for the fixer to reach it
// (hivecommons/hive#15036). A var so tests can observe it.
var markAdoptedFixerAttempt = func(repo string, number int, head string) {
if head != "" {
stagelabels.Shared().MarkFixerAttempted(stagelabels.Key(repo, number), head)
}
}

// heldRedPRNote is appended to a held PR's entry in the fix-before-new
// block: the hold is a merge checkpoint, not a repair checkpoint
// (hivecommons/hive#7438), and the agent's own policy says never to touch a
Expand Down Expand Up @@ -235,6 +245,7 @@
FromFork bool `json:"from_fork"`
ReachableAction string `json:"reachable_action"`
Adopted bool `json:"adopted"`
HeadSHA string `json:"head_sha"`
SentinelAlert bool `json:"sentinel_alert"`
HeadRepo string `json:"head_repo"`
Held bool `json:"held"`
Expand Down Expand Up @@ -341,6 +352,7 @@
}
b.WriteString(fmt.Sprintf(" #%d %s — %s\n", pr.Number, pr.Repo, pr.Title))
if pr.Adopted {
markAdoptedFixerAttempt(pr.Repo, pr.Number, pr.HeadSHA)
b.WriteString(fmt.Sprintf(" ADOPTED contributor PR (stage 074, head repo %s): the author is offline; `gh pr checkout` then push to the PR's own branch — maintainer_can_modify grants access.\n", pr.HeadRepo))
b.WriteString(adoptedPRStatusRule)
if pr.SentinelAlert {
Expand Down
Loading
Loading