Extend response latency logging to additional STT, LLM, and TTS backends

Author: andimarafiotiCreated Sep 25, 2026Updated Sep 25, 2026

Problem

Follow-up to #539 and the diagnostic request in #516.

#539 introduces response-level latency records grouped by turn/revision, with a distinct response_key for tool follow-ups. The infrastructure is platform-independent, but stage coverage is concentrated on the default Mac stack: Parakeet STT, the shared LanguageModelHandler generation path, and Qwen3 TTS. Other pipelines can therefore emit n/a for stages that did run, making it harder to diagnose latency or compare configurations.

Extend this observability to the other supported backends without expanding or blocking #539.

Scope

  • Inventory existing STT, LLM, and TTS backends and document which existing latency fields each supports.
  • Add final-STT duration to the remaining STT handlers, including Whisper variants and OpenAI-compatible transcription where applicable.
  • Add generation duration to LLM paths that bypass the instrumented shared handler, including the OpenAI-compatible Responses and Chat Completions paths.
  • Add first-audio TTS timing and speech-stop-to-first-yielded-audio timing to the remaining TTS handlers, including local and OpenAI-compatible providers.
  • Reuse #539's tracker, response identity, terminal logging, and cleanup. Deliver coverage incrementally in focused backend PRs; avoid a separate metrics framework or inference architecture migration.

Measurement contract

Preserve the existing field meanings and document backend-specific boundaries:

  • stt: elapsed final-transcription processing; do not sum repeated progressive transcriptions into it.
  • llm: elapsed generation, not time to first token.
  • tts_ttfa: elapsed synthesis to the first model/provider audio chunk, before local trimming/block assembly where those steps exist.
  • e2e: speech-stop timestamp to the first yielded TTS audio, not client playback latency.
  • For remote providers, timings are measured by this server and include network/provider waits inside the measured operation; they are not provider-only inference times.
  • These durations can overlap and are not an additive latency breakdown. Keep MLX lock waiting specific to MLX; do not invent a generalized lock-wait metric.
  • Preserve n/a when a stage did not run or a measurement is unavailable. Do not duplicate STT on a tool follow-up or overwrite first-audio values with later synthesis segments.

Acceptance criteria

  • A documented backend coverage matrix identifies supported fields and any explicitly deferred paths.
  • For each newly covered backend, a turn through the actual handler and response-finalization path produces the expected fields under the correct response key.
  • Focused tests verify timing boundaries and relevant regressions: multiple TTS segments preserve first-audio values; failed generation records elapsed work; cancellation/stale output cannot revive abandoned trackers or contaminate another response/session.
  • Existing Mac measurements and public Realtime events remain unchanged.
  • Tests may use controlled clocks and stubbed models/providers. No mandatory downloads, paid API calls, or broad performance benchmark are needed to establish bookkeeping correctness.

Non-goals

Latency optimization, changing model defaults, browser playback instrumentation, tool-duration aggregation, percentile dashboards, adding new inference backends, or the shared-inference architecture in #363. This issue extends diagnostic coverage; it does not claim to make responses faster.

Source: huggingface/speech-to-speech