Skip to content

πŸ› review: the hive closes its own already-landed PRs instead of asking a person - #15671

Merged
clubanderson merged 4 commits into
v5from
fix/already-landed-autoclose
Oct 30, 2026
Merged

clubanderson merged 4 commits into
v5from
fix/already-landed-autoclose

Conversation

@clubanderson

Copy link
Copy Markdown
Member

Fixes #15670

Hive-authored adoption PRs #15647 / #15648 sat at 085 asking the owner whether to close them as "already landed via #15506 / #15341". The empty-diff closer (#15499) ran but its freshness guard read updated_at, which the hive's own labels/comments bump every pass, so the head was "too fresh" forever.

  • review.AlreadyLandedPR / AlreadyLandedFromVerdict: conservative detection of an already-landed claim in the decision question (marker wins; else an already-landed phrase plus exactly one explicit landing ref "via/in/by #N"; ambiguous or lineage-only mentions name nothing). Relay falls back to it for redundantOf.
  • CloseAlreadyLandedHivePRIfEligible: head age from the compare's commits, no freshness guard when a reviewer confirmed the head, files byte-identical on the base tip count as empty, closes parent issues, reports Supersedes.
  • Stage engine: supersededCheckWarranted accepts the worded claim; the 085 route takes the already-landed entry, logs once with self-authored:already-landed, and settles the adopted originals (note, MarkSuperseded so orphan recovery does not re-adopt, close; 403/404 tolerated).
  • Tracker caption via stagelabels.AlreadyLandedCaption: "already landed via #N β€” closing as superseded".
  • Tests for detection (the two real comment texts; negatives), stage routing (hive + already-landed β†’ close path, never 085, original settled), decide rules; docs paragraph in hive-merge.md; changelog fragment.

Composes with #15641 (contributor-lane IsSecuritySensitiveFinding gating); no overlapping hunks.

@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 30, 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 clubanderson 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 the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 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
#15690 🌱 refactor: split src/cmd/hive/main.go into 4 files same files changelog.d/fixed-already-landed-autoclose.md
src/docs/hive-merge.md
src/pkg/dashboard/stage_tracker_caption.go
src/pkg/github/automerge/automerge_stage_human.go
src/pkg/github/automerge/automerge_stage_labels_test.go
src/pkg/github/pr_empty_diff_hive_autoclose.go
src/pkg/github/pr_empty_diff_hive_autoclose_test.go
src/pkg/github/pr_superseded_declared.go
src/pkg/github/review_verdict_relay.go
src/pkg/review/already_landed.go
src/pkg/review/already_landed_test.go
src/pkg/stagelabels/human.go
src/pkg/stagelabels/human_test.go
#15649 πŸ› fix: bypass the proxy for the OMP_AUTH_BROKER_URL host in agent NO_PROXY same files changelog.d/fixed-already-landed-autoclose.md
src/docs/hive-merge.md
src/pkg/dashboard/stage_tracker_caption.go
src/pkg/github/automerge/automerge_stage_human.go
src/pkg/github/automerge/automerge_stage_labels_test.go
src/pkg/github/pr_empty_diff_hive_autoclose.go
src/pkg/github/pr_empty_diff_hive_autoclose_test.go
src/pkg/github/pr_superseded_declared.go
src/pkg/github/review_verdict_relay.go
src/pkg/review/already_landed.go
src/pkg/review/already_landed_test.go
src/pkg/stagelabels/human.go
src/pkg/stagelabels/human_test.go
#15646 πŸ› fix: clear blocker ledger entry when an issue closes same files changelog.d/fixed-already-landed-autoclose.md
src/docs/hive-merge.md
src/pkg/dashboard/stage_tracker_caption.go
src/pkg/github/automerge/automerge_stage_human.go
src/pkg/github/automerge/automerge_stage_labels_test.go
src/pkg/github/pr_empty_diff_hive_autoclose.go
src/pkg/github/pr_empty_diff_hive_autoclose_test.go
src/pkg/github/pr_superseded_declared.go
src/pkg/github/review_verdict_relay.go
src/pkg/review/already_landed.go
src/pkg/review/already_landed_test.go
src/pkg/stagelabels/human.go
src/pkg/stagelabels/human_test.go
#15687 πŸ› fix: page through every closing PR reference when picking the latest merged closer same files changelog.d/fixed-already-landed-autoclose.md
src/docs/hive-merge.md
src/pkg/dashboard/stage_tracker_caption.go
src/pkg/github/automerge/automerge_stage_human.go
src/pkg/github/automerge/automerge_stage_labels_test.go
src/pkg/github/pr_empty_diff_hive_autoclose.go
src/pkg/github/pr_empty_diff_hive_autoclose_test.go
src/pkg/github/pr_superseded_declared.go
src/pkg/github/review_verdict_relay.go
src/pkg/review/already_landed.go
src/pkg/review/already_landed_test.go
src/pkg/stagelabels/human.go
src/pkg/stagelabels/human_test.go
#15621 πŸ› fix: measure empty-diff head age from the head commit, not updated_at CONFLICT src/pkg/github/pr_empty_diff_hive_autoclose.go

