Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-merge-lane-suppressed-sweep-front.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Serialized merge lane: a pull request that only an automerge sweep lane would merge, and whose branch update and merge writeback containment refuses (for example an auto-promoted contributor PR without `hive-review` at L6), no longer takes the lane front. It used to reach the front and hold it for the full front timeout, refused every round with `writeback: unsolicited write suppressed`, while owner-queued pull requests waited behind it; with several such PRs the lane made no merges for hours. The lane now asks containment before the PR takes a place, so it is refused without being recorded (no front churn), and a front whose sweep writes become refused leaves on its path's next call. The lgtm queue, `/hive merge` relay and dashboard paths are not asked and behave as before.
12 changes: 12 additions & 0 deletions src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,18 @@ the block, the lane records that no remaining lane action can satisfy it and pro
the next pull request. Pending, missing or unreadable required checks still
wait; an eligible pull request that returns joins the back of the lane.

The lane's branch updates and merges pass the same writeback containment as
every other write (`contributor_adopt`: L6 plus the opt-in label for an item
the hive did not author), except on the explicitly requested paths (the `lgtm`
queue, the `/hive merge` relay and the dashboard), which only an operator
pause stops. A pull request that only an automerge sweep lane would merge,
and whose writes containment refuses (for example a contributor PR without
`hive-review` at L6), takes no lane place: the sweep logs
`the sweep merge path cannot update or merge this pull request, so it takes
no lane place: …` and the next eligible pull request goes ahead. A front whose
sweep writes become refused leaves on that path's next call, and stays out
until containment allows it again.

### The remaining window, and GitHub's up-to-date rule

No GitHub merge API can be made conditional on the target branch's tip; they
Expand Down
87 changes: 81 additions & 6 deletions src/pkg/mergelane/gate.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package mergelane

import (
Expand Down Expand Up @@ -59,14 +59,19 @@
l.emit([]Event{{At: l.opts.Now(), Repo: req.Repo, Branch: branch, PR: req.Number, Action: ActionRefusal, Reason: reason}})
return ghub.LaneMergeResult{Outcome: ghub.LaneOutcomeRefused, Reason: reason}, err
}
dec, err := l.Acquire(req.Repo, branch, req.Number, req.Path)
if err != nil || dec.Outcome == OutcomeDeferred {
return ghub.LaneMergeResult{Outcome: string(dec.Outcome), Reason: dec.Reason}, err
}
method := &mergeMethod{
requested: req.Method,
solicited: req.Path == ghub.PRAuditPathQueue || req.Path == ghub.PRAuditPathRelay || req.Path == ghub.PRAuditPathDashboard,
}
if !method.solicited {
if reason := l.pathWriteSuppressed(ctx, req.Repo, branch, req.Number, req.Path); reason != "" {
return l.refuseSuppressedPath(req.Repo, branch, req.Number, reason)
}
}
dec, err := l.Acquire(req.Repo, branch, req.Number, req.Path)
if err != nil || dec.Outcome == OutcomeDeferred {
return ghub.LaneMergeResult{Outcome: string(dec.Outcome), Reason: dec.Reason}, err
}
ctx = context.WithValue(ctx, mergeMethodKey{}, method)
dec, err = l.Advance(ctx, req.Repo, branch, req.Number, Authorizer(req.Authorize))
res := ghub.LaneMergeResult{Outcome: string(dec.Outcome), Reason: dec.Reason, SHA: dec.MergeSHA, MergeError: dec.MergeError}
Expand All @@ -76,6 +81,61 @@
return res, err
}

// PathWriteChecker is an optional GitHub capability: it reports, without
// writing, whether the merge path in ctx may update and merge PR number. It
// returns an error wrapping writeback.ErrSuppressed when writeback
// containment would refuse both (RESTGitHub: the check UpdateBranch and
// Merge apply); any other error means the answer is not known.
type PathWriteChecker interface {
PathCanWrite(ctx context.Context, repo string, number int) error
}

