Code review is a human reading code and simulating it in their head, one thread at a time. A reviewer traces what happens if a call succeeds, then what happens if it fails, and the code usually looks correct both ways. What a reviewer can’t simulate well is a hundred and fifty of these paths running at once, interleaved in an order nobody chose, against infrastructure that is failing partway through. Being more careful doesn’t help, because those bugs only appear with real concurrency and real partial failure, and reading code doesn’t produce either.
A bug that looked correct until three services were down
aws-llm-inference-platform builds a chat response by making three independent upstream calls at once: pulling RAG context from a vector store, chat history from a database, and results from a web search tool. The original version combined them with Promise.all:
const [ragResult, histResult, webResult] = await Promise.all([...]);
Read in isolation, this is fine: three async calls, run concurrently, wait for all three. A reviewer has no reason to flag it. Promise.all is the standard way to run independent async work, and the code compiles, typechecks and returns the right shape when all three succeed. The bug only exists when the vector store call fails and the other two succeed. Promise.all rejects as soon as any one of its promises rejects, discarding the results of the ones that already resolved. A single Pinecone outage meant every chat request lost its conversation history and web search results too, not just RAG context, for as long as the vector store was down. The code doesn’t look wrong until you run it with one dependency down while load hits the other two, and code review doesn’t put you in that situation.
The fix swaps in Promise.allSettled, which resolves once all three promises have settled, successfully or not, and lets each result be checked independently:
// Build prompt with RAG context + web search + recent chat history.
// These three are independent upstream calls (Pinecone, DynamoDB, web
// search) -- use allSettled, not all, so one failing (e.g. a Pinecone
// outage) doesn't silently discard the other two, which may have
// succeeded.
const [ragResult, histResult, webResult] = await Promise.allSettled([...]);
if (ragResult.status === "fulfilled") {
ragContext = ragResult.value;
} else {
console.error("RAG context unavailable, continuing without it:", ragResult.reason);
}
Now a Pinecone outage removes one input to the prompt instead of failing the whole request. The bug was invisible to inspection and only showed up under partial failure, which production traffic eventually produces and a code diff never does.
A race that only shows up at 150 concurrent threads
flash-sale-system is built to sell a fixed pool of tickets without overselling under concurrent demand, and it ships its own chaos simulator to show that the concurrency-safe approach is safe, instead of asserting it in a comment. The /simulator page runs two implementations side by side against the same starting inventory: a naive read-check-write (“read the counter, check if enough tickets remain, decrement it”) and the production approach, a Redis Lua script that performs the check and decrement as a single atomic operation because Redis executes Lua scripts on one thread with no interleaving possible.
At low concurrency, both look correct. Read-check-write has a time-of-check-to-time-of-use gap: two requests can both read the counter before either has written its decrement, both see enough inventory, and both proceed to sell a ticket that only existed once. The gap is nanoseconds wide. A reviewer reads read, check, write as three lines that run in order for the one request they’re picturing. The gap only matters when a second request’s read lands inside the first request’s check-to-write window, which takes real concurrent requests.
The simulator forces that scenario by running 150 concurrent threads against both implementations at once. System A, the naive version, drifts: the final counter doesn’t match what was sold, so the same inventory was sold more than once. System B, the Lua script version, stops at exactly zero. Both implementations are a handful of readable lines, and both would pass a review that didn’t specifically ask what happens if two run at the same instant. The difference between them only shows up under load.
Where each one helps
Code review catches bugs a reviewer can picture: a wrong variable, a missing null check, an off-by-one, a backwards condition. It misses bugs that only exist when several things happen at once, because someone reading top to bottom simulates one execution. Races, partial failures and resource exhaustion under load don’t exist until concurrency or failure is introduced. Chaos and load testing find those, because the code was never wrong in the scenario the reviewer was picturing.