Skip to content
Closed
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ A pull request joins the queue when it's labelled `merge-queue` and leaves when
}
```

`admit` names the statuses or check runs a pull request's own head must pass before it joins the queue, and `threads` keeps one out while a review thread is unresolved (the queue reads its first hundred, and one with more waits). `slots` is how many candidates build at once, and `max_batch` how many pull requests each adds. Where builds cost more than a short wait does, `gather` holds a candidate back while another is building until it would add that many. The builds that find a failure's cause run beside them: three for each pull request the red build added, all at once where `started` or `begins` is set. Set `started` to a word your CI's pending status carries once a build is running (Buildkite's says "started"), so the queue can find a failure's cause in one build time, not three; check runs need no setting. Where the context that judges a build appears only at its end, set `begins` to a context that answers once your CI has queued the build's jobs, such as a pipeline's first step. Where your CI reports as a GitHub App's check runs, set `app` to that App's database ID (`"app": 15368`): every context but the queue's own status is then read only from its check runs, and a commit status or another App's check run answers nothing. The queue's own status is always a commit status, and no build, probe, admit or begins context may share its name. Set `cancels` where your CI stops a build whose branch is deleted; otherwise a build the queue no longer wants keeps its slot until it reports. `run.Config` in `internal/run/run.go` lists every setting.
`admit` names the statuses or check runs a pull request's own head must pass before it joins the queue, and `threads` keeps one out while a review thread is unresolved (the queue reads its first hundred, and one with more waits). `slots` is how many candidates build at once, and `max_batch` how many pull requests each adds. Where builds cost more than a short wait does, `gather` holds a candidate back while another is building until it would add that many. The builds that find a failure's cause run beside them: three for each pull request the red build added, all at once where `started` or `begins` is set. Set `started` to a word your CI's pending status carries once a build is running (Buildkite's says "started"), so the queue can find a failure's cause in one build time, not three; check runs need no setting. Where the context that judges a build appears only at its end, set `begins` to a context that answers once your CI has queued the build's jobs, such as a pipeline's first step. Where your CI reports as a GitHub App's check runs, set `app` to that App's database ID (`"app": 15368`): every context but the queue's own status is then read only from its check runs, and a commit status or another App's check run answers nothing. The queue's own status is always a commit status, and no build, probe, admit or begins context may share its name. Set `cancels` where your CI stops a build whose branch is deleted; otherwise a build the queue no longer wants keeps its slot until it reports. Set `spare`, where `slots` is two or more, to fill one slot fewer while a failed candidate of several pull requests that sat on the trunk's tip has its first round of builds, so the pull requests that round clears are likelier to find one free. `run.Config` in `internal/run/run.go` lists every setting.

Set `keep` (for example, `"keep": "3m"`) to leave a landed candidate's branch standing for at least that long after the queue marks it landed. The candidate at the trunk's tip is marked at the landing, or by the next read if that tick died first. A candidate beneath it is marked once its verdict is in. One failed or errored context is a verdict, so another still running, or one that appears later, does not hold the branch longer. Where `cancels` is set, a lower candidate still running is deleted at once, as without `keep`. A retry the trunk holds is a candidate like any other. A probe, a check and a round's build are never marked. A second mark from ticks run beside each other only lengthens the stand; ticks must run one at a time. Without `keep`, the landing push has the remote compare and delete the candidate's branch, so whatever deletes that branch first stops the landing. With `keep`, the queue compares the branch just before pushing the trunk alone, so deleting the branch between that comparison and the push does not stop the landing.

Expand Down
6 changes: 3 additions & 3 deletions doc/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The queue uses its own mark because the trunk's own builds report on the same co

## Blame

A red candidate at the bottom of the chain is set aside with the pull requests it added, and the chain goes on without them, built on the tip. A candidate stacked on the red one is dropped once it fails too. Until then it may yet land them all. Where rounds are probes, which answer in a fraction of a build, the chain waits for that answer. Where they are whole builds it does not wait: it is built beside the candidates still running.
A red candidate at the bottom of the chain is set aside with the pull requests it added, and the chain goes on without them, built on the tip. A candidate stacked on the red one is dropped once it fails too. Until then it may yet land them all. Where rounds are probes, which answer in a fraction of a build, the chain waits while a candidate stacked on the red one is still building, after the first round has answered too. Where they are whole builds it does not wait: it is built beside the candidates still running.

The red candidate is narrowed by rounds: builds of some of its prefixes. A round's build never lands. What the rounds have said so far is a span, from the highest prefix that passed to the lowest above it that failed. The culprit is in it. A round is read once every build in it has reported, and the rounds are read in order.

Expand Down Expand Up @@ -60,7 +60,7 @@ A test of five builds, fail, pass, fail, pass and fail, was tried for a CI that

Only the pull requests the rounds have not ruled out stay off the chain. The rest go back on it at once. One whose merge there would be the red candidate's own tree waits with them, since a build of that tree is an attempt of the red candidate and not a candidate on the chain.

A red candidate and its rounds stand while the trunk moves under them, since they prove what they prove about the commits they were built on. They go when a pull request in the trees they build leaves the queue, and when their base is no longer the tip and fails by itself. Once a pull request under a red candidate has landed, a round's build from below that landing is a build of another tree, and it goes too. So several red candidates are narrowed at once, each beside a chain that keeps landing.
A red candidate and its rounds stand while the trunk moves under them, since they prove what they prove about the commits they were built on. They go when a pull request in the trees they build leaves the queue, and when their base is no longer the tip and fails by itself. Once a pull request under a red candidate has landed, a round's build from below that landing is a build of another tree, and it goes too. So several red candidates are narrowed at once, each beside a chain that keeps landing. A suspect is judged on the trees its red candidate's rounds build, so one whose red candidate went because the trunk moved past it starts over on the new trunk.

A round's builds are whole builds by default. Where a repository's CI offers probes, a round uses them instead: a probe is an empty commit on a prefix that asks CI to run only what failed in the red build.

Expand Down Expand Up @@ -116,7 +116,7 @@ The queue posts `pending` on everything it pushes, which gives each wait a start

## Dials

`slots` is how many candidates are under test at once. A round's builds are beside them and are not counted. `max_batch` is how many pull requests a candidate adds, and `gather` how few it may add while another is building: fewer builds for each landing, for a wait of at most one build. `eval/main.go` holds the values each shape ships with, and the hillclimb moves them.
`slots` is how many candidates are under test at once. A round's builds are beside them and are not counted. With `spare` and two slots or more, while a red candidate of several pull requests built on the trunk's tip has its first round running, the chain takes one slot fewer, so those the round clears are likelier to find one free. It limits how many slots the chain fills and does not push the cleared pull requests: `gather` may still hold one back, and a landing or an ejection in the same tick ends the plan first. The round's read ends the hold, whatever it says, as does the red candidate going or the trunk moving past its base. A round that never reports reads as lost after `timeout`; where `timeout` is zero nothing ends the round, and the slot stays held until one of those. `max_batch` is how many pull requests a candidate adds, and `gather` how few it may add while another is building: fewer builds for each landing, for a wait of at most one build. `eval/main.go` holds the values each shape ships with, and the hillclimb moves them.

## Not in the engine

Expand Down
14 changes: 14 additions & 0 deletions eval/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ func TestCheckerCurrentPlanner(t *testing.T) {
}
}

func TestCheckerCurrentPlannerWithSpare(t *testing.T) {
worlds := defaultWorlds()
for i := range worlds {
worlds[i].Config.Spare = true
}
sum := checkSuite(worlds, mutant{plan: queue.Plan, verify: queue.Verify})
t.Logf("queue.Plan with spare: %d of %d whole, %d capped, %d states, %d broken",
sum.whole, sum.worlds, sum.capped, sum.states, sum.brokenWorlds)
for _, inv := range sum.brokenInvs {
sample := sum.bestByInv[inv]
t.Errorf("%s is broken in %s:\n%s", inv, sample.world.Name, formatTrace(sample.result))
}
}

func TestCheckerCounterexample(t *testing.T) {
w := checkWorld{
Name: "2 PRs crashes+stale (good+breaks, 2 of 2)",
Expand Down
13 changes: 11 additions & 2 deletions internal/queue/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ type red struct {

func (r *red) suspects() []Member { return r.chain[max(r.lo, 0):r.hi] }

// clearing says the red candidate sits on the trunk with several pull requests and its first
// round has yet to read, so some of them may be cleared to go back on the chain at any tick.
func (p *plan) clearing(r *red) bool { return r.base == p.w.Trunk && len(r.chain) > 1 && r.read == 0 }

func (p *plan) act(a Action) { p.acts = append(p.acts, a) }

// admit sorts the queue into those that may join the chain and those that wait in place.
Expand Down Expand Up @@ -604,7 +608,8 @@ func (p *plan) evidence(r *red, j int, whole bool) Build {
// candidate again in their order, whatever commits now carry them. It waits while probes are
// deciding whether a red candidate is real. While a candidate is still building, one that
// would add fewer pull requests than gather waits for more, or for that build, unless it
// holds one labelled to go first.
// holds one labelled to go first. With spare, it uses one slot fewer while a red candidate's
// first round on the trunk runs.
func (p *plan) fill() {
in := map[int]bool{}
for _, m := range p.chain {
Expand All @@ -617,7 +622,11 @@ func (p *plan) fill() {
if p.wait {
return
}
for p.pending < p.c.Slots {
slots := p.c.Slots
if p.c.Spare && slots > 1 && slices.ContainsFunc(p.reds, p.clearing) {
slots--
}
for p.pending < slots {
parent, added, held, first := p.prefix(len(p.chain)), 0, len(p.chain), false
for _, pr := range p.order {
if !free(pr) {
Expand Down
Loading