Code Room
Vibe codingHardvc-g235
Subject Ai code reviewLevel Senior–Staff~18 minCommon in Concurrency interviewsIndustries Computer games, Software development

Question

An AI agent wrote this C++ for a game server's hit-registration cache, claiming it "safely memoizes per-frame so concurrent worker threads share results":

cpp
std::unordered_map<EntityId, HitResult> cache; HitResult getHit(EntityId id, const World& w) {    auto it = cache.find(id);    if (it != cache.end()) return it->second;    HitResult r = computeHit(id, w);   // expensive    cache[id] = r;    return r;}

Workers call `getHit` from multiple threads. The agent's single-threaded test passes. What's wrong, and how do you verify it before it ships into a 128-tick server?

What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.

Describe your solution

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.