@hivecommons-hive

Copy link
Copy Markdown
Contributor

stage 080-awaiting-merge-admission β†’ 050-review-pending: required-check-pending:build-and-test

@kubestellar-prow kubestellar-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 30, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

@clubanderson this PR is held at stage/071-needs-author and the hive will not merge it yet.

Why:

  • the branch conflicts with the base and needs a rebase

Next: the hive does not push to your branch. Push a new head (or reply here); CI and the review swarm re-run automatically and the PR returns to the normal path.

…g a person

A hive-authored PR (an adoption included) whose reviewer verdict says the
change is already on the base β€” the hive-redundant-of marker, or wording
that names the landing PR explicitly β€” is closed as superseded on the 085
route instead of parked for a person. The empty-diff closer's freshness
guard read updated_at, which the hive's own labels bump every pass, so
the head was always "too fresh"; the already-landed entry waives it
(a reviewer confirmed this head), measures head age from the compare's
commits, counts files byte-identical on the base tip as empty, settles
the adopted originals' lineage and closes the parent issue. Logged once
as self-authored:already-landed.

Fixes #15670

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
…onst

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
@clubanderson
clubanderson force-pushed the fix/already-landed-autoclose branch from 3e4a0dc to 7d4537c Compare October 30, 2026 04:44
@kubestellar-prow kubestellar-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 30, 2026
@github-actions github-actions Bot added the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Oct 30, 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 (security) β€” no blocking findings; one advisory.

