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-adopt-overrides-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Approve no longer deadlocks a contributor PR the hive cannot merge as-is: when the approved head is on a fork the App cannot update and sits behind the base (`fork-not-editable`), conflicts, or lacks a sign-off, the admission no longer records `not adopted: a maintainer approved this head; the hive merges it as-is` — the hive adopts and carries the approval to its copy. Adopt now always wins over an earlier Approve: recording it clears the admission blocker at once, the row immediately reads *adopting… (queued)* with the Adopt now action gone from the menu and popover, and the decision response says `adoption-queued` instead of promising the running pass when the copy has not opened yet.
41 changes: 39 additions & 2 deletions src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,40 @@ the engine derives it from the recorded approval and writes it back. An
explicit **Adopt** / **Re-author** from the dashboard is the person choosing
re-authoring and is not refused.

**Approve means "approved to proceed", not "merge this exact head whatever
happens".** The merge-as-is hold applies only while the head *is* mergeable
as-is. When the lane cannot land the approved head unchanged — the fork is
not editable by the App and sits behind the base (`fork-not-editable`),
it conflicts (`conflicting` / `not-mergeable` / `needs-rebase`), or a
commit lacks `Signed-off-by` (`dco-missing`) — the admission does not
block adoption: the hive adopts (re-authors the commits on a hive-owned
branch) and **carries the approval to its copy** (a decision approval
recorded on the copy's head; the copy's body says *Approval carried over:
@you approved #N at head …*). Logged as `a person admitted this head but
the hive cannot merge it as-is; adopting and carrying the approval`. Before
this, an approved fork PR that fell behind `v5` deadlocked: every cycle
refused adoption (*not adopted: a maintainer approved this head; the hive
merges it as-is*) while the merge itself failed on `fork-not-editable`.

**Adopt now always wins over an earlier Approve.** Recording the forced
adoption clears the `operator-admission` blocker at once, and the adoption
engine bypasses admission, presence, grace and `maintainer_policy` on its
next pass. The response is honest about timing: `status: adopted-now` with
the copy's number when the nudged pass opened it within the handler's wait,
else `status: adoption-queued` (*Adopting… (queued): the hive opens its copy
on its next stage pass*). Either way the row is in its acted state the
moment you click — `adoption.queued_by` / `takeover.forced_by` on the
payload, chip *adopting… (queued)*, caption *Adopting… (queued by @you …)*,
no *not adopted* blocker, **Adopt now** gone from the ⋯ menu and the
popover, no decision popover asking again — until the sweep lands and the
row reads *Adopted → #N*.

| You | Head mergeable as-is | Head not mergeable as-is (fork not editable + behind, conflicting, DCO missing) |
|---|---|---|
| **Approve** | admitted; hive merges it unchanged after checks and soak; no adoption | hive adopts (supersede), approval carried to the copy |
| **Adopt** / **Re-author** | hive adopts on the next pass (grace and policy still apply to a plain Adopt) | same |
| **Adopt now** (`force: true`) | hive adopts on the next pass regardless of an earlier Approve, presence, grace, policy; row acted at once | same |

| Decision | What it does | Audit / ledger |
|---|---|---|
| `re-author` — *Re-author as hive PR* | Offered as its own lead action on a 090 PR whose head cannot merge as-is — the stage record's commit check counted commits without a `Signed-off-by` (`dco_unsigned` / `dco_total` on the row). The popover and both Approve confirms say so **before** acting (*2 of 3 commits have no Signed-off-by, so a required DCO check refuses the merge*); approving never re-authors by itself. Re-author posts its own note and the `adoption/supersede` request label; the hive re-homes the commits on a hive-owned, signed-off branch and opens a superseding PR. Disabled with the reason on a person's PR (the hive does not re-author a human's PR — ask them to `git commit -s --amend`). | `repo_item_decision_adopt` with `decision=re-author`; `last_operator_action.action: re-author`; toast *adopted*. |
Expand Down Expand Up @@ -791,8 +825,11 @@ Dashboard: Settings → Labels → "When the PR author maintains the
repository". Whatever the policy and the clocks say, the row's ⋯ menu on a
072 / 071 clanker PR offers the operator **Adopt now — hive takes it over**
(decision API `adopt` + `force: true`: supersede adoption on the next nudged
sweep, bypassing presence, grace and `maintainer_policy`; `hold` still
stops it; marker `hive:adopted reason=operator-forced by=@login`) and
sweep, bypassing presence, grace, `maintainer_policy` and an earlier
Approve's admission; `hold` still stops it; marker `hive:adopted
reason=operator-forced by=@login`; the row shows *adopting… (queued)* and
drops the action until the copy opens — see *Adopt now always wins over an
earlier Approve* above) and
**Reroute to another clanker** (decision API `reroute` + `to: <login>|any`:
the follow-up work goes to an online contributor clanker's fix queue as a
`fix-pr` interrupt — the same mechanism as the 072 nudge — with a
Expand Down
12 changes: 9 additions & 3 deletions src/pkg/dashboard/api_repo_item_decision_reroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ func (s *Server) nudgeSweepAndAwaitAdoption(ctx context.Context, store *stagelab
return rec.AdoptedBy
}

// repoItemDecisionStatusAdoptionQueued is Adopt now's status when the sweep
// has not opened the copy within the handler's wait: queued, not done. The
// earlier "adoption-forced" wording claimed the pass now running would open
// it, which the tracker then contradicted for minutes.
const repoItemDecisionStatusAdoptionQueued = "adoption-queued"

func repoItemAdoptNowResponse(repoFull string, number, superseding int) repoItemDecisionResponse {
out := repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: repoItemDecisionAdopt, Label: delegatedecision.LabelAdoptSupersede,
Result: &RowActionResult{Target: rowActionTarget(repoFull, "pr", number), Action: rowActionAdopted}}
Expand All @@ -165,9 +171,9 @@ func repoItemAdoptNowResponse(repoFull string, number, superseding int) repoItem
out.Result.Next = fmt.Sprintf("The hive rebases and fixes CI on #%d; the author's commits and sign-off are preserved.", superseding)
return out
}
out.Status = "adoption-forced"
out.Result.Outcome = "Adoption forced: hive opens its copy on the pass now running."
out.Result.Next = "The contributor PR closes as superseded (an agent's PR in the adopting pass, a person's when the hive's copy merges) and leaves the list; the author's commits and sign-off are preserved. The row updates when the pass lands."
out.Status = repoItemDecisionStatusAdoptionQueued
out.Result.Outcome = "Adopting… (queued): the hive opens its copy on its next stage pass; any earlier approval of this head no longer holds it."
out.Result.Next = "The row reads \"Adopting… (queued)\" until the pass lands, then \"Adopted → #N\". The contributor PR closes as superseded (an agent's PR in the adopting pass, a person's when the hive's copy merges); the author's commits and sign-off are preserved."
return out
}

Expand Down
49 changes: 48 additions & 1 deletion src/pkg/dashboard/api_repo_item_takeover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ func TestRepoItemAdoptNowWithoutSweepIsQueuedForm(t *testing.T) {

w := postRepoItemDecision(t, srv, 8, "writer", `{"decision":"adopt","force":true,"type":"pr"}`)
out := decodeDecision(t, w.Body.String())
if w.Code != http.StatusOK || out.Status != "adoption-forced" || !strings.HasPrefix(out.Result.Outcome, "Adoption forced:") {
if w.Code != http.StatusOK || out.Status != repoItemDecisionStatusAdoptionQueued || !strings.HasPrefix(out.Result.Outcome, "Adopting… (queued)") || out.Result.Action != rowActionAdopted {
t.Fatalf("code=%d out=%+v", w.Code, out)
}
if strings.Contains(out.Result.Outcome, "pass now running") {
t.Fatalf("queued adoption promised the running pass: %q", out.Result.Outcome)
}
rec, _ := store.Get(stagelabels.Key("testorg/testrepo", 8))
if rec.AdoptForcedBy != "writer" || !recForced(rec) {
t.Fatalf("forced mark missing: %+v", rec)
Expand Down Expand Up @@ -323,6 +326,50 @@ func TestStageTrackerTakeoverOffersAdoptNowAndReroute(t *testing.T) {
}
}

// Approve, then Adopt now (hive#15312): the moment Adopt now is recorded
// the row is in its acted state — "Adopting… (queued by @x)", no "not
// adopted: a maintainer approved this head", no Adopt now action, no
// decision popover asking the person to take it over again.
func TestStageTrackerTakeoverQueuedAfterAdoptNow(t *testing.T) {
now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC)
s, store, status := adoptionFixture(t, now, config.AdoptionMaintainerPolicyNever, offlinePresence(now.Add(-26*time.Hour)))
s.rerouteCandidates = func(string) []RerouteCandidate { return []RerouteCandidate{{Login: "bee2", Capable: true}} }
key := stagelabels.Key("hivecommons/hive", 14524)
store.NoteAdmission(key, "feed", stagelabels.OperatorApprovalAdmission("andan02"), now.Add(-10*time.Minute))
store.NoteAdoptionBlocked(key, "feed", stagelabels.AdoptBlockedOperatorAdmission, now.Add(-9*time.Minute))
it := trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14524)
if it.Adoption == nil || it.Adoption.BlockedBy != stagelabels.AdoptBlockedOperatorAdmission || !strings.Contains(it.Adoption.Text, "a maintainer approved this head") || it.Takeover == nil || !it.Takeover.AdoptNow {
t.Fatalf("precondition (approved, blocked, Adopt now offered): adoption=%+v takeover=%+v", it.Adoption, it.Takeover)
}

store.NoteAdoptionForced(key, "andan02", now.Add(-time.Minute))
it = trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14524)
a, tk := it.Adoption, it.Takeover
if a == nil || a.QueuedBy != "andan02" || a.BlockedBy != "" || a.Action != "" || !strings.HasPrefix(a.Text, "Adopting… (queued by @andan02") {
t.Fatalf("adoption after Adopt now = %+v", a)
}
if tk == nil || tk.AdoptNow || tk.AdoptNowReason != takeoverAdoptNowQueued || tk.ForcedBy != "andan02" || !tk.Reroute {
t.Fatalf("takeover after Adopt now = %+v", tk)
}
if it.DecisionNeeded != nil {
t.Fatalf("queued adoption still asks a person: %+v", it.DecisionNeeded)
}
if strings.Contains(it.Caption, "not adopted") {
t.Fatalf("caption still says not adopted: %q", it.Caption)
}
for _, o := range takeoverDecisionOptions(tk, false) {
if o.Action == decisionActionAdoptNow {
t.Fatalf("Adopt now still offered in the popover: %+v", o)
}
}
raw, _ := json.Marshal(it)
for _, want := range []string{`"queued_by":"andan02"`, `"forced_by":"andan02"`, `"adopt_now":false`} {
if !strings.Contains(string(raw), want) {
t.Errorf("payload lacks %s: %s", want, raw)
}
}
}

func TestStageTrackerTakeoverDisabledReasons(t *testing.T) {
now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC)
s, store, status := adoptionFixture(t, now, config.AdoptionMaintainerPolicyNever, offlinePresence(now.Add(-26*time.Hour)))
Expand Down
72 changes: 72 additions & 0 deletions src/pkg/dashboard/stage_tracker_adopt_queued.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Adopt now's acted state on the Activity Monitor row (hive#15312: the
// maintainer pressed Adopt now on PRs they had approved earlier and the rows
// kept reading "not adopted: a maintainer approved this head" and offering
// Adopt now again until the sweep landed minutes later). Once the payload
// carries `adoption.queued_by` / `takeover.forced_by` the chip reads
// "adopting… (queued)" and the ⋯ menu no longer offers Adopt now. The
// helpers are lifted out of index.html so this runs against the shipped
// source.
const test = require('node:test');
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');

const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8');

function pick(re, what) {
const m = html.match(re);
assert.ok(m, what + ' not found in index.html');
return m[0];
}

const src = [
pick(/const STAGE_TRACKER_ACTION_LABELS = \{[\s\S]*?\n \};\n/, 'STAGE_TRACKER_ACTION_LABELS'),
pick(/const STAGE_TRACKER_WHY_WRITE = [^\n]*\n/, 'STAGE_TRACKER_WHY_WRITE'),
pick(/function stageTrackerAdoptOffered\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptOffered'),
pick(/const STAGE_TRACKER_ADOPTION_QUEUED_CHIP = [^\n]*\n/, 'STAGE_TRACKER_ADOPTION_QUEUED_CHIP'),
pick(/function stageTrackerAdoptionQueued\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionQueued'),
pick(/function stageTrackerAdoptionChipText\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionChipText'),
pick(/const STAGE_TRACKER_ADOPT_NOW_CONSEQUENCE = [^\n]*\n/, 'STAGE_TRACKER_ADOPT_NOW_CONSEQUENCE'),
pick(/const STAGE_TRACKER_REROUTE_ANY = [^\n]*\n/, 'STAGE_TRACKER_REROUTE_ANY'),
pick(/const STAGE_TRACKER_REROUTE_PREFIX = [^\n]*\n/, 'STAGE_TRACKER_REROUTE_PREFIX'),
pick(/function stageTrackerTakeoverOf\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerTakeoverOf'),
pick(/function stageTrackerClankerLabel\(c, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerClankerLabel'),
pick(/function stageTrackerRerouteOptions\(tk, enabled, why, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerRerouteOptions'),
pick(/function stageTrackerTakeoverActions\(item, ctx, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerTakeoverActions'),
].join('\n');
const api = new Function(src + '; return { chipText: stageTrackerAdoptionChipText, queued: stageTrackerAdoptionQueued, actions: stageTrackerTakeoverActions };')();

const ctx = { user: 'clubanderson', canHold: true };
function row(over) {
return Object.assign({
repo: 'hivecommons/hive', number: 15312, kind: 'pr', stage: 72,
adoption: { author: 'odttlnt', due: true, blocked_by: 'operator-admission', nudges: 3, author_online: false, text: 'waiting on @odttlnt (offline 18m) — not adopted: a maintainer approved this head; the hive merges it as-is' },
takeover: { author: 'odttlnt', author_online: false, adopt_now: true, reroute: false, reroute_reason: 'no other clanker is online' },
}, over || {});
}

test('before Adopt now: the approved-head blocker shows and Adopt now is offered', () => {
const it = row();
assert.equal(api.queued(it), false);
assert.equal(api.chipText(it), 'not adopted');
const adopt = api.actions(it, ctx).find(a => a.id === 'decide:adopt-now');
assert.ok(adopt && adopt.enabled, 'Adopt now offered');
});

test('after Adopt now: acted state — "adopting… (queued)", no Adopt now action, Reroute still listed', () => {
const it = row({
adoption: { author: 'odttlnt', due: true, queued_by: 'clubanderson', nudges: 3, author_online: false, text: 'Adopting… (queued by @clubanderson; the hive opens its copy on the next stage pass)' },
takeover: { author: 'odttlnt', author_online: false, adopt_now: false, adopt_now_reason: 'adoption already queued', forced_by: 'clubanderson', forced_at: '2026-10-30T03:16:58Z', reroute: false, reroute_reason: 'no other clanker is online' },
});
assert.equal(api.queued(it), true);
assert.equal(api.chipText(it), 'adopting… (queued)');
const acts = api.actions(it, ctx);
assert.ok(!acts.some(a => a.id === 'decide:adopt-now'), 'Adopt now must not be offered again: ' + JSON.stringify(acts));
assert.ok(acts.some(a => a.id === 'decide:reroute'), 'Reroute stays listed');
});

test('forced_by alone (older payload without adoption.queued_by) is enough for the acted state', () => {
const it = row({ takeover: { author: 'odttlnt', adopt_now: true, forced_by: 'clubanderson', reroute: false } });
assert.equal(api.chipText(it), 'adopting… (queued)');
assert.ok(!api.actions(it, ctx).some(a => a.id === 'decide:adopt-now'));
});
24 changes: 21 additions & 3 deletions src/pkg/dashboard/stage_tracker_adoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ type StageTrackerAdoption struct {
// Action is the row action that lifts the hold ("decide:adopt"), ""
// when nothing is the owner's to decide.
Action string `json:"action,omitempty"`
// QueuedBy is the operator whose Adopt now is waiting for the sweep:
// the row is in its acted state ("Adopting… (queued by @x)") and no
// blocker or adopt action is shown.
QueuedBy string `json:"queued_by,omitempty"`
// Text is the plain-words pill/tooltip: "waiting on @hanthor
// (maintainer, offline 26h) — adopt?".
Text string `json:"text"`
Expand Down Expand Up @@ -116,6 +120,20 @@ func stageTrackerAdoption(it StageTrackerItem, rec stagelabels.Record, hasRec bo
out.Text = stageTrackerAdoptionText(it.Author, *out, now)
return out
}
if rec.AdoptedHead != "" && (it.Head == "" || rec.Adopted(it.Head) || rec.AdoptedInPlace()) {
return nil
}
if by, ok := rec.AdoptionForced(); ok {
// An operator pressed Adopt now and the sweep has not landed yet:
// the row reads as acted on, whatever held adoption before.
out := &StageTrackerAdoption{Author: it.Author, Policy: policy, Due: true, QueuedBy: by, Nudges: rec.NudgeCount}
if !rec.AdoptForcedAt.IsZero() {
since := rec.AdoptForcedAt
out.Since = &since
}
out.Text = stageTrackerAdoptionText(it.Author, *out, now)
return out
}
if rec.NudgeCount == 0 || rec.NudgeStart().IsZero() {
return nil
}
Expand All @@ -124,9 +142,6 @@ func stageTrackerAdoption(it StageTrackerItem, rec stagelabels.Record, hasRec bo
// next sweep; nothing to say about adoption yet.
return nil
}
if rec.AdoptedHead != "" && (it.Head == "" || rec.Adopted(it.Head) || rec.AdoptedInPlace()) {
return nil
}
since := rec.NudgeStart()
out := &StageTrackerAdoption{Author: it.Author, Since: &since, Nudges: rec.NudgeCount, Policy: policy}
if presence != nil && it.Author != "" {
Expand Down Expand Up @@ -166,6 +181,9 @@ func stageTrackerAdoptionText(author string, a StageTrackerAdoption, now time.Ti
if a.BlockedBy == stagelabels.AdoptBlockedAuthorPerson {
return who + " pushed this PR themselves — not adopted: the hive asks them, not adopts"
}
if a.QueuedBy != "" {
return "Adopting… (queued by @" + a.QueuedBy + "; the hive opens its copy on the next stage pass)"
}
var facts []string
if a.AuthorMaintainer {
facts = append(facts, "maintainer")
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/dashboard/stage_tracker_decision.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ func stageTrackerDecisionNeededWith(it StageTrackerItem, verdict *review.Aggrega
return decisionForUnauthorized(it, held)
case it.Kind == "pr" && it.Adoption != nil && it.Adoption.Action == decisionActionAdopt:
return decisionForAdoption(it, held, now)
case it.Kind == "pr" && it.Adoption != nil && it.Adoption.QueuedBy != "":
// Adopt now already pressed: nothing is asked until the sweep lands.
return nil
case it.Kind == "pr" && it.Takeover != nil && it.Takeover.GraceElapsed && it.Adoption != nil && it.Adoption.BlockedBy != stagelabels.AdoptBlockedAuthorMaintainer:
// The nudge grace ran out and the engine has not adopted (ask is
// the case above; never stays the policy's word): the wait is a
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/dashboard/stage_tracker_presence.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const src = [
pick(/function agentNowAgo\(ms\) \{[\s\S]*?\n \}\n/, 'agentNowAgo'),
pick(/function stageTrackerAdoptionTip\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionTip'),
pick(/function stageTrackerAdoptOffered\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptOffered'),
pick(/const STAGE_TRACKER_ADOPTION_QUEUED_CHIP = [^\n]*\n/, 'STAGE_TRACKER_ADOPTION_QUEUED_CHIP'),
pick(/function stageTrackerAdoptionQueued\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionQueued'),
pick(/function stageTrackerAdoptionChipText\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionChipText'),
pick(/function stageTrackerAdoptionChipHtml\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionChipHtml'),
pick(/const STAGE_TRACKER_ICONS = \{[\s\S]*?\n \};\n/, 'STAGE_TRACKER_ICONS'),
Expand Down
Loading
Loading