Skip to content

🐛 Close hive PRs superseded by a merged PR instead of parking them on a person; decide post-decision re-parks anew - #15278

Merged
clubanderson merged 1 commit into
v5from
fix/hive-pr-orphaned-and-stale-045
Oct 29, 2026
Merged

clubanderson merged 1 commit into
v5from
fix/hive-pr-orphaned-and-stale-045

Conversation

@clubanderson

Copy link
Copy Markdown
Member

Fixes #15276

Root cause A — hive PR #15208 parked at 085 after #15206 merged

Fix: new detectDeclaredSupersession (cross-reference timeline → merged same-repo PR whose body says Supersedes #N); IssuesClosedNoCloser for closing claims all closed not_planned; sweep asks the closer on conflicting or label:needs-rebase before the label block; stage pass runs closeSupersededBeforeHumanRoute (hive-authored only, reviewer requires_human or conflict, TTL-cached, skipped under a person's hold) and counts ClosedSuperseded. Ledger reason stagelabels.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: delegatedReparkedAfter reads 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-direction is 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%.

@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 29, 2026
@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 needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 29, 2026
@hivecommons-hive hivecommons-hive Bot added author/human A person pushed this PR themselves dco All commits are DCO signed-off stage/071-needs-author Human-authored PR: CI red, changes requested or conflicting; diagnosis posted, the author must act labels Oct 29, 2026
@clubanderson
clubanderson force-pushed the fix/hive-pr-orphaned-and-stale-045 branch from 1ce8d1e to 7eb3f7f Compare October 29, 2026 03:39
@kubestellar-prow kubestellar-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 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
#15219 🐛 fix: preserve human and owner PRs during delegated decisions same files src/pkg/dashboard/api_repo_item_decide_delegated.go
src/pkg/dashboard/api_repo_item_decide_delegated_test.go
src/pkg/dashboard/api_repo_item_decision_test.go
src/pkg/github/automerge/automerge_stage_human_test.go
src/pkg/github/automerge/automerge_stage_labels.go
src/pkg/stagelabels/human.go
#15226 ✨ feature: enqueue eligible PRs into GitHub native merge queues same files src/pkg/github/automerge/automerge_sweep.go
src/pkg/github/automerge/automerge_sweep_test.go
#15186 🐛 Activity Monitor: one coherent post-decision state for Let hive decide rows; 060 reviewed in CI / Review CONFLICT src/pkg/dashboard/delegated_decision_effect.go
#15104 🐛 Activity Monitor: Rebase, then merge as maintainer; fixer owns parked conflicting PRs; dismiss self-inflicted changes_requested CONFLICT src/pkg/dashboard/api_repo_item_decision_test.go
src/pkg/github/automerge/automerge_sweep.go
#15253 🐛 decision toast: issue decisions no longer read as 'approved for merge' CONFLICT src/pkg/dashboard/api_repo_item_decide_delegated_test.go
src/pkg/dashboard/delegated_decision_effect.go
#15134 🐛 Delegated decision on a capability gap: model the blocker, stop the un-park/re-park loop, name the missing App permission CONFLICT src/pkg/dashboard/delegated_decision_effect.go

@github-actions github-actions Bot added the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Oct 29, 2026
@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 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.

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

@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.

Reviewed (intent-alignment vs #15276) — both root causes are implemented and covered by tests; no blocker. Two advisory notes:

  1. 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 closed not_planned with 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.

  2. "ledger reason superseded-by-merge" is log-only: stagelabels.LaneReasonSupersededByMerge is 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-existing closed-superseded (automerge_sweep.go:1210,1735), and the stage pass drops the record via store.Forget(key) (automerge_stage_labels.go:918) rather than writing a reason. The changelog fragment fixed-hive-pr-superseded-by-merge.md says "(ledger reason superseded-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

@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.

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

@hivecommons-hive hivecommons-hive Bot added 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 and removed stage/071-needs-author Human-authored PR: CI red, changes requested or conflicting; diagnosis posted, the author must act labels Oct 29, 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.

Reviewed (style/maintainability) at head 1ce8d1e — no blockers; four advisory notes.

  1. StageTracker.superseded never evicts. automerge_stage_labels.go:229 keys the new map by key@head (automerge_stage_human.go:126-134), unlike the sibling checks map which is keyed by key with the head stored in the entry (automerge_stage_human.go:52-64). On the process-wide sharedStageTracker every new head of every hive PR adds an entry that is never removed. Following the checks idiom 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.)

  2. Declared-close comment can misattribute the closer. pr_superseded_hive_autoclose.go:233-235 falls back to firstClosedClaim, which returns any closed claim without checking who closed it, yet :319 then states "Superseded by #%d which closed #%d". For a PR whose Part of #N was 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)
    
  3. Comment header contradicts the new no-closer branch. pr_supersession_sweep.go:533 still 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 on closer.Number > 0 or use "is already closed" when it is 0.

  4. LaneReasonSupersededByMerge is log-only. stagelabels/human.go:237 places it among the LaneReason* constants that are written to obs.Reason/the stage store, but the only uses are slog fields (automerge_stage_human.go:151, automerge_sweep.go close log) and the close path calls store.Forget(key) (automerge_stage_labels.go:922). The PR body's "Ledger reason" overstates what lands; either persist it (e.g. on the SupersessionSweepEvent/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

@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.

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:

  1. closed-issue-closed comment contradicts itself. src/pkg/github/pr_supersession_sweep.go:554 still 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.")
	}
  1. superseded-by-merge is a log field, not a ledger reason. The body and #15276 say the close carries ledger reason superseded-by-merge, but stagelabels.LaneReasonSupersededByMerge only appears as a slog attribute (automerge_stage_human.go:159, automerge_sweep.go:1734). The sweep ledger still returns closed-superseded (automerge_sweep.go:1735), and the stage pass does store.Forget(key) (automerge_stage_labels.go:922) with sink.Closed(...) carrying no reason (pr_superseded_hive_autoclose.go:289). Either return stagelabels.LaneReasonSupersededByMerge from the sweep in place of autoMergeReasonClosedSuperseded, 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>
@clubanderson
clubanderson force-pushed the fix/hive-pr-orphaned-and-stale-045 branch from 7eb3f7f to ed786ca Compare October 29, 2026 03:52
@clubanderson
clubanderson merged commit 3a172ec into v5 Oct 29, 2026
76 of 77 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the fix/hive-pr-orphaned-and-stale-045 branch October 29, 2026 04:04
@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 29, 2026
clubanderson added a commit that referenced this pull request Oct 29, 2026
…e a needs-rebase label on a merely-behind head stays stale

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
clubanderson added a commit that referenced this pull request Oct 29, 2026
…e a needs-rebase label on a merely-behind head stays stale

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
hivecommons-hive Bot pushed a commit that referenced this pull request Oct 29, 2026
…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>
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 conflicts-with-open-pr Open PR has a merge conflict with another open PR dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

1 participant