Skip to content

πŸ› Coalesce base preparation refreshes and keep a ready owner in front - #19275

Open
clubanderson wants to merge 1 commit into
v5from
fix/coalesce-base-refresh
Open

clubanderson wants to merge 1 commit into
v5from
fix/coalesce-base-refresh

Conversation

@clubanderson

Copy link
Copy Markdown
Member

Fixes #19274

What

Two bounded waits in base preparation, both capped by preparationRefreshCoalesceMaxWait (30 minutes after the owner's last bot refresh):

  1. No re-refresh while the last refresh's CI runs. claimBasePreparationUpdate now asks preparationRefreshCoalesces first. When the PR is the owner, its live head is the result of the recorded refresh (preparationCompleted), required CI on that head is pending or not yet reported, and the base commits since the refresh provably miss every file the PR changes, the refresh waits with base-refresh:coalescing (a base-refresh: reason, so ownership is kept). It refreshes as before when that CI finished green or red, when the base delta touches the PR's files, when the delta compare errors, is not ahead, is empty or may be truncated, for a repair owner, or after the max wait.
  2. A green, reviewed owner is not overtaken. currentBaseGate now calls preparationOwnerHoldsSuccessor before comparing. If another PR owns the destination and is CI-green and approved on its completed refresh (preparationReadiness ready and known), the caller holds with base-refresh:queued-behind#<owner>. A pending or unreviewed owner holds nothing, so the readiness-first yield is unchanged. Any failed read, a repair owner, an invalid or unrefreshed owner, or the max wait holds nothing.

Why

#19228 was refreshed 5 times today, two of them 7 minutes apart; on its fourth refresh required CI finished at 16:27 and the next refresh came at 16:28, after a successor merged ahead of it. Each refresh costs about 16 workflow runs and 38 runner-minutes.

Tests

  • TestPreparationRefreshCoalescesWhileCIPending: pending and not-yet-reported CI defer the refresh and keep the owner and attempt; green CI, red CI, an overlapping base delta, an unreadable delta and the max wait all refresh.
  • TestPreparationGreenReviewedOwnerNotOvertaken: a green reviewed owner holds a current successor; pending, unreviewed and unrefreshed owners and the max wait do not.
  • The shared preparationAPI fixture gains failing and baseDelta knobs; existing behavior of the fixture is unchanged when they are unset.

Docs: src/docs/hive-merge.md preparation section. Changelog fragment included.

The preparation owner is not refreshed again while required CI on its
last bot refresh is still in flight, unless the base delta touches the
PR's files or that CI failed. A successor no longer merges ahead of an
owner that is green and reviewed on its completed refresh. Both waits
are bounded by preparationRefreshCoalesceMaxWait; unreadable evidence
keeps the previous behavior.

Fixes #19274

Signed-off-by: Andy 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 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 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
#19277 🌱 Skip heavy CI jobs on refresh-only pull request heads same files src/docs/hive-merge.md

@github-actions

Copy link
Copy Markdown
Contributor

Mutation testing

gremlins found 4 surviving mutant(s) in changed files: the code ran under tests, but changing it did not fail any test.

File Line Mutation
src/pkg/github/automerge/automerge_base_preparation.go 314 CONDITIONALS_BOUNDARY
src/pkg/github/automerge/automerge_base_preparation.go 344 CONDITIONALS_BOUNDARY
src/pkg/github/automerge/automerge_base_preparation.go 353 CONDITIONALS_NEGATION
src/pkg/github/automerge/automerge_base_preparation.go 377 CONDITIONALS_BOUNDARY

2 mutant(s) in changed files are not reached by any test (NOT COVERED). A maintainer may apply the mutation/acknowledged label to accept this.

File Line Mutation
src/pkg/github/automerge/automerge_base_preparation.go 26 ARITHMETIC_BASE
src/pkg/github/automerge/automerge_base_preparation.go 33 ARITHMETIC_BASE

Verdict: lived (#17349).

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

Style review: conventions, docs and changelog fragment are in order. One low advisory inline about the duplicated pending-CI predicate. Not blocking.

-- hive: agent=adjudicator-4 backend=claude model=claude-sonnet-5-5 claude=2.1.328

if err != nil || !requirementsKnown || st.Green {
return false
}
return stageengine.ClassifyCIReason(st.Reason) == stageengine.CIReasonPending || strings.HasPrefix(st.Reason, "required-check-missing:")

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.

Advisory: cistatus.ReasonIsPending (src/pkg/cistatus/cistatus.go) already covers the required-check-missing: prefix and pending reasons. Consider reusing it, or add a comment on why this narrower set is intended (it excludes ci-reporting-stalled:/ci-reporting-unverified:).

@hivecommons-hive

hivecommons-hive Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Hive status β€” updated in place; edits do not notify. Full history is in the Activity Monitor.

Review findings from ci-maintainer (folded here because this head already carries its hive review):

Docs-currency review at 0c0aef7. The new section in src/docs/hive-merge.md matches the code: reason base-refresh:coalescing, the two INFO log strings, the preparationRefreshCoalesceMaxWait 30-minute cap, and the repair-owner and unreadable-delta fallbacks. The changelog fragment is present.

One stale statement (in-scope, low). src/docs/hive-merge.md:555-557 is left unchanged and still says: "A successor that is already current-base, CI-green and reviewed passes every normal merge gate without waiting for a preparing owner." After this PR that is false whenever the owner is green and reviewed (currentBaseGate now returns base-refresh:queued-behind#<owner>, automerge_current_base.go:108). The new paragraph at about line 599 calls itself an exception to this sentence, but the original sentence still reads as absolute to anyone who stops there. The heading "Ownership serializes refreshes, not ready merges" also contradicts the behaviour. Qualify the original sentence:

**Ownership serializes refreshes, not ready merges, unless the owner is itself ready.** A successor that is
already current-base, CI-green and reviewed passes every normal merge gate
without waiting for a preparing owner, except behind an owner that is already
CI-green and reviewed on its refresh (see below). A behind successor cannot skip testing.

The new bullet then needs its cross-reference changed from "ownership serializes refreshes, not ready merges" above to the rule above.

Review findings from adjudicator (folded here because this head already carries its hive review):

One in-scope correctness concern on the truncation guard (inline). I read the diff, the base-preparation file at head 0c0aef7, and the issue #19274; the gate ordering, the prior == coalescedAttempt re-check under the store lock, and the owner-skip in currentBaseGate look sound. The tests cover the listed cases. I did not execute them.

Findings not on a changed line

  • src/pkg/github/automerge/automerge_base_preparation.go:343: CompareCommits(..., nil) sends no per_page, so GitHub returns its default page (30 files; the 300 figure is the total cap across pages). The truncation guard at line 344 only trips at len(cmp.Files) >= 300. A base delta of 31-299 files therefore arrives cut at 30 and passes as complete. If the PR's file is beyond the first page, the overlap check misses it and the refresh is deferred as base-refresh:coalescing (up to 30 min) even though the delta touches the PR. πŸ› Base preparation re-refreshes the front while its CI runs and lets successors overtake itΒ #19274 requires that a possibly truncated or unreadable delta keep today's behavior. Fix: request the full page and treat a full page as truncated.
    	cmp, _, err := c.gh.Repositories.CompareCommits(hgithub.WithRESTCaller(ctx, "hive:base_preparation_coalesce"), owner, repo, fromBase, toBase, &gh.ListOptions{PerPage: preparationCompareFilesCap})
    
    Also add a test where baseDelta has 30+ files and the PR's file is not in the first page. I'm not certain of the default file paging on this endpoint, so please confirm against the API.

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

Why:

  • the review swarm requested changes

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.

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

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

πŸ› Base preparation re-refreshes the front while its CI runs and lets successors overtake it

1 participant