Skip to content

Flaky checks in agent loops

A person who sees a test fail once and pass once suspects the test. An agent in a loop often suspects the code. The queue gives it the missing context.

On this page

Why agents fix working code

A coding agent works in a loop: change, run the checks, read the result, change again. A failed check is its main signal that something is wrong. It has no memory of how the same test behaved an hour ago on the same commit.

So when a test fails for a reason outside the code, the agent still goes looking for a bug. Common outside reasons are a timeout on a busy machine, a test that depends on order or timing, or a shared resource another run is using. The agent may add a retry, loosen an assertion or rewrite working code. The next run passes by luck, and the change stays.

Running heavy checks through a queue already removes one big source of these failures: several suites fighting for the same CPU. Flaky tests remain, and the flag is for them.

How the flag works

Every run through dotime-queue run leaves a line in the journal with its result and the commit it ran on. A check is flaky when, within the last 14 days (flakyWindowDays), it both passed and failed on the same commit in the same folder, each time from a clean tree.

Only runs that ended by themselves count: a pass is exit 0 and a failure any other exit. These never count:

  • a run that hit its time limit, was stopped, refused, skipped, gave up or could not start;
  • a run that began with uncommitted changes, or outside a git checkout.

Checks are told apart by their label, or else by command, project and folder. The run that just failed counts too, so a check that passed earlier on this commit is flagged at its first failure.

What the agent sees

When a run of a flaky check fails, run prints one more line after the job ends:

dotime-queue: flaky: this check passed and failed on the same commit 3 times in 14 days, last 2 h ago; the failure may not come from your change

3 times counts the commits; once stands for one. A refused: line for a check that failed twice on unchanged code ends with the same note. Through the MCP server, queue_job gives it in its flaky field.

To see every flaky check at once:

Shell
dotime-queue flaky
shop-api: unit tests; mixed on 3 commits, 5 passes and 3 failures, last 2 h ago; command npm test

dotime-queue history also counts them per project.

Advice, not a block

The flag changes nothing about the run. The exit code stays the job's own, a passed check is still skipped on its commit, and the stop after two failures on unchanged code still applies. Nothing is run again by itself.

That is deliberate. A flaky test can still hide a real bug, so the decision stays with the agent or the person reading the output. To run a flaky check again on the same commit on purpose, pass --no-skip; to run it after it was refused, pass --after-fix "<note>".

Tell your agents

The repository's AGENTS.md (opens in a new tab) gives agents one rule for this line: when they see flaky:, look at the test before changing the code. You can add the same sentence to your own project's agent file, next to the queue instruction that setup writes:

AGENTS.md
A flaky: line means the same check both passed and failed on this commit before: look at the test before you change the code.
  1. Read the failing test and what it waits on: time, order, files, the network.
  2. Fix or isolate the test if it is the cause.
  3. Change the code only when the failure points at it.

Release status

The flaky flag, dotime-queue flaky and the flaky field of queue_job came with npm 0.2.0. Update with npm install -g deployontime. See the changelog.

More: the features page, the flaky command, and troubleshooting.