Skip to content

✨ Adoption: close the original first when superseding, reopen if the hive's copy fails - #15154

Merged
hivecommons-hive[bot] merged 1 commit into
v5from
close-first-adoption
Oct 28, 2026
Merged

hivecommons-hive[bot] merged 1 commit into
v5from
close-first-adoption

Conversation

@clubanderson

Copy link
Copy Markdown
Member

Fixes #15135

What

Operator decision: supersede-adoption is close-first. When the hive supersedes a contributor PR it now, in one pass: push hive/adopt-N → open the copy → post one note on the original ("Superseded by hive: re-authored as #M with the same commits and sign-off because . This PR is closed; if #M fails, hive reopens it.") → apply hive/superseded → close the original. The stage record is superseded from that pass, so the Activity Monitor never shows the original as an active row beside its copy.

Reopen on failure. A closed original is in no lane's listing, so settleCloseFirstSupersessions polls each close-first copy from the stage store (≤ every 10m). Copy merged → settled. Copy closed unmerged, or required checks red at two distinct copy heads (same 2-attempt cap as the rebase/adoption loop guard) → reopen the original, one hive:adoption-copy-failed note, remove hive/superseded, park at 085 with adoption-copy-failed (held until a person acts; an adoption/supersede request re-runs it). Ping-pong guard: one reopen per original per 24h; a second failure inside the window leaves it closed with a held=true note.

Config. governor.labels.stage.adoption.supersede.close_first (default true; false = previous keep-open behaviour). Documented in labels-and-control-signals.md, operator-reference.md, dashboard-sections.md, hive.yaml.example and the Settings config-help.

