Repository navigation
Description
Problem / Background
The OpenAI audio endpoints (speech-to-text landed in #365; text-to-speech is upcoming in #366) dispatch work to a single dedicated AudioWorker thread over an unbounded mpsc::channel (src/server/audio_worker.rs). There is no admission bound and no per-request timeout on the audio path: can_accept_request() (src/server/state.rs, around line 513) gates only on the generation batch queue depth, which the audio path never increments, so it is effectively always true for audio requests.
The PR #371 security review classified the following as MEDIUM under load:
- Head-of-line blocking: all audio requests serialize through one worker thread, so a single slow or large clip stalls the whole audio queue.
- Unbounded memory growth: each queued command holds up to the 25 MiB per-request audio payload, and nothing caps the number of concurrent in-flight requests, so a burst can grow memory without bound.
Neither is a crash (the per-request resample/alloc bounds from #365 cap a single request), but both are availability/throughput risks on the network-facing path.
Proposed Solution
- Switch the
AudioWorkerchannel to a boundedmpsc::sync_channel(N)and usetry_send, mapping a full queue to the existing 503 "all slots are busy" response path (reuse the server's admission/error envelope rather than inventing a new one). - Add a per-request reply timeout so a stuck or pathologically slow request frees its blocking thread and returns a structured error instead of hanging.
- Make the queue bound and timeout configurable via the server config, with sensible defaults.
- This lives in the shared
AudioWorker, so it covers both the STT path and the TTS path (feat(models): TTS model + vocoder for text-to-speech (/v1/audio/speech) #366).
Acceptance Criteria
- The audio queue is bounded; when full, new audio requests get a structured 503 through the real server flow (unit/integration test).
- A per-request timeout returns a structured error and releases the blocking thread (test).
- Bound and timeout are configurable with documented defaults.
- Integrated into the live audio request path (not a standalone helper).
-
cargo test,cargo clippy --all-targets -- -D warnings,cargo fmt --checkclean.
Technical Considerations
Surfaced by the security review of PR #371 (merged). Anchors: src/server/audio_worker.rs, src/server/state.rs (can_accept_request). Related epic: #363.
Activity