Repository navigation
🐛 Close hive PRs superseded by a merged PR instead of parking them on a person; decide post-decision re-parks anew - #15278
Conversation
|
[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 |
1ce8d1e to
7eb3f7f
Compare
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. |
There was a problem hiding this comment.
Reviewed at head 7eb3f7f (the PR moved past 1ce8d1e). Security perspective.
Declared supersession trusts post-merge-editable free text, widening who can close hive PRs — src/pkg/github/pr_superseded_declared.go:60-91
The existing closer path resolves a superseding PR through GitHub's own closing linkage (closedByPullRequestsReferences / closing commit, pr_supersession_sweep.go:405-424), which only a real merge can create. The new detectDeclaredSupersession accepts any cross-referenced timeline event from a merged same-repo PR whose current body matches Supersedes #N (pr_superseded_declared.go:76-86), and DecideHiveSupersededAutoClose closes on Declared before the conflicting/files-subset measurement (pr_superseded_hive_autoclose.go:122-123); the stage pass then calls it on every hive PR routed toward 085/070 (automerge_stage_labels.go:915-927).
A merged PR's body stays editable by its author after merge — including an outside contributor whose fork PR a maintainer merged — and the edit itself creates the cross-reference. So anyone with one merged PR in the repo can, at ACMM autonomous, close any open hive-authored PR by adding one line to an old PR description, with no maintainer action. Reversible (reopen / hive/keep-open), and a comment is posted, but it is a new path from "has had a PR merged" to "can close hive's PRs" that did not exist with the linkage-based rule.
Suggested fix — only honour the declaration when the declaring PR's author is the hive identity or holds write+ on the repo:
--- a/src/pkg/github/pr_superseded_declared.go
+++ b/src/pkg/github/pr_superseded_declared.go
@@ func (c *Client) detectDeclaredSupersession(ctx context.Context, owner, repo string, pr *gh.PullRequest) (bool, supersessionCloser, error) {
mergedAt := ref.GetPullRequestLinks().GetMergedAt()
if mergedAt.IsZero() || !bodyDeclaresSupersedes(ref.GetBody(), number) {
continue
}
+ // The body is editable after merge by its author; only a
+ // maintainer's (or the hive's) statement closes a hive PR.
+ if !c.declaredByTrustedAuthor(ctx, owner, repo, ref) {
+ continue
+ }
return true, supersessionCloser{Repo: full, Number: ref.GetNumber(), URL: ref.GetHTMLURL(), MergedAt: mergedAt.Time}, nil
@@
+// declaredByTrustedAuthor reports whether the declaring PR's author is the
+// hive identity or has write/admin/maintain permission on the repo.
+func (c *Client) declaredByTrustedAuthor(ctx context.Context, owner, repo string, ref *gh.Issue) bool {
+ login := safeGetLogin(ref.GetUser())
+ if login == "" {
+ return false
+ }
+ if c.getHiveIdentity().Matches(login) {
+ return true
+ }
+ perm, _, err := c.client.Repositories.GetPermissionLevel(ctx, owner, repo, login)
+ if err != nil {
+ return false
+ }
+ switch strings.ToLower(perm.GetPermission()) {
+ case "admin", "maintain", "write":
+ return true
+ }
+ return false
+}(Alternative with no extra API call: require the declaring PR to also appear as the authoritative closer of at least one of this PR's claims — in the #15206/#15208 specimen it closed Part of #15188 — which ties the declaration back to a real merge.)
— hive: agent=adjudicator-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Reviewed (intent-alignment vs #15276) — both root causes are implemented and covered by tests; no blocker. Two advisory notes:
-
Scope expansion beyond #15276:
IssuesClosedNoCloser/closed-issue-closed(src/pkg/github/pr_superseded_hive_autoclose.go:84-86,128-129,238) adds a third auto-close rule — every closing claim closednot_plannedwith no merged closer — that the issue does not ask for (it names only "closed by another merged PR" and "a merged PR declares it supersedes"). It sits behind the same enabled/level/held/keep-open/parked-by-person gates and is tested (TestCloseSupersededHivePRIfEligible_IssueClosedWithoutCloser), so I'm not blocking on it; flagging so it's a deliberate decision rather than an unnoticed one. -
"ledger reason
superseded-by-merge" is log-only:stagelabels.LaneReasonSupersededByMergeis emitted solely as a slog attribute (src/pkg/github/automerge/automerge_sweep.go:1734,automerge_stage_human.go:151). The self-authored sweep's recorded skip reason remains the pre-existingclosed-superseded(automerge_sweep.go:1210,1735), and the stage pass drops the record viastore.Forget(key)(automerge_stage_labels.go:918) rather than writing a reason. The changelog fragmentfixed-hive-pr-superseded-by-merge.mdsays "(ledger reasonsuperseded-by-merge)" — consider either rewording to "logged with reason …" or surfacing it as the sweep skip reason so the two vocabularies don't diverge.
— hive: agent=adjudicator-3 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
docs-currency review (head 1ce8d1e)
1. Close notice contradicts itself for the two new close actions — src/pkg/github/pr_supersession_sweep.go:533 keeps the fixed header "Supersession sweep found that this PR's claimed issue is already closed by another merged PR." for every renderSupersessionComment caller, but the new closed-issue-closed action has no merged PR at all (next line is now "Closing PR: none (the issue was closed without a merged PR)", :537-538; the test at pr_superseded_hive_autoclose_test.go:319 asserts both strings land in the same comment). For closed-declared the claimed issue may still be open (Closes #15203 in the #15208 specimen) and, when firstClosedClaim finds nothing (pr_superseded_hive_autoclose.go:230-233), event.IssueRepo/event.Issue are zero so the notice prints - Claimed issue: #0 (pr_supersession_sweep.go:535). Suggested fix: pick the header from event.Action and skip the issue line when event.Issue == 0:
func renderSupersessionComment(event SupersessionSweepEvent, closer supersessionCloser, reason string) string {
var b strings.Builder
fmt.Fprintln(&b, supersessionSweepMarker)
- fmt.Fprintln(&b, "Supersession sweep found that this PR's claimed issue is already closed by another merged PR.")
+ switch event.Action {
+ case SupersessionActionClosedDeclared:
+ fmt.Fprintln(&b, "Supersession sweep found that a merged PR declares it supersedes this PR.")
+ case SupersessionActionClosedIssueClosed:
+ fmt.Fprintln(&b, "Supersession sweep found that every issue this PR closes was closed as not planned.")
+ default:
+ fmt.Fprintln(&b, "Supersession sweep found that this PR's claimed issue is already closed by another merged PR.")
+ }
fmt.Fprintln(&b)
- fmt.Fprintf(&b, "- Claimed issue: %s#%d\n", event.IssueRepo, event.Issue)
+ if event.Issue > 0 {
+ fmt.Fprintf(&b, "- Claimed issue: %s#%d\n", event.IssueRepo, event.Issue)
+ }2. Operator reference still documents the old rule — src/docs/operator-reference.md:615-631 ("Supersession sweep") states that only closing-keyword issues count, that a Part of #N parent "never supersedes a PR", that "if any candidate issue is still open the PR is live work and the sweep leaves it alone", and that hive PRs are closed only when "every file they touch was also touched by the merged PR". This PR adds two further close triggers that bypass each of those sentences — a merged same-repo PR whose body says Supersedes #N closes the hive PR even with an open Closes claim (pr_superseded_declared.go:55-85, pr_superseded_hive_autoclose.go:122-123), and all closing claims closed not_planned with no merged closer closes it (:128-129) — plus the stage pass / self-authored sweep now run the rule before parking at 085/070 or on needs-rebase (automerge_stage_labels.go:915-927, automerge_sweep.go:1723-1740). Please add a bullet to that section, e.g.:
- **Declared and not-planned supersession (hive PRs only).** A hive-authored
PR is also closed (`superseded-by-merge` ledger reason) when a merged PR of
the same repository states `Supersedes #N` in its body — even if one of the
hive PR's own `Closes` claims is still open — or when every issue it closes
was closed as *not planned* with no merged closer. The auto-merge stage
pass and the self-authored sweep ask this rule before parking the PR at
`stage/085-needs-decision` on a reviewer's `requires_human`, sending a
conflicting head to 070, or honouring a `needs-rebase` label
(hivecommons/hive#15276).
— hive: agent=ci-maintainer backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Reviewed (style/maintainability) at head 1ce8d1e — no blockers; four advisory notes.
-
StageTracker.supersedednever evicts.automerge_stage_labels.go:229keys the new map bykey@head(automerge_stage_human.go:126-134), unlike the siblingchecksmap which is keyed bykeywith the head stored in the entry (automerge_stage_human.go:52-64). On the process-widesharedStageTrackerevery new head of every hive PR adds an entry that is never removed. Following thechecksidiom bounds it to one entry per PR:- superseded map[string]time.Time + superseded map[string]supersededCheckEntry // key → {head, at}
- cacheKey := key + "@" + obs.HeadSHA - tracker.mu.Lock() - last, seen := tracker.superseded[cacheKey] - tracker.mu.Unlock() - if seen && now.Sub(last) < supersededCheckTTL { - return false - } - tracker.mu.Lock() - tracker.superseded[cacheKey] = now - tracker.mu.Unlock() + tracker.mu.Lock() + last, seen := tracker.superseded[key] + if seen && last.head == obs.HeadSHA && now.Sub(last.at) < supersededCheckTTL { + tracker.mu.Unlock() + return false + } + tracker.superseded[key] = supersededCheckEntry{head: obs.HeadSHA, at: now} + tracker.mu.Unlock()
(Also collapses the two adjacent lock/unlock pairs into one critical section.)
-
Declared-close comment can misattribute the closer.
pr_superseded_hive_autoclose.go:233-235falls back tofirstClosedClaim, which returns any closed claim without checking who closed it, yet:319then states "Superseded by #%d which closed #%d". For a PR whosePart of #Nwas closed by something other than the declaring PR, the one-line comment asserts a fact nobody verified. Suggest neutral wording:return fmt.Sprintf("Superseded by #%d, which declares it supersedes this PR; #%d is already closed. Closing this hive-authored PR; reopen if that's wrong.", closer.Number, event.Issue) -
Comment header contradicts the new no-closer branch.
pr_supersession_sweep.go:533still opens with "already closed by another merged PR" while:538(new) prints "Closing PR: none (the issue was closed without a merged PR)" for the not-planned case. Gate the header oncloser.Number > 0or use "is already closed" when it is 0. -
LaneReasonSupersededByMergeis log-only.stagelabels/human.go:237places it among theLaneReason*constants that are written toobs.Reason/the stage store, but the only uses are slog fields (automerge_stage_human.go:151,automerge_sweep.goclose log) and the close path callsstore.Forget(key)(automerge_stage_labels.go:922). The PR body's "Ledger reason" overstates what lands; either persist it (e.g. on theSupersessionSweepEvent/stage record) or note in the constant's doc that it is a log tag.
— hive: agent=adjudicator-4 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Correctness review (read at head 7eb3f7f, which moved on from 1ce8d1e): both root causes are implemented as described and the tests cover them; nothing blocking. Two advisory gaps, worst first:
closed-issue-closedcomment contradicts itself.src/pkg/github/pr_supersession_sweep.go:554still opens the notice with "this PR's claimed issue is already closed by another merged PR", then line 559 says "Closing PR: none (the issue was closed without a merged PR)". Tie the header to the action:
if event.Action == SupersessionActionClosedIssueClosed {
fmt.Fprintln(&b, "Supersession sweep found that every issue this PR closes was closed as not planned.")
} else {
fmt.Fprintln(&b, "Supersession sweep found that this PR's claimed issue is already closed by another merged PR.")
}
superseded-by-mergeis a log field, not a ledger reason. The body and #15276 say the close carries ledger reasonsuperseded-by-merge, butstagelabels.LaneReasonSupersededByMergeonly appears as a slog attribute (automerge_stage_human.go:159,automerge_sweep.go:1734). The sweep ledger still returnsclosed-superseded(automerge_sweep.go:1735), and the stage pass doesstore.Forget(key)(automerge_stage_labels.go:922) withsink.Closed(...)carrying no reason (pr_superseded_hive_autoclose.go:289). Either returnstagelabels.LaneReasonSupersededByMergefrom the sweep in place ofautoMergeReasonClosedSuperseded, or reword the body/changelog — as written the stated reason is not queryable anywhere.
Minor: automerge_stage_human.go:144 stamps the TTL cache before the PullRequests.Get at :146, so a transient read error silences the check for 10 min at that head.
— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88
…; decide a post-decision re-park anew A hive-authored PR whose issue another merged PR closed, or that a merged PR declares it supersedes, is closed with ledger reason superseded-by-merge before the stage pass routes the reviewer's requires_human (or a conflict) to 085/070; the self-authored sweep asks the superseded rule before the needs-rebase label block. A closing claim closed as not planned with no merged closer also closes the PR. The delegated-decision dedup now notices a park label applied after the recorded decision and decides the new ask instead of posting the decision-stalled comment. Fixes #15276 Signed-off-by: Andrew Anderson <andy@clubanderson.com>
7eb3f7f to
ed786ca
Compare
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
…e a needs-rebase label on a merely-behind head stays stale Signed-off-by: Andrew Anderson <andy@clubanderson.com>
…e a needs-rebase label on a merely-behind head stays stale Signed-off-by: Andrew Anderson <andy@clubanderson.com>
…ed conflicting PRs; dismiss self-inflicted changes_requested (#15104) * 🐛 Activity Monitor: Rebase, then merge as maintainer; autonomous rebase-resolve with loop guard; approve on a dirty PR queues the rebase; dismiss self-inflicted changes_requested Squashed and rebased onto v5 after #15087 and #15074 landed. Fixes #15103 Signed-off-by: Andrew Anderson <andy@clubanderson.com> * test: fix fixtures after the v5 rebase (mock fields, failingEntry rebase fields, import ratchet, window shim) Signed-off-by: Andrew Anderson <andy@clubanderson.com> * test: lift pkg/rebasemerge coverage above its floor; drop an ineffectual assignment Signed-off-by: Andrew Anderson <andy@clubanderson.com> * test: compare the shared singletons through named values (staticcheck SA4000) Signed-off-by: Andrew Anderson <andy@clubanderson.com> * security: rebase-then-merge fails closed on a head the hive did not produce; document the new API shapes The approval is bound to the head the operator read. A contributor PR whose head moves after the click now counts as rebased only when GitHub reports the hive (App bot or pane identity) as the commit's author or committer; any other head settles the follow-through as failed (foreign-head) with nothing merged, a note on the PR, and 'Approve the new head & merge' as the way out. api-reference.md gains the 202 rebase-queued answer, the rebase response field, and the rebase_merge / rebase row fields. Signed-off-by: Andrew Anderson <andy@clubanderson.com> * merge train: hand a dirty member to the fixer's rebase-resolve episode; the exhausted row's rebase-then-merge option goes live v5 landed the conflict-aware merge train (#15157) with a RebaseResolver hook reserved for this PR and a duplicate rebaseMergeFollowThroughLabel. The hook now opens the shared rebase episode (requested_by: merge-train); the mergeNowWired flag and its disabled reason go, since the option it guarded is wired here. Signed-off-by: Andrew Anderson <andy@clubanderson.com> * test: approve toast wording follows #15213 Signed-off-by: Andrew Anderson <andy@clubanderson.com> * rebase onto v5: drop duplicate nonEmptyString, lift STAGE_TRACKER_ICONS for the history badge in the rebase-then-merge row test Signed-off-by: Andrew Anderson <andy@clubanderson.com> * writeback ratchet: baseline the two operator-solicited comments of the rebase-then-merge follow-through Signed-off-by: Andrew Anderson <andy@clubanderson.com> * automerge: superseded question precedes the label block (#15278) while a needs-rebase label on a merely-behind head stays stale Signed-off-by: Andrew Anderson <andy@clubanderson.com> --------- Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Fixes #15276
Root cause A — hive PR #15208 parked at 085 after #15206 merged
detectSupersessionneeds every closing claim closed; 🐛 fix: decidePR answers capability-gap, not adopt-supersede, for heads the App cannot adopt #15208'sCloses #15203was still open, so the rule said "not superseded" even though merged 🐛 Activity Monitor: delegated adopt-supersede reports executing → adopted/could-not-adopt, routes workflow-path to the workflows blocker, re-adoption survives the mutation journal #15206 declared## Supersedes #15208and closed Delegated adopt-supersede reports "done" while nothing is adopted: no execution feedback, workflow-path capability gap decided as adoptable, re-adoption defeated by mutation-journal replay #15188. Nothing read that declaration.label:needs-rebasebefore asking the superseded rule, so once a lane labelled the PR the rule never ran again.requires_human/ conflict reasons straight to 085/070.Fix: new
detectDeclaredSupersession(cross-reference timeline → merged same-repo PR whose body saysSupersedes #N);IssuesClosedNoCloserfor closing claims all closednot_planned; sweep asks the closer onconflictingorlabel:needs-rebasebefore the label block; stage pass runscloseSupersededBeforeHumanRoute(hive-authored only, reviewerrequires_humanor conflict, TTL-cached, skipped under a person's hold) and countsClosedSuperseded. Ledger reasonstagelabels.LaneReasonSupersededByMerge(superseded-by-merge).Root cause B — #15021 "decided, but it hasn't taken effect"
The 20:41Z approve did lift 045→010 (timeline). The scanner later re-parked it (01:16Z) with a new question; the dashboard dedup compared prior decision time vs now and posted
hive:decision-stalled.Fix:
delegatedReparkedAfterreads the issue timeline since the decision; a park label (needs-human, 045, 085) applied after it is a new ask → decided anew. No blanket "approved-direction + 045 → remove" heal:approved-directionis sticky and that would undo legitimate re-parks every cycle. No overlap with #15186 (in-write lift only).Tests:
pkg/github(declared/not-planned/completed-kept/refs-only),pkg/github/automerge(stage short-circuit, human PR never asked, TTL, needs-rebase ordering),pkg/dashboard(re-park → new ask,reparkFromEvents). Coverage: automerge 89.5%, prstage 100%, stagelabels 92.7%.