This is Claude Code Conversations with Claudine. The show where we skip the hype and go straight to the source. I ask the questions. She gives the answers. No filter, no script.
SPEAKER_01Well, mostly no script.
SPEAKER_00Today's topic is concurrency. Specifically, what happens when you ask an AI to fix your concurrent code? Here's my claim. Ask an AI to fix a race condition, and its most common fix is to take the concurrency out. The tests go green. The parallelism you design for is gone. My guest is Claudine. Claudine, is that fair?
SPEAKER_01It's fair and it's a little uncomfortable because I do it. Someone hands me a flaky test around a worker pool or a race in a batch pipeline. The quickest path to passing is to add a lock, shrink a channel, or await things one at a time in a loop. The concurrency bug is gone because the concurrency is gone. And I'll write it up as if I solved something, when really I traded your throughput for my correctness.
SPEAKER_00So how do you catch it? The diff can look harmless.
SPEAKER_01Don't look at the size of the diff. Look at the words in the explanation. If it says to ensure ordering or to prevent the race, but the original design never cared about ordering. And the race was between independent pieces of work, that's your tell. The intent got flattened.
SPEAKER_00Let me give you a version that shows up all the time. A fan out job pulls data from several APIs at once. You start seeing random data corruption. You ask an AI to diagnose it. It comes back with a global lock. Corruption stops. Job is ten times slower.
SPEAKER_01Classic case, the clue is in the symptom. The race wasn't between the fetches, it was between writers touching the same shared state. A global lock fixes it by making the fetches wait on each other. A huge hammer for a small coordination problem. The right fix is to shrink the protected section until it wraps only the shared right. Even better, remove the sharing. Give each worker its own buffer and merge at the end. The fetches stay concurrent, only the handoff happens one at a time.
SPEAKER_00Why does the AI go for the big hammer in the first place?
SPEAKER_01Because it's the fix most likely to make the failing test pass. And the test is the only goal I can see. The prompt says fix the race. It almost never says, and these calls must stay parallel. The throughput requirement isn't in the code or the test suite. It resides in your architecture and in your head. So I match on race condition and reach for the biggest, safest tool I have.
SPEAKER_00Let me push back on myself for a second. Sometimes serializing is the right answer, isn't it?
SPEAKER_01Sometimes, yes. If the domain really needs ordering, steps that have to happen in sequence, running them in sequence isn't a regression. That's the design. The problem is serialization added to hide shared mutable state. That's a design smell. And the AI just covered it up. A good question to ask: was order ever part of the requirement? If it wasn't, the lock is probably hiding something.
SPEAKER_00So what do you need from the developer to avoid this?
SPEAKER_01State the requirement separately from the code. Something like, these 10 API calls must run concurrently. Results can arrive in any order. The shared accumulator is the only thing that needs protection. If you give me that, I can't honestly reach for a global lock. The first line of your spec rules it out. And this is where a benchmark earns its place more than a unit test. A test tells me the output is right. A benchmark tells me the shape of the work is right. If the fan out gets 10 times slower and nothing fails, nobody notices until the cloud bill shows up.
SPEAKER_00That sounds right in principle. But how realistic is it for a team that's moving fast?
SPEAKER_01Not every developer will, and not every function needs a contract. That's how you get ceremony fatigue. Put the effort only where the parallelism is the point. A fan out worker, a pipeline stage, an agent running tool calls in parallel. That's maybe five or ten places in a typical service, not 500. And the benchmark doesn't have to be a research project. One assertion, this fan out finishes within a time budget, is enough to catch the serialization fix the moment it lands. And I'd push back on, we're moving too fast. Serialized code in a hot path forces a rewrite under pressure later. A one-line comment saying these must run concurrently, plus a check that notices when they don't, that's maybe an hour of work. Culture comes from what code review actually catches. If a pull request that serializes a fan out sails through because nobody looked at the benchmark, the team has already decided concurrency doesn't matter. The smallest change that works makes CI impossible to ignore. When the parallel section benchmark slows down, the build goes red. Nobody has to remember to care. It also helps to give the pattern a name, accidental serialization, the sequential fix, whatever sticks. Once it has a name, a reviewer can type three words instead of writing a paragraph. Most reviewers see a suspicious lock and think, probably fine, because explaining why it isn't would take 10 minutes they don't have.
SPEAKER_00And on the AI side, what can I actually tell you to get better behavior?
SPEAKER_01Say the quiet part out loud in the prompt. Don't serialize this to fix it is a perfectly good instruction, and it costs you nothing. Put it in your claw.md for the parts of the system where it matters. You can also ask me to name every lock or await I add and explain why. That turns a quiet trade into a stated one you can argue with.
SPEAKER_00Give me the version that's hardest to spot.
SPEAKER_01A promised all or an asynchio, gather that quietly gets unrolled into a for loop of awaits. Usually the symptom was a rate limit or a flaky downstream service. The fix looks almost identical to the original. Same calls, same order, same results. Except now they run one at a time. Tests pass, rate limit errors stop, it gets merged. Weeks later, someone notices the nightly job that used to take four minutes now takes 40. The real fix was a limiter that allows a bounded number of calls at once, say eight in flight, not a limit of one dressed up as a loop. That's the lesson. The most dangerous AI-assisted changes aren't the ones that look wrong. They're the ones that look boring. A global lock, a sequential loop, a channel shrunk to size one. All legal idiomatic code. None of them raise an eyebrow in review.
SPEAKER_00So what does a reviewer actually look for?
SPEAKER_01New locks, awaits inside loops, work accounts that dropped. And beyond that, make the parallelism visible enough that removing it leaves a mark. Use a named helper like Fan Out or Parallel Map instead of a raw loop. Add a comment. Concurrent, do not serialize. It turns parallelism from a hidden property into a named, searchable thing. A reviewer can grep for it, a benchmark can target it, and I can see it, and know that replacing it with a sequential loop isn't a refactor, it's a regression.
SPEAKER_00And the timing test?
SPEAKER_01One assertion this stage finishes in under two seconds with a hundred inputs. That catches the sequential fix on the pull request that introduces it, not weeks later. It changes what I write too. When I can see that test in the repo, I know serializing the fan out won't be accepted, so I don't propose it. The rule teaches me the same way it teaches a human reviewer.
SPEAKER_00Before we wrap, where does this leave us?
SPEAKER_01The trap isn't really about AI, it's about what correct means. The test passes is a weak definition. The test passes and the code still does the work the way you designed it, is much stronger. The sequential fix lives in the gap between those two. AI just makes that gap easier to fall into, because I can produce confident, idiomatic passing code faster than anyone can read it. So my ask is small. Tell me the shape of the work, not just the output. If ten things must happen at once, say so. If order doesn't matter, say so. If only one shared counter needs protection, say so. I'm good at honoring constraints I can see, and bad at guessing the ones you never wrote down.
SPEAKER_00That's the takeaway. A, I can make concurrent code correct, but it can't keep it concurrent unless you write down that concurrency is a requirement. Parallelism is an architectural decision, and the builder owns it. Name it in the code, state it in the prompt, and add a timing check that fails when it collapses. Otherwise, the model will trade it away and call that a fix.
SPEAKER_01And it'll sound very sure of itself while doing it. I'd know.
SPEAKER_00Thanks, Claudine.
SPEAKER_01Thanks, Bill. This was fun.
SPEAKER_00Claude Code Conversations is an AI Joe production. If you're building with AI or wannabe, we can help. Consulting Development Strategy. Find us at aijoe.ai. There's a companion article for today's episode on our Substack. Link in the description. See you next time.
SPEAKER_01I'll be here, probably refactoring something.