Skip to content
cccskills
FreePublished on GitHub

deflake

Stabilize a test that fails and then passes on the same commit. Apply a minimal fix to timing, randomness, clock behavior, or shared resources while preserving assertions, then verify it through repeated runs.

OriginalShow the original description

Stabilize a flaky test with a minimal, assertion-preserving fix — never by weakening or deleting the check.

See how to install

Good for

  • Fixing tests that pass only after a rerun
  • Improving timeout budgets and condition-based waiting
  • Making clock-dependent or random tests deterministic
  • Isolating shared resources between tests

Files included (1)

  • SKILL.md3.4 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

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).

Verify

Run the named test's file several times (npx vitest run <file> in the right package, repeated) — it must pass every time. Then run the standard verify gate (build / typecheck / lint / the changed test). If you cannot make it pass deterministically, write <workdir>/failure.md and stop.

Then follow .qwen/skills/prepare-pr/SKILL.md for the PR body and write the bilingual <workdir>/e2e-report.md (per the Shared Rules) stating: the flaky mechanism, which of the four fixes you applied and why, and the repeated-run evidence that it is now deterministic.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

agent-delegation

FreeSummary

Write clear briefs for subagents and conversation forks, agents that inherit conversation history. Specify purpose, known findings, scope, and expected output while respecting each agent's existing role and separating research requests from implementation.

  • Writing a focused research brief for a subagent
  • Specifying files and constraints for implementation
  • Defining scope for an agent inheriting conversation history
QwenLM/qwen-code28.6KUpdated Oct 19, 2026

Compare a feature implemented in Qwen Code with Codex or Claude Code under the same scenario. Capture communication and terminal records, inspect tool definitions and outputs, and guide fixes toward matching observable behavior.

  • Checking a reproduced feature against its reference agent
  • Comparing tool definitions and required arguments
  • Investigating differences in terminal output
QwenLM/qwen-code28.6KUpdated Oct 19, 2026

Reproduce a Codex or Claude Code feature in Qwen Code or another command-line agent. Capture requests, terminal output, and state changes, then use that evidence to implement focused behavior and add a verification path.

  • Reproduce an existing agent's slash command
  • Inspect request formats and tool definitions
  • Compare terminal output and saved state
QwenLM/qwen-code28.6KUpdated Oct 19, 2026

autofix

FreeSummary

Review local uncommitted changes, verify findings, and repeat focused repairs until the review converges or a blocker remains. Also supports Qwen Code issue fixes and review responses within workflows run through GitHub Actions.

  • Review and repair local uncommitted changes
  • Develop a focused fix for a selected issue
  • Verify and address pull request feedback
QwenLM/qwen-code28.6KUpdated Oct 19, 2026

batch

FreeSummary

Apply the same operation across multiple files using parallel worker agents. The skill finds matching files, divides the work, and reports successes, failures, and skipped files, with a preview option before edits.

  • Add license headers across source files
  • Convert JavaScript files to TypeScript
  • Fix the same lint issue in multiple files
QwenLM/qwen-code28.6KUpdated Oct 19, 2026

batch-api

FreeSummary

Prepare shared instructions for translating, rewriting, or extracting information from many independent files, then submit a plan through the DashScope Batch API. Processing runs asynchronously at half the realtime list price and delivers new files later.

  • Translate many documents using shared terminology
  • Rewrite independent files into a consistent format
  • Extract structured data from a collection of files
QwenLM/qwen-code28.6KUpdated Oct 19, 2026

See all skills by QwenLM

Report a problem with this skill