// pathWriteSuppressed returns a refusal when an unsolicited merge path (the
// automerge sweep lanes) cannot write to pr: writeback containment refuses
// its branch update and merge alike, so as the front it could only hold the
// lane until the front timeout while queued pull requests waited. Such a PR
// takes no lane place. An admitted waiter is not re-checked, so waiting
// costs no extra GitHub call; it is checked again once it is the front.
func (l *Lane) pathWriteSuppressed(ctx context.Context, repo, branch string, pr int, path string) string {
checker, ok := l.opts.GitHub.(PathWriteChecker)
if !ok {
return ""
}
rec, _, err := l.Snapshot(repo, branch)
if err != nil {
return ""
}
if (rec.Front == nil || rec.Front.PR != pr) && rec.waiterIndex(pr) >= 0 {
return ""
}
err = checker.PathCanWrite(ctx, repo, pr)
if !errors.Is(err, writeback.ErrSuppressed) {
return ""
}
if path == "" {
path = "calling"
}
return fmt.Sprintf("the %s merge path cannot update or merge this pull request, so it takes no lane place: %v", path, err)
}

// refuseSuppressedPath refuses pr with reason. A PR already in the lane
// leaves it (a front ends and the oldest waiter is promoted) and the refusal
// is audited once; a PR outside the lane is not recorded, so asking again on
// every sweep changes nothing.
func (l *Lane) refuseSuppressedPath(repo, branch string, pr int, reason string) (ghub.LaneMergeResult, error) {
res := ghub.LaneMergeResult{Outcome: ghub.LaneOutcomeRefused, Reason: reason}
rec, _, err := l.Snapshot(repo, branch)
if err != nil {
return res, err
}
if (rec.Front == nil || rec.Front.PR != pr) && rec.waiterIndex(pr) < 0 {
return res, nil
}
err = l.Release(repo, branch, pr, reason)
l.emit([]Event{{At: l.opts.Now(), Repo: repo, Branch: branch, PR: pr, Action: ActionRefusal, Reason: reason}})
return res, err
}

// advanceRejectedFront serves a merge path that rejected pr before the lane
// gate (#11023). A PR that is not the front is neither recorded nor read on
// GitHub. The front runs one round without the path's authorization, so it
Expand Down Expand Up @@ -144,6 +204,11 @@
return ""
}

// laneWriteKind is the writeback kind the lane's branch update and merge are
// contained under; PathCanWrite asks the same question before a PR takes a
// lane place.
const laneWriteKind = writeback.KindContributorAdopt

// RESTGitHub is the lane's GitHub over the hive's App client. Client is read
// on every call so a rebuilt client is followed. Reads are live.
type RESTGitHub struct {
Expand Down Expand Up @@ -310,7 +375,7 @@
return err
}
// Mutations have no comment body: never reserve comment dedupe on a retry.
if err := g.allowWriteback(ctx, c, repo, number, writeback.KindContributorAdopt, ""); err != nil {
if err := g.allowWriteback(ctx, c, repo, number, laneWriteKind, ""); err != nil {
return err
}
var apiErr error
Expand Down Expand Up @@ -381,6 +446,16 @@
return nil
}

// PathCanWrite applies the containment UpdateBranch and Merge apply, without
// writing: nil when ctx's merge path may update and merge number.
func (g *RESTGitHub) PathCanWrite(ctx context.Context, repo string, number int) error {
c, _, _, _, err := g.rest(repo)
if err != nil {
return err
}
return g.allowWriteback(ctx, c, repo, number, laneWriteKind, "")
}

// Merge is the REST merge with head pinned. The method is the calling path's;
// squash is upgraded to a merge commit for forward-merge and upstream-sync
// PRs, as MergePR does.
Expand All @@ -390,7 +465,7 @@
return "", err
}
// The mutation journal, not comment-content dedupe, reconciles merge attempts.
if err := g.allowWriteback(ctx, c, repo, number, writeback.KindContributorAdopt, ""); err != nil {
if err := g.allowWriteback(ctx, c, repo, number, laneWriteKind, ""); err != nil {
return "", err
}
method, _ := ctx.Value(mergeMethodKey{}).(*mergeMethod)
Expand Down
Loading
Loading