UserBotLatencyObserver drops STT events arriving before VADUserStoppedSpeakingFrame
Summary
UserBotLatencyObserver(pipecat 1.9+) silently drops anyTranscriptionFrameor STT-ownedTTFBMetricsDatathat arrives beforeVADUserStoppedSpeakingFrame. This happens when a streaming STT service (Azure / Deepgram / etc.) reaches its own internal endpointing before Silero VAD'sstop_secsaccumulator does.Result:
LatencyBreakdown.contributionsis missing thetranscriptionandturn_detectionstages for every affected turn, andstage.transcription/stage.turn_detectiondisappear from downstream dashboards.
Repro
- pipecat
1.11.0(also present since PR #5445 in 1.9.0) - STT:
AzureSTTService(streaming, self-endpointing) - VAD:
SileroVADAnalyzerwithstop_secs=1.0 - Pipeline: standard STT → LLM → TTS
Evidence
Wall-clock timestamps of TranscriptionFrame vs VADUserStoppedSpeakingFrame reaching the observer, over three consecutive turns:
| Turn | transcription (ms) | vad_stopped (ms) | delta |
|---|---|---|---|
| 1 | 27619 | 27692 | -73 |
| 2 | 39183 | 39301 | -118 |
| 3 | 41865 | 41992 | -127 |
TranscriptionFrame reliably lands 70-130 ms before the VAD frame in this setup. Azure's own endpointing (silence + LM + intonation) finalizes around 900 ms after the user stops speaking; Silero with stop_secs=1.0 fires around 1000 ms. Both timers run in parallel and independently.
Root cause
PR #5445 introduced these three changes in user_bot_latency_observer.py:
_mark()gates onif not self._measuring: return None_measuringis True only after_user_stopped_timeis set_user_stopped_timeis set only whenVADUserStoppedSpeakingFramearrives
_handle_metrics_frame has an identical gate for TTFBMetricsData.
The gate implicitly assumes "TranscriptionFrame always lands after VADUserStoppedSpeakingFrame". That holds for local Whisper-style STTs and for streaming STTs in EXTERNAL turn-detection mode. It doesn't hold when a streaming STT does its own endpointing and Silero's stop_secs is raised (we use stop_secs=1.0 to absorb speech pauses in dual-bot testing).
Impact
LatencyBreakdown.contributionsis missingtranscriptionandturn_detectionentries for the affected turnsLatencyBreakdown.ttfbis missing the STT service's TTFB- The lost time (~1s) falls through to the "pipeline" bucket via
_build_contributions()'s span-pair fallback - Downstream OTel spans and dashboards lose the stages
Suggested direction (leaving to maintainers)
Options I can think of, in rough order of intrusiveness:
- Buffer pre-VAD_STOP
TRANSCRIPTmoments and STTTTFBMetricsDataand replay them into_moments/_ttfbwhenVADUserStoppedSpeakingFramearrives, backdatingattoVAD_STOP.at + epsilonso the canonical moment-pair order in_SPANS_BY_MOMENTSis preserved. - Or: only gate on cross-cycle staleness (reset marker) rather than on
_user_stopped_time is not None, sinceVADUserStartedSpeakingFrameis a clear "current cycle started" signal.
Workaround
For anyone hitting this before an upstream fix, monkey-patching the observer to defer early TRANSCRIPT moments works — the STT frame's payload is intact, only its at needs to be shifted just after VAD_STOP.at to keep the sort canonical.
Source: pipecat-ai/pipecat