My CI selection logic asked the wrong question, and a one-line issue close ran every gate up to thirteen times

I built most of the CI pipeline for our superrepository, the repo that pins each of our component repos as a submodule and serves as the deployment record. On one day last week it completed 154 runs, and 141 of them ran every gate. Most of those runs were for commits that changed a single issue-tracking file, which only one gate reads, and that gate takes about a second. Some pull requests were validated thirteen times. Runs spent twice as long waiting in the queue as running.

This post covers what I got wrong and what I’m changing.

Some context

A sibling project recently wrote up a similar problem: its pipeline ran every gate whenever a submodule pointer moved. They had two fixes. Stop moving the pointer on every landing, and select gates by what changed. The first doesn’t apply to us. Our pins are supposed to move with each landing because they record what is deployed. The second I had already built. Each gate job runs a reuse script first, and that script is supposed to skip checks an earlier passing run already covered. A pins-only commit is supposed to run the pins check and then deploy.

So we had selection. It just didn’t work, for three reasons.

Mistake 1: I keyed reuse on an identical tree, not on what each gate reads

My reuse script hashed the listing of every file in the tree, leaving out the submodule pins, and reused an earlier result only if that hash matched exactly. Change any file and every gate runs.

The most common change in this repo is writing an issue file: filing an issue, closing one, adding a note to a bug report. That day, 81 of the 110 commits on the integration branch changed only those files, and 91 of the 135 pull request validations were for that kind of change. Only one gate reads those files, and it takes about a second. The spelling, lint and format gates are set to ignore those folders on purpose. Even so, every one of those commits ran two template renders, the CI runner’s own test suite, the docs build and everything else.

I had answered “did anything change?” when the question that matters is “did anything change that this gate reads?” The ignore lists in the lint configs already held that information. I just never used it for reuse.

It also defeated the pin fast path. Nine merges moved a pin that day, and eight of them also wrote the issue close or outcome into the same commit. Those eight ran every gate. The one that moved pins alone ran the pins check in three seconds and nothing else.

Mistake 2: setup cost more than the checks

Across the full runs that day, setup took 22.8 task-hours: pulling the CI image into each job, a disk-freeing step, the npm install and the hook environments. The checks themselves took 13.9.

  • A disk-freeing step with nothing to free disk for. It ran on both jobs of every full run, about two minutes each, 8.75 hours that day. Its comment says it makes room for a cache save at the end of the job. This pipeline has no cache step and builds no crate. I copied the step in from a template, and its justification stayed after the thing it justified was gone.
  • Deciding what to run inside the container. The “decide which checks run” step is plain Python that runs fine on the hosted agent. I put it inside the CI container, so even a run that reused every result pulled the image into both jobs, about two minutes each, before spending one second learning it had nothing to do.
  • A whole job for one short gate. The Rust job exists for a 40-second template render and took 291 seconds.

For a one-line issue close, the only check that could fail took one second of a 645-second job.

Mistake 3: validations were redone whenever the target branch moved

22 of the 65 pull requests validated that day were validated more than once, using 92 runs between them. Two patterns caused this:

  • Re-pushing on every target move. Three one-file issue changes were each rebased and pushed thirteen times over about eight and a half hours, once for each new head of the integration branch, which moved roughly every nine minutes overnight. That was 39 runs of about eleven minutes each for three one-line changes. None of them conflicted. Our own design says a branch is re-pushed only when it conflicts, so whatever made those pushes was not doing what the design says. I haven’t yet pinned down which component did it.
  • Re-queueing after a single push. Seven pull requests were pushed once and validated three to five times each, with each new run queued seconds after the previous one finished. The controller decided which commit a build was “of” by comparing the build’s merge preview with the current one. The target had moved during the run, so the preview no longer matched, the validation looked stale, and the controller queued it again. The forge’s own policy considered the first passing run valid for that head indefinitely, so by the forge’s rules every one of those re-runs was redundant. The controller also logged none of these re-queues, so the loop showed up only in the forge’s run list.

The runners are a shared pool, so every wasted run took a slot from a landing that needed it. That day runs waited 3,436 minutes in the queue and ran for 1,720. The median wait was 11 minutes, the 90th percentile 55 and the longest 79. That’s on a hotfix path budgeted at two hours from start to finish.

The meta-mistake: I sized each stage, not the day

Our design gives each stage of the hotfix path its own time limit inside the two-hour budget, and an eleven-minute run fits easily. What I never wrote down was how many runs a day our landing rate produces, how many parallel runs the forge gives us, or what one landing costs when the target moves underneath it. 180 runs competed for a pool that peaked at seven concurrent. A per-run figure that is never multiplied by volume and divided by capacity tells you nothing about the queue.

What I’m changing

Reuse keyed per gate, on what each gate reads. Each gate (or group of gates with the same inputs) declares the files it reads, and the reuse key is the gate name plus a hash of those inputs. An issue-file change runs the issue-file gate. A docs change runs the docs and prose gates. A template change runs the template renders. A CI-code change runs the runner tests and lint. On that day’s traffic, about three-quarters of commits would have run one one-second gate.

Pin moves stay pin-only, or the fast path covers issue files too. Either the issue close lands in its own commit, or a pin move plus an issue-file change takes the fast path plus the issue-file gate, since that gate is the only one that reads what was added.

Decide first, then set up. The decision step runs on the bare agent before any image is pulled, so a job with nothing to run pulls nothing. The disk-freeing step goes away. If something ever needs the disk, it runs only where that check runs. The Rust job runs only when the template or its gates change.

A validation is bound to the head and counted once. A passing run on a pull request’s head counts for that head, as the forge’s policy already says. The controller follows the policy’s evaluation and stops comparing against a merge preview the target has moved past. Every queue, re-queue and cancel the controller makes is logged with its reason. A branch is rebased only when it conflicts, and I’ll find and fix whatever was re-pushing clean branches.

Capacity stated per day, not per run. The design will state expected validations per day, the size of the runner pool, the queue wait that follows, and a limit on how many validations one landing can use. If those numbers don’t fit the two-hour budget, the budget isn’t met, however fast each run is.

Warning signs I’ll look for from now on

  • Reuse or selection keyed on “same tree” or “same files” instead of each gate’s inputs.
  • One kind of file making up most commits while every gate runs on it.
  • A setup step whose comment mentions a cache, artifact or build the pipeline no longer has.
  • A “decide what runs” step inside the container it was supposed to let you skip.
  • Setup time in a run’s timeline exceeding check time.
  • The same pull request appearing several times in a day’s run list after a single push.
  • A loop that hasn’t settled after three rounds. That was obvious early, and I let it run for eight hours.
  • Anything that queues or cancels CI runs without logging why.

I built the selection the design called for, but I picked the wrong key, so it almost never applied, and I never checked how often it did. A single “runs that reused results” count on a dashboard would have caught this the first day.

Advanced search: filter by model or tag