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-auto-adopt-offer-predicate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Adoption of a stuck contributor-clanker PR is automatic: the predicate that makes the activity monitor offer Adopt (`automerge.AutoAdoption`) is the sweep's trigger, so a PR at 072 whose author is offline past the grace (one heartbeat buys one window, `mode=queued` nudges count as offline) is adopted by hive on that sweep for conflicts, requested changes, failing required or optional checks and `fork-not-editable` forks; the row says when (`hive adopts it in 3m unless a new head lands`), names the fork blocker, and the log carries the trigger. Adopt now stays as the override.
35 changes: 35 additions & 0 deletions src/docs/labels-and-control-signals.md
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,41 @@ When a contributor-agent PR goes red the hive does not just relabel it (a human-
base tip β€” is updated from the base when behind, or has its failed
jobs re-run when current, once per (head, base tip), before the dwell
escalates it to 085 (hivecommons/hive#14500).
**When hive adopts automatically.** One predicate β€”
`automerge.AutoAdoption` β€” answers both "may the activity monitor offer
Adopt / say when hive adopts" and "does this sweep adopt". Whenever the
tracker would say `hive adopts it on the next sweep`, that sweep does it;
no click is needed (owner rule, 2026-10-29 on hivecommons/hive#15565,
#15566, #15609 and #15312: PRs by an offline clanker sat at 072 with
"waiting on @author (offline 13m, 1 nudge)" until a person pressed
Adopt, while the sweep's own clock ran from a later heartbeat). The hive
adopts an `author/clanker` PR on its own when **all** of these hold:
- the PR is at 072 with work its author's clanker is not doing: a
conflict with the base, changes requested by the review swarm, a
failing check β€” required, or an optional one the merge gate reads
(`optional-check-failing:<name>`), DCO / sign-off, a diff the lane
cannot read, or a fork the App cannot push to (`fork-not-editable`:
hive cannot rebase it, so re-authoring on a hive branch is the only
mover; the caption reads *fork not editable by hive*);
- the author was nudged on **this** head and the head has not moved
since β€” a clanker that is pushing is never adopted; a new head
restarts the nudge and the clock;
- the author is unavailable by the clock above: offline for
`adoption.after_offline` (15m) counted from the later of the first
nudge and the last heartbeat, where a heartbeat after the nudge
("acknowledged") buys **one** window at most β€” a relay that
reconnects every few minutes without pushing no longer resets it;
online but silent for `contributor_grace_online` (2h); unregistered
for `adoption.after_unregistered` (15m). A `mode=queued` nudge (the
task waits server-side) counts as offline, not online;
- nothing holds it: no `hold` / `do-not-merge`, not person-authored, and
`maintainer_policy` is `adopt` (the default) or the owner answered `ask`.
The adoption log line carries `trigger=automatic:<reason>`
(`operator-forced` / `operator-requested` for the manual paths); the
tracker's 072 pill reads `… β€” hive adopts it in 3m unless a new head
lands` while the clock runs and `… β€” hive adopts it on the next sweep`
once it has. **Adopt now** stays as the override for a clock that has
not run out yet.
A PR carrying `hold`, `do-not-merge` or `do-not-merge/hold` is never
adopted (a human parked it; one log line, the stage stays 072).
A PR whose diff trips the contributor lane's diff fences β€” it touches
Expand Down
14 changes: 13 additions & 1 deletion src/pkg/dashboard/stage_tracker_adoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ type StageTrackerAdoption struct {
// the row is in its acted state ("Adopting… (queued by @x)") and no
// blocker or adopt action is shown.
QueuedBy string `json:"queued_by,omitempty"`
// AutoAdoptAt is when the engine's predicate (automerge.AutoAdoption)
// adopts this head on its own, while its clock runs and nothing holds
// it; AutoDue is true once it has fired (the next sweep adopts).
AutoAdoptAt *time.Time `json:"auto_adopt_at,omitempty"`
AutoDue bool `json:"auto_due,omitempty"`
// Text is the plain-words pill/tooltip: "waiting on @hanthor
// (maintainer, offline 26h) β€” adopt?".
Text string `json:"text"`
Expand Down Expand Up @@ -105,7 +110,7 @@ func (s *Server) stageTrackerMaintainerPolicy() string {
// stage/072 from its stage record and the author's live presence; nil
// when the row was never nudged at its current head (nothing to adopt
// yet) or is already adopted.
func stageTrackerAdoption(it StageTrackerItem, rec stagelabels.Record, hasRec bool, presence func(login string) (automerge.ContributorPresence, bool), policy string, now time.Time) *StageTrackerAdoption {
func stageTrackerAdoption(it StageTrackerItem, rec stagelabels.Record, hasRec bool, presence func(login string) (automerge.ContributorPresence, bool), policy string, clock stageTrackerAdoptionClock, now time.Time) *StageTrackerAdoption {
if it.Kind != "pr" || !hasRec {
return nil
}
Expand Down Expand Up @@ -163,6 +168,9 @@ func stageTrackerAdoption(it StageTrackerItem, rec stagelabels.Record, hasRec bo
if by == stagelabels.AdoptBlockedAuthorMaintainer && policy == config.AdoptionMaintainerPolicyAsk {
out.Action = decisionActionAdopt
}
} else if v := stageTrackerAutoAdoption(it, rec, hasRec, presence, clock, now); v.Running {
at := v.At
out.AutoAdoptAt, out.AutoDue = &at, v.Due
}
out.Text = stageTrackerAdoptionText(it.Author, *out, now)
return out
Expand Down Expand Up @@ -206,6 +214,10 @@ func stageTrackerAdoptionText(author string, a StageTrackerAdoption, now time.Ti
text += " β€” not adopted: a maintainer approved this head; the hive merges it as-is"
case a.BlockedBy != "":
text += " β€” not adopted: " + a.BlockedBy
case a.AutoDue:
text += " β€” hive adopts it on the next sweep"
case a.AutoAdoptAt != nil && a.AutoAdoptAt.After(now):
text += " β€” hive adopts it in " + stageTrackerShortDuration(max(a.AutoAdoptAt.Sub(now), time.Minute)) + " unless a new head lands"
}
return text
}
Expand Down
89 changes: 83 additions & 6 deletions src/pkg/dashboard/stage_tracker_adoption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,38 @@ func TestStageTrackerAdoptionNeverSaysSo(t *testing.T) {
}
}

// adopt (default): nothing is held, so the row only reports the wait, the
// nudges and the presence; no Adopt is offered.
// adopt (default): nothing is held, so the row reports the wait, the
// nudges, the presence and β€” since the engine's own predicate
// (automerge.AutoAdoption) is what the row reads β€” that the hive adopts
// on its next sweep; no Adopt click is asked for.
func TestStageTrackerAdoptionDefaultReportsWait(t *testing.T) {
now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC)
s, store, status := adoptionFixture(t, now, "", offlinePresence(now.Add(-3*time.Hour)))
a := trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14524).Adoption
if a == nil || a.Due || a.BlockedBy != "" || a.Action != "" || a.Policy != "adopt" {
if a == nil || a.Due || a.BlockedBy != "" || a.Action != "" || a.Policy != "adopt" || !a.AutoDue {
t.Fatalf("adoption = %+v", a)
}
if a.Text != "waiting on @hanthor (offline 3h, 2 nudges)" {
if a.Text != "waiting on @hanthor (offline 3h, 2 nudges) β€” hive adopts it on the next sweep" {
t.Fatalf("text = %q", a.Text)
}
// Online author: no offline span.
// Online author: no offline span; 26h past the first nudge is past the
// 2h online grace too.
s.presenceLookup = func(string) (automerge.ContributorPresence, bool) {
return automerge.ContributorPresence{Registered: true, Online: true}, true
}
if a = trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14524).Adoption; a == nil || a.Text != "waiting on @hanthor (online, 2 nudges)" {
if a = trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14524).Adoption; a == nil || a.Text != "waiting on @hanthor (online, 2 nudges) β€” hive adopts it on the next sweep" {
t.Fatalf("online text = %+v", a)
}
// Nudged 13 minutes ago, offline: the row says when the hive adopts.
store2 := stagelabels.NewStore("", func() time.Time { return now })
key := stagelabels.Key("hivecommons/hive", 14524)
store2.Observe(key, stagelabels.ReturnedToContributor, "conflicting")
store2.MarkNudged(key, "feed", 1, false, now.Add(-13*time.Minute))
s.stageStore = store2
s.presenceLookup = offlinePresence(now.Add(-13 * time.Minute))
if a = trackerItem(t, s.buildStageTracker(status, store2, now), "pr", 14524).Adoption; a == nil || a.AutoDue || a.AutoAdoptAt == nil || !a.AutoAdoptAt.Equal(now.Add(2*time.Minute)) || a.Text != "waiting on @hanthor (offline 13m, 1 nudge) β€” hive adopts it in 2m unless a new head lands" {
t.Fatalf("pending text = %+v", a)
}
}

// A stale blocked mark (head moved) and an adopted record carry nothing.
Expand Down Expand Up @@ -402,3 +415,67 @@ func TestStageTrackerReturnedToHiveCaption(t *testing.T) {
t.Errorf("no author changed the caption: %q", got)
}
}

// hive#15565/#15566/#15609 and #15312: PRs by an offline clanker sat at 072
// with "waiting on @Karibhou (offline 13m, 1 nudge)" until a person clicked
// Adopt. The row now says when the hive adopts, offers Adopt now only as an
// override, and the fork-not-editable row names its blocker.
func TestStageTrackerAutoAdoptionExampleCaptions(t *testing.T) {
now := time.Date(2026, 10, 29, 22, 45, 0, 0, time.UTC)
s := newTestServer()
store := stagelabels.NewStore("", func() time.Time { return now })
s.stageStore = store
s.deps = &Dependencies{Config: &config.Config{}}
nudged := now.Add(-13 * time.Minute)
s.presenceLookup = func(login string) (automerge.ContributorPresence, bool) {
// One heartbeat a minute after the nudge: acknowledged, then gone.
return automerge.ContributorPresence{Registered: true, Online: false, LastSeen: nudged.Add(time.Minute)}, true
}
rows := []struct {
number int
reason string
author string
want string
}{
{15565, "conflicting", "Karibhou", "conflicting"},
{15566, "contributor-lane:changes-requested", "Karibhou", "changes requested"},
{15609, "optional-check-failing:overlayfs-exec-guard", "Karibhou", "overlayfs-exec-guard"},
{15312, "fork-not-editable", "odttlnt", "fork not editable by hive"},
}
status := minimalPayload()
status.HiveID = "hive"
var prs []any
for _, r := range rows {
key := stagelabels.Key("hivecommons/hive", r.number)
store.Observe(key, stagelabels.ReturnedToContributor, r.reason)
store.MarkNudged(key, "feed", 1, false, nudged)
prs = append(prs, FrontendPR{PullRequest: github.PullRequest{Number: r.number, Title: "Change", Author: r.author, HeadSHA: "feed", Labels: []string{"stage/072-returned-to-contributor", "author/clanker", "role/contributor"}}})
}
status.Repos = []FrontendRepo{{Name: "hive", Full: "hivecommons/hive", OpenPrs: prs}}
s.UpdateStatus(status)

for _, r := range rows {
it := trackerItem(t, s.buildStageTracker(status, store, now), "pr", r.number)
wantTail := "waiting on @" + r.author + " (offline 12m, 1 nudge) β€” hive adopts it in 3m unless a new head lands"
if !strings.Contains(it.Caption, r.want) || !strings.HasSuffix(it.Caption, wantTail) {
t.Fatalf("#%d caption = %q, want %q … %q", r.number, it.Caption, r.want, wantTail)
}
if strings.Contains(it.Caption, "No stage recorded yet") {
t.Fatalf("#%d caption keeps the empty-stage clause: %q", r.number, it.Caption)
}
if it.Adoption == nil || it.Adoption.AutoDue || it.Adoption.AutoAdoptAt == nil || !it.Adoption.AutoAdoptAt.Equal(nudged.Add(16*time.Minute)) {
t.Fatalf("#%d adoption = %+v", r.number, it.Adoption)
}
if it.Takeover == nil || !it.Takeover.AdoptNow || it.Takeover.GraceElapsed || it.Takeover.AutoAdoptAt == nil {
t.Fatalf("#%d takeover = %+v", r.number, it.Takeover)
}
}
// Three minutes on: the sweep's clock has run out; the row says so.
later := nudged.Add(16 * time.Minute)
for _, r := range rows {
it := trackerItem(t, s.buildStageTracker(status, store, later), "pr", r.number)
if !strings.HasSuffix(it.Caption, "β€” hive adopts it on the next sweep") || it.Adoption == nil || !it.Adoption.AutoDue || it.Takeover == nil || !it.Takeover.GraceElapsed {
t.Fatalf("#%d at +16m: caption=%q adoption=%+v takeover=%+v", r.number, it.Caption, it.Adoption, it.Takeover)
}
}
}
6 changes: 3 additions & 3 deletions src/pkg/dashboard/stage_tracker_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
workers := stageTrackerWorkersFromStatus(status)
isClankerOwner := stageTrackerIsClankerOwner()
adoptionClock := s.stageTrackerAdoptionClock()
rerouteCandidates, adoptionEnabled, takeoverGrace := s.stageTrackerRerouteCandidates(), s.stageAdoptionEnabled(), s.takeoverGrace()
rerouteCandidates := s.stageTrackerRerouteCandidates()
finish := func(it *StageTrackerItem, labels []string, stage stagelabels.Stage, rec stagelabels.Record, hasRec bool, draft bool) {
// "Needs human decision" is read from the item's current labels, not
// a store record that outlived them: once the park label is gone
Expand Down Expand Up @@ -182,15 +182,15 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
// (hivecommons/hive#15202): that row says "not adopted" wherever it sits.
personRefused := hasRec && it.Kind == "pr" && rec.AdoptionBlocked(it.Head) == stagelabels.AdoptBlockedAuthorPerson
if personRefused || (stage == stagelabels.ReturnedToContributor && it.Kind == "pr" && it.AuthorKind != authorKindHuman) {
if it.Adoption = stageTrackerAdoption(*it, rec, hasRec, presence, maintainerPolicy, now); it.Adoption != nil {
if it.Adoption = stageTrackerAdoption(*it, rec, hasRec, presence, maintainerPolicy, adoptionClock, now); it.Adoption != nil {
it.Caption = stageTrackerAdoptionCaption(it.Caption, it.Adoption)
}
}
if login := stageTrackerWaitingOn(*it, stage); login != "" {
it.Presence = stageTrackerPresenceFor(*it, login, stage, rec, hasRec, presence, adoptionClock, now)
it.Rework = stageTrackerReworkFor(*it, login, stage, rec, hasRec, fixWork, now)
}
if it.Takeover = stageTrackerTakeover(*it, rec, hasRec, presence, rerouteCandidates, adoptionEnabled, takeoverGrace, now); it.Takeover != nil {
if it.Takeover = stageTrackerTakeover(*it, rec, hasRec, presence, rerouteCandidates, adoptionClock, now); it.Takeover != nil {
it.Caption = stageTrackerTakeoverCaption(it.Caption, it.Takeover)
}
base, approver := stagelabels.HumanApprovedReason(it.Reason)
Expand Down
5 changes: 5 additions & 0 deletions src/pkg/dashboard/stage_tracker_caption.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ func humanizeStageReason(reason string) string {
return "human-merge path"
case stageengineprstage.AutoMergeReasonHumanMergeRequired:
return "human merge"
case stageengineprstage.AutoMergeReasonForkNotEditable:
// The App cannot update a fork the author did not open to
// maintainer edits; only adoption (hive re-authoring on its own
// branch) moves it (hivecommons/hive#15312).
return "fork not editable by hive"
}
if rest, ok := strings.CutPrefix(lower, "contributor-lane:"); ok {
return strings.ReplaceAll(strings.ReplaceAll(rest, "-", " "), "_", " ")
Expand Down
85 changes: 45 additions & 40 deletions src/pkg/dashboard/stage_tracker_presence.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ type StageTrackerPresence struct {
}

// stageTrackerAdoptionClock is the slice of governor.labels.stage the
// adopt-at projection needs, mirroring what cmd/hive hands the adoption
// engine as automerge.StageLabelPolicy.
// adopt-at projection and the takeover offer need: the same
// automerge.AdoptionClock cmd/hive hands the adoption engine, so the
// tracker's "adopt?" and the sweep's adoption are one verdict
// (automerge.AutoAdoption).
type stageTrackerAdoptionClock struct {
Enabled bool
GraceOnline time.Duration
AdoptAfterOffline time.Duration
AdoptAfterUnregistered time.Duration
Enabled bool
automerge.AdoptionClock
}

func (s *Server) stageTrackerAdoptionClock() stageTrackerAdoptionClock {
Expand All @@ -76,13 +76,37 @@ func (s *Server) stageTrackerAdoptionClock() stageTrackerAdoptionClock {
stage = s.deps.Config.Governor.Labels.Stage
}
return stageTrackerAdoptionClock{
Enabled: stage.Adoption.IsEnabled(),
GraceOnline: stage.EffectiveContributorGraceOnline(),
AdoptAfterOffline: stage.Adoption.EffectiveAfterOffline(),
AdoptAfterUnregistered: stage.Adoption.EffectiveAfterUnregistered(),
Enabled: s.stageAdoptionEnabled(),
AdoptionClock: automerge.AdoptionClock{
GraceOnline: stage.EffectiveContributorGraceOnline(),
GraceOffline: stage.EffectiveContributorGraceOffline(),
AdoptAfterOffline: stage.Adoption.EffectiveAfterOffline(),
AdoptAfterUnregistered: stage.Adoption.EffectiveAfterUnregistered(),
AdoptOfflineGrace: stage.Adoption.EffectiveOfflineGrace(),
},
}
}

// stageTrackerAutoAdoption is the engine's verdict for a row: whether the
// adoption clock runs on its head and when (or that) it fires. It is the
// one predicate the sweep acts on, so a row that says "adopting" is one
// the hive adopts on its next sweep without a click.
func stageTrackerAutoAdoption(it StageTrackerItem, rec stagelabels.Record, hasRec bool, presence func(string) (automerge.ContributorPresence, bool), clock stageTrackerAdoptionClock, now time.Time) automerge.AdoptionVerdict {
if !hasRec || !clock.Enabled || it.Kind != "pr" || it.AuthorKind == authorKindHuman {
return automerge.AdoptionVerdict{}
}
head := it.Head
if head == "" {
head = rec.NudgeHead
}
var p automerge.ContributorPresence
hasPresence := false
if presence != nil && it.Author != "" {
p, hasPresence = presence(it.Author)
}
return automerge.AutoAdoption(rec, head, clock.AdoptionClock, now, p, hasPresence)
}

// stageTrackerWaitingOn names the person a PR row waits on: its author at
// the stages whose caption says "@author must act", and a clanker's PR the
// engine has not classified yet (the row reads "PR in progress Β·
Expand Down Expand Up @@ -149,10 +173,9 @@ func stageTrackerPresenceFor(it StageTrackerItem, login string, stage stagelabel
}
out := &StageTrackerPresence{Login: login, State: presenceStateUnknown, Kind: presenceKindHuman, Next: presenceNextWait}
var p automerge.ContributorPresence
hasPresence := false
if presence != nil {
if got, ok := presence(login); ok {
p = got
}
p, hasPresence = presence(login)
}
switch {
case p.Registered && p.Online:
Expand Down Expand Up @@ -180,46 +203,28 @@ func stageTrackerPresenceFor(it StageTrackerItem, login string, stage stagelabel
}
// The adoption clock runs only where adoption itself does: a nudged
// clanker PR at 072 whose head has not moved since the nudge, not yet
// adopted, with nothing holding it.
// adopted, with nothing holding it β€” automerge.AutoAdoption, the
// sweep's own predicate.
if stage != stagelabels.ReturnedToContributor || !clock.Enabled || it.AuthorKind == authorKindHuman || out.Kind != presenceKindClanker {
return out
}
if !hasRec || rec.NudgeCount == 0 || rec.NudgeStart().IsZero() {
return out
}
head := it.Head
if head == "" {
head = rec.NudgeHead
}
if rec.NudgeHead != "" && head != rec.NudgeHead {
return out
}
if rec.AdoptedHead != "" && (rec.Adopted(head) || rec.AdoptedInPlace()) {
return out
}
if rec.AdoptionBlocked(head) != "" {
if hasRec && rec.AdoptionBlocked(head) != "" {
// Held (maintainer_policy ask / never): the adoption text says so;
// the engine will not adopt on its own.
return out
}
nudged := rec.NudgeStart()
var at time.Time
switch out.State {
case presenceStateOnline:
// Mirrors adoptionDue: an online clanker keeps the online grace; the
// hive waits for it meanwhile.
at = nudged.Add(orDefault(clock.GraceOnline, config.DefaultContributorGraceOnline))
case presenceStateOffline:
since := nudged
if p.LastSeen.After(since) {
since = p.LastSeen
}
at = since.Add(orDefault(clock.AdoptAfterOffline, config.DefaultAdoptAfterOffline))
out.Next = presenceNextAdopt
default:
at = nudged.Add(orDefault(clock.AdoptAfterUnregistered, config.DefaultAdoptAfterUnregistered))
v := automerge.AutoAdoption(rec, head, clock.AdoptionClock, now, p, hasPresence)
if !v.Running {
return out
}
if v.Reason != automerge.AdoptReasonGrace || out.State != presenceStateOnline {
out.Next = presenceNextAdopt
}
at := v.At
out.AdoptAt = &at
return out
}
Expand Down
Loading
Loading