Flaky tests

Hunt a flaky test from several angles at once. Each agent tries a different way to make it fail reliably, in its own worktree so their test runs can't interfere. The first one with a reliable reproduction wins.

One worktree per hypothesis

Flaky tests usually fail for one of a few reasons. Give each its own agent:

beswarm worktree add --name flaky-order --workspace api
beswarm worktree add --name flaky-timing --workspace api
beswarm worktree add --name flaky-state --workspace api

Start the hunters

beswarm agent start --name order --agent claude <terminal-id> --group flaky \
  --prompt "tests/test_checkout.py::test_refund fails about 1 run in 20. Hypothesis: test order dependence. Run it with random ordering and in isolation, many times. Don't fix anything yet. If you get a reliable failure, write the exact command and failure rate to ../../reports/flaky/order.md."
beswarm agent start --name timing --agent codex <terminal-id> --group flaky \
  --prompt "Same test. Hypothesis: timing or concurrency — sleeps, timeouts, async ordering, the clock. Try running under load or with a frozen clock. Don't fix anything yet. Write findings to ../../reports/flaky/timing.md."
beswarm agent start --name state --agent gemini <terminal-id> --group flaky \
  --prompt "Same test. Hypothesis: shared state — files, env vars, database rows, caches, globals left by other tests. Don't fix anything yet. Write findings to ../../reports/flaky/state.md."

Agents in a worktree work inside .worktrees/<name>/, so ../../reports/ is the repo root's reports/.

Stop the others when one wins

beswarm agent list

When one report has a reliable reproduction, stop the rest:

beswarm agent stop --name timing
beswarm agent stop --name state

Fix with the reproduction in hand

Give the fix to the agent that found it, in the same worktree:

beswarm agent prompt --name order --wait --timeout 1800 \
  --prompt "Fix the root cause you found, not the symptom. No retries or longer sleeps. Prove it with your reproduction command: it must pass 50 runs in a row."

Merge the fix, then beswarm agent close --group flaky and remove the worktrees.