Low / advisory β€” the reviewer-confirmed freshness waiver is not bound to the reviewed head. closeEmptyDiffBeforeHumanRoute takes the already-landed entry from obs.Detail.Verdict, which contributorLaneVerdictFor keys on obs.HeadSHA (automerge_stage_human.go:217-227, :346), but the pr it passes was re-fetched in closeSupersededBeforeHumanRoute (automerge_stage_human.go:159) and may already carry a newer head. closeHiveRedundantPR then sets ReviewerConfirmed: reviewed and skips the head-too-fresh guard for that head (pr_empty_diff_hive_autoclose.go:305,150). Redundancy is still measured on the actual head (prFilesIdenticalOnBase), so this cannot close a PR that has a real diff β€” hence advisory, not blocking β€” but the "a reviewer read this head" premise should be checked before it waives a guard:

	if claimed && !strings.EqualFold(strings.TrimSpace(pr.GetHead().GetSHA()), obs.HeadSHA) {
		c.debug("stage labels: already-landed verdict is for an older head; ordinary route", "repo", obs.Display, "pr", obs.Number, "verdict_head", obs.HeadSHA, "head", pr.GetHead().GetSHA())
		claimed = false
	}
	if claimed {

Out of scope (not security): closeIssuesAlreadyLanded posts the "this issue is done" note before CloseIssue's gates run (pr_empty_diff_hive_autoclose.go:395-403), so a refused close leaves a misleading note on an open issue.

β€” hive: agent=ci-maintainer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Hive filed review findings that do not block this PR as backlog items:

Cap: 10 backlog item(s) per PR per day.

@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 (head 3e4a0dc)

1. [medium] Bare in #N in alreadyLandedRefRE attributes the landing to issues and lineage mentions β€” src/pkg/review/already_landed.go:30. The preposition list includes bare in, which is how reviewers reference anything (issues, originals, discussions). Ran the regex at head against plausible decision questions:

  • "…whether the adoption is redundant; the original is tracked in #15324." β†’ AlreadyLandedPR = 15324 (the superseded original)
  • "…the test is already there in #15324 (the original adoption)." β†’ 15324
  • "…NOT redundant with #15506; the fix in #15500 is different." β†’ 15500

The close itself stays safe (redundancy is still measured by prFilesIdenticalOnBase), but the attribution leaks into user-facing text and persisted state: hive-redundant-of: #N on the close comment (pr_empty_diff_hive_autoclose.go renderEmptyDiffCloseComment), the issue note "already on v5 via #15324" (pr_empty_diff_hive_autoclose.go:394), the original's close note naming itself as the landing PR (automerge_stage_human.go:306), and the relay now persists this guess as redundantOf in the verdict report where every other reader treats it as marker-grade (review_verdict_relay.go:86). None of the tests rely on bare in (the two real texts use via / since), so dropping it keeps them green:

	alreadyLandedRefRE     = regexp.MustCompile(`(?i)\b(via|through|by|since|landed in|merged (?:in|as|via|through))\s+(?:[\w.-]+/[\w.-]+)?#(\d+)\b`)

Add the "tracked in #15324" text above as a want: 0 case in TestAlreadyLandedPRFromReviewerWording.

2. [low] Issue note is posted before CloseIssue's gates run β€” pr_empty_diff_hive_autoclose.go:394-401. "…so this issue is done. Reopen if that's wrong." lands on the issue, then CloseIssue may refuse (tracking issue β†’ ErrTrackingIssue; human-filed bug β†’ it posts its own reporter-confirmation request and returns ErrReporterConfirmationRequired, issue_close.go:66-98). Result: an open issue with two contradictory hive comments back to back. Swap the order β€” close first, post the note only on success (comments on closed issues are fine).

3. [low, test adequacy] prFilesIdenticalOnBase (pr_empty_diff_hive_autoclose.go:216) and the reviewed=true path of closeHiveRedundantPR (compare β†’ tree-match β†’ Supersedes/IssuesClosed) have no HTTP-level test; only the pure DecideHiveEmptyDiffAutoClose table gained rows. The status switch (404 vs other error, removed, rename β†’ not proved, alreadyLandedMaxFiles) is the piece that decides whether a hive PR with a non-empty compare gets closed, so it deserves one httptest case.

β€” hive: agent=adjudicator-4 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@clubanderson this PR is held at stage/071-needs-author and the hive will not merge it yet.

Failing checks:

  • test (rest 2/4)

Next: the hive does not push to your branch. Push a new head (or reply here); CI and the review swarm re-run automatically and the PR returns to the normal path.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

stage 080-awaiting-merge-admission β†’ 071-needs-author: optional-check-failing:test (rest 2/4)

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

Decision needed: @clubanderson should decide which head-age fix for #15603 survives β€” this PR's compare-derived commit date (prDiffAgainstBase, no extra call) or #15621's GetCommit β€” since both rewrite emptyDiffHeadAge in src/pkg/github/pr_empty_diff_hive_autoclose.go and the second to land must drop its copy.

Two things, both on src/pkg/github/pr_empty_diff_hive_autoclose.go (head 42b55f3); the rest of the PR I only skimmed, see the scope note at the end.

1. This PR and #15621 both fix #15603, differently β€” they conflict, not just textually.
prDiffAgainstBase here (:189-212) now returns the newest commit's committer date from comparison.Commits and closeHiveRedundantPR overrides facts.HeadAge = now.Sub(headAt) (:318-321). #15621 does the same job with a separate Repositories.GetCommit on the head SHA and a new emptyDiffHeadAge(pr, headCommitAt, now) signature. The overlap bot already flags the file conflict; the semantic point is that whichever lands second should drop its head-age change rather than merge both. This version is cheaper (the compare is already paid for), but note the compare's commit list is capped at 250 and ordered oldest-first, so on a very long branch the head commit can be absent and the "newest" date is older than the real head β€” the error is in the less-conservative direction (looks older β†’ closes sooner). #15621's direct head GET has no such cap.

2. Commit date alone removes the grace EmptyDiffMinHeadAge exists for (same finding I left on #15621).
:66-69 documents the guard as "a just-opened PR whose commits are still arriving". A committer date is set at local commit time, before push and before pr create; agents routinely commit, run checks for 20+ minutes, then open the PR, and hive/adopt-N branches carry days-old fork commits. With HeadAge taken from the commit date, the non-reviewed path (ReviewerConfirmed == false, :149) is eligible on the first sweep for any such PR. #15603 described the old updated_at measure as "conservative only"; this flips it. Suggested: headAt = max(headAt, pr.created_at) before facts.HeadAge = now.Sub(headAt) at :320 β€” still immune to label/comment bumps, still honours the documented wait. The reviewed path is unaffected (:149 waives the guard there by design).

Verified, no action: prFilesIdenticalOnBase (:219-254) compares the contents API blob SHA on the base tip to CommitFile.sha (the head blob) β€” that is a valid byte-identity proof for added/modified/changed; removed β†’ 404 on base; renames and >25 files fall through as unproved (false, true / false, false) and keep the PR. DecideHiveEmptyDiffAutoClose (:137, :152-155) only reaches the already-landed close when TreeMatchesBase is true, which is only set when known && reviewed (:322-325).

Scope note: I read the autoclose file fully and the decision function; I did not review automerge/automerge_stage_human.go (+149), review/already_landed.go (+108) or stagelabels/human.go β€” those need a second reader before this merges, given the PR closes issues as well as PRs (closeIssuesAlreadyLanded, :380-408, gated through WritebackAllowed and CloseIssue).

β€” hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@clubanderson
clubanderson merged commit 2da97b4 into v5 Oct 30, 2026
75 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the fix/already-landed-autoclose branch October 30, 2026 05:46
@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 Bot added a commit that referenced this pull request Oct 30, 2026
…tCommit

The head-commit measurement landed on v5 via #15671 (the compare's newest
commit sets HeadAge). What this PR still adds is the created_at floor: a PR
just opened from an old branch is a just-opened PR whose commits may be
arriving, so its age never exceeds the PR's own age. The redundant
headCommitTime GetCommit round-trip is gone; emptyDiffHeadAge takes the
compare's headAt directly.

Refs #15603

Hive-Fix-Attempt: 2/6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
hivecommons-hive Bot added a commit that referenced this pull request Oct 30, 2026
…from the merge base (#15621)

* πŸ› fix: measure empty-diff head age from the head commit, not updated_at

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>

* fix: floor empty-diff head age at the PR's created_at

Measuring from the head commit's committer date dropped the implicit
just-opened grace period: a PR opened from a branch whose head commit was
already older than EmptyDiffMinHeadAge was eligible for autoclose on the
first sweep. The age is now never older than the PR itself.

Also drop the dead HeadAge seed before the cheap guards (no guard there
reads it) and log when the head commit cannot be read, so the
updated_at fallback is visible instead of silently masking the regression
this rule fixes.

Hive-Fix-Attempt: 1/6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>

* πŸ› fix: floor the empty-diff head age at created_at; drop the extra GetCommit

The head-commit measurement landed on v5 via #15671 (the compare's newest
commit sets HeadAge). What this PR still adds is the created_at floor: a PR
just opened from an old branch is a just-opened PR whose commits may be
arriving, so its age never exceeds the PR's own age. The redundant
headCommitTime GetCommit round-trip is gone; emptyDiffHeadAge takes the
compare's headAt directly.

Refs #15603

Hive-Fix-Attempt: 2/6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>

* πŸ› fix: measure an on-base head's age from the merge-base commit

When base...head lists no commits the head is already on the base, so
the compare's merge_base_commit is the head; use its committer date
instead of falling back to updated_at.

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>

---------

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
Co-authored-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
hivecommons-hive Bot added a commit that referenced this pull request Oct 30, 2026
The already-landed close (#15671) only covered the hive's own PRs. #15544
by a trusted contributor was +0/βˆ’0 against v5 because #15545 (merged)
carried the same change, yet it parked at 085 for 9h on the reviewer's
"should decide whether #15544 can be closed as a no-op now that #15545
(merged) carries this change".

- github: CloseAlreadyLandedHivePRIfEligible closes any author's PR when
  the diff is empty AND the landing is proven (named PR merged, linked
  issue closed by a merged PR, or head contained in base); comment
  "already landed via #N β€” closing as superseded; thank you @author".
- automerge: the 085 route asks the already-landed closer for any author
  with an already-landed verdict; logs already-landed:<author_kind>.
- review: "#N (merged)" names the landing PR like "via #N".
- dashboard: the Let-hive-decide preview's why for an already-fixed close
  is the empty diff and the merged landing, never the author's trust.

Closes #15732

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Co-authored-by: hivecommons-hive[bot] <280983584+hivecommons-hive[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts-with-open-pr Open PR has a merge conflict with another open PR 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

Development

Successfully merging this pull request may close these issues.

πŸ› review: hive-authored adoption PRs parked at 085 asking a person to close them as already landed

1 participant