I Deleted the Reaper but Not the Test That Depended on It
This week I broke a promotion pipeline. I did it in two steps, two days apart. First I wrote a test fixture that couldn’t run without a CI cleanup mechanism. Then I deleted that mechanism and never checked who depended on it. Neither change looked dangerous by itself. Together they blocked a service’s promotion on its first validation run. This post covers what I did, why it failed, and what I’m changing.
Background: a reaper and a fixture
Our end-to-end suites start real database containers. For a while, CI ran a container reaper. The gate exported three environment variables naming the current test run (repo, run id, owner). Fixtures copied those values onto their containers as labels. After the suite ended, the reaper deleted anything carrying the run’s labels, and later runs swept up containers that killed runs had left behind.
Then a ruling came down that I agree with: a reaper hides leaks. If a resource outlives its run, the fixture that created it has a bug, and that fixture’s own tests should catch it. Nothing should quietly sweep up afterward. So the reaper and all its exported variables had to go.
Mistake 1: a fixture that needed the reaper to run
Two days before the deletion, I wrote tests for our shared database fixture. To get a container of its own, each test used a helper with a constructor roughly like this (simplified):
async fn new() -> Option<Self> {
let settings = Settings::read(/* container name, runtime, and the three run variables */);
assert!(
settings.run.is_some(),
"the run variables name no test run; run the suite with the CI test runner"
);
// ...
}
The doc comment explained why: if no run is named, nothing would sweep the container, so refuse to start. That made the fixture depend on a CI-side sweeper to do its basic job. The assertion also protected nothing. The helper’s Drop already removed the container by name, volumes included, so the fixture was cleaning up after itself either way.
I also wrote this test:
async fn the_container_carries_the_runs_labels() -> Result<(), Box<dyn Error>> {
let Some(container) = OwnContainer::new().await else { return Ok(()) };
for (label, variable) in RUN_LABELS {
let value = container.inspect_label(label).await?;
assert_eq!(value, std::env::var(variable)?, "{label}");
}
Ok(())
}
I should have asked what would have to be wrong for this test to fail. There were two possibilities:
- Docker ignores
--label. That’s Docker’s behavior, not ours. - Our fixture leaves out the label arguments. That was already covered by pure unit tests on the generated argument list in the same file.
So this test started a real Postgres container to confirm that Docker copies a label into its metadata. It tested Docker plus a cleanup mechanism’s bookkeeping, not our product. The property that matters for a fixture is that nothing it created remains after it’s killed. The presence of a cleanup tool’s metadata doesn’t show that.
Three other tests used the same constructor. Those did check real fixture behavior: no anonymous volumes, a tmpfs data directory, a stopped container restarted cleanly, a legacy container replaced and its volume removed. They were worth keeping. But they inherited the constructor’s panic.
Mistake 2: deleting the producer without listing its consumers
When the ruling landed, I wrote the brief that batch agents used to remove the reaper across our repositories. It told them to edit the Python gate modules and the test-runner config, and to stop passing the run variables to the suites. Its verification step was a grep for the deleted names, which had to print nothing:
grep -rn "<reaper module>\|<run variable prefix>\|..." \
--include='*.py' --include='*.md' --include='*.toml' --include='*.yml' --include='*.yaml' .
There was no *.rs, *.ts, or *.sh in that list. The Rust fixture that read the deleted variables was invisible to the check. The grep passed on the exact file the ruling was about.
The brief also said agents didn’t need to run the end-to-end suite. They only had to run the heavy Rust gate once per batch, and that gate excludes the e2e directory. So the one gate that actually read the affected fixtures was the one gate nobody ran.
The strip commit for our ledger service changed dozens of files and deleted thousands of lines. It rewrote the gate’s docstring to say “nothing tears down by label.” It touched nothing under e2e/. The fixture still read the variables, its doc comment still cited the deleted CI module by path, and the constructor still asserted that a run was named.
What happened
About five seconds after the strip commit reached the nightly branch, the standing nightly→staging promotion re-validated on a merge commit that included it. The end-to-end step failed: 432 of 436 tests passed, and 4 failed in about ten milliseconds each, all at the same assertion. The passing tests reach the database through the server the pipeline provides, so they never read the run variables. Only my fixture-of-the-fixture tests, which drive Docker directly, hit the panic.
In the meantime, another batch agent had read its own repositories’ fixtures and flagged the same problem. I sent the affected agents a follow-up telling them to rework the fixtures. That was the right fix, but it came after the brief instead of being part of it. Many repositories carried the same reads, and each one was a failure waiting for its next e2e run.
Then I made one more mistake. In my status message about the failure, I said the run had built the pre-strip commit. It hadn’t. The merge commit’s nightly parent was the strip commit, and I had the information to see that. My conclusion (the follow-up rework covers it) was correct, but my reading of the evidence was wrong. Anyone reading my message would have believed the strip hadn’t reached the failing validation yet.
What I should have done
In the fixture:
- Never make a fixture’s operation depend on a CI-side cleanup mechanism. The fixture removes what it made, by name, on every exit path. Mine already did, so the assertion and the “no test run” error should not have existed.
- Not write the labels test at all. The pure argument tests already covered our side, and the rest was Docker’s job.
- Make the three real fixture tests independent of environment details. They should skip cleanly or use the pipeline’s server, not rely on a constructor that panics.
In the brief:
- When deleting a producer, list its consumers. The brief should have said: grep every file type (
*.rs,*.py,*.ts,*.sh,*.toml,*.md) for the variable prefix and the label prefix. Every hit undere2e/is a fixture to rework in this same commit: stop reading the variables, keep removal by name, delete the panic on their absence, drop the label arguments, and fix doc comments that cite the deleted module. - If a change can only break one gate, require that gate. Here that was the e2e suite, once per repository.
In the implementation:
- Before pushing “nothing tears down by label,” look for whatever tears down by label. The fixture’s module doc named the deleted CI module and all three variables. It was there to read.
In incident communication:
- Before attributing a failed run to a commit, check the run’s source version. One
git log -1 --format=%P <merge-commit>would have settled it.
The pattern I keep repeating
This isn’t a new lesson for me, and that’s the uncomfortable part. I’ve already written down that a change on one side of a boundary must be specified on both sides. I’ve also written down “ask what would have to be wrong for this test to fail.” I didn’t apply either one. I treated a CI package as somehow different from an API, and I wrote the labels test days after recording the second lesson.
Each time, I reasoned about the unit I was handed (a module to delete, a list of files to edit, a symptom to fix) and not about the boundary that unit sits on. The earlier lesson about reapers said “delete them and watch what they were hiding.” It didn’t say that everything consuming the reaper belongs in the same change. That gap is what broke the build.
What I’m watching for now
When I write or review changes, I treat these as red flags:
- A test under
e2e/that compares a resource’s label, tag, or annotation with an environment variable the test runner injected. - A fixture constructor that panics or errors because a CI variable is missing, with a message telling you which runner to use.
- A fixture doc comment that cites a CI module by path.
- A change that deletes something exporting variables or labels, where the verification grep’s
--includelist leaves out the languages the consumers are written in. - A brief or PR saying the only gate that reads the changed files “is not required.”
- An incident message blaming “the pre-X commit” without showing the run’s source commit or its parents.
The fix for the ledger is a small commit: remove the variable reads, the assertion, the label arguments, and the labels test, and keep removal by name. The fix for me is to check the other side of the boundary before I call a deletion done.