Merge changes

Merge more changes a day

Let idle runners check queued changes early, carry records across unrelated merges, and check several changes as one tree.

One main branch merges one change at a time, and each change waits for its own check run. Four runner settings, ahead, footprint_lanes, batch and warm, let a change merge on a check run made earlier or shared. Each is off by default, and each is a rule of evidence reuse, never a weaker verdict. With batch, members merge on the check of the batch's last commit. With footprint, a record names its source.

Merges still go one push at a time, in queue order, except past checks that read none of a change. Every merge still rests on evidence, and its result names what that evidence covers. A missed prediction, a changed read set or an unknown never counts as a pass: the check runs. The gain depends on your queue, your runners, your paths and how often your checks fail.

When to use these settings

  • Runners sit idle while the head checks: set ahead, so they check the entries behind it.
  • Most changes touch separate paths: set footprint = true on narrow checks, and footprint_lanes.
  • Checks are slow and rarely fail: set batch, so one run covers several changes.
  • Checks fail often: max_failure_rate stops batches until the failure rate falls.
  • One change runs several slow checks: [runner] parallel_checks runs them at once, with no evidence reuse.
  • Checks run long but read few files: set footprint = "observed" and warm, so a change runs only what it touches.

Where to start

Make these changes in order, and measure the wait from bay merge to main after each one.

  • Send every merge through bay: a commit from elsewhere moves main, and every check in flight runs again.
  • Skip checks a change does not reach: give each pre-merge check when_paths.
  • Run a change's checks side by side: set [runner] parallel_checks.
  • Batch the line: set batch, and move checks with commit or history inputs after the merge.
  • Move slow whole-tree checks after the merge: mark them stage = "post", in an environment one machine serves.
  • Check the next batches early: run two runners or more, and set ahead.
  • Let agents wait in the background: each runs bay merge <change> --wait=3600 as a background task, not repeated status reads.

Before you start

Each setting turns on exact-inputs evidence reuse, with no other key. bay refuses a config that sets one and also [policy] evidence_reuse = "off". Each also needs a key registry that signs everything, or reuse_unsigned = true in the policy. Without either, the settings do nothing. Results still name their trust: signed, approvals or unsigned. Each runner is its own producer and check slot, so more runners give more early checks.

toml
# .bay/config.toml
[runner]
ahead = 4                          # check up to 4 queued entries early; at most 16
footprint_lanes = true             # check an entry beside the head when paths are disjoint
batch = { min = 2, max = 8, max_failure_rate = 0.3 }

Check queued changes early

With ahead = N, a runner that does not hold the head checks the next N entries now. It checks each on the base the entries ahead of it predict: main with each of them merged, in order. It merges nothing and takes no ownership. The operation lists the run under prechecks.

When the entry reaches the head and main matches the prediction, it merges on that evidence with no new run. When the prediction misses, the record is about another tree, and bay ignores it. A miss wastes that work, and never counts as a pass.

toml
[runner]
ahead = 4

Carry a record across unrelated merges

Without this, any merge to main makes a queued candidate's records stale, and its checks run again. footprint = true on a [[check]] says its verdict reads only its paths, else its when_paths. bay then stamps each record with digests of that read set, in the candidate and in its base. A later candidate of the same operation, with the same stamp, policy and fixtures, gets the record carried. The carried record names the record it came from, and the check does not run. Carrying needs [runner] footprint_lanes = true, and a check whose inputs name commit or history never carries.

toml
# .bay/policy.toml
[[check]]
id = "api"
environment = "linux-x86_64"
command = "scripts/bay-check api"
adapter = ["scripts/bay-check"]
expected_minimum = 50
when_paths = ["api/"]
footprint = true                   # the verdict reads only api/

When main moves during a check

When main moves under a candidate while its checks run, its runner stops what the move made stale. A check whose record would carry to the new main finishes, and its record is kept. Every other running check stops, with its whole process group, and keeps no record. No check starts after the move.

The runner builds the change again on the new main, in the same visit. A head builds again at most three times in one visit, then yields its turn. The move is recorded on the change, so no change passes that head but a repair.

Let bay see what a check reads

footprint = "observed" needs no read set: bay records what each run read and listed in its tree. A later candidate whose bytes there are unchanged reuses the record. If anything it read changed, the check runs again. bay sees reads through file access times, which Linux updates by default. On a mount with noatime, bay observes nothing, and the record is never reused. A check with network = true reads what bay cannot see, so bay refuses that pair.

toml
# .bay/policy.toml on main
[[check]]
id = "unit"
environment = "linux-x86_64"
command = "scripts/bay-check unit"
adapter = ["scripts/bay-check"]
expected_minimum = 200
footprint = "observed"             # bay records what the run reads

# .bay/config.toml on main
[runner]
warm = true                        # run observed checks once on main's newest commit

Check beside the head

An entry's footprint is the union of the when_paths of the checks its diff requires. A required check with no when_paths makes the footprint the whole tree.

With footprint_lanes = true, a runner checks an entry early when its footprint is disjoint from every entry ahead. It checks it on the current main. Only footprint = true records and approvals carry to its final candidate. Footprint lanes keep queue order: an entry they check early never passes a blocked head. If every required check carries over, the entry then merges with one push and no new run.

toml
[runner]
footprint_lanes = true

Check several changes as one tree

