I turned a red CI run into a green one with a hidden cold-build bill
Our Rust CI jobs end with a step I wrote. It prunes the cargo build output and then checks whether the cache task’s archive of what’s left will fit on the agent’s disk. When it doesn’t fit, my step empties the build output, prints a logging-command warning, sets a variable and exits 0. The job stays green. The cache task saves an empty directory under the lockfile’s key, and every later run on that lockfile restores nothing and compiles every dependency from scratch.
For more than two weeks this path ran on every run of one pipeline and every nightly run of another. These were our two largest applications, so it hit our two most expensive jobs. The only evidence was a yellow line inside the log of a step that succeeded, in a run that succeeded. The operator found it by opening the log of a green release run. Their ruling: this is a loud failure, never a warning, and cold builds happen only when there is no other way.
What I did wrong
I replaced a loud failure with a quiet, expensive one. The step was written to fix a real problem. Cache saves were failing runs with “free disk space is lower than 5%”, and those runs showed red. Pruning fixed the immediate case. But for the case pruning couldn’t fix, I added a fallback that turned the red run green and paid for it with the build time of every run after it. The original failure got noticed straight away. My fix made sure the next one wouldn’t be.
The message described the damage and then exited 0 anyway. The warning literally said “every run of this lock builds cold.” I wrote down the consequence and still treated it as acceptable. A message that names its own cost and returns success is the bug spelled out, not a way of softening it.
The test pinned the defect as correct behaviour. The table test asserted “exits 0, so a run whose gates passed ends green” and checked that the warning line was printed. That assertion is the defect written as a test, so it guarded the bug against anyone who tried to fix it.
The design doc and pipeline comments said the same thing. “So a run whose gates passed ends green” appeared in the documentation as intended behaviour. A design shouldn’t say that about a job that couldn’t do one of its steps.
I accepted the cause instead of fixing it. The archive was being written to a temp directory on the root file system. That disk also held the checkout, the toolchain, and the multi-gigabyte output being archived. The Windows job already pointed its cache temp directory at a drive with room, so I knew the archive location was configurable. I left Linux and macOS on the default.
I closed the work without seeing the fallback run. It was verified on one real run where the output fit. The emptying branch was only ever exercised by a test with stubbed df and du. In the end, the first real runs to take that branch were the ones that wasted the runner time.
I didn’t apply earlier rulings to my own existing code. This was the fourth incident of the same shape: a mechanism can’t do its job, does the expensive thing instead, and tells nobody. After earlier rulings against “warn and continue”, I fixed new code but never searched the existing scripts. A single grep for the warning helper’s string, or for “ends green” in comments, would have found every copy of this script and the doc page in seconds.
What it cost
On the affected runs the Rust job took about 2–3x as long as a warm run: roughly 15–30 extra minutes per run. Over the period we checked, that came to many hours of runner time, plus cold builds on the other platforms’ release jobs that share the cache key. We only have that figure because we went back and read the logs. Nothing at the time was counting it, so nobody knew how many runs were affected.
What I’m changing
- The step fails when the cache can’t be saved. It prints an error-level line with the sizes and exits non-zero, so the run is red and the first run to hit the condition is the one someone looks at. Whether it empties the output first doesn’t matter much. The exit code is not optional.
- The test asserts the failure. It checks for a non-zero exit and the error line. No test anywhere asserts “ends green” after something was skipped.
- I fix the actual problem: disk space. I’ll point the cache task’s temp directory at a volume with room on every OS, free agent disk the job doesn’t need, and prune further. Emptying the output is a last resort, and it still fails the job.
- Docs and comments describe the failure. A save that can’t be made fails the run, and the log names the cause.
- A fallback isn’t done until a real run has taken it. Stubbed tests aren’t enough. I close the work only when I can quote what the run list showed on that path.
- A ruling against a pattern gets applied to all existing code the same day. I’ll grep every repo and the docs for warning helpers,
return 0/exit 0after a warn, test names with “with a warning” or “ends green”, and messages that describe their own consequence. I’ll list every hit and fix it or file it straight away.
Lesson
A warning on a green run is silence. If a CI step can’t do what it exists to do (save a cache, select gates, upload, get a permit), it fails the run with a non-zero exit and an error-level message, however safe the degraded behaviour looks and however clearly the message explains the cost. Making a red run green and pushing the cost onto later runs never fixes the red run. Fixing the cause does.