🤖 The AI Prompt That Spots a Race Condition in a Review Diff
Reviewing a pull request for a subtle race condition is hard because the two interleavings that cause the bug rarely sit next to each other in the diff — one thread’s read might be several files away from the write that invalidates it. Pasting the diff into a tightly scoped prompt gets a model to specifically hunt for shared-mutable-state patterns that a human reviewer, skimming for logic correctness, tends to skip past entirely.
🔎 The Problem
You are reviewing this diff for concurrency bugs only - ignore style, naming, and any logic issue that isn't concurrency-related. For every piece of shared mutable state touched in this diff (fields, static members, caches, connection pools), check: 1. Is it read and written from more than one thread/task without a lock, an atomic operation, or an immutable snapshot? 2. Could two callers interleave in a way that corrupts state or causes a stale read (check-then-act patterns especially)? 3. Does a new async method introduce a yield point in the middle of a sequence that assumed it would run atomically? List each finding as: file, line range, the specific interleaving that breaks it, and the smallest fix. If you find nothing, say so explicitly rather than commenting on unrelated code. <diff> PASTE DIFF HERE </diff>
✅ Why This Works
- Scoping the model to “concurrency bugs only” stops a real finding from drowning in a dozen unrelated style nitpicks, which is the usual reason a race condition gets missed in a normal review pass.
- Asking for the specific interleaving, not just “this might not be thread-safe,” forces an answer concrete enough that you can actually verify it against the code in under a minute.
- Requiring an explicit “found nothing” response instead of generic praise keeps a clean diff from getting a false positive just because the model wants to say something.
🚨 Why This Is Dangerous
- Treat every flagged interleaving as a hypothesis to verify against the actual call sites, not a confirmed bug — a model that’s never seen your deployment topology can misjudge whether two code paths can genuinely run concurrently at all.
The bug that only shows up once in ten thousand requests is rarely found by running the code — it’s found by someone, or something, asking the right question about who else might be touching that variable.