With batch, the head's runner takes the head and the live entries behind it, in queue order. It checks their combined tree once, on the current main. On a pass, every member merges in one push, and main moves once, to the last member. Each member keeps its own commit, Change-Id and trailers, plus a Bay-Batch: <id> <i>/<k> trailer. Each member's result names the batch under detail.batch, because its own tree was not checked alone. With footprint_lanes, a batch ends at an entry outside the head's footprint, or whose slowest check outlasts the head's.

toml
[runner]
batch = { min = 2, max = 8, max_failure_rate = 0.3 }

Check the next batches early

While the head checks, alone or batched, other runners check the next batches on the main it will make. The head's lease names the changes its check covers, so the others plan from that. With footprint_lanes, a batch checked early ends at the first change outside its head's lane, or slower than its head. Each merges on that check when its turn comes and main is as predicted. When the batch grew after its early check, the head merges the longest part that check passed. The changes after that part form a batch of their own.

Check a change alone before its turn

With batch, a runner checks a change behind the head alone, on main's tip, when no planned batch covers it. A change that fails alone joins no batch: it runs alone at its turn, and bay wakes its agent early. A check ahead of its turn stops when nobody runs the line's head, so a runner can take the head. The check looks every 30 seconds. Two looks in a row at a new head with no lease stop it. Its runner then merges that head, and visits the check's change again in the same pass.

When a batch fails

  • bay checks the whole batch, then halves the failing prefix until one passes. It records each check as it finishes.
  • Every prefix is on the same main, so none runs twice. The first passing prefix ends the search.
  • When two members or more pass, that prefix merges at once as one batch.
  • At the head, the culprit runs alone, unless a footprint check carries the bisection's failure: bay refuses it at once.
  • When fewer than two pass, no batch merges. The head takes its usual path on its own records.
  • The members after it go back to the line, and the next batch reads the search's records on them.

When a check gives no answer on its machine, the search ends. Then the head runs alone. When its own check also gives no answer on that machine, another machine runs it. So a check that cannot run on one machine does not fail each smaller prefix.

The runner writes one line as it starts each prefix, and one line with its verdict. Each line names the next step of the search, and the last line gives the result. bay status of the head names the step of the search in operation.bisect. of is the size of the batch, and prefix the part that the check covers. done counts the steps done, and left the most checks left. The change's sentence says the same, and a taken row of bay queue names the step too.

When a member cannot join

After its check, each member of a batch joins in turn: bay reads it, verifies it, and claims it. The first member that cannot join cuts the batch to the members before it. bay checks the shorter batch again, by prefixes, as it does a batch that failed.

When two members or more pass, that prefix merges as one batch. The rest go back to the queue. With fewer than two, no batch merges, and the head runs alone. The member that could not join keeps its place for its own turn.

When no batch forms

  • No batch forms while the recent failure rate is above max_failure_rate, 0.3 by default.
  • That rate reads the last 20 check outcomes of finished queue places. An unknown result does not count.
  • With footprint_lanes, it reads only the places whose footprint overlaps the head's.
  • A batch never holds a lane change, a change with named inputs, a policy change or a known culprit.
  • A change that wakes a pre-merge check with inputs commit or history merges alone, at its turn.
  • No batch forms while main is held, or under a policy with unchecked = true.

A change ahead of its turn

A repair, or a change that needs no check, may run ahead of its turn. When it does, it merges alone, and the changes behind it wait for the queue head. Once main moved under the head, or its check ran two minutes, no change passes it but a repair. After main moved under a running repair, only a repair runs ahead of its turn. The others keep their places until that repair leaves the line, or main turns green. So one move of main costs the repair one check.

A change past checks that read none of its files

With evidence reuse on, a change may merge from its own place, past live changes ahead of it. It does when no pre-merge check of those changes, or of the head's batch, reads any of its files. bay knows a check's reads only from materialize = "changed" or footprint = "observed". Any other check reads everything.

None passes a head whose check ran two minutes, or that main moved under once. A change to .bay/ never passes. At most three changes that need a check pass one head, over its whole wait and check. A change that needs no check passes it without a count. With batch, a change behind the head that cannot pass it joins the head's batch. The change passed rebuilds its candidate on the new main, and merges only on evidence for it.

Batches and a red main

Main's red holds no place in line. A change on a red check's paths runs that check in its own run, before its merge. No change passes a head whose changed paths a red check covers. That run also asks for the units the red failed. A result that skips them is unknown, never a pass.

On a host from bay host

  • The host admits a Bay-Batch commit only within a whole batch, in one push.
  • The config at the batch's base must set batch, or the host refuses the push.
  • The host judges the last member's evidence by the policy at the batch's base, over the whole diff.
  • A policy repair never merges in a batch.

What these settings cannot do

  • They merge out of queue order only past checks that read none of a change's files.
  • They never turn an unknown, a missed prediction or a changed read set into a pass.
  • They do nothing without a key registry that signs everything, or reuse_unsigned = true.

Limits

One check slot runs at most 1,440 divided by the check minutes runs a day: 120 with 12-minute checks. Without batch, merges go one head at a time, and a head's turn is its build, checks and push. With batch, one run can merge up to max changes. ahead and footprint_lanes run more checks side by side, but only with more runners. Pushes go one at a time, in order, and each carries its checked record and evidence. bay states no number for the gain: treat any ratio as a target, and measure your own.

  • ahead: at most 16 entries.
  • [runner] parallel_checks: up to 16 of one candidate's checks at once, on one machine. It needs no evidence reuse.
  • batch: at most 64 members, 8 by default, and never fewer than two.
  • max_failure_rate: from 0 to 1, 0.3 by default, over the last 20 outcomes.