Code Room
Vibe codingHardvc-g298
Subject Ai collaborationLevel Senior–Staff~20 minCommon in Concurrency interviewsIndustries Software development

Question

An AI agent generated a Go worker-pool that processes a channel of jobs with a fixed number of goroutines and a `sync.WaitGroup`. A reviewer asks you to explain, line by line, how it guarantees all jobs finish before the function returns and whether it can deadlock or leak goroutines. You directed the generation but didn't write it. Below is the code. Walk through your defense and name any real issue.

```go func process(jobs []Job, workers int) []Result { jobCh := make(chan Job) resCh := make(chan Result) var wg sync.WaitGroup for i := 0; i < workers; i++ { wg.Add(1) go func() { defer wg.Done() for j := range jobCh { resCh <- handle(j) } }() } go func() { for _, j := range jobs { jobCh <- j } close(jobCh) }() var results []Result for r := range resCh { results = append(results, r) } wg.Wait() return results }

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.