Establish a single concurrency standard: in async code, never block the event loop; in multi-thread/state-machine code, make ownership and cancellation atomic; and in cleanup/shutdown, use bounded, interrupt-friendly paths.
1) Keep async nonblocking
subprocess.run, CPU-heavy work (ffprobe/ffmpeg, compressors, summary generation), synchronous SDK calls, or blocking I/O must be offloaded.result = subprocess.run([…], timeout=60)
result = await asyncio.to_thread(subprocess.run, […], timeout=60)
result = await adapter._run_blocking(func, *args)
2) Re-check cancellation/flags after waits
- If a worker can be paused in `Event.wait()` (or similar), it must re-check the controlling mode/flag at every boundary where it could restart capture/playback/processing.
- Pattern:
```py
await voice_done.wait()
if cli_ref._voice_continuous is False:
return # cancel boundary
3) Lock/claim correctly; snapshot atomically
4) Shutdown/cleanup must be bounded and interrupt-friendly
shutdown(wait=True)) before the code path that needs to deliver an interrupt/watchdog action.pool.shutdown(wait=True, cancel_futures=True)
pool.shutdown(wait=False, cancel_futures=True)
```
5) Add regression coverage for the real concurrency boundary
put_threadsafe()), tests must involve a real worker thread, not only same-loop calls.Enter the URL of a public GitHub repository