fix-flaky-test

fix-flaky-test is a skill for Claude Code, Codex from tmj-90/gaffer. It costs 77 tokens per session (1,256 once invoked), scanned A, original, Apache-2.0.

A workflow for diagnosing tests that sometimes pass and sometimes fail. Such tests are called flaky tests because their result changes without a relevant code change.

In plain words
What is it for?
Use it to reproduce an intermittent test failure, identify its source, fix the cause, and confirm the test and full suite remain stable.
Why use it?
It targets the underlying cause, such as timing, shared state, randomness, clocks, or external services, instead of hiding the problem with retries or longer waits.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to reproduce an intermittent test failure, identify its source, fix the cause, and confirm the test and full suite remain stable.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/tmj-90/gaffer/fix-flaky-test
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add tmj-90/gaffer --skill fix-flaky-test
Clone the repo
git clone --depth 1 https://github.com/tmj-90/gaffer

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for fix-flaky-test

README.md
[![agentmods](https://agentmods.dev/badge/skills/tmj-90/gaffer/fix-flaky-test/github.svg)](https://agentmods.dev/skills/tmj-90/gaffer/fix-flaky-test)
Your own site
<a href="https://agentmods.dev/skills/tmj-90/gaffer/fix-flaky-test"><img src="https://agentmods.dev/badge/skills/tmj-90/gaffer/fix-flaky-test/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for fix-flaky-test

Your own site · 80×15
<a href="https://agentmods.dev/skills/tmj-90/gaffer/fix-flaky-test"><img src="https://agentmods.dev/badge/skills/tmj-90/gaffer/fix-flaky-test.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 77 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,256 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00077 $0.01256
Opus 5.5 $0.00031 $0.00502
Sonnet 5.5 $0.00015 $0.00251
Haiku 4.5 $0.00008 $0.00126

Measured 1mo ago against content hash 8912ca23c48d, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

fix-flaky-test scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

runner/skills/fix-flaky-test/SKILL.md · 82 lines

How it starts

The opening of the file, as written. The whole thing — 82 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Fix a flaky test

A flaky test passes and fails on the same code. Google measured ~1.5% of all test runs flaky and ~16% of tests flaky at least occasionally; the cost is that people stop believing red builds. The job is to find the source of non-determinism and remove it. First decide whether the flake is in the test or in the product: a test that fails one run in fifty under parallel writes may be the only thing reporting a real race — the same class of lost-update and lock defect that shipped past review in live runs. "Fixing" that by serialising the test hides a production bug.

Procedure

  1. Reproduce and measure. Run the single test in a loop until it fails, and record the failure rate:
    • Vitest/Jest: for i in {1..50}; do npx --no -- vitest run <file> -t "<name>" || break; done (Jest: --runInBand vs default to compare parallelism); Playwright: npx --no -- playwright test <spec> --repeat-each=50 --retries=0.
    • pytest: pytest <path>::<test> --count=50 (pytest-repeat) or a shell loop; random order via pytest-randomly and -n auto via xdist — only if the repo already has them; never install plugins.
    • Go: go test -run '^TestName$' -count=200 -race ./pkg/...; JUnit: repeat via the runner or a @RepeatedTest. Also try the conditions CI has: full suite (not just the file), random order, parallel workers, CI=1, a different TZ/locale, a loaded machine (stress/taskset). Keep the failing output — you cannot fix what you have not observed.
  2. Classify the cause from the failure (Fowler's "Eradicating Non-Determinism in Tests" and Google's flaky-test analyses list the same families):
    • Async timing: unawaited promise, fixed sleep, assertion before the event, a timeout too tight for CI.
    • Order / shared state: leaked globals, singletons, DB rows, files, env vars, module caches, a port reused between tests. Passes alone, fails in the suite (or vice versa).
    • Concurrency in the product: unsynchronised read-modify-write, temp-file name collisions, check-then-act on files or rows, lock or lease expiry. Fails more under parallelism or load.
    • Time and environment: real clock, midnight/DST/month-end, timezone, locale, float formatting, hash/map iteration order.
    • Randomness: unseeded generators, random data hitting a rare edge.
    • External: real network, third-party service, container start-up races, resource leaks (open handles, file descriptors) that accumulate.
  3. Fix the root cause where it lives.
    • Test timing → await properly; wait for a condition (poll with a deadline, web-first assertions), never a longer sleep.
    • Order/state → fresh state per test, teardown that runs on failure, unique temp dirs and ports (the test-fixtures-and-factories skill).
    • Time/randomness → inject or fake the clock, pin TZ, seed the RNG and log the seed.
    • External → stub at the boundary, or make the dependency hermetic (a container started and awaited by the test).
    • Product race → fix the code (the concurrency-and-async skill), and keep or add a deterministic test that reproduces the interleaving (a barrier, controlled scheduler such as fast-check scheduler, or N parallel real processes). If the ticket does not scope a product fix, record the finding and raise request_decision rather than quietly stabilising the test.
  4. Prove it. Re-run the same loop that reproduced it — at least 10× the runs it took to fail, with the same parallelism and order randomisation — with zero failures. Then run the full suite with the repo's command (the run-tests skill).
  5. Evidence and stop. Use the record-evidence skill: the reproduction command and failure rate before, the root cause in one sentence, the fix, and the clean streak after (test_output). The runner submits for review, not you.

Read the full file on GitHub · 82 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago Changed 8912ca23c48d
  2. 2mo ago Changed · +44 lines · +8 tokens per session d75afa2e712e
  3. 3mo ago First seen · 38 lines · 69 tokens per session scan A 232d854c28a4

Subscribe to this mod's changes

fix-flaky-test is a skill published in the GitHub repository tmj-90/gaffer (1 stars, last pushed 4d ago), licensed Apache-2.0. It adds 77 tokens to every session and 1,256 once invoked, about $0.0003 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

fix-flaky-test compared with skills from other repositories

fix-flaky-test next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
fix-flaky-testtmj-90/gafferSkill14d agoApache-2.0A77Claude Code, Codex
bulwark-brainstormQBall-Inc/the-bulwarkSkill9yesterdayMITA50Claude Code
plan-creationQBall-Inc/the-bulwarkSkill9yesterdayMITA38Claude Code
anthropic-validatorQBall-Inc/the-bulwarkSkill9yesterdayMITA40Claude Code
create-subagentQBall-Inc/the-bulwarkSkill9yesterdayMITA42Claude Code
test-auditQBall-Inc/the-bulwarkSkill9yesterdayMITA0Claude Code
code-reviewQBall-Inc/the-bulwarkSkill9yesterdayMITA61Claude Code