fix-flaky-test
Skill1 starsChanged 2 days agoMITView on GitHub
Find and fix the cause of a test that fails only sometimes, such as on CI, on a slow machine or in a certain order. Use this for any intermittent failure, timeout in a test or "passes on rerun" situation. It replaces retries and longer sleeps with a proven fix.
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 23
Run the test many times in a loop.
- Distinctive: line 24
Run it with other tests, in a different order, or in parallel.
- Distinctive: line 25
Add CPU load, or limit the CPU.
- Distinctive: line 44
Make sure a timeout prints enough output to explain itself.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Fix a flaky test
A flaky test is a real defect, in the test or in the product. Retrying hides it and teaches everyone to ignore red builds. The aim is to reproduce it on demand, fix the cause, and show that the same conditions no longer break it.
When to use
A test fails intermittently, or passes when rerun without changes.
Steps
- Collect the failures. Save the exact message, OS, job and commit. Note what the failing runs have in common.
Reproduce it. Try these until it fails:
- Run the test many times in a loop.
- Run it with other tests, in a different order, or in parallel.
- Add CPU load, or limit the CPU.
- Slow down the code it waits for with a temporary delay.
Slowing the code is often the quickest way to prove a timing bug.
Classify the cause.
Type Signs Usual fix Fixed wait too short Fails on slow hosts Wait for the outcome Shared state Depends on test order Give each test its own state Real clock Fails near midnight or a boundary Inject the clock Unordered results Order changes between runs Sort or compare as a set Port, file or process conflict Fails in parallel Use unique resources Real race in the product Wrong result under load Fix the product External dependency Fails with the network Stub the boundary - Fix the cause. Replace a fixed wait with a check on the actual outcome. A deadline only catches a hang, so set it longer than the time the product allows. Make sure a timeout prints enough output to explain itself.
- Check the assertions are unchanged. The fix must not make the test accept behaviour it used to reject.
- Prove the fix. Repeat the conditions from step 2. The old code must fail and the new code must pass under the same stress.
- Finish. Follow
verify-and-report.
Stop and ask when
- You cannot reproduce it after trying everything in step 2. Report what you tried, and add diagnostics instead of guessing.
- The cause is a real product race that needs a design change.
Common mistakes
| Tempting move | Why it fails | Do this instead |
| Add a retry | Hides the defect | Find the cause |
| Increase a sleep | Slower, and still flaky | Wait for the outcome |
| Mark it as skipped | Removes the protection | Fix it, or file a linked issue with the owner's approval |
| Loosen the assertion | Accepts wrong behaviour | Keep the assertion |
| Declare it fixed after one pass | One pass proves nothing | Repeat under stress |
Example
Failure: replaced=false after 5 seconds, on Windows runners only.
Weak fix: raise the wait from 5 to 15 seconds.
Strong fix:
Reproduce: slowed the old process's shutdown to 6 seconds, and the test failed
with the same message as CI.
Cause: the test stopped after a fixed 5 seconds, while the handoff can take longer.
Fix: wait until the handoff finishes, with a 60-second bound for hangs.
Proof: with the same 6-second delay, the old test fails and the new one passes.
Assertions: unchanged.Report
Failure: <message, where it occurred>
Reproduced by: <command or condition>
Cause: <type and explanation>
Fix: <what changed>
Proof: <old fails, new passes, under the same condition>
Assertions changed: <none, or why>Other versions5 projects use a version of this.
Word for word · 2
- Remote-Arc/remote-arc★ 5100% same
- yaohuangguan/remote-arc★ 5100% same
Edited · 0
None found.
Wrote their own version · 3
- dotnet/aspire★ 6.4ksame name
- microsoft/aspire★ 6.4ksame name
- qazando/skills-qas★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- AGENTS.mdAGENTS.md
- audit-test-suiteSkill
- change-data-safelySkill
- debug-failureSkill
- hand-off-workSkill
- implement-changeSkill
- orient-in-codebaseSkill
- refactor-safelySkill
- review-codeSkill
- secure-changeSkill
- use-external-apiSkill
- verify-and-reportSkill
- write-pull-requestSkill
- write-testsSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

