Test Intelligence: What I’ve Learned Running CI for AI Agents

A browser test suite in our shared library failed 3 times in 18 runs on idle machines, each time in a different test. Every instinct said "flaky, add a retry." The real cause was a disk that stalled for a few seconds at a time.
TL;DR
- Test intelligence is the set of written rules that decides what a test failure means and what happens next. With AI agents writing the code, we use four: one reported retry, never a silent one; a broken main branch that blocks everything except its fix; a person who sets CI priority; and capacity decisions made from measurements.
- A retry that quietly passes hides a problem you will pay for again. Ours are counted, reported and fixed at the root.
- When the main branch breaks, the fix comes first, and one status issue tracks it.
- Long waits are not always a hardware problem. Our worst ones came from scheduling.
- This builds on the CI rules we wrote for AI agents. That post set the contract; this one is what running it taught me.
Why do test results matter more when agents write the code?
Because agents push changes all day, and every push spends test time. A failure that gets waved through comes back on every later run, for every agent. Test results stop being a pass/fail light and become a shared, limited resource. The work is deciding what each failure means before deciding what to do about it.
An agent will happily add a retry and call the job done. It will treat its own work as the most urgent thing in the queue. Neither is malice; both are what a capable tool does without written rules. So we wrote the rules down, and the agents follow them exactly.
How should you treat a test that fails "randomly"?
Treat it as a real failure until the evidence says otherwise. Retry once, in the open. If it fails again, it is real, and you fix it. If it passes only on the retry, it is a flaky test: it gets reported, leaves the merge check with an owner and an expiry date, and must pass 20 times in a row before it returns.
Today's rule, in full:
- No job or run is ever retried automatically. Inside the pull-request check, a failed test gets one retry in the same job, and a pass on that retry is recorded as a flake, never hidden. An agent may rerun failed jobs once by hand, under the same rule.
- Quarantine has a clock. A flaky test leaves the merge check with a named owner, an issue and a 14-day expiry that CI enforces. It still runs every night.
- "The machine did it" needs proof. A failure counts as infrastructure only with evidence from that time window: the job never started, a lost runner, a full disk, or a host stall in the telemetry. A timeout without that evidence is a test failure. Never raise a timeout, add a retry or skip a test to make red go away.
The rule took three tries. On October 2 our test runner quietly re-ran any suite that failed under load and let the quiet run decide. On October 20 we removed automatic retries entirely. On November 18 we allowed one retry inside the check, as long as it is reported. We moved from hiding retries to counting them.
What did the "random" failures turn out to be?
A storage stall. The browser suite kept failing after merges, even when it ran alone. A sampler showed the test machine's disk pressure rising to 60–67% exactly over the failing steps, against 10–29% in passing runs. Every failure was a time budget expiring while the disk froze.
We moved the suite's scratch files to memory-backed storage. Repeats still failed 2 times in 8, which led to the second finding: the first use of each kind of browser action loaded code from that disk, and that first use was the one that stalled. A warm-up pass now runs before the measured tests. The assertions and time limits never changed. If a retry had been the answer, we would still be paying for that disk on every run.
What happens when the main branch breaks?
Everything in that repository stops except the fix. When the full test suite fails on the main branch after a merge, a status issue opens automatically (we label it "main-red"). Nothing else merges there until main is green again. Only pull requests that name the fix in their title are allowed through, and no other pull request may use that name.
It works because we test in two tiers. A short check runs before every merge, with a 10-minute budget and a 20-minute ceiling. The full suite runs once after the merge, targeting 60 minutes and capped at 90. The owner's rule from October 19 is that the same suite never runs twice. The trade-off is that the full suite can find a problem after a merge lands, so main-red is the safety net that makes running it once acceptable.
Two lessons from running it:
- One issue, not thirty. Our first shared reporter opened about 30 main-red issues across 8 repositories. It now keeps exactly one status issue per repository: updated while red, closed when green, and never reopening anyone else's issue.
- A cancelled run proves nothing. It counts as neither red nor green. Missing or unreadable evidence is never a pass.
On one client platform, a repair merged and the full suite failed again in a different test. The single allowed rerun failed too, so under the flake rule it was real. Memory logs from the test environment showed the test workers starving, and the next repair raised their memory budget. That stall did not come back. Other work in that repository was held until the fresh post-merge run had reported. Nobody argued about whether to merge around it, because the rule had already decided.
Who decides whose tests run first?
A person does. A small scheduled program we call the CI governor runs every 10 minutes and enforces traffic rules GitHub's own settings cannot express. When I set a priority order (the "CI focus"), it pauses lower-priority merge checks while a higher-priority project waits, comments on each paused pull request and restores the check later. Agents may read the focus. They never set it.
What the governor does:
- Keeps only the newest post-merge run. On November 18, one product repository had 14 post-merge runs stacked up, the oldest waiting 25.7 hours. Only the newest commit's run could tell us anything. Now older waiting runs are cancelled, and the fix is built into the workflow templates every repository is generated from.
- Frees slots that cancelled runs were still holding. A cancelled run's final summary job could sit in the queue waiting for a machine, holding up the next check by about 30 minutes per push.
- Defers by priority, with guardrails. Repairs for a broken main branch are never deferred. The focus carries an expiry of at most seven days, shared infrastructure can be marked neutral, and a malformed focus means "no focus", never "keep the old order".
The hardest part was not the code. Over two days, one project outside the focus saw 17 deferrals, and about 14 automatic restores were dropped, mostly because its agent had already rerun the check by hand. The operating guide now says it plainly: don't fight a deferral. Never rerun, re-push or toggle a pull request to undo one; wait, and escalate if the restore does not come.
Why didn't more machines fix the waiting?
Because the first bottleneck we found was scheduling. When the large test lane stayed full one morning, the obvious move was another slot. Measuring first showed that every repository's nightly runs had been starting 8–9 hours late. They took the large slots in the afternoon, and by design the governor never defers nightly or post-merge runs.
The fixes came in that order: cancel stale nightly runs, stagger the nightly start times, and propose deferring lower-priority nightlies. Capacity still matters, and we are measuring it. One post-merge run took 5 hours 6 minutes of wall time for about 177 minutes of actual testing; the rest was waiting for a runner. That number now drives the capacity decision, instead of a hunch.
Three habits that came out of it:
- Measure where the time went before buying more of anything. When we measured our own model servers, parallel slots bought isolation, not speed. The same mistake is easy to make with CI.
- Treat capacity as one shared ceiling. Every running agent, reviewer and interactive session counts against it, across all projects. When it runs out, the rule is to wait, never to raise the cap. Slow is not failed.
- Count the hidden budgets too. Every agent and the governor share one GitHub API allowance, so agents now check CI status every 120 seconds instead of every 30, and each keeps at most two of its own runs in flight.
What do people get wrong about test intelligence?
- "Flaky tests are noise." They are signal you haven't read yet. Ours was a disk problem showing up as test noise.
- "Retries make CI reliable." They make it look reliable. Count every one.
- "Slow means broken." On shared capacity, slow often means waiting your turn behind something that should not be first. Fix the order before the hardware.
The same discipline applies to where the agents' files live: the unglamorous setup decides whether the fast parts hold up.
Frequently Asked Questions
What is a flaky test, and should I just retry it?
A flaky test passes or fails without a code change. Retry once, in the open, and record a pass-on-retry as a flake. Then pull the test out of the merge check with an owner and a 14-day expiry, keep running it nightly, and require 20 consecutive passes before it returns. A silent retry hides the cause.
What should happen when the main branch fails after a merge?
Fixing it comes first. Open one status issue for the repository, merge nothing else there until main is green, and let through only pull requests that name the fix. A cancelled run counts as no evidence either way. Recompute the state from the CI history so an old green run cannot close the issue by accident.
How do I stop AI agents from overloading shared test machines?
Give a person the priority call and let a small scheduler enforce it. Our governor keeps only the newest post-merge run, frees slots held by cancelled runs, and pauses lower-priority checks during a focus with an expiry. Agents read the focus but never set it, and they never rerun a check to get around a pause.
Will adding more CI runners fix slow pipelines?
Not until you know where the time goes. Our worst waits came from nightly runs starting hours late and holding slots ahead of urgent work. Measure queue time against run time per job first. Then fix the schedule and the priority order, and add capacity once the numbers show it is truly the ceiling.
If your team is starting to let AI agents change your software and your test runs are getting slower or harder to trust, let's set up the rules before you buy more machines.
About the author: William Rodriguez is the founder of Analytical Ants. He sets the CI focus and the verification rules the agents follow across our product family, and keeps the decisions they leave to a person: what runs first, what counts as proof, and when to spend on capacity. The build is done for you. The decisions stay yours. More about Analytical Ants.