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-offline-clanker-adopt-rebase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Adoption now resolves merge conflicts for a returned-to-contributor PR whose clanker is offline instead of handing the PR back: when the supersede's replay of the base onto `hive/adopt-<n>` conflicts, the hive opens the copy anyway and the fixer's rebase-resolve episode (`requested_by: adoption`, two attempts) resolves it; after two failures the PR parks at `stage/085` with `rebase-failed-twice` (copy) / `adoption-stalled:rebase-failed-twice` (original) offering *Adopt into fresh branch* / *Close as superseded*. An attempt that opened nothing is re-admitted once the clanker has stayed offline for `governor.labels.stage.adoption.offline_grace` (default 30m), and its branch push is a fresh journal claim so the branch an earlier attempt deleted is recreated. Tracker row reads "Adopting · fixer resolving conflicts" while the fixer works.
16 changes: 15 additions & 1 deletion src/cmd/hive/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

import (
Expand Down Expand Up @@ -2581,10 +2581,24 @@
// episode (#15104): the request admits the PR to the fixer router —
// which still requires a head the hive can push to — under the shared
// two-attempt guard, and the lane merges the clean head on its next pass.
// The adoption lane opens the same episode on the hive's own copy of
// a contributor PR whose head would not replay onto the base
// (hivecommons/hive#15307), with RequestedBy naming it.
autoMergeOpts.RebaseResolver = automerge.RebaseResolverFunc(func(_ context.Context, req automerge.RebaseRequest) error {
rebasemerge.SharedAttempts().Request(req.Repo, req.Number, req.HeadSHA, mergeTrainRebaseRequester, time.Now())
requester := mergeTrainRebaseRequester
if req.RequestedBy != "" {
requester = req.RequestedBy
}
rebasemerge.SharedAttempts().Request(req.Repo, req.Number, req.HeadSHA, requester, time.Now())
return nil
})
autoMergeOpts.RebaseEpisode = func(repo string, number int) (automerge.RebaseEpisode, bool) {
a, ok := rebasemerge.SharedAttempts().Get(repo, number)
if !ok {
return automerge.RebaseEpisode{}, false
}
return automerge.RebaseEpisode{Attempt: a.Count(), MaxAttempts: rebasemerge.MaxRebaseAttempts, Exhausted: a.Exhausted(), RequestedBy: a.RequestedBy}, true
}
autoMergeOpts.MergeTrain = func() automerge.MergeTrainPolicy {
if b.cfg == nil {
return automerge.DefaultMergeTrainPolicy
Expand Down
1 change: 1 addition & 0 deletions src/cmd/hive/merge_eligibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func stageLabelPolicyFunc(cfg *config.Config) func() automerge.StageLabelPolicy
GraceOffline: stage.EffectiveContributorGraceOffline(),
AdoptAfterOffline: stage.Adoption.EffectiveAfterOffline(),
AdoptAfterUnregistered: stage.Adoption.EffectiveAfterUnregistered(),
AdoptOfflineGrace: stage.Adoption.EffectiveOfflineGrace(),
AdoptInPlace: stage.Adoption.InPlaceEnabled(),
AdoptionStrictAttribution: stage.Adoption.StrictAttributionEnabled(),
AdoptionAutoMerge: stage.Adoption.AutoMergeEnabled(),
Expand Down
6 changes: 5 additions & 1 deletion src/docs/labels-and-control-signals.md
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,7 @@ stateDiagram-v2
s100 --> s070: new head red (backward hop, commented)
s100 --> s072: contributor head red (backward hop, commented)
s070 --> s050: fixed head pushed
s070 --> s085: the hive's adoption copy (hive/adopt-N) still conflicts with the base after the fixer's two rebase-resolve attempts (rebase-failed-twice)
s071 --> s050: author pushes a new head
s072 --> s050: author pushes a new head
s072 --> s074: contributor agent unavailable (offline / unregistered / grace), adopted in place or superseded
Expand All @@ -1192,6 +1193,7 @@ stateDiagram-v2
s074 --> s100: lane admits the hive's head, soak complete
s074 --> [*]: superseder merged (original closed); close_first (default) closes the original in the adopting pass instead
s074 --> s085: close-first copy closed unmerged or red at two heads → original reopened, adoption-copy-failed
s074 --> s085: the superseding copy still conflicts with the base after the fixer's two rebase-resolve attempts (adoption-stalled:rebase-failed-twice; Adopt into fresh branch / Close as superseded)
s074 --> s072: superseder closed unmerged, or contributor pushed over an in-place adoption (handed back; 050 if that head is green)
s074 --> s085: adopted head unchanged past the dwell with CI idle and a real blocker the hive cannot push past (adoption-stalled:<reason>; a red optional check alone never counts), or the re-home failed
s085 --> s074: the adoption-stalled reason cleared (CI re-ran, check green, verdict landed); escalation released
Expand Down Expand Up @@ -1991,7 +1993,9 @@ When a contributor-agent PR goes red the hive does not just relabel it (a human-
`adoption-stalled:<lane reason>` (e.g.
`adoption-stalled:reviewer-verdict:changes_requested`,
`adoption-stalled:check-failing:unit`,
`adoption-stalled:supersede-failed:dco-rehome`) and ONE
`adoption-stalled:supersede-failed:dco-rehome`,
`adoption-stalled:rebase-failed-twice` when the hive's copy still
conflicts after the fixer's two rebase-resolve attempts) and ONE
`<!-- hive:adoption-stalled head=<sha> reason=<r> -->` comment naming
the exact blocker (the verdict and its summaries, the red check, or the
failed re-home). The dwell is measured from the head, not the adoption:
Expand Down
17 changes: 16 additions & 1 deletion src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,22 @@ original** with one note naming the copy and why ("Superseded by hive:
re-authored as #M … This PR is closed; if #M fails, hive reopens it."),
labelled `hive/superseded`, so one issue never shows two active PRs
(`governor.labels.stage.adoption.supersede.close_first`, default on;
hivecommons/hive#15135). If the copy is closed unmerged or its required
hivecommons/hive#15135). A contributor head that **conflicts with the base**
(`needs-rebase` / `conflicting`) is first replayed onto `hive/adopt-<n>`
(a merge of the base); when that replay itself conflicts the copy still
opens, on the hive's own branch, and the fixer's rebase-resolve episode
takes it (`requested_by: adoption`, the same two-attempt guard as the
merge-train, hivecommons/hive#15104) — the row reads "Adopting · fixer
resolving conflicts". If both attempts fail the copy parks at `stage/085`
with `rebase-failed-twice` and the original (when still open) with
`adoption-stalled:rebase-failed-twice`; the Needs-human popover offers
**Adopt into fresh branch** / **Close as superseded**. A plain conflict
never hands a PR back to a contributor who cannot act (hivecommons/hive#15307):
an earlier attempt that opened nothing is re-admitted once the clanker has
stayed offline or unregistered for `governor.labels.stage.adoption.offline_grace`
(default 30m) since the attempt or its last heartbeat. (Without a fixer
wired the replay conflict is still terminal for the head: one note,
`supersede-conflict`.) If the copy is closed unmerged or its required
checks are red at two heads, the hive reopens the original, removes
`hive/superseded`, and parks it at `stage/085` with `adoption-copy-failed`
("needs a person"); at most one reopen per original per 24h. The note,
Expand Down
14 changes: 14 additions & 0 deletions src/pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package config

import (
Expand Down Expand Up @@ -2893,6 +2893,14 @@
// profile on this hive (another hive posted it; default 15m — no
// presence reads as offline).
AfterUnregistered string `yaml:"after_unregistered,omitempty"`
// OfflineGrace is the stage-stalled escape for an adoption attempt that
// opened nothing (the supersede's replay onto the base failed) while
// the author's clanker is still offline or unregistered: once the head
// has sat that long since the attempt (or the clanker's last heartbeat,
// whichever is later) it re-enters adoption instead of staying at
// 072/085 for a contributor who cannot act (default 30m;
// hivecommons/hive#15307).
OfflineGrace string `yaml:"offline_grace,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.
Expand Down Expand Up @@ -2987,8 +2995,14 @@
const (
DefaultAdoptAfterOffline = 15 * time.Minute
DefaultAdoptAfterUnregistered = 15 * time.Minute
DefaultAdoptOfflineGrace = 30 * time.Minute
)

// EffectiveOfflineGrace parses OfflineGrace (default 30m).
func (c StageAdoptionConfig) EffectiveOfflineGrace() time.Duration {
return parseDurationOr(c.OfflineGrace, DefaultAdoptOfflineGrace)
}

// EffectiveAfterOffline parses AfterOffline (default 15m).
func (c StageAdoptionConfig) EffectiveAfterOffline() time.Duration {
return parseDurationOr(c.AfterOffline, DefaultAdoptAfterOffline)
Expand Down
1 change: 1 addition & 0 deletions src/pkg/config/testdata/agent_runtime_golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
"Enabled": null,
"AfterOffline": "",
"AfterUnregistered": "",
"OfflineGrace": "",
"InPlace": null,
"StrictAttribution": null,
"AutoMerge": null,
Expand Down
16 changes: 15 additions & 1 deletion src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dashboard

import (
Expand Down Expand Up @@ -1720,8 +1720,11 @@
case stagelabels.AdoptedByHive:
c := adoptedWorkCaption(reason)
if hasRec && rec.AdoptedBy > 0 {
if stageTrackerAdoptedByState(rec) == stageTrackerAdoptedClosed {
switch stageTrackerAdoptedByState(rec) {
case stageTrackerAdoptedClosed:
return joinClause("The hive's copy #"+strconv.Itoa(rec.AdoptedBy)+" was closed without merging; the hive is opening a fresh copy from the same head", clause), "hive"
case stageTrackerAdoptedResolving:
return joinClause("Adopting: the hive's copy #"+strconv.Itoa(rec.AdoptedBy)+" conflicts with the base and the fixer is resolving the conflicts on it", clause), "hive"
}
c += " (superseded by #" + strconv.Itoa(rec.AdoptedBy) + ")"
}
Expand All @@ -1737,6 +1740,11 @@
return stageTrackerAdoptionLoopCaption(rec), "maintainer"
case stageTrackerAdoptedCopyFailed:
return "The hive's copy #" + strconv.Itoa(rec.AdoptedBy) + " failed; this PR was reopened and needs a person", "maintainer"
case stageTrackerAdoptedResolving:
return "Rebase failed twice: the hive's copy #" + strconv.Itoa(rec.AdoptedBy) + " still conflicts with the base after two fixer attempts; a person decides", "maintainer"
}
if strings.TrimSpace(strings.ToLower(reason)) == stagelabels.LaneReasonRebaseFailedTwice {
return "Rebase failed twice: the fixer could not resolve the conflicts with the base; a person decides", "maintainer"
}
if step, _ := stageTrackerUnauthorized(reason); step != "" {
// hivecommons/hive#14589: not a decision but a step only a
Expand Down Expand Up @@ -1866,6 +1874,10 @@
// stageTrackerAdoptedCopyFailed: a close-first supersession whose copy
// failed; the original was reopened for a person (hivecommons/hive#15135).
stageTrackerAdoptedCopyFailed = "copy-failed"
// stageTrackerAdoptedResolving: the copy opened conflicting with its
// base and the hive's fixer is on its rebase-resolve episode
// (hivecommons/hive#15307).
stageTrackerAdoptedResolving = "resolving-conflicts"
)

// stageTrackerAdoptedByState reads the copy's state from the record
Expand All @@ -1881,6 +1893,8 @@
return stageTrackerAdoptedCopyFailed
case rec.AdoptOrphanedBy == rec.AdoptedBy:
return stageTrackerAdoptedClosed
case rec.AdoptCopyConflicting:
return stageTrackerAdoptedResolving
}
return ""
}
Expand Down
54 changes: 54 additions & 0 deletions src/pkg/dashboard/stage_tracker_adoption_close_first_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,57 @@ assert.strictEqual(stageTrackerLinkedPRItem(issue, { number: 2 }).supersedes, nu
}, "\n")
runStageTrackerRowActionsScript(t, script)
}

// hivecommons/hive#15307: a copy the fixer is rebasing reads "Adopting ·
// fixer resolving conflicts" (one label) at 074 and, once the episode is
// spent, 085 offers Adopt into fresh branch / Close as superseded.
func TestStageTrackerAdoptionCopyResolvingConflicts(t *testing.T) {
now := time.Date(2026, 10, 29, 9, 0, 0, 0, time.UTC)
s, store, status, key := orphanTrackerFixture(t, now, stagelabels.AdoptedByHive, "conflicting", []string{"stage/074-adopted-by-hive", "needs-rebase"})
store.MarkAdopted(key, "bc3a6ea", 15123, now.Add(-time.Hour))
store.NoteAdoptCopyConflicting(key, true)

it := trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14947)
if it.AdoptedBy != 15123 || it.AdoptedByState != "resolving-conflicts" {
t.Fatalf("adopted_by=%d state=%q", it.AdoptedBy, it.AdoptedByState)
}
if !strings.Contains(it.Caption, "Adopting") || !strings.Contains(it.Caption, "#15123") || !strings.Contains(it.Caption, "fixer is resolving the conflicts") {
t.Fatalf("caption = %q", it.Caption)
}

reason := stagelabels.LaneReasonAdoptionStalledPrefix + stagelabels.LaneReasonRebaseFailedTwice
store.MarkAdoptionEscalated(key, "bc3a6ea", reason)
store.Observe(key, stagelabels.NeedsDecision, reason)
status.Repos[0].OpenPrs = []any{FrontendPR{PullRequest: github.PullRequest{Number: 14947, Title: "Fix", Author: "thatguywob", HeadSHA: "bc3a6ea", Labels: []string{"author/clanker", "role/contributor", "stage/085-needs-decision", "needs-rebase"}}}}
s.UpdateStatus(status)
it = trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14947)
if !strings.Contains(it.Caption, "Rebase failed twice") || !strings.Contains(it.Caption, "#15123") {
t.Fatalf("085 caption = %q", it.Caption)
}
d := it.DecisionNeeded
if d == nil || !strings.Contains(d.Question, "two attempts") || len(d.Options) < 2 || d.Options[0].Action != decisionActionAdopt || d.Options[0].Label != "Adopt into fresh branch" {
t.Fatalf("decision_needed = %+v", d)
}
closeSup := false
for _, o := range d.Options {
closeSup = closeSup || (o.Action == decisionActionCloseSuperseded && o.Label == "Close as superseded")
}
if !closeSup {
t.Fatalf("Close as superseded missing: %+v", d.Options)
}

// The hive's own copy at 085 rebase-failed-twice gets the same options.
copyItem := StageTrackerItem{Repo: "hivecommons/hive", Number: 15123, Kind: "pr", Stage: 85, Reason: stagelabels.LaneReasonRebaseFailedTwice}
cd := decisionForPR(copyItem, nil, "", false)
if cd.Options[0].Action != decisionActionAdopt || !strings.Contains(cd.Question, "fresh branch") {
t.Fatalf("copy decision = %+v", cd)
}

html := indexHTML(t)
runStageTrackerRowActionsScript(t, strings.Join([]string{
"const assert = require('assert');",
jsConstLine(t, html, "STAGE_TRACKER_ADOPTED_BY_HIVE"),
jsFunc(t, html, "stageTrackerAdoptedWord"),
`assert.strictEqual(stageTrackerAdoptedWord({ adopted_by: 15123, adopted_by_state: 'resolving-conflicts' }), 'Adopting · fixer resolving conflicts');`,
}, "\n"))
}
11 changes: 11 additions & 0 deletions src/pkg/dashboard/stage_tracker_decision.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"unicode"

"github.com/hivecommons/hive/pkg/delegatedecision"
"github.com/hivecommons/hive/pkg/rebasemerge"
"github.com/hivecommons/hive/pkg/review"
"github.com/hivecommons/hive/pkg/stageengine"
stageengineprstage "github.com/hivecommons/hive/pkg/stageengine/prstage"
Expand Down Expand Up @@ -682,6 +683,9 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel
laneRule := decisionLaneRule(base)
adoptionLane, adoptionStalled := strings.CutPrefix(base, stagelabels.LaneReasonAdoptionStalledPrefix)
forkGuard, forkGuarded := strings.CutPrefix(base, stageengineprstage.StageReasonForkGuard)
// hivecommons/hive#15307: the hive's adoption copy (or the original it
// supersedes) after the fixer's two rebase-resolve attempts failed.
rebaseFailedTwice := lower == stagelabels.LaneReasonRebaseFailedTwice || (adoptionStalled && adoptionLane == stagelabels.LaneReasonRebaseFailedTwice)
reviewerDeferred := lower == stageengine.StageReasonVerdictRequiresHuman || lower == stageengine.StageReasonDecisionRequested

// WHAT it is waiting on: the question, most specific source first. A
Expand Down Expand Up @@ -732,6 +736,8 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel
d.Question = "The security check flagged " + reason + at + ". Accept it as is, give direction, or close it?"
case lower == stagelabels.LaneReasonAdoptionChildClosedTwice:
d.Question = "The hive's copies of this PR were closed without merging twice within an hour, so the hive stopped opening copies. Reopen the last copy (#" + strconv.Itoa(it.AdoptedBy) + "), give direction, or close it?"
case rebaseFailedTwice:
d.Question = "The hive adopted this PR but its fixer could not resolve the conflicts with the base in two attempts. Adopt the commits into a fresh branch, give direction, or close it as superseded?"
case lower == stagelabels.LaneReasonAdoptionCopyFailed:
d.Question = "The hive's copy of this PR (#" + strconv.Itoa(it.AdoptedBy) + ") failed, so this PR was reopened. Ask the hive to supersede it again, give direction, or close it?"
case adoptionStalled:
Expand Down Expand Up @@ -797,6 +803,11 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel
if stageTrackerNeedsRebase(it) && !sentinel {
d.Options = slices.Insert(d.Options, 2, decisionMergeNowOption(it, held))
}
if rebaseFailedTwice {
// The two answers to a rebase nobody could finish lead, as they do
// for merge-now (rebaseMergeFailureOptions).
d.Options = slices.Insert(d.Options, 0, decisionOption(decisionActionAdopt, rebasemerge.OptionAdoptFreshLabel, true, ""))
}
if selfHold != nil {
// Release leads: it is the one action that answers the question.
d.Options = append([]StageTrackerDecisionOption{decisionHoldOption(true)}, d.Options[:len(d.Options)-1]...)
Expand Down
Loading
Loading