Fix wg race

Race detector caught this when I was writing new code using the embedded client/coordinator (that PR coming soon).

This is super tricky and subtle and would deadlock if I did it wrong so... have fun reviewing!

(Lines 356-362 are technically unrelated to the race condition. Just enforcing invariants.)