Code RoomDefending worker pool implementation
HardPrep Room Coding #4630

Defending worker pool implementation

Vibe & agenticConcurrencySenior–Staff~20 min

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 }

Implement
diagnose_worker_pool(events: list[str]) → str
Examples
in[["producer:send_jobs","producer:close_jobs","main:range_results","main:wg_wait"]]out"deadlock:results-never-closed"
in[["producer:send_jobs","producer:close_jobs","closer:wg_wait","closer:close_results","main:range_results"]]out"ok"
in[["producer:close_jobs","main:range_results","main:wg_wait","main:close_results"]]out"deadlock:close-after-range"
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.

0:00 of about 20 min

Vibe & agentic: describe the solution in plain language (or narrate it) and the coach grades your approach.

Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.