diff --git a/changelog.d/fixed-offline-clanker-adopt-rebase.md b/changelog.d/fixed-offline-clanker-adopt-rebase.md new file mode 100644 index 0000000000..0b37c87c4a --- /dev/null +++ b/changelog.d/fixed-offline-clanker-adopt-rebase.md @@ -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-` 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. \ No newline at end of file diff --git a/src/cmd/hive/main.go b/src/cmd/hive/main.go index a24e6f37f1..3a246d5e8e 100644 --- a/src/cmd/hive/main.go +++ b/src/cmd/hive/main.go @@ -2581,10 +2581,24 @@ func (b *boot) bootAgentsWith(deps bootAgentsDeps) { // 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 diff --git a/src/cmd/hive/merge_eligibility.go b/src/cmd/hive/merge_eligibility.go index 79a4083026..73b2ad6941 100644 --- a/src/cmd/hive/merge_eligibility.go +++ b/src/cmd/hive/merge_eligibility.go @@ -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(), diff --git a/src/docs/labels-and-control-signals.md b/src/docs/labels-and-control-signals.md index 936716640f..ec0c9da4fa 100644 --- a/src/docs/labels-and-control-signals.md +++ b/src/docs/labels-and-control-signals.md @@ -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 @@ -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:; 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 @@ -1991,7 +1993,9 @@ When a contributor-agent PR goes red the hive does not just relabel it (a human- `adoption-stalled:` (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 `` 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: diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index 8610f1725a..fd26a98d3e 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -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-` +(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, diff --git a/src/pkg/config/config.go b/src/pkg/config/config.go index c55e7bab46..d4dc535b65 100644 --- a/src/pkg/config/config.go +++ b/src/pkg/config/config.go @@ -2893,6 +2893,14 @@ type StageAdoptionConfig struct { // 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. @@ -2987,8 +2995,14 @@ func (c StageAdoptionConfig) StrictAttributionEnabled() bool { 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) diff --git a/src/pkg/config/testdata/agent_runtime_golden.json b/src/pkg/config/testdata/agent_runtime_golden.json index d1d58fc263..1dfc005a14 100644 --- a/src/pkg/config/testdata/agent_runtime_golden.json +++ b/src/pkg/config/testdata/agent_runtime_golden.json @@ -202,6 +202,7 @@ "Enabled": null, "AfterOffline": "", "AfterUnregistered": "", + "OfflineGrace": "", "InPlace": null, "StrictAttribution": null, "AutoMerge": null, diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 23d32a2d4d..6109c376f7 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -1720,8 +1720,11 @@ func stageTrackerCaption(stage stagelabels.Stage, reason, author string, kind st 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) + ")" } @@ -1737,6 +1740,11 @@ func stageTrackerCaption(stage stagelabels.Stage, reason, author string, kind st 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 @@ -1866,6 +1874,10 @@ const ( // 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 @@ -1881,6 +1893,8 @@ func stageTrackerAdoptedByState(rec stagelabels.Record) string { return stageTrackerAdoptedCopyFailed case rec.AdoptOrphanedBy == rec.AdoptedBy: return stageTrackerAdoptedClosed + case rec.AdoptCopyConflicting: + return stageTrackerAdoptedResolving } return "" } diff --git a/src/pkg/dashboard/stage_tracker_adoption_close_first_test.go b/src/pkg/dashboard/stage_tracker_adoption_close_first_test.go index a878671247..207125f35c 100644 --- a/src/pkg/dashboard/stage_tracker_adoption_close_first_test.go +++ b/src/pkg/dashboard/stage_tracker_adoption_close_first_test.go @@ -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")) +} diff --git a/src/pkg/dashboard/stage_tracker_decision.go b/src/pkg/dashboard/stage_tracker_decision.go index 24b22bde89..35b22cbd15 100644 --- a/src/pkg/dashboard/stage_tracker_decision.go +++ b/src/pkg/dashboard/stage_tracker_decision.go @@ -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" @@ -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 @@ -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: @@ -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]...) diff --git a/src/pkg/dashboard/static-src/js/config-governor.js b/src/pkg/dashboard/static-src/js/config-governor.js index a5c0ddf032..649cf750bb 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).
+
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 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).
${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 e8cbfe27ce..c431add812 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' }, + { 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.offline_grace offline grace rebase failed twice fixer resolving conflicts' }, { 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-src/js/tracker-words.js b/src/pkg/dashboard/static-src/js/tracker-words.js index eab7cd8d41..2c3d64458f 100644 --- a/src/pkg/dashboard/static-src/js/tracker-words.js +++ b/src/pkg/dashboard/static-src/js/tracker-words.js @@ -34,6 +34,8 @@ if (state === 'closed') return 'Adopted → #' + by + ' (closed) · recovering'; if (state === 'closed-twice') return 'Adopted → #' + by + ' (closed twice) · needs a person'; if (state === 'copy-failed') return 'Adopted → #' + by + ' (copy failed) · reopened, needs a person'; + // hivecommons/hive#15307: one label while the fixer works (#15416 rule). + if (state === 'resolving-conflicts') return 'Adopting · fixer resolving conflicts'; return 'Adopted → #' + by; } const STAGE_TRACKER_UNAUTHORIZED_WORD = 'Awaiting human'; diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 0aa2513327..342dc28bff 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -14217,6 +14217,8 @@

Where to get help

if (state === 'closed') return 'Adopted → #' + by + ' (closed) · recovering'; if (state === 'closed-twice') return 'Adopted → #' + by + ' (closed twice) · needs a person'; if (state === 'copy-failed') return 'Adopted → #' + by + ' (copy failed) · reopened, needs a person'; + // hivecommons/hive#15307: one label while the fixer works (#15416 rule). + if (state === 'resolving-conflicts') return 'Adopting · fixer resolving conflicts'; return 'Adopted → #' + by; } const STAGE_TRACKER_UNAUTHORIZED_WORD = 'Awaiting human'; @@ -45778,7 +45780,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' }, + { 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.offline_grace offline grace rebase failed twice fixer resolving conflicts' }, { 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' }, @@ -52656,7 +52658,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).
+
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 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).
${renderReporterTrustBlock()}

Writing guide

diff --git a/src/pkg/github/automerge/automerge_adoption_offline_rebase_test.go b/src/pkg/github/automerge/automerge_adoption_offline_rebase_test.go new file mode 100644 index 0000000000..9034417b0b --- /dev/null +++ b/src/pkg/github/automerge/automerge_adoption_offline_rebase_test.go @@ -0,0 +1,339 @@ +package automerge + +import ( + "context" + "slices" + "strings" + "testing" + "time" + + gh "github.com/google/go-github/v72/github" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// hivecommons/hive#15307: a returned-to-contributor PR whose clanker is +// offline must be adopted even when the contributor head conflicts with +// the base. These tests cover the admission (adoptionDue with an attempt +// that opened nothing), the supersede route (clean head → copy; dirty head +// → copy + fixer rebase-resolve episode), the second-failure park (085 +// rebase-failed-twice on the copy and on the original) and the retry after +// an earlier attempt deleted the hive branch. + +func TestAdoptionRetryAdmissionAfterAttemptOpenedNothing(t *testing.T) { + at := time.Date(2026, 10, 16, 12, 0, 0, 0, time.UTC) + attempted := stagelabels.Record{ + NudgeHead: "aaa", NudgeCount: 1, FirstNudgeAt: at.Add(-time.Hour), + AdoptedHead: "aaa", AdoptedBy: 0, AdoptedAt: at, AdoptMode: stagelabels.AdoptModeSupersede, + } + copyOpen := attempted + copyOpen.AdoptedBy = 90 + policy := adoptPolicy() + short := adoptPolicy() + short.AdoptOfflineGrace = 10 * time.Minute + online := ContributorPresence{Registered: true, Online: true} + offline := ContributorPresence{Registered: true} + seenLater := ContributorPresence{Registered: true, LastSeen: at.Add(20 * time.Minute)} + cases := []struct { + name string + rec stagelabels.Record + policy StageLabelPolicy + now time.Time + presence ContributorPresence + has bool + due bool + reason string + }{ + {"online clanker waits", attempted, policy, at.Add(3 * time.Hour), online, true, false, ""}, + {"offline inside grace waits", attempted, policy, at.Add(29 * time.Minute), offline, true, false, ""}, + {"offline past grace re-enters", attempted, policy, at.Add(30 * time.Minute), offline, true, true, AdoptReasonOffline}, + {"offline grace counts from the last heartbeat", attempted, policy, at.Add(49 * time.Minute), seenLater, true, false, ""}, + {"offline heartbeat then grace re-enters", attempted, policy, at.Add(50 * time.Minute), seenLater, true, true, AdoptReasonOffline}, + {"unregistered past grace re-enters", attempted, policy, at.Add(30 * time.Minute), ContributorPresence{}, true, true, AdoptReasonUnregistered}, + {"no presence past grace re-enters", attempted, policy, at.Add(30 * time.Minute), ContributorPresence{}, false, true, AdoptReasonGrace}, + {"configured grace", attempted, short, at.Add(10 * time.Minute), offline, true, true, AdoptReasonOffline}, + {"copy open is live, not retried", copyOpen, policy, at.Add(3 * time.Hour), offline, true, false, ""}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + due, reason := adoptionDue(tc.rec, "aaa", tc.policy, tc.now, tc.presence, tc.has) + if due != tc.due || (due && reason != tc.reason) { + t.Fatalf("adoptionDue = %v %q, want %v %q", due, reason, tc.due, tc.reason) + } + }) + } +} + +// offlineAdoptHarness is the adopt harness with the author's clanker +// offline (registered, no heartbeat) and a recording RebaseResolver. +type offlineAdoptHarness struct { + *adoptHarness + requests []RebaseRequest + episode map[int]RebaseEpisode +} + +func newOfflineAdoptHarness(t *testing.T, withResolver bool) (*offlineAdoptHarness, func()) { + t.Helper() + fake := &fakeNudgeSink{outcome: ContributorNudgeOutcome{Mode: "comment"}, presence: &ContributorPresence{Registered: true}} + h, done := newAdoptHarnessWith(t, fake, fake, adoptPolicy()) + o := &offlineAdoptHarness{adoptHarness: h, episode: map[int]RebaseEpisode{}} + if withResolver { + o.wireResolver() + } + return o, done +} + +func (o *offlineAdoptHarness) wireResolver() { + o.e.rebaseResolver = RebaseResolverFunc(func(_ context.Context, req RebaseRequest) error { + o.requests = append(o.requests, req) + return nil + }) + o.e.rebaseEpisode = func(_ string, number int) (RebaseEpisode, bool) { + ep, ok := o.episode[number] + return ep, ok + } +} + +var offlineReturnedLabels = []string{"stage/072-returned-to-contributor", "role/contributor", "author/clanker"} + +// returnThenWaitOffline nudges once and advances past the offline wait +// (15m after the nudge) without sweeping again. +func (o *offlineAdoptHarness) returnThenWaitOffline(reason string) { + o.t.Helper() + o.observe(adoptPR(7, "aaa"), reason) + o.api.reset() + o.clock.advance(15 * time.Minute) +} + +func (o *offlineAdoptHarness) dirtyPR(labels ...string) *gh.PullRequest { + return adoptPR(7, "aaa", append(append([]string{}, labels...), "needs-rebase")...) +} + +func (o *offlineAdoptHarness) record() stagelabels.Record { + rec, _ := o.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) + return rec +} + +func (o *offlineAdoptHarness) supersedeConflictNotes() int { + n := 0 + for _, c := range o.api.comments { + if strings.HasPrefix(c, AdoptionSupersedeConflictMarker) { + n++ + } + } + return n +} + +func TestAdoptionOfflineClankerSupersedeRoutes(t *testing.T) { + cases := []struct { + name string + online bool + dirty bool + replayStatus int + wantPulls int + wantReplays int + wantFixer bool + }{ + {name: "online clanker waits", online: true, dirty: true, replayStatus: 409}, + {name: "offline clean head opens the copy", wantPulls: 1}, + {name: "offline dirty head replays then opens the copy", dirty: true, wantPulls: 1, wantReplays: 1}, + {name: "offline dirty head conflicting replay opens the copy for the fixer", dirty: true, replayStatus: 409, wantPulls: 1, wantReplays: 1, wantFixer: true}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + o, done := newOfflineAdoptHarness(t, true) + defer done() + if tc.online { + o.sink.presence = &ContributorPresence{Registered: true, Online: true} + } + o.adopt.mergeStatus = tc.replayStatus + reason, pr := "check-failing:unit", adoptPR(7, "aaa", offlineReturnedLabels...) + if tc.dirty { + reason, pr = "conflicting", o.dirtyPR(offlineReturnedLabels...) + } + o.returnThenWaitOffline(reason) + o.observe(pr, reason) + if len(o.adopt.pulls) != tc.wantPulls || len(o.adopt.merges) != tc.wantReplays { + t.Fatalf("pulls=%v merges=%v, want %d/%d", o.adopt.pulls, o.adopt.merges, tc.wantPulls, tc.wantReplays) + } + rec := o.record() + if !tc.wantFixer { + if len(o.requests) != 0 || rec.AdoptCopyConflicting { + t.Fatalf("fixer episode requested without a conflict: %+v rec=%+v", o.requests, rec) + } + return + } + if _, kept := o.adopt.refs["refs/heads/hive/adopt-7"]; !kept || slices.Contains(o.adopt.deletedRefs, "refs/heads/hive/adopt-7") { + t.Fatalf("conflicting hive branch not kept for the fixer: refs=%v deleted=%v", o.adopt.refs, o.adopt.deletedRefs) + } + if o.supersedeConflictNotes() != 0 { + t.Fatalf("give-up note posted although the fixer takes the conflict: %v", o.api.comments) + } + if len(o.requests) != 1 { + t.Fatalf("rebase requests = %+v, want one", o.requests) + } + req := o.requests[0] + if req.RequestedBy != AdoptionRebaseRequester || req.Number != 90 || req.Head != "hive/adopt-7" || req.Base != "v5" || req.Attempt != 1 || req.MaxAttempts != DefaultMergeTrainPolicy.MaxRebaseAttempts || req.Repo != "acme/widget" { + t.Fatalf("rebase request = %+v", req) + } + if !rec.AdoptCopyConflicting || rec.AdoptedBy != 90 || !rec.AdoptionLive("aaa") { + t.Fatalf("record after adoption = %+v", rec) + } + body, _ := o.adopt.pulls[0]["body"].(string) + if !strings.Contains(body, "fixer is resolving the conflicts") { + t.Fatalf("copy body does not name the conflict: %q", body) + } + // Next sweep: 074 while the fixer works, nothing re-requested. + o.api.reset() + o.clock.advance(time.Minute) + o.observe(o.dirtyPR(offlineReturnedLabels...), "conflicting") + if added := o.addedLabels(); !slices.Contains(added, "stage/074-adopted-by-hive") { + t.Fatalf("074 not written while the fixer resolves: %v", o.api.added) + } + if len(o.requests) != 1 || len(o.adopt.pulls) != 1 { + t.Fatalf("re-requested or re-opened: requests=%d pulls=%d", len(o.requests), len(o.adopt.pulls)) + } + }) + } +} + +// The original parks at 085 adoption-stalled:rebase-failed-twice once the +// copy's episode is exhausted and the copy still reads dirty; a copy that +// reads mergeable clears the mark instead. +func TestAdoptionCopyRebaseExhaustedParksOriginal(t *testing.T) { + o, done := newOfflineAdoptHarness(t, true) + defer done() + o.adopt.mergeStatus = 409 + o.returnThenWaitOffline("conflicting") + o.observe(o.dirtyPR(offlineReturnedLabels...), "conflicting") + if len(o.requests) != 1 || !o.record().AdoptCopyConflicting { + t.Fatalf("setup: requests=%d rec=%+v", len(o.requests), o.record()) + } + labels074 := []string{"stage/074-adopted-by-hive", "role/contributor", "author/clanker"} + + // First attempt used, second running: still 074. + o.episode[90] = RebaseEpisode{Attempt: 2, MaxAttempts: 2, RequestedBy: AdoptionRebaseRequester} + o.api.reset() + o.clock.advance(time.Minute) + o.observe(o.dirtyPR(labels074...), "conflicting") + if rec := o.record(); rec.Stage != stagelabels.AdoptedByHive { + t.Fatalf("stage while the second attempt runs = %s (%q)", rec.Stage, rec.Reason) + } + + // Both attempts failed: 085 with the reason, one note naming the options. + o.episode[90] = RebaseEpisode{Attempt: 2, MaxAttempts: 2, Exhausted: true, RequestedBy: AdoptionRebaseRequester} + o.api.reset() + o.clock.advance(time.Minute) + o.observe(o.dirtyPR(labels074...), "conflicting") + want := stagelabels.LaneReasonAdoptionStalledPrefix + stagelabels.LaneReasonRebaseFailedTwice + rec := o.record() + if rec.Stage != stagelabels.NeedsDecision || rec.Reason != want { + t.Fatalf("stage after exhaustion = %s (%q), want %s (%q)", rec.Stage, rec.Reason, stagelabels.NeedsDecision, want) + } + if !slices.Contains(o.addedLabels(), "stage/085-needs-decision") { + t.Fatalf("085 not written: %v", o.api.added) + } + notes := 0 + for _, c := range o.api.comments { + if strings.HasPrefix(c, AdoptionStalledMarker) { + notes++ + if !strings.Contains(c, "#90") || !strings.Contains(c, "fresh branch") || !strings.Contains(c, "close this PR as superseded") { + t.Fatalf("stall note does not name the copy and the options: %q", c) + } + } + } + if notes != 1 { + t.Fatalf("stall notes = %d: %v", notes, o.api.comments) + } + o.api.reset() + o.clock.advance(time.Minute) + o.observe(o.dirtyPR("stage/085-needs-decision", "role/contributor", "author/clanker"), "conflicting") + if len(o.api.comments) != 0 { + t.Fatalf("stall note repeated: %v", o.api.comments) + } + + // The copy reads mergeable (a later push took): the mark clears and the + // PR is the hive's again. + o.adopt.mu.Lock() + o.adopt.superseders[90] = map[string]any{"number": 90, "state": "open", "merged": false, "mergeable": true, "mergeable_state": "clean"} + o.adopt.mu.Unlock() + o.api.reset() + o.clock.advance(adoptCheckInterval) + o.observe(o.dirtyPR("stage/085-needs-decision", "role/contributor", "author/clanker"), "conflicting") + rec = o.record() + if rec.AdoptCopyConflicting { + t.Fatalf("mergeable copy left the conflicting mark: %+v", rec) + } + o.clock.advance(time.Minute) + o.observe(o.dirtyPR("stage/085-needs-decision", "role/contributor", "author/clanker"), "conflicting") + if rec = o.record(); rec.Stage != stagelabels.AdoptedByHive { + t.Fatalf("stage after the copy went mergeable = %s (%q)", rec.Stage, rec.Reason) + } +} + +// The hive's own copy (a hive/adopt-* branch) parks at 085 +// rebase-failed-twice when its episode is exhausted and it still conflicts. +func TestAdoptionCopyRebaseExhaustedParksCopy(t *testing.T) { + o, done := newOfflineAdoptHarness(t, true) + defer done() + copy := func(labels ...string) *gh.PullRequest { + pr := adoptPR(90, "ccc", labels...) + pr.User = &gh.User{Login: gh.Ptr(testHiveAppBotLogin), Type: gh.Ptr("Bot")} + pr.Head.Ref = gh.Ptr("hive/adopt-7") + pr.Head.Repo = &gh.Repository{FullName: gh.Ptr("acme/widget")} + return pr + } + o.observeSelf(copy("stage/070-fixing", "needs-rebase"), "conflicting") + key := stageKey("acme", "widget", 90) + if rec, _ := o.e.stageStoreOrShared().Get(key); rec.Stage != stagelabels.Fixing { + t.Fatalf("copy with attempts left = %s", rec.Stage) + } + o.episode[90] = RebaseEpisode{Attempt: 2, MaxAttempts: 2, Exhausted: true, RequestedBy: AdoptionRebaseRequester} + o.api.reset() + o.clock.advance(time.Minute) + o.observeSelf(copy("stage/070-fixing", "needs-rebase"), "conflicting") + rec, _ := o.e.stageStoreOrShared().Get(key) + if rec.Stage != stagelabels.NeedsDecision || rec.Reason != stagelabels.LaneReasonRebaseFailedTwice { + t.Fatalf("copy after exhaustion = %s (%q)", rec.Stage, rec.Reason) + } + // A different branch of the hive's is not an adoption copy. + other := copy("stage/070-fixing", "needs-rebase") + other.Number = gh.Ptr(91) + other.Head.Ref = gh.Ptr("hive/fix-91") + o.episode[91] = RebaseEpisode{Exhausted: true} + o.observeSelf(other, "conflicting") + if rec, _ := o.e.stageStoreOrShared().Get(stageKey("acme", "widget", 91)); rec.Stage == stagelabels.NeedsDecision { + t.Fatalf("non-adoption branch parked at 085: %+v", rec) + } +} + +// Without a resolver the old give-up stands (one note, branch deleted), but +// the offline clanker's PR is re-admitted after the grace, and under a +// journaling boundary the re-admitted push is a new claim: the branch the +// first attempt deleted is recreated instead of the journal answering +// "already applied" and the replay merging into nothing (the 07:15Z +// "hive has nothing it can push" on hivecommons/hive#15307). +func TestAdoptionOfflineRetryRecreatesDeletedBranch(t *testing.T) { + o, done := newOfflineAdoptHarness(t, false) + defer done() + jb := &journalBoundary{applied: map[string]string{}} + o.e.mutation = jb + o.adopt.mergeStatus = 409 + o.returnThenWaitOffline("conflicting") + o.observe(o.dirtyPR(offlineReturnedLabels...), "conflicting") + if o.supersedeConflictNotes() != 1 || len(o.adopt.pulls) != 0 || !slices.Contains(o.adopt.deletedRefs, "refs/heads/hive/adopt-7") { + t.Fatalf("give-up path: notes=%d pulls=%d deleted=%v", o.supersedeConflictNotes(), len(o.adopt.pulls), o.adopt.deletedRefs) + } + delete(o.adopt.refs, "refs/heads/hive/adopt-7") + + // The fixer is wired now (an upgrade); the clanker is still offline. + o.wireResolver() + o.api.reset() + o.clock.advance(adoptionOfflineGrace(adoptPolicy())) + o.observe(o.dirtyPR(offlineReturnedLabels...), "conflicting") + if sha, ok := o.adopt.refs["refs/heads/hive/adopt-7"]; !ok || sha != "aaa" { + t.Fatalf("branch not recreated on the retry: refs=%v replays=%v", o.adopt.refs, jb.replays) + } + if len(o.adopt.pulls) != 1 || len(o.requests) != 1 || !o.record().AdoptCopyConflicting { + t.Fatalf("retry did not open the copy for the fixer: pulls=%d requests=%d rec=%+v", len(o.adopt.pulls), len(o.requests), o.record()) + } +} diff --git a/src/pkg/github/automerge/automerge_contributor_adopt.go b/src/pkg/github/automerge/automerge_contributor_adopt.go index 6376b89cef..41ecd9e5e9 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopt.go +++ b/src/pkg/github/automerge/automerge_contributor_adopt.go @@ -163,6 +163,9 @@ func adoptionDue(rec stagelabels.Record, head string, policy StageLabelPolicy, n return false, "" } if rec.Adopted(head) || rec.AdoptedInPlace() { + if adoptionRetryDue(rec, head, policy, now, presence, hasPresence) { + return true, adoptionRetryReason(presence, hasPresence) + } return false, "" } if !hasPresence { @@ -194,6 +197,49 @@ func adoptionDue(rec stagelabels.Record, head string, policy StageLabelPolicy, n } } +// adoptionOfflineGrace is policy.AdoptOfflineGrace with its default. +func adoptionOfflineGrace(policy StageLabelPolicy) time.Duration { + if policy.AdoptOfflineGrace > 0 { + return policy.AdoptOfflineGrace + } + return 30 * time.Minute +} + +// adoptionRetryDue is the stage-stalled escape for a recorded adoption +// attempt that opened nothing (hivecommons/hive#15307: the supersede's +// replay onto the base conflicted and the attempt was recorded for the +// head, so adoptionDue never fired again while the PR sat at 072/085). +// When the author's clanker is still offline or unregistered — nobody on +// the contributor side can rebase — the head is admitted again once +// AdoptOfflineGrace has passed since the attempt or the clanker's last +// heartbeat, whichever is later. An online clanker keeps the PR: it can +// still push. An adoption that opened a copy or holds the branch in place +// is live, not stalled, and is never re-admitted here. +func adoptionRetryDue(rec stagelabels.Record, head string, policy StageLabelPolicy, now time.Time, presence ContributorPresence, hasPresence bool) bool { + if !rec.AdoptionAttemptedNothingOpened(head) || rec.AdoptedAt.IsZero() { + return false + } + if hasPresence && presence.Registered && presence.Online { + return false + } + since := rec.AdoptedAt + if hasPresence && presence.LastSeen.After(since) { + since = presence.LastSeen + } + return now.Sub(since) >= adoptionOfflineGrace(policy) +} + +// adoptionRetryReason names why a retried adoption fired. +func adoptionRetryReason(presence ContributorPresence, hasPresence bool) string { + switch { + case !hasPresence: + return AdoptReasonGrace + case presence.Registered: + return AdoptReasonOffline + } + return AdoptReasonUnregistered +} + // adoptReasonText is the human-readable half of the adoption note. func adoptReasonText(reason string, grace time.Duration, online bool) string { switch reason { @@ -447,6 +493,12 @@ func adoptionBodyCause(reason string) string { func AdoptionStalledComment(obs stageObservation, rec stagelabels.Record, reason string, sat time.Duration) string { var b strings.Builder fmt.Fprintf(&b, "%s head=%s reason=%s -->\n", AdoptionStalledMarker, obs.HeadSHA, reason) + if reason == stagelabels.LaneReasonAdoptionStalledPrefix+stagelabels.LaneReasonRebaseFailedTwice { + // hivecommons/hive#15307: the copy opened and the fixer tried. + fmt.Fprintf(&b, "The hive adopted this PR (`%s`) into its copy #%d, but the copy still conflicts with `%s` after the fixer's two rebase-resolve attempts: `%s`.\n\n", stagelabels.AdoptedByHive.Label(), rec.AdoptedBy, obs.BaseRef, reason) + fmt.Fprintf(&b, "**Options:** adopt the commits into a fresh branch, or close this PR as superseded.\n\nMoving to `%s` so a person decides.", stagelabels.NeedsDecision.Label()) + return b.String() + } fmt.Fprintf(&b, "The hive adopted this PR (`%s`) but its head `%s` has not moved for %s and the hive has nothing it can push: `%s`.\n\n", stagelabels.AdoptedByHive.Label(), shortSHA(obs.HeadSHA), formatSat(sat), reason) b.WriteString("**Blocker:** ") b.WriteString(adoptionBlockerText(obs, rec)) @@ -823,13 +875,18 @@ func (c *Engine) supersedeAdoptedPR(ctx context.Context, store *stagelabels.Stor priorCopy = stored.AdoptedBy } claimInputs := priorCopyInputs + // The claim names the attempt (hivecommons/hive#15307): the journal + // otherwise reads a re-admitted head's push as "already applied" and + // skips it, leaving no branch for the replay to merge into after an + // earlier attempt deleted it ("hive has nothing it can push"). + attemptStamp := now.UTC().Format(time.RFC3339) // resignedTip stays "" when the branch falls back to the unsigned // contributor head; the body then keeps the manual DCO repair steps. var resignedTip string pushBranch := func(prior int) error { _, err := effects.Execute(ctx, c.mutation, effects.Claim{ Repo: fullRepo, Kind: effects.KindBranchPush, Target: branch, Actor: "stage_labels", - Inputs: claimInputs(prior, map[string]string{"pr": strconv.Itoa(number), "head_sha": obs.HeadSHA, "adopt": "true"}), + Inputs: claimInputs(prior, map[string]string{"pr": strconv.Itoa(number), "head_sha": obs.HeadSHA, "adopt": "true", "attempt": attemptStamp}), }, func(ctx context.Context) (effects.Result, error) { tip := obs.HeadSHA if dcoRehome { @@ -866,14 +923,28 @@ func (c *Engine) supersedeAdoptedPR(ctx context.Context, store *stagelabels.Stor if err := pushBranch(priorCopy); err != nil { return 0, err } + // fixerResolves is set when the replay conflicted and the fixer's + // rebase-resolve episode takes the conflict on the hive's copy. + fixerResolves := false if supersedeHeadConflicts(obs) { - // The head is red on a conflict: opening the copy as-is would just - // move the conflict. Replay the base onto the hive branch first; a - // git conflict is terminal for this head (one note, 07x reason). - conflicted, n, err := c.replaySupersedeOntoBase(ctx, store, key, obs, branch, priorCopy, now) - if err != nil || conflicted { + // The head is red on a conflict: replay the base onto the hive + // branch first so the copy opens mergeable. A git conflict used to + // be terminal for this head (one note, 07x reason) — which handed + // the PR back to a contributor who, by the time adoption fires, + // cannot act (hivecommons/hive#15307). With a RebaseResolver wired + // the copy opens as it is, on a branch the hive can push to, and + // the fixer's rebase-resolve episode resolves it under the + // two-attempt guard (#15104). + conflicted, n, err := c.replaySupersedeOntoBase(ctx, store, key, obs, branch, priorCopy, attemptStamp, now) + if err != nil { return n, err } + if conflicted { + if c.rebaseResolver == nil { + return n, nil + } + fixerResolves = true + } } // openCopy returns the PR it opened, or nil and the journal's recorded @@ -889,7 +960,7 @@ func (c *Engine) supersedeAdoptedPR(ctx context.Context, store *stagelabels.Stor Title: gh.Ptr(nonEmpty(strings.TrimSpace(obs.Title), fmt.Sprintf("Adopt #%d", number))), Head: gh.Ptr(branch), Base: gh.Ptr(obs.BaseRef), - Body: gh.Ptr(AdoptionPRBody(obs, rec, dcoRehome, resignedTip)), + Body: gh.Ptr(AdoptionPRBody(obs, rec, dcoRehome, resignedTip) + adoptionCopyConflictNote(obs, fixerResolves)), }) if apiErr != nil { return effects.Result{}, effects.NotApplied(apiErr) @@ -925,7 +996,10 @@ func (c *Engine) supersedeAdoptedPR(ctx context.Context, store *stagelabels.Stor superseding := created.GetNumber() store.MarkAdopted(key, obs.HeadSHA, superseding, now) store.NoteAdoptReason(key, reason) - c.info("stage labels: contributor PR adopted", "repo", obs.Display, "pr", number, "head", obs.HeadSHA, "superseded_by", superseding, "branch", branch, "fence", rec.AdoptDiffFence, "forced_by", forcedBy) + c.info("stage labels: contributor PR adopted", "repo", obs.Display, "pr", number, "head", obs.HeadSHA, "superseded_by", superseding, "branch", branch, "fence", rec.AdoptDiffFence, "forced_by", forcedBy, "fixer_resolves_conflicts", fixerResolves) + if fixerResolves { + c.requestAdoptionCopyRebase(ctx, store, key, obs, branch, superseding, created.GetHead().GetSHA()) + } if policy.AdoptSupersedeCloseFirst { // hivecommons/hive#15135: one PR per issue — the original closes @@ -986,12 +1060,12 @@ func AdoptionSupersedeConflictComment(obs stageObservation, branch string, files // recorded as supersede-conflict so the request is consumed and the 07x // reason names it, and one note is posted. Other API failures return the // error with the attempt already recorded by the caller. -func (c *Engine) replaySupersedeOntoBase(ctx context.Context, store *stagelabels.Store, key string, obs stageObservation, branch string, priorCopy int, now time.Time) (conflicted bool, comments int, err error) { +func (c *Engine) replaySupersedeOntoBase(ctx context.Context, store *stagelabels.Store, key string, obs stageObservation, branch string, priorCopy int, attemptStamp string, now time.Time) (conflicted bool, comments int, err error) { owner, repo, number := obs.Owner, obs.Repo, obs.Number var status int _, err = effects.Execute(ctx, c.mutation, effects.Claim{ Repo: owner + "/" + repo, Kind: effects.KindBranchPush, Target: branch, Actor: "stage_labels", - Inputs: priorCopyInputs(priorCopy, map[string]string{"pr": strconv.Itoa(number), "head_sha": obs.HeadSHA, "base": obs.BaseRef, "reason": "supersede-replay"}), + Inputs: priorCopyInputs(priorCopy, map[string]string{"pr": strconv.Itoa(number), "head_sha": obs.HeadSHA, "base": obs.BaseRef, "reason": "supersede-replay", "attempt": attemptStamp}), }, func(ctx context.Context) (effects.Result, error) { commit, resp, apiErr := c.gh.Repositories.Merge(ctx, owner, repo, &gh.RepositoryMergeRequest{ Base: gh.Ptr(branch), @@ -1015,6 +1089,10 @@ func (c *Engine) replaySupersedeOntoBase(ctx context.Context, store *stagelabels return false, 0, err } files := c.mergeForwardConflictFiles(ctx, owner, repo, obs.BaseRef, obs.HeadSHA) + if c.rebaseResolver != nil { + c.info("stage labels: supersede replay conflicts with the base; opening the copy for the fixer's rebase-resolve episode", "repo", obs.Display, "pr", number, "head", obs.HeadSHA, "branch", branch, "base", obs.BaseRef, "files", files) + return true, 0, nil + } store.ClearAdoption(key) store.NoteAdoptionBlocked(key, obs.HeadSHA, stagelabels.AdoptBlockedSupersedeConflict, now) c.warn("stage labels: supersede replay conflicts with the base; not opening the copy", "repo", obs.Display, "pr", number, "head", obs.HeadSHA, "branch", branch, "base", obs.BaseRef, "files", files, "reason", stagelabels.AdoptBlockedSupersedeConflict) @@ -1028,6 +1106,55 @@ func (c *Engine) replaySupersedeOntoBase(ctx context.Context, store *stagelabels return true, 1, nil } +// adoptionCopyConflictNote is the paragraph appended to the copy's body +// when it opened conflicting with its base. +func adoptionCopyConflictNote(obs stageObservation, conflicting bool) string { + if !conflicting { + return "" + } + return fmt.Sprintf("\n\n**Conflicts with `%s`:** the contributor head could not be replayed onto the base, so this copy opened as it is and the hive's fixer is resolving the conflicts on this branch (rebase-resolve episode, two attempts). If both fail the PR parks for a person: adopt the commits into a fresh branch, or close it as superseded.\n", obs.BaseRef) +} + +// requestAdoptionCopyRebase opens the fixer's rebase-resolve episode on the +// hive's conflicting copy (hivecommons/hive#15307) and records on the +// original that its copy is in the fixer's hands. The copy is the hive's +// own PR on a base-repo branch, so the fixer router admits it whatever +// the original's head reachability was; the request names the adoption as +// requester and the shared two-attempt guard applies. A resolver error is +// logged: the copy stays on its conflicting path like any hive PR. +func (c *Engine) requestAdoptionCopyRebase(ctx context.Context, store *stagelabels.Store, key string, obs stageObservation, branch string, copy int, copyHead string) { + store.NoteAdoptCopyConflicting(key, true) + req := RebaseRequest{Repo: obs.Owner + "/" + obs.Repo, Number: copy, Base: obs.BaseRef, Head: branch, HeadSHA: nonEmpty(copyHead, obs.HeadSHA), Attempt: 1, MaxAttempts: DefaultMergeTrainPolicy.MaxRebaseAttempts, Lane: obs.Lane, RequestedBy: AdoptionRebaseRequester} + if err := c.rebaseResolver.RequestRebase(ctx, req); err != nil { + c.warn("stage labels: adoption copy rebase-resolve request failed; the copy keeps its conflicting path", "repo", obs.Display, "pr", obs.Number, "superseded_by", copy, "branch", branch, "error", err) + return + } + c.info("stage labels: adoption copy conflicts with the base; fixer rebase-resolve episode requested", "repo", obs.Display, "pr", obs.Number, "superseded_by", copy, "branch", branch, "base", obs.BaseRef, "head", req.HeadSHA, "requested_by", AdoptionRebaseRequester, "max_attempts", req.MaxAttempts) +} + +// adoptionCopyRebaseExhausted reports whether the fixer's rebase-resolve +// episode on the hive's copy of this adoption used both attempts without +// the copy reading mergeable (the original's 085 reason +// adoption-stalled:rebase-failed-twice; hivecommons/hive#15307). +func (c *Engine) adoptionCopyRebaseExhausted(obs stageObservation, rec stagelabels.Record) bool { + if !rec.AdoptCopyConflicting || rec.AdoptedBy <= 0 || c.rebaseEpisode == nil { + return false + } + ep, ok := c.rebaseEpisode(obs.Owner+"/"+obs.Repo, rec.AdoptedBy) + return ok && ep.Exhausted +} + +// adoptionCopyRebaseFailedTwice reports whether obs is the hive's own +// adoption copy (a hive/adopt-* branch the App opened), reads conflicting, +// and the fixer's rebase-resolve episode on it is exhausted. +func (c *Engine) adoptionCopyRebaseFailedTwice(obs stageObservation) bool { + if c.rebaseEpisode == nil || obs.Lane != stageLaneSelf || !strings.HasPrefix(obs.HeadRef, adoptBranchPrefix) || !supersedeHeadConflicts(obs) { + 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 { @@ -1276,9 +1403,32 @@ func (c *Engine) settleSuperseder(ctx context.Context, store *stagelabels.Store, case strings.EqualFold(sup.GetState(), "closed"): return c.recoverOrphanedAdoption(ctx, store, key, obs, rec, policy, now) } + c.settleAdoptionCopyConflict(store, key, obs, rec, sup) return 0, nil } +// settleAdoptionCopyConflict clears the copy-conflicting mark once GitHub +// reads the hive's copy as mergeable (the fixer's rebase took), so the +// original's row and the 085 guard stop naming the conflict. +func (c *Engine) settleAdoptionCopyConflict(store *stagelabels.Store, key string, obs stageObservation, rec stagelabels.Record, sup *gh.PullRequest) { + if !rec.AdoptCopyConflicting || sup == nil || !adoptionCopyReadsMergeable(sup) { + return + } + store.NoteAdoptCopyConflicting(key, false) + c.info("stage labels: adoption copy reads mergeable again; conflict resolved", "repo", obs.Display, "pr", obs.Number, "superseded_by", sup.GetNumber(), "copy_head", sup.GetHead().GetSHA(), "mergeable_state", sup.GetMergeableState()) +} + +// adoptionCopyReadsMergeable is GitHub's answer on the copy: mergeable +// true, or a mergeable_state that is not "dirty"; an unknown (still +// computing) answer keeps the mark. +func adoptionCopyReadsMergeable(sup *gh.PullRequest) bool { + if sup.Mergeable != nil { + return sup.GetMergeable() + } + state := strings.ToLower(strings.TrimSpace(sup.GetMergeableState())) + return state != "" && state != "dirty" && state != "unknown" +} + // supersederCarriesHead reports whether the merged superseder landed the // original's current head: the adoption took that head, or the superseder's // own head is it (the fix lane re-pushed the contributor's later commits, @@ -1803,7 +1953,20 @@ func inPlaceRehomeReason(obs stageObservation, rec stagelabels.Record, policy St // sat past the dwell with CI idle and a real blocker named. A live // superseder is progress; an optional check alone is not a blocker. func adoptionStalledReason(obs stageObservation, rec stagelabels.Record, policy StageLabelPolicy, now time.Time) string { - if rec.AdoptedBy > 0 || obs.HeadSHA == "" { + return adoptionStalledReasonWith(obs, rec, policy, now, false) +} + +// adoptionStalledReasonWith is adoptionStalledReason with the copy's +// rebase-resolve verdict: an exhausted episode on a still-conflicting copy +// (hivecommons/hive#15307) is the one stall a live superseder can carry. +func adoptionStalledReasonWith(obs stageObservation, rec stagelabels.Record, policy StageLabelPolicy, now time.Time, copyRebaseExhausted bool) string { + if obs.HeadSHA == "" { + return "" + } + if rec.AdoptedBy > 0 { + if copyRebaseExhausted && rec.AdoptCopyConflicting { + return stagelabels.LaneReasonAdoptionStalledPrefix + stagelabels.LaneReasonRebaseFailedTwice + } return "" } if rec.AdoptionAttemptedNothingOpened(obs.HeadSHA) { @@ -1840,7 +2003,11 @@ func (c *Engine) escapeStalledAdoption(ctx context.Context, store *stagelabels.S if rehomeReason == "" && rec.AdoptedInPlace() && obs.HeadSHA == rec.AdoptedHead && !adoptedHeadDCORed(obs, rec) && adoptionBlocked(obs.Labels) == "" && !verdictNeedsHuman(obs.Detail) && c.pushAccessLost(ctx, obs) { rehomeReason = AdoptReasonPushRehome } - if rehomeReason == "" && adoptionStalledReason(obs, rec, policy, now) != "" { + copyExhausted := c.adoptionCopyRebaseExhausted(obs, rec) + stalledReason := func(rec stagelabels.Record) string { + return adoptionStalledReasonWith(obs, rec, policy, now, copyExhausted) + } + if rehomeReason == "" && stalledReason(rec) != "" { // Before a red head is handed to a person, try the recovery a // since-fixed base or shared-CI flake needs (hivecommons/hive#14500): // an attempt holds the escalation while CI runs on the result, and @@ -1856,7 +2023,7 @@ func (c *Engine) escapeStalledAdoption(ctx context.Context, store *stagelabels.S if rec.AdoptionEscalated(obs.HeadSHA) { // A workflow-path refusal is a verdict on the head itself: it holds // until the head moves, whatever the re-home or stall reasons say. - if rec.AdoptEscalatedReason == adoptionWorkflowRefusedReason || rec.AdoptEscalatedReason == stagelabels.LaneReasonAdoptionChildClosedTwice || rec.AdoptEscalatedReason == stagelabels.LaneReasonAdoptionCopyFailed || (rehomeReason == "" && adoptionStalledReason(obs, rec, policy, now) != "") { + if rec.AdoptEscalatedReason == adoptionWorkflowRefusedReason || rec.AdoptEscalatedReason == stagelabels.LaneReasonAdoptionChildClosedTwice || rec.AdoptEscalatedReason == stagelabels.LaneReasonAdoptionCopyFailed || (rehomeReason == "" && stalledReason(rec) != "") { return adoptionEscape{Escalated: true, Reason: rec.AdoptEscalatedReason}, 0, nil } store.ClearAdoptionEscalation(key) @@ -1912,7 +2079,7 @@ func (c *Engine) escapeStalledAdoption(ctx context.Context, store *stagelabels.S firstErr = err rec, _ = store.Get(key) } - reason = adoptionStalledReason(obs, rec, policy, now) + reason = stalledReason(rec) if reason == "" { return adoptionEscape{}, comments, firstErr } diff --git a/src/pkg/github/automerge/automerge_merge_train.go b/src/pkg/github/automerge/automerge_merge_train.go index 48e6417174..1bba995f74 100644 --- a/src/pkg/github/automerge/automerge_merge_train.go +++ b/src/pkg/github/automerge/automerge_merge_train.go @@ -65,6 +65,24 @@ type RebaseRequest struct { MaxAttempts int // Lane is the sweep lane that owns the PR (prstage.StageLane*). Lane string + // RequestedBy names the requester the episode is opened for: "" (the + // merge train) or AdoptionRebaseRequester for the hive's conflicting + // copy of an adopted PR (hivecommons/hive#15307). + RequestedBy string +} + +// AdoptionRebaseRequester is RebaseRequest.RequestedBy for a rebase the +// adoption lane asks of the fixer on the hive's own copy branch. +const AdoptionRebaseRequester = "adoption" + +// RebaseEpisode is what Options.RebaseEpisode reports for a PR with an +// open conflict episode: how many attempts the fixer has used of the +// guard, and whether the guard is exhausted. +type RebaseEpisode struct { + Attempt int + MaxAttempts int + Exhausted bool + RequestedBy string } // RebaseResolver enqueues a rebase-resolve task for a conflicting PR. diff --git a/src/pkg/github/automerge/automerge_stage_labels.go b/src/pkg/github/automerge/automerge_stage_labels.go index 2f4aab8e91..eebf4ef12c 100644 --- a/src/pkg/github/automerge/automerge_stage_labels.go +++ b/src/pkg/github/automerge/automerge_stage_labels.go @@ -72,6 +72,13 @@ type StageLabelPolicy struct { // source (ContributorPresenceSource); without one the graces above apply. AdoptAfterOffline time.Duration AdoptAfterUnregistered time.Duration + // AdoptOfflineGrace is the stage-stalled escape for a recorded adoption + // attempt that opened nothing (a supersede whose replay failed) while + // the author's clanker is still offline or unregistered: after it the + // head is admitted to adoption again instead of sitting at 072/085 + // (governor.labels.stage.adoption.offline_grace, default 30m; + // hivecommons/hive#15307). + AdoptOfflineGrace time.Duration // AdoptInPlace allows adoption by pushing to the PR's own branch when // GitHub permits (same-repo head or maintainer_can_modify) instead of a // superseding App PR (governor.labels.stage.adoption.in_place, default on). @@ -1075,6 +1082,16 @@ func (c *Engine) ApplyStageLabels(ctx context.Context) (StageLabelResult, error) obs.Reason = stagelabels.AdoptBlockedSupersedeConflict pass.AdoptionRefusedReason = stagelabels.AdoptBlockedSupersedeConflict } + if !verdict.Terminal && verdict.Stage == fixingStage(obs) && c.adoptionCopyRebaseFailedTwice(obs) { + // The hive's own adoption copy, still conflicting after the + // fixer's two rebase-resolve attempts (hivecommons/hive#15307): + // a person decides (adopt into a fresh branch / close as + // superseded) instead of the copy idling on its fixing stage. + verdict.Stage = stagelabels.NeedsDecision + verdict.Rank = stageRankOwned + obs.Reason = stagelabels.LaneReasonRebaseFailedTwice + pass.RebaseFailedTwice = true + } tr = store.Observe(key, verdict.Stage, obs.Reason) // hivecommons/hive#12502: remember the author so the dashboard can // list "PRs returned to this contributor" from the store alone. @@ -1237,7 +1254,18 @@ func (c *Engine) ApplyStageLabels(ctx context.Context) (StageLabelResult, error) } } } - if !hasLabel(obs.Labels, delegatedecision.LabelAdoptSupersede) && (want.Stage == stagelabels.ReturnedToContributor || want.Stage == stagelabels.NeedsAuthor) && (policy.ContributorNudge || policy.Adoption) { + // hivecommons/hive#15307: an adoption attempt that opened nothing + // pins the PR at 074/085 where this block never ran, so a clanker + // that stayed offline was never adopted again. The retry runs the + // adoption half only (adoptionRetryDue gates it on the offline + // grace); nobody is re-nudged. + adoptionRetry := false + if policy.Adoption && !obs.Merged && (want.Stage == stagelabels.AdoptedByHive || want.Stage == stagelabels.NeedsDecision) { + if rec, ok := store.Get(key); ok && rec.AdoptionAttemptedNothingOpened(obs.HeadSHA) { + adoptionRetry = true + } + } + if !hasLabel(obs.Labels, delegatedecision.LabelAdoptSupersede) && (want.Stage == stagelabels.ReturnedToContributor || want.Stage == stagelabels.NeedsAuthor || adoptionRetry) && (policy.ContributorNudge || policy.Adoption) { // The 072 interrupt machinery (nudge + adoption) is for // author/clanker only: there is a hive on the other end to // interrupt or stand in for. A human-authored PR simply waits @@ -1250,7 +1278,7 @@ func (c *Engine) ApplyStageLabels(ctx context.Context) (StageLabelResult, error) kind = c.stageAuthorKind(obs, policy, true) } if kind == authorkind.Clanker { - if policy.ContributorNudge { + if policy.ContributorNudge && !adoptionRetry { n, err := c.nudgeContributor(ctx, store, key, obs, policy, now) result.Comments += n if err != nil && firstErr == nil { diff --git a/src/pkg/github/automerge/automerge_sweep.go b/src/pkg/github/automerge/automerge_sweep.go index 3c78307572..104c9ae149 100644 --- a/src/pkg/github/automerge/automerge_sweep.go +++ b/src/pkg/github/automerge/automerge_sweep.go @@ -203,6 +203,11 @@ type Options struct { // RebaseResolver receives the train's rebase-resolve requests for a // conflicting PR; nil leaves a dirty front on its conflicting path. RebaseResolver RebaseResolver + // RebaseEpisode reads the fixer's rebase-resolve episode for a PR (the + // pkg/rebasemerge attempts ledger through cmd/hive): the adoption lane + // parks a copy whose episode is exhausted at 085 instead of leaving it + // on its fixing stage (hivecommons/hive#15307). nil reads as no episode. + RebaseEpisode func(repo string, number int) (RebaseEpisode, bool) // HotspotRecorder receives the merge train's PR file lists and the // conflicts it asks the resolver to repair, so the merge-hotspot // advisor (pkg/hotspot) derives its evidence without polling GitHub @@ -334,6 +339,7 @@ type Engine struct { mergeTrainPolicy func() MergeTrainPolicy rebaseResolver RebaseResolver + rebaseEpisode func(repo string, number int) (RebaseEpisode, bool) hotspotRecorder HotspotRecorder mergeTrainState } @@ -388,6 +394,7 @@ func New(transport Transport, opts Options) *Engine { sweepTrigger: opts.SweepTrigger, mergeTrainPolicy: mergeTrainPolicyOption(opts), rebaseResolver: opts.RebaseResolver, + rebaseEpisode: opts.RebaseEpisode, hotspotRecorder: opts.HotspotRecorder, evaluatedHeads: make(map[string]string), requiredChecksFallbackWarned: make(map[string]bool), diff --git a/src/pkg/stageengine/derive_pr.go b/src/pkg/stageengine/derive_pr.go index 0a1a31620d..9383592d2e 100644 --- a/src/pkg/stageengine/derive_pr.go +++ b/src/pkg/stageengine/derive_pr.go @@ -288,6 +288,11 @@ func passDecision(verdict stageVerdict, role stagelabels.Role, obs stageObservat if !verdict.Terminal && pass.AdoptionRefusedReason != "" && verdict.Stage == FixingStage(obs) { obs.Reason = pass.AdoptionRefusedReason } + if !verdict.Terminal && pass.RebaseFailedTwice && verdict.Stage == FixingStage(obs) { + verdict.Stage = stagelabels.NeedsDecision + verdict.Rank = stageRankOwned + obs.Reason = stagelabels.LaneReasonRebaseFailedTwice + } d := Decision{ Stage: verdict.Stage, Role: role, diff --git a/src/pkg/stageengine/facts.go b/src/pkg/stageengine/facts.go index 18870bd5bc..cec26eed80 100644 --- a/src/pkg/stageengine/facts.go +++ b/src/pkg/stageengine/facts.go @@ -275,6 +275,11 @@ type PRPassFacts struct { // fixing stage but the reason names the failed replay, not the // generic conflict, so the owner sees why the copy never opened. AdoptionRefusedReason string + // RebaseFailedTwice is set on the hive's own adoption copy when it + // still conflicts after the fixer's two rebase-resolve attempts: the + // PR reads 085 with stagelabels.LaneReasonRebaseFailedTwice so a + // person decides (hivecommons/hive#15307). + RebaseFailedTwice bool // Stalled is the pass's dwell verdict (stagelabels.StalledWith over the // store record after this pass's Observe); KindLabels are the // configured author/ names. Both are outputs of the pass the diff --git a/src/pkg/stageengine/transition_table.go b/src/pkg/stageengine/transition_table.go index 57d92a6249..fc19fdf269 100644 --- a/src/pkg/stageengine/transition_table.go +++ b/src/pkg/stageengine/transition_table.go @@ -47,6 +47,7 @@ var diagramEdges = map[Edge]bool{ {stagelabels.MergeQueue, stagelabels.Fixing}: true, // new head red (backward hop, commented) {stagelabels.MergeQueue, stagelabels.ReturnedToContributor}: true, // contributor head red (backward hop, commented) {stagelabels.Fixing, stagelabels.ReviewPending}: true, // fixed head pushed + {stagelabels.Fixing, stagelabels.NeedsDecision}: true, // hive adoption copy still conflicting after two fixer rebase attempts (rebase-failed-twice) {stagelabels.NeedsAuthor, stagelabels.ReviewPending}: true, // author pushes a new head {stagelabels.ReturnedToContributor, stagelabels.ReviewPending}: true, // author pushes a new head {stagelabels.ReturnedToContributor, stagelabels.AdoptedByHive}: true, // clanker unavailable, adopted diff --git a/src/pkg/stagelabels/human.go b/src/pkg/stagelabels/human.go index 2ed660a8a7..7ac6f03020 100644 --- a/src/pkg/stagelabels/human.go +++ b/src/pkg/stagelabels/human.go @@ -259,6 +259,12 @@ const ( // could push; the suffix is the lane reason it was stuck on // ("adoption-stalled:reviewer-verdict:changes_requested"). LaneReasonAdoptionStalledPrefix = "adoption-stalled:" + // LaneReasonRebaseFailedTwice is the 085 reason for the hive's copy of + // an adopted PR (hive/adopt-) that opened conflicting and stayed + // dirty after the fixer's rebase-resolve episode used both attempts + // (hivecommons/hive#15104 guard); the same suffix under + // LaneReasonAdoptionStalledPrefix parks a still-open original. + LaneReasonRebaseFailedTwice = "rebase-failed-twice" ) // RouteHuman decides which stage a lane's "a human must act" resolves to. diff --git a/src/pkg/stagelabels/store.go b/src/pkg/stagelabels/store.go index cc3207a65d..65f3097a81 100644 --- a/src/pkg/stagelabels/store.go +++ b/src/pkg/stagelabels/store.go @@ -100,6 +100,13 @@ type Record struct { AdoptCopyRedHeads []string `json:"adopt_copy_red_heads,omitempty"` AdoptReopenedAt time.Time `json:"adopt_reopened_at,omitempty"` AdoptReopenedFrom int `json:"adopt_reopened_from,omitempty"` + // AdoptCopyConflicting is set when the hive's copy (AdoptedBy) opened + // conflicting with its base because the contributor head could not be + // replayed onto it and the fixer's rebase-resolve episode owns the + // conflict (hivecommons/hive#15307); cleared when the copy reads + // mergeable again. The tracker row reads "Adopting · fixer resolving + // conflicts" while it is set. + AdoptCopyConflicting bool `json:"adopt_copy_conflicting,omitempty"` // SupersederMergedNotedHead is the original's head for which the // "superseder merged but this PR has moved on" note was posted, so a // diverged original is told once per head rather than every poll. @@ -1151,6 +1158,7 @@ func (s *Store) MarkAdopted(key, head string, by int, now time.Time) { } r.AdoptedHead, r.AdoptedBy, r.AdoptedAt, r.AdoptCheckedAt = head, by, now, now r.AdoptMode = AdoptModeSupersede + r.AdoptCopyConflicting = false r.AdoptBlockedHead, r.AdoptBlockedBy, r.AdoptBlockedAt = "", "", time.Time{} r.AdoptForcedBy, r.AdoptForcedAt = "", time.Time{} r.RerouteTo, r.RerouteBy, r.RerouteAt, r.RerouteReason, r.RerouteHead = "", "", time.Time{}, "", "" @@ -1533,6 +1541,22 @@ func (s *Store) ClearAdoption(key string) { r.AdoptOrphanedBy, r.AdoptOrphanedAt, r.AdoptOrphanCount = 0, time.Time{}, 0 r.SupersededBy, r.SupersededAt, r.SupersededOpen, r.SupersederMergedNotedHead = 0, time.Time{}, false, "" r.SupersededClosedFirst, r.AdoptCopyRedHeads, r.AdoptReopenedFrom = false, nil, 0 + r.AdoptCopyConflicting = false + s.items[key] = r + s.dirty = true +} + +// NoteAdoptCopyConflicting records whether the hive's copy of this +// adoption is conflicting with its base and in the fixer's hands +// (hivecommons/hive#15307). No-op when nothing changes. +func (s *Store) NoteAdoptCopyConflicting(key string, conflicting bool) { + s.mu.Lock() + defer s.mu.Unlock() + r, ok := s.items[key] + if !ok || r.AdoptCopyConflicting == conflicting { + return + } + r.AdoptCopyConflicting = conflicting s.items[key] = r s.dirty = true }