Repository navigation
✨ Adoption: close the original first when superseding, reopen if the hive's copy fails - #15154
Conversation
…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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
|
@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. |
|
merged by Hive trusted-author auto-merge: author @clubanderson holds role owner and GitHub permission admin on repo; CI green at dd60819. |
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
There was a problem hiding this comment.
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.LastSeenis written in exactly one place:Store.Seton observation (src/pkg/stagelabels/store.go:552). Nothing in the close-first path (MarkSupersededClosedFirst,MarkAdoptChecked,NoteAdoptCopyRedHead) touches it.settleCloseFirstSupersessionsruns each pass (automerge_stage_labels.go:1260) and is immediately followed bystore.Prune(stageStorePruneAge)(:1266), which deletes every record withLastSeenolder 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 momentcloseSupersededOriginalFirst(:113) closes the original, itsLastSeenis 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 recordopen=trueso the keep-open path takes over. reopenSupersededOriginal(:246) records the reopen before posting the note, and the 24hAdoptionReopenWindowguard posts a held note instead of flipping the PR again.MarkAdoptionReopened(store.go:1450) clearsSupersededBybut keepsAdoptedBy, soAdoptionCopyFailed()(:1468) holds and the requested-adopt bypass inadoptContributorPR:590lets an explicit operator Adopt re-run after a failure, whilesettleSupersederskips it.AdoptionCopyFailedMarkeradded toAdoptionSettledMarkerso the orphan scan does not resurrect a settled one.go buildpasses 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
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.") → applyhive/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
settleCloseFirstSupersessionspolls 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, onehive:adoption-copy-failednote, removehive/superseded, park at 085 withadoption-copy-failed(held until a person acts; anadoption/supersederequest re-runs it). Ping-pong guard: one reopen per original per 24h; a second failure inside the window leaves it closed with aheld=truenote.Config.
governor.labels.stage.adoption.supersede.close_first(defaulttrue;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/writebackgate 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.settleSupersederadditionally skips records whose copy failed (Record.AdoptionCopyFailed()), so a reopened original is not re-adopted by orphan recovery, andhive:adoption-copy-failedis a settled marker for the marker scan. Keep-open mode (close_first: false) keeps #15072 behaviour unchanged.Tracker / SPA (minimal — overlaps with agent 97f08182)
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 instageTrackerAdoptedWord("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_firstoff, 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.