Code Room
Vibe codingMediumvc-g189
Subject Ai code reviewLevel Mid–Senior~18 minCommon in Concurrency interviewsIndustries Software development

Question

An AI wrote this Go in-memory metrics aggregator that's updated from many request-handling goroutines. It says maps are fine for this. Review concurrency safety.

go
type Metrics struct {	counts map[string]int} func NewMetrics() *Metrics { return &Metrics{counts: map[string]int{}} } func (m *Metrics) Incr(key string) {	m.counts[key]++} func (m *Metrics) Snapshot() map[string]int {	return m.counts}

What fails at runtime, and what's the proper fix?

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.