Code Room
Vibe codingHardvc-g500
Subject Ai code reviewLevel Senior–Staff~20 minCommon in Concurrency interviewsIndustries Software development

Question

An AI set up this FastAPI dependency for per-request context (the current tenant). Under concurrency, requests intermittently read or write data for the WRONG tenant. Explain the scope bug and how you'd fix it safely.

python
class RequestContext:    tenant_id: str = None ctx = RequestContext()  # module-level singleton def get_ctx(x_tenant: str = Header(...)):    ctx.tenant_id = x_tenant    return ctx @app.get("/data")async def get_data(ctx: RequestContext = Depends(get_ctx)):    await asyncio.sleep(0)  # any await / yield point    return query_for_tenant(ctx.tenant_id)
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.