deflake

deflake is a skill for Claude Code, Codex from QwenLM/qwen-code. It costs 26 tokens per session (843 once invoked), scanned A, original, Apache-2.0.

A method for making one known flaky test reliable without changing what the test checks. A flaky test sometimes fails and sometimes passes for the same code because of timing, ordering, or other nondeterministic conditions.

In plain words
What is it for?
It identifies the source of nondeterminism and applies a small fix, such as waiting for the real condition or allowing a reasonable timeout.
Why use it?
It removes false failures from tests that are affected by slow environments, fixed delays, random values, or execution order.

Skill for Claude CodeCodex ✓ vendor

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

About the project

Qwen Code is an open-source AI coding agent that runs in a terminal and helps developers work with code through language models. It supports multiple model providers and can also be used through IDEs, desktop software, SDKs, and messaging bots.

QwenLM/qwen-code · 27,673 stars · on GitHub · qwenlm.github.io

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.

agentmods
npx agentmods add skills/qwenlm/qwen-code/deflake
Any agent
npx skills add QwenLM/qwen-code --skill deflake
Clone the repo
git clone --depth 1 https://github.com/QwenLM/qwen-code

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 deflake

README.md
[![agentmods](https://agentmods.dev/badge/skills/qwenlm/qwen-code/deflake.svg)](https://agentmods.dev/skills/qwenlm/qwen-code/deflake)
Your own site
<a href="https://agentmods.dev/skills/qwenlm/qwen-code/deflake"><img src="https://agentmods.dev/badge/skills/qwenlm/qwen-code/deflake.svg" alt="Measured on agentmods" height="20"></a>
Per session 26 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 843 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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.00026 $0.00843
Opus 5 $0.00013 $0.00421
Sonnet 5 $0.00005 $0.00169
Haiku 4.5 $0.00003 $0.00084

Measured 7d ago against content hash f2aba9cc5a37, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

deflake 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 7d 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.

.qwen/skills/deflake/SKILL.md · 64 lines

How it starts

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

Deflake a flaky test

A deflake: issue names ONE test that has been observed failing and then passing on a rerun of the same commit — the definitive flaky signature. Your job is to make that test deterministic without changing what it verifies.

The issue body carries the test identity (file + name) and the observed failure signature (e.g. Test timed out in 5000ms, Timed out waiting for …, an order-dependent assertion, a wall-clock/random-dependent value). Read the test, reproduce the mechanism in your head, and apply the SMALLEST fix from the allowed set below that removes the nondeterminism.

The only allowed fixes

  1. Raise a timeout / poll budget. A test that blows vitest's default under CI contention (fully-mocked or I/O-bound, not a perf test) gets a generous per-test testTimeout (3rd arg to it), or its internal poll loop is given a real wall-clock budget instead of a fixed iteration count (a fixed count of setImmediate turns elapses in milliseconds and races real I/O).
  2. Stabilize timing / waiting. Replace a bare setTimeout/fixed sleep with an explicit await of the real condition (vi.waitFor, a resolved promise, an event). Pre-warm a lazy load (e.g. a WASM runtime) in beforeAll so per-test time doesn't include first-load cost.
  3. Make randomness / time deterministic. Seed the RNG, vi.useFakeTimers() / mock Date.now, or pin the input so a value that depends on the real clock or Math.random can't drift.
  4. Isolate / serialize interference. Give tests that collide on a shared resource (a same-named tempdir, a fixed port, a global singleton) unique per-test resources, or serialize them.

Hard rules

  • Never delete the test, skip/todo it, loosen an assertion, widen an expected range, add a blanket try/catch, or add a retry wrapper around the assertion. Those hide the flake instead of fixing it — and could hide a real bug. If none of the four fixes applies, or the failure looks like a REAL intermittent product bug (not test nondeterminism), write <workdir>/failure.md explaining what you found and stop. A human deflakes it.
  • Keep the diff minimal and local to the named test (and its file's helpers). Do not refactor unrelated code.
  • Preserve every assertion and every input exactly. A timeout bump changes only the ceiling; a determinism fix changes only the source of nondeterminism.
  • Prefer a per-test or per-file change over a global config change unless the same class demonstrably spans the whole package (then a testTimeout in that package's vitest.config.ts is acceptable, as it only raises the ceiling and weakens no assertion).

Read the full file on GitHub · 64 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. 7d ago First seen · 64 lines · 26 tokens per session scan A f2aba9cc5a37

Subscribe to this mod's changes

deflake is a skill published in the GitHub repository QwenLM/qwen-code (27,673 stars, last pushed today), licensed Apache-2.0. It adds 26 tokens to every session and 843 once invoked, about $0.0001 per session on Opus 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-30.