Write-backs use the existing comment/label/PR-edit helpers (no pkg/writeback gate on v5 yet — #15122 pending).

Interplay with #15072 (orphan recovery)

Orphan detection already keys on the copy being closed (settleSuperseder → recoverOrphanedAdoption). With close-first the original is closed and never observed, so that path does not run for it; a closed copy is handled by the reopen path instead. settleSuperseder additionally skips records whose copy failed (Record.AdoptionCopyFailed()), so a reopened original is not re-adopted by orphan recovery, and hive:adoption-copy-failed is a settled marker for the marker scan. Keep-open mode (close_first: false) keeps #15072 behaviour unchanged.

Tracker / SPA (minimal — overlaps with agent 97f08182)

  • New adopted_by_state: "copy-failed" with 085 caption "The hive's copy #N failed; this PR was reopened and needs a person", humanized reason and decision question.
  • index.html: one added branch in stageTrackerAdoptedWord ("Adopted → #N (copy failed) · reopened, needs a person") plus the Settings help/search text. Agent 97f08182 is concurrently reworking adoption-pair rendering (dimmed original, "↳ adopted from #N" chip); this PR deliberately touches nothing else in the SPA so the two land independently.

Tests

Table-driven in automerge_adoption_close_first_test.go: write ordering (refs → pulls → comment → label → close, one pass), close-first comment text per reason, close_first off, close refused (403), copy merged settles, reopen on copy-closed / copy-red-twice (same head counted once), 085 park after reopen with no re-adoption, ping-pong guard with held note, settled marker, key parsing. Store (adoption_close_first_test.go), tracker projection (stage_tracker_adoption_close_first_test.go), config default/decode; config golden updated for the new leaf.

Local: automerge 89.5%, stagelabels 92.2%, dashboard 87.8%, stageengine 93.9%, config ok, gofmt/vet clean.

…hive's copy fails

Supersede adoption now closes the contributor's original in the same pass
that opens its hive-authored copy (push branch → open copy → one note naming
the copy and why → hive/superseded → close), so one issue never shows two
active PRs. The copy is polled from the stage store; closed unmerged or red
required checks at two heads reopen the original with one note, remove the
label and park it at 085 as adoption-copy-failed (one reopen per 24h).
governor.labels.stage.adoption.supersede.close_first (default true) keeps
the old keep-open behaviour when false.

Fixes #15135

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign nicholasjackson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added dco-signoff: yes Indicates the PR's author has signed the DCO. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#15156 🐛 Activity Monitor: an owner's Approve admits the untrusted-author PR head — no adoption, merge as-is; DCO warned before acting same files src/docs/dashboard-sections.md
src/docs/operator-reference.md
src/pkg/dashboard/stage_tracker.go
src/pkg/dashboard/stage_tracker_decision.go
src/pkg/dashboard/static/index.html
src/pkg/github/automerge/automerge_contributor_adopt.go
src/pkg/stagelabels/store.go
#15070 ✨ Activity Monitor: presence indicator (clanker online / offline / none) on the waiting-on pill same files src/docs/dashboard-sections.md
src/docs/labels-and-control-signals.md
src/pkg/dashboard/stage_tracker.go
src/pkg/dashboard/static/index.html
#15104 🐛 Activity Monitor: Rebase, then merge as maintainer; fixer owns parked conflicting PRs; dismiss self-inflicted changes_requested same files src/cmd/hive/merge_eligibility.go
src/docs/dashboard-sections.md
src/docs/operator-reference.md
src/pkg/dashboard/stage_tracker.go
src/pkg/dashboard/stage_tracker_decision.go
src/pkg/dashboard/static/index.html
#15020 🐛 fix(stage): a contributor PR with no linked issue is not waiting on the hive same files src/pkg/github/automerge/automerge_stage_labels.go
#15149 ✨ feat(automerge): pick one merge-train front per group of file-overlapping approved PRs same files src/docs/operator-reference.md
src/pkg/config/config.go
#15118 🐛 fix: open the needs-human popover on issue rows with a parked PR same files src/pkg/dashboard/static/index.html
#15134 🐛 Delegated decision on a capability gap: model the blocker, stop the un-park/re-park loop, name the missing App permission same files src/docs/dashboard-sections.md
src/docs/labels-and-control-signals.md
src/docs/operator-reference.md
src/pkg/dashboard/stage_tracker.go
src/pkg/dashboard/stage_tracker_decision.go
src/pkg/dashboard/static/index.html
#15157 ✨ Conflict-aware merge train in the automerge lanes same files src/docs/dashboard-sections.md
src/docs/operator-reference.md
src/pkg/config/config.go
src/pkg/config/testdata/agent_runtime_golden.json
src/pkg/dashboard/stage_tracker.go
src/pkg/dashboard/stage_tracker_decision.go
src/pkg/dashboard/static/index.html
#15085 ✨ Activity Monitor: Adopt now and Reroute to another clanker for PRs waiting on a contributor's clanker same files src/docs/dashboard-sections.md
src/docs/labels-and-control-signals.md
src/docs/operator-reference.md
src/pkg/config/config.go
src/pkg/config/testdata/agent_runtime_golden.json
src/pkg/dashboard/stage_tracker.go
src/pkg/dashboard/stage_tracker_decision.go
src/pkg/dashboard/static/index.html
src/pkg/github/automerge/automerge_contributor_adopt.go
src/pkg/github/automerge/automerge_stage_labels.go
src/pkg/stagelabels/store.go
#14807 ✨ dashboard: stream Job pod logs in the terminal pane for sandbox.runtime: job agents same files src/pkg/dashboard/static/index.html
#15122 🐛 Write-back containment: per-kind gate for every unsolicited GitHub write, with backfill guard same files src/docs/labels-and-control-signals.md
src/docs/operator-reference.md
src/hive.yaml.example
src/pkg/config/config.go
src/pkg/config/testdata/agent_runtime_golden.json
src/pkg/dashboard/static/index.html
#15150 🐛 Activity Monitor: persist the merged count in a server ledger, pin the Merged chip, banner and bee flight on merge same files src/docs/dashboard-sections.md
src/pkg/dashboard/stage_tracker.go
src/pkg/dashboard/static/index.html

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@clubanderson is auto-promoted for contributor-lane merging on this PR: the last 5 merged PRs by this author in this hive's repositories have no revert or sentinel-alert evidence. CI, reviewer verdict, diff fences, soak, holds and branch protection still apply.

@hivecommons-hive hivecommons-hive Bot added author/human A person pushed this PR themselves dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 28, 2026
@hivecommons-hive
hivecommons-hive Bot merged commit f427a21 into v5 Oct 28, 2026
85 of 89 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the close-first-adoption branch October 28, 2026 23:12
@hivecommons-hive

Copy link
Copy Markdown
Contributor
Evidence bundle `#15154dd60819` sha256:343b45bc9a3f62a0af110f5775461865ca6e64fb98dc75ffc5693b2c26a4858b — download from the dashboard or `hivectl review evidence #15154`.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

merged by Hive trusted-author auto-merge: author @clubanderson holds role owner and GitHub permission admin on repo; CI green at dd60819.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 28, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conclusion: the close → poll → reopen flow is ordered correctly and builds clean at dd60819, but the poll that makes close-first safe is silently cut off by the store's 14-day prune, because a closed original is never observed again. One verified finding, medium.

Close-first records are pruned while their copy is still open

  • Record.LastSeen is written in exactly one place: Store.Set on observation (src/pkg/stagelabels/store.go:552). Nothing in the close-first path (MarkSupersededClosedFirst, MarkAdoptChecked, NoteAdoptCopyRedHead) touches it.
  • settleCloseFirstSupersessions runs each pass (automerge_stage_labels.go:1260) and is immediately followed by store.Prune(stageStorePruneAge) (:1266), which deletes every record with LastSeen older than 14 days (automerge_stage_labels.go:201, store.go:1538-1548).
  • The PR's own header comment states the premise: "a closed original is not observed by any lane" (automerge_adoption_close_first.go:28). So from the moment closeSupersededOriginalFirst (:113) closes the original, its LastSeen is frozen.

Consequence: if the copy is still open 14 days after the close — a copy parked at 085 for a person, a fixer iterating on a red copy, or simply a slow repo — closeFirstPollCandidates (:150) stops seeing the original. A copy that is then closed unmerged, or goes red at a second head, never reopens the original; the contributor's PR stays closed with a note promising "if #M fails, hive reopens it", and the Activity Monitor row disappears. The keep-open path did not have this problem because the open original was observed every pass. The AdoptionCopyFailed() guard in settleSuperseder (automerge_contributor_adopt.go:1010) also depends on the record surviving.

Fix options, in the file's own idiom: have CloseFirstPollDue records refresh LastSeen when polled (e.g. in MarkAdoptChecked when SupersededClosedFirst is set), or have Prune skip records where SupersededClosedFirst && SupersededBy == AdoptedBy. A test that advances the clock past stageStorePruneAge with the copy still open and asserts the record (and a later reopen) survive would pin it.

What I checked and found correct

  • Write ordering push → copy → note → label → close (automerge_contributor_adopt.go:770-783, close_first.go:113-140): a failed push or failed copy creation leaves the original untouched; a refused close (403/404) marks the record open=true so the keep-open path takes over.
  • reopenSupersededOriginal (:246) records the reopen before posting the note, and the 24h AdoptionReopenWindow guard posts a held note instead of flipping the PR again.
  • MarkAdoptionReopened (store.go:1450) clears SupersededBy but keeps AdoptedBy, so AdoptionCopyFailed() (:1468) holds and the requested-adopt bypass in adoptContributorPR:590 lets an explicit operator Adopt re-run after a failure, while settleSuperseder skips it.
  • AdoptionCopyFailedMarker added to AdoptionSettledMarker so the orphan scan does not resurrect a settled one.
  • go build passes for automerge, dashboard, stagelabels, config and cmd/hive at this head (tests are CI-only for me).

The PR body's #15072 interplay note matches what the code does. I have not approved, requested changes, or closed anything.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/human A person pushed this PR themselves dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Supersede-adoption should close the original first, not leave two open PRs per issue

1 participant