From cb6e2394237a9526aa59ec2d2d8a8da22b97474c Mon Sep 17 00:00:00 2001
From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
Date: Sat, 31 Oct 2026 07:58:54 -0400
Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix(automerge):=20time-box?=
=?UTF-8?q?=20adopted-PR=20rebase=20attempts=20and=20re-home=20when=20exha?=
=?UTF-8?q?usted?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
Co-authored-by: clubanderson <407614+clubanderson@users.noreply.github.com>
---
changelog.d/fixed-16023.md | 1 +
src/cmd/hive/adopted_pr_fixer_test.go | 82 ++++++++++++++
src/cmd/hive/merge_eligibility.go | 47 +++++++-
.../stage-labels.md | 8 +-
src/hive.yaml.example | 2 +
src/pkg/config/config.go | 19 +++-
src/pkg/config/stage_labels_getters_test.go | 4 +-
.../dashboard/rebase_merge_followthrough.go | 7 +-
.../rebase_merge_followthrough_test.go | 14 ++-
src/pkg/dashboard/stage_tracker_build.go | 2 +-
.../static-src/js/config-governor.js | 2 +-
.../dashboard/static-src/js/config-state.js | 2 +-
src/pkg/dashboard/static/index.html | 4 +-
.../automerge_adoption_escape_test.go | 61 ++++++++++-
.../automerge/automerge_contributor_adopt.go | 22 +++-
src/pkg/rebasemerge/attempts.go | 103 ++++++++++++++++--
src/pkg/rebasemerge/rebasemerge_test.go | 72 ++++++++++++
17 files changed, 419 insertions(+), 33 deletions(-)
create mode 100644 changelog.d/fixed-16023.md
diff --git a/changelog.d/fixed-16023.md b/changelog.d/fixed-16023.md
new file mode 100644
index 0000000000..fb35f82742
--- /dev/null
+++ b/changelog.d/fixed-16023.md
@@ -0,0 +1 @@
+- An adopted (or otherwise hive-owned) conflicting PR no longer sits on "Rebasing · attempt 1/2" while the fixer is busy: each rebase attempt is routed once and gets `governor.labels.stage.adoption.rebase_attempt_timeout` (default 15m) to push before it counts as failed and the next attempt is dispatched, the row shows the wait ("Rebasing · attempt 1/2 · waiting for scanner 12m"), and an in-place adoption whose attempts are spent re-homes to a hive-owned superseding PR at once instead of after the 3h dwell ([#16023](https://github.com/hivecommons/hive/issues/16023)).
diff --git a/src/cmd/hive/adopted_pr_fixer_test.go b/src/cmd/hive/adopted_pr_fixer_test.go
index 6f311de2f7..4fdb6ca2a1 100644
--- a/src/cmd/hive/adopted_pr_fixer_test.go
+++ b/src/cmd/hive/adopted_pr_fixer_test.go
@@ -1,6 +1,9 @@
package main
import (
+ "bytes"
+ "log/slog"
+ "path/filepath"
"strings"
"testing"
"time"
@@ -229,3 +232,82 @@ func TestWriteMergeEligible_UntrustedConflictIsNotHiveRebaseWork(t *testing.T) {
t.Fatalf("ci_failing = %+v, want nothing when the trusted-author tier is off", failing)
}
}
+
+// sweepRebaseLogged runs one writeMergeEligible sweep at now and returns the
+// ci-failing rows and the number of "routed to fixer for rebase" lines.
+func sweepRebaseLogged(t *testing.T, prs []github.PullRequest, now time.Time) ([]failingEntry, int) {
+ t.Helper()
+ dir := t.TempDir()
+ origMerge, origFail, origNow := mergeEligiblePath, ciFailingPath, rebaseAttemptNow
+ mergeEligiblePath = filepath.Join(dir, "merge-eligible.json")
+ ciFailingPath = filepath.Join(dir, "ci-failing.json")
+ rebaseAttemptNow = func() time.Time { return now }
+ defer func() { mergeEligiblePath, ciFailingPath, rebaseAttemptNow = origMerge, origFail, origNow }()
+ var logs bytes.Buffer
+ actionable := &github.ActionableResult{PRs: github.PRResult{Items: prs}}
+ writeMergeEligible(actionable, github.HoldResult{}, "hivecommons", nil, false, nil, false, nil, nil, nil, slog.New(slog.NewTextHandler(&logs, nil)))
+ var payload struct {
+ CIFailing []failingEntry `json:"ci_failing"`
+ }
+ readJSON(t, ciFailingPath, &payload)
+ return payload.CIFailing, strings.Count(logs.String(), "PR routed to fixer for rebase")
+}
+
+// hivecommons/hive#16023: an adopted conflicting PR whose fixer never
+// pushes must not sit on attempt 1 forever. The attempt is routed (and
+// logged) once; past the per-attempt deadline it counts as failed and
+// attempt 2 is routed with one line; past the cap the row leaves the fixer
+// list so the adoption lane can re-home it.
+func TestWriteMergeEligible_AdoptedRebaseAttemptTimesOutWithoutPush(t *testing.T) {
+ store := useMemoryRebaseAttempts(t)
+ const repo = "hivecommons/hive"
+ adoptInPlace(t, repo, 15998, "f00dfac")
+ pr := github.PullRequest{Number: 15998, Repo: "hive", Author: "clanker-bot", HeadSHA: "f00dfac",
+ HeadRef: "feat/x", HeadRepo: "hivecommons/hive", BaseRef: "v5",
+ Mergeable: github.MergeableNo, MergeableState: "dirty", CIStatus: "pending",
+ Labels: []string{"needs-rebase", "stage/074-adopted-by-hive", "author/clanker"}}
+ t0 := time.Date(2026, 10, 31, 9, 0, 0, 0, time.UTC)
+ timeout := config.DefaultAdoptRebaseAttemptTimeout
+
+ failing, routed := sweepRebaseLogged(t, []github.PullRequest{pr}, t0)
+ if len(failing) != 1 || failing[0].RebaseAttempt != 1 || routed != 1 {
+ t.Fatalf("first sweep: rows=%+v routed=%d, want attempt 1 routed once", failing, routed)
+ }
+ // Later sweeps inside the deadline keep the row listed, not re-routed.
+ failing, routed = sweepRebaseLogged(t, []github.PullRequest{pr}, t0.Add(5*time.Minute))
+ if len(failing) != 1 || failing[0].RebaseAttempt != 1 || routed != 0 {
+ t.Fatalf("second sweep: rows=%+v routed=%d, want attempt 1 listed but not re-routed", failing, routed)
+ }
+ if a, _ := store.Get(repo, 15998); !a.DispatchedAt.Equal(t0) || a.Fixer != "scanner" {
+ t.Fatalf("dispatch = %+v, want the first sweep's dispatch to scanner kept", a)
+ }
+ if got := rebasemerge.AttemptTextAt(mustAttempt(t, store, repo, 15998), t0.Add(12*time.Minute)); got != "Rebasing · attempt 1/2 · waiting for scanner 12m" {
+ t.Fatalf("caption = %q", got)
+ }
+ // No push by the deadline: attempt 1 failed, attempt 2 routed once.
+ failing, routed = sweepRebaseLogged(t, []github.PullRequest{pr}, t0.Add(timeout))
+ if len(failing) != 1 || failing[0].RebaseAttempt != 2 || routed != 1 {
+ t.Fatalf("deadline sweep: rows=%+v routed=%d, want attempt 2 routed once", failing, routed)
+ }
+ failing, routed = sweepRebaseLogged(t, []github.PullRequest{pr}, t0.Add(timeout+time.Minute))
+ if len(failing) != 1 || failing[0].RebaseAttempt != 2 || routed != 0 {
+ t.Fatalf("attempt 2 re-sweep: rows=%+v routed=%d", failing, routed)
+ }
+ // Attempt 2 also times out: exhausted, off the fixer list.
+ failing, routed = sweepRebaseLogged(t, []github.PullRequest{pr}, t0.Add(2*timeout))
+ if len(failing) != 0 || routed != 0 {
+ t.Fatalf("exhausted sweep: rows=%+v routed=%d, want nothing", failing, routed)
+ }
+ if a := mustAttempt(t, store, repo, 15998); !a.Exhausted() || a.Stalled != 2 {
+ t.Fatalf("episode = %+v, want exhausted by two timed-out attempts", a)
+ }
+}
+
+func mustAttempt(t *testing.T, store *rebasemerge.Attempts, repo string, number int) rebasemerge.Attempt {
+ t.Helper()
+ a, ok := store.Get(repo, number)
+ if !ok {
+ t.Fatalf("no rebase episode for %s#%d", repo, number)
+ }
+ return a
+}
diff --git a/src/cmd/hive/merge_eligibility.go b/src/cmd/hive/merge_eligibility.go
index 8c9a317198..992781e6d6 100644
--- a/src/cmd/hive/merge_eligibility.go
+++ b/src/cmd/hive/merge_eligibility.go
@@ -830,6 +830,19 @@ func hiveAuthoredPR(pr github.PullRequest) bool {
// rebaseAttempts is the conflict loop-guard ledger; tests swap it.
var rebaseAttempts = rebasemerge.SharedAttempts
+// rebaseAttemptNow is the clock for the rebase episode; tests swap it.
+var rebaseAttemptNow = time.Now
+
+// rebaseAttemptTimeout is how long one fixer rebase attempt may wait for a
+// push before it counts as failed
+// (governor.labels.stage.adoption.rebase_attempt_timeout, default 15m).
+func rebaseAttemptTimeout(cfg *config.Config) time.Duration {
+ if cfg == nil {
+ return config.DefaultAdoptRebaseAttemptTimeout
+ }
+ return cfg.Governor.Labels.Stage.Adoption.EffectiveRebaseAttemptTimeout()
+}
+
// mergeTrainRebaseRequester is the RequestedBy the merge train writes on a
// rebase episode it opens for a member it could not update-branch
// (hivecommons/hive#15117 → #15104).
@@ -1236,13 +1249,30 @@ func writeMergeEligible(actionable *github.ActionableResult, hold github.HoldRes
// Loop guard: attempt n of MaxRebaseAttempts per conflict
// episode; a fixer's pushed head that is still dirty is the
// next attempt, and past the cap the hive stops re-kicking.
- attempt := rebaseAttempts().Observe(fullRepo, pr.Number, pr.HeadSHA, time.Now())
+ // A fixer-owned attempt (adopted, trusted-author, requested)
+ // that saw no push within its deadline is the next attempt too
+ // (hivecommons/hive#16023): a busy fixer must not hold the
+ // episode at attempt 1 forever.
+ fixerRebase := adopted || trustedRebase || requested
+ rebaseNow := rebaseAttemptNow()
+ attempt := rebaseAttempts().Observe(fullRepo, pr.Number, pr.HeadSHA, rebaseNow)
+ var timedOut *rebasemerge.Attempt
+ if fixerRebase {
+ prev := attempt
+ if next, ok := rebaseAttempts().Expire(fullRepo, pr.Number, rebaseAttemptTimeout(cfg), rebaseNow); ok {
+ timedOut, attempt = &prev, next
+ }
+ }
row.RebaseAttempt = attempt.Count()
row.RebaseAttemptsMax = rebasemerge.MaxRebaseAttempts
row.BaseRef = pr.BaseRef
row.TrustedAuthor = trustedRebase
if attempt.Exhausted() {
- logger.Warn("rebase attempts exhausted; leaving the conflict to a person", "repo", fullRepo, "number", pr.Number, "head", pr.HeadSHA, "attempts", attempt.Count()-1, "max", rebasemerge.MaxRebaseAttempts, "mergeable_state", pr.MergeableState)
+ args := []any{"repo", fullRepo, "number", pr.Number, "head", pr.HeadSHA, "attempts", attempt.Count() - 1, "max", rebasemerge.MaxRebaseAttempts, "timed_out", attempt.Stalled, "mergeable_state", pr.MergeableState}
+ if timedOut != nil {
+ args = append(args, "waited_for", timedOut.Fixer, "waited", timedOut.Waiting(rebaseNow).Round(time.Second).String())
+ }
+ logger.Warn("rebase attempts exhausted; leaving the conflict to a person", args...)
continue
}
agent := prFixAgent(pr, prAgents[fmt.Sprintf("%s#%d", fullRepo, pr.Number)])
@@ -1262,8 +1292,17 @@ func writeMergeEligible(actionable *github.ActionableResult, hold github.HoldRes
if trustedRebase || requested {
row.ReachableAction = github.ReachableActionPush
}
- if adopted || trustedRebase || requested {
- logger.Info("PR routed to fixer for rebase", "repo", fullRepo, "number", pr.Number, "work", "rebase", "adopted", adopted, "trusted_author", trustedRebase, "requested_by", attempt.RequestedBy, "attempt", attempt.Count(), "max", rebasemerge.MaxRebaseAttempts, "mergeable_state", pr.MergeableState, "fixer", agent, "sentinel_alert", row.SentinelAlert)
+ if fixerRebase {
+ // The row stays listed every sweep (the fixer's kick overlay
+ // reads it), but each attempt is routed and announced once;
+ // the dispatch time is the attempt's deadline clock.
+ if _, first := rebaseAttempts().Dispatch(fullRepo, pr.Number, agent, rebaseNow); first {
+ args := []any{"repo", fullRepo, "number", pr.Number, "work", "rebase", "adopted", adopted, "trusted_author", trustedRebase, "requested_by", attempt.RequestedBy, "attempt", attempt.Count(), "max", rebasemerge.MaxRebaseAttempts, "mergeable_state", pr.MergeableState, "fixer", agent, "sentinel_alert", row.SentinelAlert}
+ if timedOut != nil {
+ args = append(args, "previous_attempt_timed_out", true, "waited_for", timedOut.Fixer, "waited", timedOut.Waiting(rebaseNow).Round(time.Second).String())
+ }
+ logger.Info("PR routed to fixer for rebase", args...)
+ }
}
failing = append(failing, row)
continue
diff --git a/src/docs/labels-and-control-signals/stage-labels.md b/src/docs/labels-and-control-signals/stage-labels.md
index 5250872bc0..903ec7cd75 100644
--- a/src/docs/labels-and-control-signals/stage-labels.md
+++ b/src/docs/labels-and-control-signals/stage-labels.md
@@ -876,7 +876,13 @@ When a contributor-agent PR goes red the hive does not just relabel it (a human-
adopted branch first reaches the normal fixer, which rebases onto the
PR base and pushes to the actual fork with a head-bound lease,
preserving authorship and sign-offs. If the head stays idle past the
- 074 dwell, supersede in that sweep rather than escalate to 085.
+ 074 dwell, supersede in that sweep rather than escalate to 085. Each
+ fixer attempt is routed once and gets
+ `governor.labels.stage.adoption.rebase_attempt_timeout` (default 15m)
+ to push; one with no push counts as failed and the next attempt is
+ dispatched (the row reads "Rebasing · attempt 1/2 · waiting for
+ scanner 12m" meanwhile). Once both attempts are spent the adoption
+ supersedes at once instead of waiting out the dwell (#16023).
- `reason=in-place-stalled` (always `mode=supersede`) — second takeover:
an in-place-adopted head sat unchanged for the 074 dwell (3h) with CI
idle (not pending) and the review swarm's latest verdict on it
diff --git a/src/hive.yaml.example b/src/hive.yaml.example
index f6b785d47f..57158a8f59 100644
--- a/src/hive.yaml.example
+++ b/src/hive.yaml.example
@@ -525,6 +525,8 @@ governor:
# after_offline: 15m # default 15m; registered relay offline, measured from the later
# # of its last heartbeat and the first stage/072 nudge
# after_unregistered: 15m # default 15m; no contributor profile, wait after the nudge with no new head
+ # rebase_attempt_timeout: 15m # default 15m; a fixer rebase attempt with no push by then counts as failed;
+ # # once attempts are spent an in-place adoption re-homes to a superseding PR
# supersede:
# close_first: true # default true; close the original (hive/superseded, one note naming the
# # copy) in the pass that opens the copy; reopened if the copy fails.
diff --git a/src/pkg/config/config.go b/src/pkg/config/config.go
index c2089268c7..7256747ed7 100644
--- a/src/pkg/config/config.go
+++ b/src/pkg/config/config.go
@@ -2930,6 +2930,13 @@ type StageAdoptionConfig struct {
// 072/085 for a contributor who cannot act (default 30m;
// hivecommons/hive#15307).
OfflineGrace string `yaml:"offline_grace,omitempty"`
+ // RebaseAttemptTimeout is how long one fixer rebase attempt on an
+ // adopted (or otherwise hive-owned) conflicting PR may wait for the
+ // fixer's push before it counts as failed and the next attempt is
+ // dispatched; past the attempt cap an in-place adoption re-homes to a
+ // hive-owned superseding PR at once (default 15m;
+ // hivecommons/hive#16023).
+ RebaseAttemptTimeout string `yaml:"rebase_attempt_timeout,omitempty"`
// InPlace lets the hive adopt by pushing to the PR's own branch when
// GitHub allows it (same-repo head or maintainer_can_modify) instead of
// opening a superseding App PR. nil = true.
@@ -3057,11 +3064,17 @@ func (c StageAdoptionConfig) StrictAttributionEnabled() bool {
// Defaults for the offline-adoption waits (stage 074, hivecommons/hive#12436).
const (
- DefaultAdoptAfterOffline = 15 * time.Minute
- DefaultAdoptAfterUnregistered = 15 * time.Minute
- DefaultAdoptOfflineGrace = 30 * time.Minute
+ DefaultAdoptAfterOffline = 15 * time.Minute
+ DefaultAdoptAfterUnregistered = 15 * time.Minute
+ DefaultAdoptOfflineGrace = 30 * time.Minute
+ DefaultAdoptRebaseAttemptTimeout = 15 * time.Minute
)
+// EffectiveRebaseAttemptTimeout parses RebaseAttemptTimeout (default 15m).
+func (c StageAdoptionConfig) EffectiveRebaseAttemptTimeout() time.Duration {
+ return parseDurationOr(c.RebaseAttemptTimeout, DefaultAdoptRebaseAttemptTimeout)
+}
+
// EffectiveOfflineGrace parses OfflineGrace (default 30m).
func (c StageAdoptionConfig) EffectiveOfflineGrace() time.Duration {
return parseDurationOr(c.OfflineGrace, DefaultAdoptOfflineGrace)
diff --git a/src/pkg/config/stage_labels_getters_test.go b/src/pkg/config/stage_labels_getters_test.go
index d53f793689..f2f74500b0 100644
--- a/src/pkg/config/stage_labels_getters_test.go
+++ b/src/pkg/config/stage_labels_getters_test.go
@@ -13,6 +13,7 @@ func TestStageLabelsConfigGetterDefaults(t *testing.T) {
}
if s.Adoption.EffectiveAfterOffline() != DefaultAdoptAfterOffline ||
s.Adoption.EffectiveAfterUnregistered() != DefaultAdoptAfterUnregistered ||
+ s.Adoption.EffectiveRebaseAttemptTimeout() != 15*time.Minute ||
s.EffectiveContributorGraceOnline() != DefaultContributorGraceOnline ||
s.EffectiveContributorGraceOffline() != DefaultContributorGraceOffline ||
s.EffectivePresenceWindow() != DefaultPresenceWindow ||
@@ -33,7 +34,7 @@ func TestStageLabelsConfigGetterDefaults(t *testing.T) {
ContributorNudge: ContributorNudgeConfig{Enabled: &off, RenudgeInterval: "30m"},
Adoption: StageAdoptionConfig{
Enabled: &off, InPlace: &off, StrictAttribution: &off, AutoMerge: &off,
- AfterOffline: "2m", AfterUnregistered: "0s",
+ AfterOffline: "2m", AfterUnregistered: "0s", RebaseAttemptTimeout: "20m",
},
Stalled: StageStalledConfig{RequireQuiet: &off},
}
@@ -42,6 +43,7 @@ func TestStageLabelsConfigGetterDefaults(t *testing.T) {
t.Fatal("explicit false turns each toggle off")
}
if s.EffectivePresenceWindow() != time.Minute || s.Adoption.EffectiveAfterOffline() != 2*time.Minute ||
+ s.Adoption.EffectiveRebaseAttemptTimeout() != 20*time.Minute ||
s.ContributorNudge.EffectiveRenudgeInterval() != 30*time.Minute {
t.Fatal("valid durations parse")
}
diff --git a/src/pkg/dashboard/rebase_merge_followthrough.go b/src/pkg/dashboard/rebase_merge_followthrough.go
index cccda1a44b..f19ed4bc41 100644
--- a/src/pkg/dashboard/rebase_merge_followthrough.go
+++ b/src/pkg/dashboard/rebase_merge_followthrough.go
@@ -381,8 +381,9 @@ type StageTrackerRebase struct {
}
// applyRebaseAttempts stamps rebase onto PR rows with an open conflict
-// episode in the fixer's attempts ledger.
-func applyRebaseAttempts(items []StageTrackerItem) {
+// episode in the fixer's attempts ledger; a dispatched attempt names the
+// fixer and how long it has waited at now (hivecommons/hive#16023).
+func applyRebaseAttempts(items []StageTrackerItem, now time.Time) {
attempts := rebaseAttemptsStore()
if attempts == nil {
return
@@ -396,7 +397,7 @@ func applyRebaseAttempts(items []StageTrackerItem) {
if !ok {
continue
}
- it.Rebase = &StageTrackerRebase{Attempt: min(max(a.Count(), 1), rebasemerge.MaxRebaseAttempts), Max: rebasemerge.MaxRebaseAttempts, Exhausted: a.Exhausted(), Head: rebaseMergeShortSHA(a.Head()), Text: rebasemerge.AttemptText(a)}
+ it.Rebase = &StageTrackerRebase{Attempt: min(max(a.Count(), 1), rebasemerge.MaxRebaseAttempts), Max: rebasemerge.MaxRebaseAttempts, Exhausted: a.Exhausted(), Head: rebaseMergeShortSHA(a.Head()), Text: rebasemerge.AttemptTextAt(a, now)}
}
}
diff --git a/src/pkg/dashboard/rebase_merge_followthrough_test.go b/src/pkg/dashboard/rebase_merge_followthrough_test.go
index 3ddf4bde54..8bab66b4e4 100644
--- a/src/pkg/dashboard/rebase_merge_followthrough_test.go
+++ b/src/pkg/dashboard/rebase_merge_followthrough_test.go
@@ -215,18 +215,24 @@ func TestRebaseAttemptsPillAndFollowThroughExhaustion(t *testing.T) {
t.Cleanup(func() { rebaseMergeNow = time.Now })
items := []StageTrackerItem{{Repo: "hivecommons/hive", Number: 15087, Kind: "pr", Stage: 90, Modifiers: []string{modNeedsRebase}}, {Repo: "hivecommons/hive", Number: 1, Kind: "pr", Stage: 90}}
- applyRebaseAttempts(items)
+ applyRebaseAttempts(items, now)
if items[0].Rebase != nil || items[1].Rebase != nil {
t.Fatalf("no episode, no pill: %+v %+v", items[0].Rebase, items[1].Rebase)
}
attempts.Observe("hivecommons/hive", 15087, "aaa1111aaa1111", now)
- applyRebaseAttempts(items)
+ applyRebaseAttempts(items, now)
if r := items[0].Rebase; r == nil || r.Attempt != 1 || r.Max != 2 || r.Exhausted || r.Head != "aaa1111" || r.Text != "Rebasing · attempt 1/2" {
t.Fatalf("attempt 1 pill = %+v", r)
}
+ // hivecommons/hive#16023: a dispatched attempt shows who it waits on.
+ attempts.Dispatch("hivecommons/hive", 15087, "scanner", now)
+ applyRebaseAttempts(items, now.Add(12*time.Minute))
+ if r := items[0].Rebase; r == nil || r.Attempt != 1 || r.Text != "Rebasing · attempt 1/2 · waiting for scanner 12m" {
+ t.Fatalf("waiting pill = %+v", r)
+ }
attempts.Observe("hivecommons/hive", 15087, "bbb2222", now)
attempts.Observe("hivecommons/hive", 15087, "ccc3333", now)
- applyRebaseAttempts(items)
+ applyRebaseAttempts(items, now)
if r := items[0].Rebase; r == nil || !r.Exhausted || r.Attempt != 2 || r.Text != "Rebase failed · 2/2 — needs a person" {
t.Fatalf("exhausted pill = %+v", r)
}
@@ -299,7 +305,7 @@ func TestRepoItemDecisionApproveOnDirtyPRQueuesRebase(t *testing.T) {
t.Fatalf("a dirty head gets no update-branch: %d", mock.updates)
}
items := []StageTrackerItem{{Repo: "testorg/testrepo", Number: 8, Kind: "pr", Stage: 85}}
- applyRebaseAttempts(items)
+ applyRebaseAttempts(items, time.Now())
if items[0].Rebase == nil || items[0].Rebase.Text != "Rebasing · attempt 1/2" {
t.Fatalf("row = %+v", items[0].Rebase)
}
diff --git a/src/pkg/dashboard/stage_tracker_build.go b/src/pkg/dashboard/stage_tracker_build.go
index a77175f644..58eca5d6d9 100644
--- a/src/pkg/dashboard/stage_tracker_build.go
+++ b/src/pkg/dashboard/stage_tracker_build.go
@@ -490,7 +490,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
resp.Items = stageTrackerDropOperatorClosed(resp.Items, now, operatorActionClosedGrace())
resp.OpenIssues, resp.OpenPRs = stageTrackerOpenCounts(resp.Items)
s.applyDecidedProjection(resp.Items, now)
- applyRebaseAttempts(resp.Items)
+ applyRebaseAttempts(resp.Items, now)
s.applyRebaseMergeFollowThrough(resp.Items, now)
resp.NeedsHuman, resp.OnHold = stageTrackerHumanCounts(resp.Items)
resp.WaitingOnHuman = stageTrackerWaitingOnHuman(resp.Items)
diff --git a/src/pkg/dashboard/static-src/js/config-governor.js b/src/pkg/dashboard/static-src/js/config-governor.js
index 1d469f99d6..d24ca31645 100644
--- a/src/pkg/dashboard/static-src/js/config-governor.js
+++ b/src/pkg/dashboard/static-src/js/config-governor.js
@@ -799,7 +799,7 @@
-
Go duration after the comment-only nudge before an offline or external author's red PR is adopted. With live hub presence the hive instead waits ${yamlHint('governor.labels.stage.adoption.after_offline')} (default 30m) after a registered relay's last heartbeat, or ${yamlHint('governor.labels.stage.adoption.after_unregistered')} (default 2h) for an author with no profile here, and adopts in place on the PR's own branch when GitHub permits ${yamlHint('governor.labels.stage.adoption.in_place')} (default on) rather than opening a superseding PR. An in-place adoption keeps a changed head only when GitHub links the commit to the App bot ${yamlHint('governor.labels.stage.adoption.strict_attribution')} (default on); otherwise the hive hands the PR back to the contributor. Once the hive owns the head, the contributor lane merges it under the hive's own authority when the hive-authored gates pass (CI green on the adopted head, reviewer verdict, DCO, diff fences, soak), without requiring the original author's trust tier ${yamlHint('governor.labels.stage.adoption.auto_merge')} (default on). When the hive supersedes instead, it closes the original in the same pass that opens its copy — one note naming the copy, hive/superseded — and reopens it if the copy is closed unmerged or red at two heads ${yamlHint('governor.labels.stage.adoption.supersede.close_first')} (default on; off keeps the original open at stage 074 until the copy merges). A clanker- or hive-authored original closes in that pass by policy even without the repo's write-back opt-in label, since the copy carries its commits and sign-off ${yamlHint('governor.labels.stage.adoption.close_superseded')} (default on_adopt; on_merge waits for the copy to merge; a person's PR always waits unless the label is present). A copy that conflicts with the base is handed to the fixer's rebase-resolve episode (two attempts, then stage 085 rebase-failed-twice); an adoption attempt that opened nothing is retried once the author's clanker has stayed offline for ${yamlHint('governor.labels.stage.adoption.offline_grace')} (default 30m).
+
Go duration after the comment-only nudge before an offline or external author's red PR is adopted. With live hub presence the hive instead waits ${yamlHint('governor.labels.stage.adoption.after_offline')} (default 30m) after a registered relay's last heartbeat, or ${yamlHint('governor.labels.stage.adoption.after_unregistered')} (default 2h) for an author with no profile here, and adopts in place on the PR's own branch when GitHub permits ${yamlHint('governor.labels.stage.adoption.in_place')} (default on) rather than opening a superseding PR. An in-place adoption keeps a changed head only when GitHub links the commit to the App bot ${yamlHint('governor.labels.stage.adoption.strict_attribution')} (default on); otherwise the hive hands the PR back to the contributor. Once the hive owns the head, the contributor lane merges it under the hive's own authority when the hive-authored gates pass (CI green on the adopted head, reviewer verdict, DCO, diff fences, soak), without requiring the original author's trust tier ${yamlHint('governor.labels.stage.adoption.auto_merge')} (default on). When the hive supersedes instead, it closes the original in the same pass that opens its copy — one note naming the copy, hive/superseded — and reopens it if the copy is closed unmerged or red at two heads ${yamlHint('governor.labels.stage.adoption.supersede.close_first')} (default on; off keeps the original open at stage 074 until the copy merges). A clanker- or hive-authored original closes in that pass by policy even without the repo's write-back opt-in label, since the copy carries its commits and sign-off ${yamlHint('governor.labels.stage.adoption.close_superseded')} (default on_adopt; on_merge waits for the copy to merge; a person's PR always waits unless the label is present). A copy that conflicts with the base is handed to the fixer's rebase-resolve episode (two attempts, then stage 085 rebase-failed-twice); each fixer rebase attempt that sees no push within ${yamlHint('governor.labels.stage.adoption.rebase_attempt_timeout')} (default 15m) counts as failed, and an in-place adoption whose attempts are spent re-homes to a superseding PR at once; an adoption attempt that opened nothing is retried once the author's clanker has stayed offline for ${yamlHint('governor.labels.stage.adoption.offline_grace')} (default 30m).
${renderReporterTrustBlock()}
Writing guide
diff --git a/src/pkg/dashboard/static-src/js/config-state.js b/src/pkg/dashboard/static-src/js/config-state.js
index 5dbbc34a06..433f6e0fb1 100644
--- a/src/pkg/dashboard/static-src/js/config-state.js
+++ b/src/pkg/dashboard/static-src/js/config-state.js
@@ -81,7 +81,7 @@
{ tab: 'Labels', section: 'Labels', label: 'Stage dwell overrides', key: 'governor.labels.stage.dwell', text: 'stage dwell stalled threshold governor.labels.stage.dwell' },
{ tab: 'Labels', section: 'Labels', label: 'Adoption of a maintainer\'s PR', key: 'governor.labels.stage.adoption.maintainer_policy', text: 'adoption maintainer policy adopt ask never maintainer own pr clanker disconnected offline adopt action governor.labels.stage.adoption.maintainer_policy' },
{ tab: 'Labels', section: 'Labels', label: 'Contributor nudge', key: 'governor.labels.stage.contributor_nudge.enabled', text: 'contributor nudge returned-to-contributor red ci fix-pr relay interrupt renudge presence window governor.labels.stage.contributor_nudge.enabled governor.labels.stage.contributor_nudge.renudge_interval governor.labels.stage.presence_window' },
- { tab: 'Labels', section: 'Labels', label: 'Adopt red contributor PRs', key: 'governor.labels.stage.adoption.enabled', text: 'adoption adopted-by-hive stage 074 red contributor pr grace online offline supersede takeover in place after offline unregistered heartbeat governor.labels.stage.adoption.enabled governor.labels.stage.contributor_grace_online governor.labels.stage.contributor_grace_offline governor.labels.stage.adoption.after_offline governor.labels.stage.adoption.after_unregistered governor.labels.stage.adoption.in_place governor.labels.stage.adoption.strict_attribution strict attribution governor.labels.stage.adoption.auto_merge auto merge adopted head hive authority governor.labels.stage.adoption.supersede.close_first close first superseded reopen copy failed governor.labels.stage.adoption.close_superseded close superseded on adopt on merge clanker authored opt-in label governor.labels.stage.adoption.offline_grace offline grace rebase failed twice fixer resolving conflicts' },
+ { tab: 'Labels', section: 'Labels', label: 'Adopt red contributor PRs', key: 'governor.labels.stage.adoption.enabled', text: 'adoption adopted-by-hive stage 074 red contributor pr grace online offline supersede takeover in place after offline unregistered heartbeat governor.labels.stage.adoption.enabled governor.labels.stage.contributor_grace_online governor.labels.stage.contributor_grace_offline governor.labels.stage.adoption.after_offline governor.labels.stage.adoption.after_unregistered governor.labels.stage.adoption.in_place governor.labels.stage.adoption.strict_attribution strict attribution governor.labels.stage.adoption.auto_merge auto merge adopted head hive authority governor.labels.stage.adoption.supersede.close_first close first superseded reopen copy failed governor.labels.stage.adoption.close_superseded close superseded on adopt on merge clanker authored opt-in label governor.labels.stage.adoption.offline_grace offline grace rebase failed twice fixer resolving conflicts governor.labels.stage.adoption.rebase_attempt_timeout rebase attempt timeout' },
{ tab: 'Hub', section: 'Contributor Relay', label: 'Fix budget', key: 'contribute.max_parallel_fixes', text: 'fix budget parallel fixes focus window red pr fix-pr preempt spawn contribute.max_parallel_fixes contribute.min_focus_window' },
{ tab: 'Logging', section: 'Logging', label: 'Governor logging', key: 'governor.logging.max_size_mb', text: 'governor logging directory level compression max size age backups governor.logging.compress governor.logging.dir governor.logging.level governor.logging.max_age_days governor.logging.max_backups governor.logging.max_size_mb' },
{ tab: 'Advisory', section: 'Advisory', label: 'Advisory digest', key: 'governor.advisory.max_findings', text: 'advisory digest max findings show all staleness pr autoclose target linear issue retry backoff' },
diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html
index 02b1f175c6..cb3636afb3 100644
--- a/src/pkg/dashboard/static/index.html
+++ b/src/pkg/dashboard/static/index.html
@@ -50248,7 +50248,7 @@
Configure LiteLLM
{ tab: 'Labels', section: 'Labels', label: 'Stage dwell overrides', key: 'governor.labels.stage.dwell', text: 'stage dwell stalled threshold governor.labels.stage.dwell' },
{ tab: 'Labels', section: 'Labels', label: 'Adoption of a maintainer\'s PR', key: 'governor.labels.stage.adoption.maintainer_policy', text: 'adoption maintainer policy adopt ask never maintainer own pr clanker disconnected offline adopt action governor.labels.stage.adoption.maintainer_policy' },
{ tab: 'Labels', section: 'Labels', label: 'Contributor nudge', key: 'governor.labels.stage.contributor_nudge.enabled', text: 'contributor nudge returned-to-contributor red ci fix-pr relay interrupt renudge presence window governor.labels.stage.contributor_nudge.enabled governor.labels.stage.contributor_nudge.renudge_interval governor.labels.stage.presence_window' },
- { tab: 'Labels', section: 'Labels', label: 'Adopt red contributor PRs', key: 'governor.labels.stage.adoption.enabled', text: 'adoption adopted-by-hive stage 074 red contributor pr grace online offline supersede takeover in place after offline unregistered heartbeat governor.labels.stage.adoption.enabled governor.labels.stage.contributor_grace_online governor.labels.stage.contributor_grace_offline governor.labels.stage.adoption.after_offline governor.labels.stage.adoption.after_unregistered governor.labels.stage.adoption.in_place governor.labels.stage.adoption.strict_attribution strict attribution governor.labels.stage.adoption.auto_merge auto merge adopted head hive authority governor.labels.stage.adoption.supersede.close_first close first superseded reopen copy failed governor.labels.stage.adoption.close_superseded close superseded on adopt on merge clanker authored opt-in label governor.labels.stage.adoption.offline_grace offline grace rebase failed twice fixer resolving conflicts' },
+ { tab: 'Labels', section: 'Labels', label: 'Adopt red contributor PRs', key: 'governor.labels.stage.adoption.enabled', text: 'adoption adopted-by-hive stage 074 red contributor pr grace online offline supersede takeover in place after offline unregistered heartbeat governor.labels.stage.adoption.enabled governor.labels.stage.contributor_grace_online governor.labels.stage.contributor_grace_offline governor.labels.stage.adoption.after_offline governor.labels.stage.adoption.after_unregistered governor.labels.stage.adoption.in_place governor.labels.stage.adoption.strict_attribution strict attribution governor.labels.stage.adoption.auto_merge auto merge adopted head hive authority governor.labels.stage.adoption.supersede.close_first close first superseded reopen copy failed governor.labels.stage.adoption.close_superseded close superseded on adopt on merge clanker authored opt-in label governor.labels.stage.adoption.offline_grace offline grace rebase failed twice fixer resolving conflicts governor.labels.stage.adoption.rebase_attempt_timeout rebase attempt timeout' },
{ tab: 'Hub', section: 'Contributor Relay', label: 'Fix budget', key: 'contribute.max_parallel_fixes', text: 'fix budget parallel fixes focus window red pr fix-pr preempt spawn contribute.max_parallel_fixes contribute.min_focus_window' },
{ tab: 'Logging', section: 'Logging', label: 'Governor logging', key: 'governor.logging.max_size_mb', text: 'governor logging directory level compression max size age backups governor.logging.compress governor.logging.dir governor.logging.level governor.logging.max_age_days governor.logging.max_backups governor.logging.max_size_mb' },
{ tab: 'Advisory', section: 'Advisory', label: 'Advisory digest', key: 'governor.advisory.max_findings', text: 'advisory digest max findings show all staleness pr autoclose target linear issue retry backoff' },
@@ -57127,7 +57127,7 @@
Stage labels
-
Go duration after the comment-only nudge before an offline or external author's red PR is adopted. With live hub presence the hive instead waits ${yamlHint('governor.labels.stage.adoption.after_offline')} (default 30m) after a registered relay's last heartbeat, or ${yamlHint('governor.labels.stage.adoption.after_unregistered')} (default 2h) for an author with no profile here, and adopts in place on the PR's own branch when GitHub permits ${yamlHint('governor.labels.stage.adoption.in_place')} (default on) rather than opening a superseding PR. An in-place adoption keeps a changed head only when GitHub links the commit to the App bot ${yamlHint('governor.labels.stage.adoption.strict_attribution')} (default on); otherwise the hive hands the PR back to the contributor. Once the hive owns the head, the contributor lane merges it under the hive's own authority when the hive-authored gates pass (CI green on the adopted head, reviewer verdict, DCO, diff fences, soak), without requiring the original author's trust tier ${yamlHint('governor.labels.stage.adoption.auto_merge')} (default on). When the hive supersedes instead, it closes the original in the same pass that opens its copy — one note naming the copy, hive/superseded — and reopens it if the copy is closed unmerged or red at two heads ${yamlHint('governor.labels.stage.adoption.supersede.close_first')} (default on; off keeps the original open at stage 074 until the copy merges). A clanker- or hive-authored original closes in that pass by policy even without the repo's write-back opt-in label, since the copy carries its commits and sign-off ${yamlHint('governor.labels.stage.adoption.close_superseded')} (default on_adopt; on_merge waits for the copy to merge; a person's PR always waits unless the label is present). A copy that conflicts with the base is handed to the fixer's rebase-resolve episode (two attempts, then stage 085 rebase-failed-twice); an adoption attempt that opened nothing is retried once the author's clanker has stayed offline for ${yamlHint('governor.labels.stage.adoption.offline_grace')} (default 30m).
+
Go duration after the comment-only nudge before an offline or external author's red PR is adopted. With live hub presence the hive instead waits ${yamlHint('governor.labels.stage.adoption.after_offline')} (default 30m) after a registered relay's last heartbeat, or ${yamlHint('governor.labels.stage.adoption.after_unregistered')} (default 2h) for an author with no profile here, and adopts in place on the PR's own branch when GitHub permits ${yamlHint('governor.labels.stage.adoption.in_place')} (default on) rather than opening a superseding PR. An in-place adoption keeps a changed head only when GitHub links the commit to the App bot ${yamlHint('governor.labels.stage.adoption.strict_attribution')} (default on); otherwise the hive hands the PR back to the contributor. Once the hive owns the head, the contributor lane merges it under the hive's own authority when the hive-authored gates pass (CI green on the adopted head, reviewer verdict, DCO, diff fences, soak), without requiring the original author's trust tier ${yamlHint('governor.labels.stage.adoption.auto_merge')} (default on). When the hive supersedes instead, it closes the original in the same pass that opens its copy — one note naming the copy, hive/superseded — and reopens it if the copy is closed unmerged or red at two heads ${yamlHint('governor.labels.stage.adoption.supersede.close_first')} (default on; off keeps the original open at stage 074 until the copy merges). A clanker- or hive-authored original closes in that pass by policy even without the repo's write-back opt-in label, since the copy carries its commits and sign-off ${yamlHint('governor.labels.stage.adoption.close_superseded')} (default on_adopt; on_merge waits for the copy to merge; a person's PR always waits unless the label is present). A copy that conflicts with the base is handed to the fixer's rebase-resolve episode (two attempts, then stage 085 rebase-failed-twice); each fixer rebase attempt that sees no push within ${yamlHint('governor.labels.stage.adoption.rebase_attempt_timeout')} (default 15m) counts as failed, and an in-place adoption whose attempts are spent re-homes to a superseding PR at once; an adoption attempt that opened nothing is retried once the author's clanker has stayed offline for ${yamlHint('governor.labels.stage.adoption.offline_grace')} (default 30m).
${renderReporterTrustBlock()}
Writing guide
diff --git a/src/pkg/github/automerge/automerge_adoption_escape_test.go b/src/pkg/github/automerge/automerge_adoption_escape_test.go
index 6e6da71e6f..1a61b222c5 100644
--- a/src/pkg/github/automerge/automerge_adoption_escape_test.go
+++ b/src/pkg/github/automerge/automerge_adoption_escape_test.go
@@ -302,7 +302,7 @@ func TestAdoptionEscapeHelpers(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
- if got := inPlaceRehomeReason(tc.obs, tc.rec, policy, tc.at); got != tc.wantRehome {
+ if got := inPlaceRehomeReason(tc.obs, tc.rec, policy, tc.at, false); got != tc.wantRehome {
t.Fatalf("inPlaceRehomeReason=%q, want %q", got, tc.wantRehome)
}
if got := adoptionStalledReason(tc.obs, tc.rec, policy, tc.at); got != tc.wantStall {
@@ -312,6 +312,65 @@ func TestAdoptionEscapeHelpers(t *testing.T) {
}
}
+// hivecommons/hive#16023: an in-place adoption whose fixer rebase episode
+// is exhausted re-homes to a superseding PR at once instead of waiting out
+// the 074 dwell; a live episode, a non-conflicting head or a moved head
+// does not.
+func TestInPlaceRehomeOnExhaustedRebaseEpisode(t *testing.T) {
+ policy := adoptPolicy()
+ now := time.Date(2026, 10, 31, 9, 0, 0, 0, time.UTC)
+ inPlace := stagelabels.Record{AdoptedHead: "aaa", AdoptMode: stagelabels.AdoptModeInPlace, AdoptedAt: now, AdoptedHeadAt: now}
+ conflict := stageObservation{Owner: "acme", Repo: "widget", Number: 7, HeadSHA: "aaa", Reason: "conflicting", LaneReason: "conflicting", Labels: []string{"needs-rebase"}}
+ red := stageObservation{Owner: "acme", Repo: "widget", Number: 7, HeadSHA: "aaa", Reason: "check-failing:unit", LaneReason: "check-failing:unit"}
+ moved := conflict
+ moved.HeadSHA = "bbb"
+ at := now.Add(30 * time.Minute)
+ tests := []struct {
+ name string
+ obs stageObservation
+ exhausted bool
+ want string
+ }{
+ {"exhausted conflict re-homes before the dwell", conflict, true, AdoptReasonRebaseRehome},
+ {"live episode waits for the dwell", conflict, false, ""},
+ {"exhausted but not conflicting stays", red, true, ""},
+ {"exhausted on a moved head stays", moved, true, ""},
+ }
+ for _, tc := range tests {
+ t.Run(tc.name, func(t *testing.T) {
+ if got := inPlaceRehomeReason(tc.obs, inPlace, policy, at, tc.exhausted); got != tc.want {
+ t.Fatalf("inPlaceRehomeReason=%q, want %q", got, tc.want)
+ }
+ })
+ }
+ if got := inPlaceRehomeReason(conflict, inPlace, policy, now.Add(adoptedDwell), false); got != AdoptReasonRebaseRehome {
+ t.Fatalf("dwell path still re-homes: %q", got)
+ }
+
+ episodes := map[int]RebaseEpisode{7: {Attempt: 3, MaxAttempts: 2, Exhausted: true}, 8: {Attempt: 1, MaxAttempts: 2}}
+ e := &Engine{rebaseEpisode: func(repo string, number int) (RebaseEpisode, bool) {
+ if repo != "acme/widget" {
+ return RebaseEpisode{}, false
+ }
+ ep, ok := episodes[number]
+ return ep, ok
+ }}
+ live := conflict
+ live.Number = 8
+ none := conflict
+ none.Number = 9
+ supersede := stagelabels.Record{AdoptedHead: "aaa", AdoptMode: stagelabels.AdoptModeSupersede, AdoptedBy: 90, AdoptedAt: now}
+ if !e.inPlaceRebaseExhausted(conflict, inPlace) {
+ t.Fatal("exhausted episode on the in-place adoption not reported")
+ }
+ if e.inPlaceRebaseExhausted(live, inPlace) || e.inPlaceRebaseExhausted(none, inPlace) || e.inPlaceRebaseExhausted(conflict, supersede) {
+ t.Fatal("live, missing or supersede-mode episode reported exhausted")
+ }
+ if (&Engine{}).inPlaceRebaseExhausted(conflict, inPlace) {
+ t.Fatal("no episode reader reports exhausted")
+ }
+}
+
func TestAdoptionBodyCauseAndBlockerText(t *testing.T) {
for reason, want := range map[string]string{
AdoptReasonOffline: "adopted after CI went red",
diff --git a/src/pkg/github/automerge/automerge_contributor_adopt.go b/src/pkg/github/automerge/automerge_contributor_adopt.go
index 6198c0424a..b508953c34 100644
--- a/src/pkg/github/automerge/automerge_contributor_adopt.go
+++ b/src/pkg/github/automerge/automerge_contributor_adopt.go
@@ -1152,6 +1152,17 @@ func (c *Engine) adoptionCopyRebaseFailedTwice(obs stageObservation) bool {
return ok && ep.Exhausted
}
+// inPlaceRebaseExhausted reports whether the fixer's rebase-resolve episode
+// on this in-place adoption used every attempt without the head reading
+// mergeable (hivecommons/hive#16023).
+func (c *Engine) inPlaceRebaseExhausted(obs stageObservation, rec stagelabels.Record) bool {
+ if c.rebaseEpisode == nil || !rec.AdoptedInPlace() {
+ return false
+ }
+ ep, ok := c.rebaseEpisode(obs.Owner+"/"+obs.Repo, obs.Number)
+ return ok && ep.Exhausted
+}
+
// priorCopyInputs keys a claim by the closed copy it follows, so a
// re-adoption is not answered by the first adoption's journal entry.
func priorCopyInputs(prior int, inputs map[string]string) map[string]string {
@@ -1926,8 +1937,11 @@ func adoptedHeadSignoffUnfixable(obs stageObservation, rec stagelabels.Record) b
// supersession this sweep, or "" to stay in place. A DCO-red head is left to
// settleAdoption's DCO re-home, which carries the repair instructions. A
// squash-unsafe hive sign-off re-homes immediately; rebase work first gets
-// the normal fixer window on the contributor branch.
-func inPlaceRehomeReason(obs stageObservation, rec stagelabels.Record, policy StageLabelPolicy, now time.Time) string {
+// the normal fixer window on the contributor branch, which ends at the 074
+// dwell or as soon as the fixer's rebase-resolve episode on the adopted PR
+// is exhausted (rebaseExhausted: every attempt pushed a dirty head or timed
+// out with no push; hivecommons/hive#16023).
+func inPlaceRehomeReason(obs stageObservation, rec stagelabels.Record, policy StageLabelPolicy, now time.Time, rebaseExhausted bool) string {
if !rec.AdoptedInPlace() || obs.HeadSHA == "" || obs.HeadSHA != rec.AdoptedHead || adoptedHeadDCORed(obs, rec) || adoptionBlocked(obs.Labels) != "" || verdictNeedsHuman(obs.Detail) {
return ""
}
@@ -1935,7 +1949,7 @@ func inPlaceRehomeReason(obs stageObservation, rec stagelabels.Record, policy St
return AdoptReasonSignoffRehome
}
if humanConflictReasons[obs.Reason] || humanConflictReasons[obs.LaneReason] || hasLabelFold(obs.Labels, "needs-rebase") {
- if adoptionStale(obs, rec, policy, now) {
+ if rebaseExhausted || adoptionStale(obs, rec, policy, now) {
return AdoptReasonRebaseRehome
}
}
@@ -1996,7 +2010,7 @@ func (c *Engine) escapeStalledAdoption(ctx context.Context, store *stagelabels.S
c.info("stage labels: adopted head had no clock; starting the 074 dwell from this sweep", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "adopted_at", rec.AdoptedAt)
rec, _ = store.Get(key)
}
- rehomeReason := inPlaceRehomeReason(obs, rec, policy, now)
+ rehomeReason := inPlaceRehomeReason(obs, rec, policy, now, c.inPlaceRebaseExhausted(obs, rec))
if rehomeReason == "" && rec.AdoptedInPlace() && obs.HeadSHA == rec.AdoptedHead && !adoptedHeadDCORed(obs, rec) && adoptionBlocked(obs.Labels) == "" && !verdictNeedsHuman(obs.Detail) && c.pushAccessLost(ctx, obs) {
rehomeReason = AdoptReasonPushRehome
}
diff --git a/src/pkg/rebasemerge/attempts.go b/src/pkg/rebasemerge/attempts.go
index 6568b20688..8042f170e3 100644
--- a/src/pkg/rebasemerge/attempts.go
+++ b/src/pkg/rebasemerge/attempts.go
@@ -22,13 +22,23 @@ var AttemptsPath = "/data/rebase-attempts.json"
// Attempt is one PR's conflict episode: the dirty heads seen, oldest
// first. The first dirty head is attempt 1 (the fixer's first task); a
-// pushed head that is still dirty is the next attempt; past
-// MaxRebaseAttempts dirty heads the episode is exhausted. A PR that stops
-// conflicting ends its episode (Clear) so a later conflict starts fresh.
+// pushed head that is still dirty is the next attempt, and so is an
+// attempt the fixer never pushed for within the per-attempt deadline
+// (Expire; hivecommons/hive#16023). Past MaxRebaseAttempts the episode is
+// exhausted. A PR that stops conflicting ends its episode (Clear) so a
+// later conflict starts fresh.
type Attempt struct {
Repo string `json:"repo"`
Number int `json:"number"`
Heads []string `json:"heads"`
+ // Stalled counts attempts that timed out with no push from the fixer;
+ // each one is a failed attempt.
+ Stalled int `json:"stalled,omitempty"`
+ // DispatchedAttempt is the attempt the router last handed to Fixer,
+ // at DispatchedAt; the router announces an attempt once.
+ DispatchedAttempt int `json:"dispatched_attempt,omitempty"`
+ DispatchedAt time.Time `json:"dispatched_at,omitempty"`
+ Fixer string `json:"fixer,omitempty"`
// RequestedBy is the operator whose approval (or merge-now) asked for
// the rebase from the dashboard, so the fixer router lists the PR even
// when neither the hive nor a trusted author opened it.
@@ -37,11 +47,26 @@ type Attempt struct {
UpdatedAt time.Time `json:"updated_at"`
}
-// Count is the attempt number the current head represents (1-based).
-func (a Attempt) Count() int { return len(a.Heads) }
+// Count is the current attempt number (1-based): dirty heads seen plus
+// attempts that timed out waiting for the fixer.
+func (a Attempt) Count() int { return len(a.Heads) + a.Stalled }
-// Exhausted: more dirty heads than the cap allows rebases.
-func (a Attempt) Exhausted() bool { return len(a.Heads) > MaxRebaseAttempts }
+// Exhausted: more attempts than the cap allows rebases.
+func (a Attempt) Exhausted() bool { return a.Count() > MaxRebaseAttempts }
+
+// Dispatched reports whether the current attempt was handed to a fixer.
+func (a Attempt) Dispatched() bool {
+ return a.DispatchedAttempt > 0 && a.DispatchedAttempt == a.Count() && !a.DispatchedAt.IsZero()
+}
+
+// Waiting is how long the current attempt has waited for the fixer's
+// push since it was dispatched; 0 when it was not dispatched.
+func (a Attempt) Waiting(now time.Time) time.Duration {
+ if !a.Dispatched() || now.Before(a.DispatchedAt) {
+ return 0
+ }
+ return now.Sub(a.DispatchedAt)
+}
// Head is the newest dirty head seen.
func (a Attempt) Head() string {
@@ -157,6 +182,48 @@ func (s *Attempts) Request(repo string, number int, head, actor string, now time
return a
}
+// Dispatch records that the current attempt of repo#number's open episode
+// was routed to fixer. first is true only the first time an attempt is
+// dispatched, so the router announces each attempt once and later sweeps
+// keep the original dispatch time.
+func (s *Attempts) Dispatch(repo string, number int, fixer string, now time.Time) (a Attempt, first bool) {
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ s.load()
+ key := Key(repo, number)
+ a, ok := s.items[key]
+ if !ok || a.Exhausted() || a.Dispatched() {
+ return a, false
+ }
+ a.DispatchedAttempt = a.Count()
+ a.DispatchedAt = now
+ a.Fixer = strings.TrimSpace(fixer)
+ a.UpdatedAt = now
+ s.items[key] = a
+ s.persist()
+ return a, true
+}
+
+// Expire counts the dispatched attempt of repo#number as failed once it
+// has waited timeout with no push from the fixer (a push is a new head,
+// which Observe already counts as the next attempt). advanced is true when
+// the episode moved to its next attempt; a timeout <= 0 never expires.
+func (s *Attempts) Expire(repo string, number int, timeout time.Duration, now time.Time) (a Attempt, advanced bool) {
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ s.load()
+ key := Key(repo, number)
+ a, ok := s.items[key]
+ if !ok || timeout <= 0 || a.Exhausted() || !a.Dispatched() || now.Sub(a.DispatchedAt) < timeout {
+ return a, false
+ }
+ a.Stalled++
+ a.UpdatedAt = now
+ s.items[key] = a
+ s.persist()
+ return a, true
+}
+
// Get returns the episode for repo#number, if one is open.
func (s *Attempts) Get(repo string, number int) (Attempt, bool) {
s.mu.Lock()
@@ -192,3 +259,25 @@ func AttemptText(a Attempt) string {
}
return "Rebasing · attempt " + strconv.Itoa(n) + "/" + strconv.Itoa(MaxRebaseAttempts)
}
+
+// AttemptTextAt is AttemptText with the wait on a dispatched attempt:
+// "Rebasing · attempt 1/2 · waiting for scanner 12m".
+func AttemptTextAt(a Attempt, now time.Time) string {
+ text := AttemptText(a)
+ if a.Exhausted() || !a.Dispatched() {
+ return text
+ }
+ fixer := a.Fixer
+ if fixer == "" {
+ fixer = "the fixer"
+ }
+ return text + " · waiting for " + fixer + " " + waitingText(a.Waiting(now))
+}
+
+func waitingText(d time.Duration) string {
+ m := int(d / time.Minute)
+ if m < 1 {
+ return "<1m"
+ }
+ return strconv.Itoa(m) + "m"
+}
diff --git a/src/pkg/rebasemerge/rebasemerge_test.go b/src/pkg/rebasemerge/rebasemerge_test.go
index 91bfe644de..83dc28bfeb 100644
--- a/src/pkg/rebasemerge/rebasemerge_test.go
+++ b/src/pkg/rebasemerge/rebasemerge_test.go
@@ -211,6 +211,78 @@ func TestAttemptsLoopGuard(t *testing.T) {
}
}
+// hivecommons/hive#16023: a dispatched attempt the fixer never pushes for
+// counts as failed past the deadline, so the episode advances (and is
+// exhausted) without a new dirty head; each attempt is dispatched once.
+func TestAttemptsExpireAdvancesStalledAttempt(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "attempts.json")
+ s := NewAttempts(path)
+ now := time.Date(2026, 10, 31, 9, 0, 0, 0, time.UTC)
+ const timeout = 15 * time.Minute
+ s.Observe("o/r", 1, "aaa", now)
+ if _, ok := s.Expire("o/r", 1, timeout, now.Add(time.Hour)); ok {
+ t.Fatal("an attempt never dispatched must not expire")
+ }
+ a, first := s.Dispatch("o/r", 1, "scanner", now)
+ if !first || !a.Dispatched() || a.Fixer != "scanner" || a.DispatchedAttempt != 1 {
+ t.Fatalf("first dispatch: %+v first=%v", a, first)
+ }
+ if a, first = s.Dispatch("o/r", 1, "scanner", now.Add(5*time.Minute)); first || !a.DispatchedAt.Equal(now) {
+ t.Fatalf("re-dispatch of the same attempt: %+v first=%v", a, first)
+ }
+ if got := AttemptTextAt(a, now.Add(12*time.Minute)); got != "Rebasing · attempt 1/2 · waiting for scanner 12m" {
+ t.Fatalf("caption: %q", got)
+ }
+ if got := AttemptTextAt(a, now.Add(30*time.Second)); got != "Rebasing · attempt 1/2 · waiting for scanner <1m" {
+ t.Fatalf("fresh caption: %q", got)
+ }
+ if _, ok := s.Expire("o/r", 1, timeout, now.Add(14*time.Minute)); ok {
+ t.Fatal("expired before the deadline")
+ }
+ if _, ok := s.Expire("o/r", 1, 0, now.Add(time.Hour)); ok {
+ t.Fatal("a zero timeout must never expire")
+ }
+ a, ok := s.Expire("o/r", 1, timeout, now.Add(timeout))
+ if !ok || a.Count() != 2 || a.Stalled != 1 || a.Exhausted() || a.Dispatched() || a.Head() != "aaa" {
+ t.Fatalf("timed-out attempt 1: %+v ok=%v", a, ok)
+ }
+ if got := AttemptTextAt(a, now.Add(timeout)); got != "Rebasing · attempt 2/2" {
+ t.Fatalf("undispatched attempt 2 caption: %q", got)
+ }
+ if a, first = s.Dispatch("o/r", 1, "", now.Add(timeout)); !first || a.DispatchedAttempt != 2 {
+ t.Fatalf("attempt 2 dispatch: %+v first=%v", a, first)
+ }
+ if got := AttemptTextAt(a, now.Add(timeout+3*time.Minute)); got != "Rebasing · attempt 2/2 · waiting for the fixer 3m" {
+ t.Fatalf("no-fixer caption: %q", got)
+ }
+ a, ok = s.Expire("o/r", 1, timeout, now.Add(2*timeout))
+ if !ok || !a.Exhausted() || AttemptTextAt(a, now.Add(2*timeout)) != "Rebase failed · 2/2 — needs a person" {
+ t.Fatalf("timed-out attempt 2: %+v ok=%v", a, ok)
+ }
+ if _, first = s.Dispatch("o/r", 1, "scanner", now.Add(2*timeout)); first {
+ t.Fatal("an exhausted episode must not be dispatched")
+ }
+ if _, ok = s.Expire("o/r", 1, timeout, now.Add(3*timeout)); ok {
+ t.Fatal("an exhausted episode must not expire again")
+ }
+ if got, ok := NewAttempts(path).Get("o/r", 1); !ok || got.Stalled != 2 || !got.Exhausted() {
+ t.Fatalf("reload: %+v ok=%v", got, ok)
+ }
+ // A push (new dirty head) is the next attempt and needs a fresh dispatch.
+ s.Clear("o/r", 1)
+ s.Observe("o/r", 1, "bbb", now)
+ s.Dispatch("o/r", 1, "scanner", now)
+ if a = s.Observe("o/r", 1, "ccc", now.Add(5*time.Minute)); a.Count() != 2 || a.Dispatched() {
+ t.Fatalf("pushed head: %+v", a)
+ }
+ if _, ok = s.Expire("o/r", 1, timeout, now.Add(time.Hour)); ok {
+ t.Fatal("a pushed attempt not yet dispatched must not expire")
+ }
+ if _, first = s.Dispatch("o/r", 9, "scanner", now); first {
+ t.Fatal("dispatch without an episode")
+ }
+}
+
// Request opens the episode on an operator's behalf (approve / merge-now on
// a dirty PR): the actor is recorded once, a blank actor records nothing,
// and the request rides the same head count as the sweep's Observe.
From 1a69ac24b9dc2e6eb4062d4e50155f8bdbf2887d Mon Sep 17 00:00:00 2001
From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
Date: Sat, 31 Oct 2026 08:04:40 -0400
Subject: [PATCH 2/2] test(config): add rebase_attempt_timeout to agent-runtime
golden
The new governor.labels.stage.adoption.rebase_attempt_timeout key made
TestAgentRuntimeConfigGolden report the field as unexpected; pin its
empty default in the golden JSON.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
---
src/pkg/config/testdata/agent_runtime_golden.json | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/pkg/config/testdata/agent_runtime_golden.json b/src/pkg/config/testdata/agent_runtime_golden.json
index 5ee4c4fb08..6c829f2337 100644
--- a/src/pkg/config/testdata/agent_runtime_golden.json
+++ b/src/pkg/config/testdata/agent_runtime_golden.json
@@ -203,6 +203,7 @@
"AfterOffline": "",
"AfterUnregistered": "",
"OfflineGrace": "",
+ "RebaseAttemptTimeout": "",
"InPlace": null,
"StrictAttribution": null,
"AutoMerge": null,