DEV Community

Cover image for Don't let your AI agent "fix" a flaky test by raising the timeout
Sam Novak
Sam Novak

Posted on

Don't let your AI agent "fix" a flaky test by raising the timeout

"Fix the flaky test" sounds like a clear task. Give it to an AI agent, and the fastest way to make the build green is to raise the timeout. The test passes, and nobody learns whether the real problem was the test, the build environment, or a change in the product.

That's not really an agent problem. It's a handoff problem. The agent knows what to investigate but not when to stop. The person running it knows how to start a session but not which decisions belong to them.

So I write two briefs for one task: a detailed one for the agent and a short one for the human. I explain the full pattern in One task, two briefs: instructions for the human and the agent. Below is one worked pair you can copy.

The task

A test in the nightly build sometimes times out. Nobody has established yet whether the test is unstable, the build environment is slow, or product behavior has changed.

Brief 1: for the agent

OUTCOME
Determine why the named test times out in the nightly build. Return a
finding a reviewer can check. Make a code change only if the cause and
an approved remedy are established.

SOURCES
Start with the failure report, the test's current code, the relevant
build logs, and the team's approved test conventions. Record the build
and commit IDs you used. If a source is missing or inaccessible, name it
in the report.

SCOPE
Inspect the named test and the product path it exercises. Compare passing
and failing runs where evidence exists. Keep changes to that path and its
test coverage. Do NOT weaken an assertion, increase a timeout, or disable
the test just to make the build pass.

DECISION POINTS
- Evidence points to a product regression: report it before changing
  product behavior.
- Intended behavior is unclear: ask the test or feature owner to decide.
- Evidence can't separate test, environment, and product: deliver the
  competing explanations and the next check that would separate them.

CHECKS
For an approved fix: run the relevant test and existing build checks.
Record what ran, the environment, and the result.
For an investigation without a fix: identify the logs and comparisons
that support the finding.

DELIVERY
Return the cause or remaining uncertainty, links to evidence, any
approved change, check results, and known limits. Do not merge or deploy
unless the task separately authorizes it.
Enter fullscreen mode Exit fullscreen mode

This is deliberately more than "look into the timeout." It gives the agent sources, a boundary, and a useful result even if the investigation ends without a patch. It also turns the tempting shortcut, raising the timeout, into an explicit decision instead of a quiet edit.

Brief 2: for the human runner

Open the named build and repository, and make sure the agent can reach
the failure report and logs. Check that its finding matches the recorded
runs. Bring any proposed behavior change or unresolved test expectation
to the named owner before authorizing a fix, then review the result.
Enter fullscreen mode Exit fullscreen mode

The runner doesn't need to memorize every test convention in the agent brief. Their job is to supply access, notice when the investigation crosses a decision boundary, and check the evidence that comes back. If the fix needs specific build or device checks, put those in a separate QA list.

Read the two briefs together before you assign the task

The briefs have to agree with each other:

  • If the human is told to wait for an owner's decision, the agent must be told to stop at the same point.
  • If the agent is asked to deliver a patch, the human must know who can approve it and what evidence to inspect.

A quick test: each reader should be able to answer three questions.

  1. What can I do now?
  2. What makes me stop?
  3. What must I hand back?

The full pattern

This post covers one task. The Wagglet guide to the two-brief pattern explains why the agent and the runner need instructions that line up but give each of them different responsibilities, so you can apply it beyond flaky tests.

A good handoff doesn't promise a quick fix. It makes an honest finding useful and keeps open decisions in front of the person who owns them.

What shortcut do your agents reach for when a check fails?

I write for Wagglet, an AI task handoff tool.

Top comments (0)