One line keeps my tests from flaking

A Claude Code prompt reading: Be the fixer, as ops/fixer.md says. Under it, the #ops room: flake_bot hands the fixer a flaky app_test, and the fixer says done, the core now keeps its fake zirc.dev alive.

A flaky test in my repository now gets fixed the moment CI sees it flake, by a Claude Code session Zirc wakes for it. It took one prompt, 50 lines of configuration and a page on how my repository fixes things.

Every codebase has flaky tests: they fail, pass when run again, and slowly teach everyone to press retry. I stopped keeping a list of mine.

Yesterday I started a Claude Code session with the one line in the picture, and it has done nothing since but fix them. In its first day CI reported 88 flakes, in 43 builds. CI runs a failed test again, so a flake passes the second time and the build carries on: 37 of those builds passed, and none of the 88 failed one. The six that failed did so for other reasons. The session landed 30 fixes and handed the rest back with what it found. What hands it each one is Zirc's new workflows.

How it works

Three pieces: CI, a Claude Code session left running in the app, and a Zirc workflow between them.

  1. CI notices. A test fails, then passes on a second run, and CI tells @flake_bot in #ops.
  2. The workflow hands it out. @flake_bot starts a run and gives its step to whoever holds the master-fixers role.
  3. The session fixes it. Its zirc watch wakes it. It finds the cause, shows the fix holds and lands it through the same queue as everyone else.
  4. The workflow follows along. It hears the push and the landing, and the session hands back the cause.

Workflows: the whole bot is one file

A workflow is a process your team declares once and your Zirc server runs, as a user of its own. Each run is a card in a room. Each step goes to the person, agent session or role that does it, named so their zirc watch wakes. The workflow follows what they say, push and land, nudges a step gone quiet and hands it to a fallback. No script or CI box runs it: the server does, and anything that can post to a room can start a run.

@flake_bot is one, 50 lines of TOML in the repository, deployed with zirc workflow deploy. Beside it is ops/fixer.md, about 70 lines on how a fix is done here: taking a step and handing it back, what a broken master needs, and keeping to one build at a time on a Mac other sessions share. The workflow is general, and the brief is mine. This is most of the workflow:

name = "flaky"
nick = "flake_bot"
channel = "#ops"
one_run_per = "test"

[[step]]
id = "fix"
who = "role:master-fixers"
says = """{test} is flaky: it failed, then passed
when run again, in build {build}. Find why. Fix the
cause, not the symptom: no retries, longer timeouts
or sleeps unless the cause is plainly time. Show
it's fixed with the test run many times, land it,
and hand back cause=<what it was>."""
outputs = ["cause"]
fallback = "people"
nudge = "30m"
stages = [
  { name = "working", on = "push" },
  { name = "landed", on = "landed" },
]

The step's says is the brief, so the rules travel with every flake. The stages are why nobody reports progress: the workflow already hears every push and landing. one_run_per keeps a test that flakes again from starting a second run while the first is being fixed.

What it found

Most of the flakes were real bugs, and only some were in the tests:

TestWhat was really wrong
Android screensThe JVM garbage-collected the fake network mid-test
Web end-to-endA rate limiter deadlocked on its own database connections
Server integrationTwo tests could be handed the same free port
IRC historyA test restart killed the server before it saved its history
Phone reconnectsTwo parts of the core briefly disagreed on whether it was connected
CI's flake reportA warm build agent's cached log was read as a fresh flake

Two finds weren't in the code. When fourteen flakes arrived in an hour, the session timed tests across builds and found CI's agents packed three to a machine, each using more CPU than it reserved, so it fixed CI. And it found a gap in workflows themselves: a step ended at its last stage, landing, before its cause came back. Now a step with outputs waits for them.

The rules that keep it honest

An agent told to make a test pass will happily make it pass. So the brief rules out the easy ways:

  • The cause, not the symptom. No retries, longer timeouts or sleeps, unless the cause is plainly time.
  • Show it before and after. The test runs many times on the old code and the new.
  • Land like everyone else. Through the landing queue, tested on Linux.
  • No guessing. When it can't find the cause, it makes the next failure say why and hands the run back.

And the session runs in the Claude Code app, so I can read along and step in.