7 min read

Our CI gate took an hour. Now it takes 9 minutes, and every test still runs

At work, the check between finishing a pull request and merging it now takes a median of 9 minutes. Back in May it took 64. On a bad day it ate the whole afternoon. The slowest 5% of runs took more than five and a half hours.

We didn’t make the slow tests any faster. Every one of them still runs. They just stopped blocking the merge.

The slow suite is called premerge. It’s mostly end-to-end tests. Each run spins up a private copy of the platform, real cloud resources included. It pokes at that copy for about an hour. It ran on every pull request and every push. Every merge waited for green.

Here’s what red looked like. You push, wait an hour, see red and open the logs. You spend 15 minutes working out what happened. Next you search the CI channel to see if anyone else hit it. You hesitate to ask, not wanting to be the person who raises a non-issue. Half an hour in, it’s a flake, an outage or a fix already on main. So you rerun and wait another hour. Dozens of engineers ran that loop in parallel on the same failures, each investigating from scratch.

In the 30 days before we changed it, premerge passed 71% of 1,744 builds. Roughly one in three times, you paid the hour twice. I wanted to know why it was failing.

Over 90 days there were 1,330 failed builds. I sorted them by cause. External outages and test infrastructure topped the list. Next came flaky tests and main already broken by someone else. Failures caused by the pull request’s own diff came to about 8%.

We paid an hour on every pull request to catch the 8%.

My sorting wasn’t great. Colleagues read the draft and pushed back. Some of what I’d called flaky were real data races already sitting on main. A couple of my examples were build cache problems. They were right. One offered a full scrape of our build logs to redo the numbers properly. None of that moved those failures into the “caused by this pull request” column. Whichever way you cut it, the author’s share stayed small.

So I wrote a simple RFC. Keep a fast set of checks, about ten minutes, as a hard gate on every pull request. Move the slow suite to after the merge. Same tests, same coverage. It just runs against main instead of sitting in front of you. On top of that, add a merge queue. The queue runs those fast checks against the latest main before any pull request lands.

The merge queue covered a failure we had no protection against. Two pull requests each pass on their own, then break main together. It had bitten me twice in three weeks.

The most common question was the obvious one. Why not put the whole slow suite on the merge queue? That’s the classic setup. Main would break less, true. It would also put an hour-long suite that fails a third of the time right back on the path to merging. The queue would spend most of its time rerunning flakes. Innocent pull requests would get kicked out to wait again. A flaky queue is a traffic jam. Living in Los Angeles, I know a traffic jam when I see one. So we drew a line. Fast, reliable checks stay a hard gate. Slow, flaky ones run after the fact.

That leaves one honest question. If the slow suite runs after merge, what happens when it catches something real?

The plan was an AI safety net. When a post-merge run went red, an agent would read the logs and the diff to figure out whose problem it was. If it looked external, it would stay quiet. If it looked like this pull request, it would revert it automatically. The author would get a draft to keep working on. If it wasn’t sure, it would tell a human. It was the most carefully designed part of the RFC. It had rollout gates and false-revert metrics. It even had rules for pull requests stacked on top of a reverted one.

On June 4, a colleague from the CI team and I flipped the switch. The real Buildkite work was theirs. The auto-revert wasn’t built yet, so I watched post-merge by hand in the meantime.

On day one, the merge queue rejected a pull request that had passed on its own. The author asked if something was wrong with the queue. Nothing was. A pull request merged a few minutes earlier had removed something this one still used. Together they didn’t compile. Before the queue, that would have been a broken main and somebody’s afternoon.

Then the numbers came in. The blocking gate dropped from a median of 64 minutes to 9. The slowest 5% fell from more than five and a half hours to 24 minutes. Median time from opening a pull request to merging it dropped from 46.7 hours to 22.2. That includes review time, so I don’t lean on it too hard. One thing caught me off guard. In the first week, people started shipping pull requests roughly 30% smaller.

And the safety net?

We never properly built it. Only the classifier shipped. When the fast checks fail, it reads the log. It posts one plain-English line on the pull request about what broke and whether it looks like your change. That comment lands a median of 100 seconds after the build goes red. Over one two-week stretch, 46% of its verdicts were “not your diff”. Each one was a blind rerun nobody had to do. People act on it. One engineer pushed a fix eight minutes after it named an async bug.

The auto-revert never earned its place. When post-merge broke, it was almost never one pull request’s simple mistake. It was something external or a library update. Part of why, I think, is that coding agents have gotten good at finding and running the tests a change affects. Fewer breaking changes get merged in the first place. The classifier wasn’t as sharp as I’d hoped either. Neither mattered because nothing was leaning on it. In October I deleted the part that watched post-merge and messaged me about every failure. I’d stopped reading those messages months before.

The net was the part I designed most carefully. We ended up not needing it.

The last surprise was the habit. Two months after the switch, plenty of people still added the label that triggers premerge. They put it on every single pull request out of muscle memory. Someone suggested a bigger announcement. Someone else said nobody remembers announcements. Better to remind people the moment they add the label. I asked our coding agent to build that. It did. Then the same CI colleague stepped in. A small GitHub Action triggered by the label would do the same thing with far fewer moving parts. They were right again. We merged that instead.

They also had the best answer to “when should I still run premerge by hand?” Run it when your change isn’t well covered by unit and integration tests. While you wait the hour, go write the tests that would have covered you.

If you run CI that everyone waits on, I’d look at three things before making it faster:

The slow suite is still slow. It still runs. It just doesn’t stand in anyone’s way anymore.

Somewhere in your pipeline sits an hour everyone agreed to wait. It’s worth asking what it’s buying.