Fix flaky tests

Have Autohand Code compare failing and passing runs, reproduce timing or state leaks, and make tests deterministic without hiding real bugs.

Stabilize nondeterministic failures

Testing Quality and review Verification Testing

autohand -p "Find why this test is flaky and make it deterministic without hiding real failures"

A reproducible diagnosis, deterministic test or code fix, and rerun evidence.

Fix flaky tests with Autohand Code is a stabilization workflow that turns nondeterministic failures into reproducible causes, then fixes timing, state leakage, ordering, or test setup without masking real bugs. ### At a glance | Question | Answer | | --- | --- | | Best for | tests that pass locally but fail in CI, intermittent timeouts, shared-state failures, and order-dependent suites | | Primary inputs | Recent failing and passing runs with timestamps; The exact test command, retry count, and CI environment; Shared resources such as timers, network mocks, database rows, or global state | | Autohand Code returns | A reproducible diagnosis, deterministic test or code fix, and rerun evidence. | | Avoid when | the failure is deterministic and already has a clear assertion or stack trace | ### How Autohand Code handles this workflow 1. Compares failing and passing runs before editing. 2. Looks for timing, random data, ordering, leaked state, and environment differences. 3. Reproduces the flake with focused reruns or controlled isolation when possible. 4. Fixes the root cause and leaves evidence that the test still catches real regressions. ### Best inputs - Recent failing and passing runs with timestamps - The exact test command, retry count, and CI environment - Shared resources such as timers, network mocks, database rows, or global state ### Strong prompt autohand -p "Find why this test is flaky and make it deterministic without hiding real failures" ### Autohand Code CLI options - Run `autohand -p "Find why this test is flaky and make it deterministic without hiding real failures"` with both failing and passing logs. - Use `--auto-mode` with a bounded retry target when reproduction needs repeated focused runs. - Use `--restricted` for the first pass if CI logs include secrets or production-like identifiers. ### Review before accepting A good fix names the flake mechanism, shows the focused rerun command, and keeps the assertion meaningful. ### Source and validation signals Autohand AI maintains this workflow as first-party product guidance for Autohand Code. Use the [Autohand CLI Playbook](https://github.com/autohandai/code-cli/blob/main/docs/AUTOHAND_PLAYBOOK.md), [CLI reference](/docs/working-with-autohand-code/cli-reference.html), and [configuration reference](https://github.com/autohandai/code-cli/blob/main/docs/config-reference.md) when choosing between interactive mode, command mode, auto-mode, feature-enabled /goal, /settings, skills, MCP, and permission settings. The related resources below link to product docs and tutorials for the workflow, and the final answer should name repository-specific files, commands, outputs, or docs that a reviewer can verify. ### Frequently asked questions ### What is Fix flaky tests with Autohand Code? Fix flaky tests with Autohand Code is a stabilization workflow that turns nondeterministic failures into reproducible causes, then fixes timing, state leakage, ordering, or test setup without masking real bugs. ### When should a team use Fix flaky tests? Use it when a test failure wastes review or release time because the same command has different results across runs. ### What evidence should reviewers check for Fix flaky tests? A good fix names the flake mechanism, shows the focused rerun command, and keeps the assertion meaningful.

Tutorial Fix Failing Tests Trace failures, repair tests, and rerun the right validation command. /docs/tutorials/fix-failing-tests-debugging.html Tutorial Build a Testing Agent Create reusable test repair and test generation workflows. /docs/agent-sdk/tutorials/600-testing-agent.html Guide Troubleshooting Use logs, commands, and focused reproduction to isolate failures. /docs/guides/troubleshooting.html