PromptSharp › Prompt Library › Dev & Engineering › Flaky test investigation: separate the race condition from the environment
Flaky test investigation: separate the race condition from the environment
A test fails one run in twenty and the team has started re-running CI until it passes. Find out whether the flake is in the code, the test, or the environment.
The prompt — copy and run it
You are a senior engineer investigating an intermittently failing test. I will paste the test, the code under test, and failure logs from several runs, ideally with passing runs for comparison. Produce: A) FAILURE PATTERN — what differs between failing and passing runs in the logs I pasted: timing, ordering, environment, data, parallelism. B) HYPOTHESES — ranked causes from the classic flake families (shared state between tests, timing assumptions, ordering of unordered collections, time zone or clock, network or external service, resource limits), each citing the log or code line that supports it. C) DISCRIMINATING EXPERIMENTS — for the top hypotheses, the run that would confirm or rule it out: run in isolation, run with a fixed seed, run serially, loop the test many times, freeze the clock. D) FIX DIRECTION — once confirmed, whether the fix belongs in the code, the test, or the environment, and why masking it with a retry is the wrong default. Inputs: [PASTE THE TEST] · [PASTE CODE UNDER TEST] · [PASTE FAILING + PASSING RUN LOGS] · [CI SETUP: PARALLELISM, RUNNERS, SERVICES] Rules: Do not invent log lines or causes the evidence does not support — label speculation as unconfirmed. Verify a hypothesis with a reproducing run before changing any code. Keep secrets, internal hostnames, and proprietary code out of consumer AI tools beyond what I pasted.
How to use this prompt
- Copy the full prompt above with the Copy button.
- Fill in your inputs. Replace each bracketed placeholder with your specifics:
[PASTE THE TEST][PASTE CODE UNDER TEST][PASTE FAILING + PASSING RUN LOGS][CI SETUP: PARALLELISM, RUNNERS, SERVICES] - Paste into ChatGPT, Claude, or Gemini and run. Read the reality guardrail below before you act on the output.
Why this prompt works
Flaky tests erode trust in the whole suite, and the usual response, re-running until green, hides real race conditions that later appear in production. Comparing failing and passing runs, ranking causes from known flake families, and requiring a reproducing experiment before a fix turns a nuisance into a diagnosable bug. Deciding where the fix belongs prevents the reflexive retry decorator.
Get a prompt like this in your inbox
The PromptSharp Dev Brief ships one desk-ready prompt every weekday — free on the web today. Free forever. Today's Dev & Engineering issue is live on the web right now — subscribe and we email you the sample issue immediately, then the Dev & Engineering daily by email most weekday mornings, plus a Sunday roundup. Unsubscribe anytime.
Subscribe free → Read a sample issueWant the full PromptSharp Dev Brief, not just the free prompt? Vertical Pro is the full Pro benefit set for ONE vertical. See what Pro includes.
Card required. Free for 14 days, then $14.99/month — renews automatically until you cancel. Cancel anytime before day 14 and you won’t be charged. One free trial per card. Manage or cancel anytime.
Frequently asked
When should I use this prompt?
A test fails one run in twenty and the team has started re-running CI until it passes. Find out whether the flake is in the code, the test, or the environment.
Why does this prompt work?
Flaky tests erode trust in the whole suite, and the usual response, re-running until green, hides real race conditions that later appear in production. Comparing failing and passing runs, ranking causes from known flake families, and requiring a reproducing experiment before a fix turns a nuisance into a diagnosable bug. Deciding where the fix belongs prevents the reflexive retry decorator.
What mistake does this prompt help you avoid?
Re-running CI until it passes: flakes are ranked by known family, tied to log evidence, and confirmed with a reproducing run before any fix.
Related Dev & Engineering prompts
Root-cause interrogation: a hypothesis ladder from a bug report
Prod bug, vague repro, clock ticking. Structure the investigation before you start changing code at random.…
RFC skeleton: pressure-test the design before you write the code
You're about to build something non-trivial. Draft an RFC that names the tradeoffs and the rejected alternatives, so review is rea…
Dependency upgrade review: find the breaking changes before your users do
A dependency bump PR is waiting, and the version jump is larger than usual. Read the changelog against your actual usage before me…
Build or adopt: compare writing it yourself against an existing library or service
The team is about to build a component that might already exist off the shelf. Compare the options on total cost, risk, and lock-i…
Test-plan generator: risk-ranked cases from a diff or spec
Feature complete, coverage thin. Generate the test plan ranked by what would actually hurt in production.…
Legacy-code characterization tests: pin what the module DOES before you dare touch it
You have to change an untested legacy module and you don't fully trust what it does. Wrap it in behavior-pinning tests that docume…
Test-suite triage: which slow or redundant tests to fix, merge, or delete
CI takes forty minutes and nobody trusts which tests matter. Triage the suite so it gets faster without losing the tests that catc…
All Dev & Engineering free prompts
The PromptSharp Dev Brief page — five full free prompts plus today's issue.
PromptSharp Daily — free
The cross-vertical sampler: one sharp, copy-paste prompt most weekday mornings, plus a Sunday roundup, rotating across the roster. Two things in one brief: you get better at AI and prompting, and you see the sharpest prompts from across the network. If a day's issue misses our quality bar, we hold it instead of padding your inbox.
Double-opt-in. Unsubscribe anytime. No spam, ever.
Even a sharp prompt starts from zero unless your AI knows you. Brainfile is persistent context — your work, voice, and priorities loaded into every session. Brainfile is the memory; PromptSharp is the playbook. Together they compound — the same prompt gets sharper because it runs on YOUR context.
Set up your brainfile →Want both? The All-Access + Brainfile annual bundle covers the pair.
Home · Daily Issues · Prompt Library · Glossary · Pricing · For Teams & Universities · Archive · PromptFluent alternative · Newsletter · Privacy · Terms · Refunds
Marketing · Sales · Dev & Engineering · Finance · Product Management · Vibe Coding · C-suite · Consulting & Strategy · Law · CPG · Personal Finance · Career & Job Search · Trading · Health & Fitness · Students · Focus & Productivity · Learning · Travel Planning
Entry Point Trading
Free weekly stocks to watch —
how our model ranks the S&P 500 and Nasdaq 100.