Turn commits with end_of_turn_probability: null when STT transcript arrives after turn flush, splitting one utterance into two turns
Bug Description
Turn commits with end_of_turn_probability: null when STT transcript arrives after turn flush, splitting one utterance into two turns
Summary
When a turn is committed by VAD and the final STT transcript arrives shortly afterwards, the late transcript triggers a second turn commit with end_of_turn_probability: null and unlikely_threshold: null. The single spoken utterance is delivered to the LLM as two separate conversation items.
Two distinct problems:
- A turn commits with no end-of-turn decision.
end_of_turn_probabilityandunlikely_thresholdare bothnull, andspeech_start_timeisnull. The pipeline proceeds anyway. - The log contradicts itself. In one variant,
stt transcript arrived after a turn flush, skipping eot predictionis logged, and aneot predictionevent is then emitted with null fields on the next line.
The user-visible effect is that a continuous sentence reaches the LLM fragmented, with the second fragment having bypassed turn detection entirely.
Environment
livekit 1.1.13
livekit-agents 1.6.5
livekit-api 1.2.0
livekit-blingfire 1.1.0
livekit-local-inference 0.2.6
livekit-plugins-ai-coustics 0.3.0
livekit-protocol 1.1.19
Python 3.14.5, Windows 11
agent-starter-pythontemplate, running inconsolemode- STT:
deepgram/nova-3,language="multi"(viainference.STT) - Turn detection:
inference.TurnDetector()(no arguments) — hosted inference path, notlivekit-plugins-turn-detector(that package is not installed) preemptive_generation=True- Turn detector reports
"model": "turn-detector-v1",default_threshold: 0.56
Reproduction
Speak a sentence with a pause of roughly one second mid-phrase, so that VAD commits the turn before STT has finalised the trailing words.
Observed on multiple occasions across two sessions.
Expected
Either the late transcript is merged into the already-committed turn, or it is genuinely skipped as the log message states. A turn should not commit with a null end-of-turn probability.
Actual
Case 1 — enhancement disabled
Spoken: "No. Date needed now."
04:48:24.760 DEBUG received user transcript
{"user_transcript": "Date", "transcript_delay": 0.058}
04:48:25.794 DEBUG eot prediction
{"probability": 0.737298846244812, "unlikely_threshold": 0.56,
"endpointing_delay": 0.3, "trigger": "vad", "from_cache": false}
04:48:25.805 DEBUG user turn committed
{"delay_completed": false, "source": "vad",
"end_of_turn_probability": 0.737298846244812}
04:48:25.822 DEBUG conversation_item_added
{"role": "user", "text": "No. Date"}
04:48:25.857 DEBUG received user transcript
{"user_transcript": "needed now."}
04:48:25.864 WARNING transcript arrives after turn has been committed. consider
raising `min_delay` in the endpointing options to accommodate a slow stt.
04:48:25.876 DEBUG eot prediction
{"probability": null, "unlikely_threshold": null,
"endpointing_delay": 0.3, "trigger": "stt", "from_cache": false}
04:48:26.158 DEBUG user turn committed
{"speech_start_time": null, "delay_completed": true, "source": "stt",
"end_of_turn_probability": null, "unlikely_threshold": null}
04:48:26.191 DEBUG conversation_item_added
{"role": "user", "text": "needed now."}
One utterance, two conversation items, second turn committed on a null probability.
Case 2 — the logged contradiction
Spoken: "Yeah. Can you share the link of that property?"
21:53:44.634 DEBUG user turn committed
{"delay_completed": false, "source": "vad",
"end_of_turn_probability": 0.7216790318489075}
21:53:44.640 DEBUG conversation_item_added
{"role": "user", "text": "Yeah. Can you share the link of the link of that"}
21:53:44.756 DEBUG received user transcript
{"user_transcript": "property?"}
21:53:44.759 DEBUG stt transcript arrived after a turn flush, skipping eot prediction
21:53:44.762 DEBUG eot prediction
{"probability": null, "unlikely_threshold": null,
"endpointing_delay": 0.3, "trigger": "stt", "from_cache": false}
21:53:45.059 DEBUG user turn committed
{"speech_start_time": null, "end_of_turn_probability": null,
"unlikely_threshold": null}
21:53:45.078 DEBUG conversation_item_added
{"role": "user", "text": "property?"}
skipping eot prediction is logged, then an eot prediction event is emitted 3 ms later with null fields.
Ruled out
The starter template applies ai_coustics audio enhancement on the input path by default. I disabled it and re-ran; the behaviour reproduces identically. The enhancement layer is not the cause.
Note on the min_delay suggestion
The warning suggests raising min_delay to accommodate slow STT. That may reduce how often the race occurs, but it does not address either problem above: a turn still commits with a null probability when it does occur, and the log still contradicts itself. Raising min_delay also directly increases response latency, which is costly in a telephony context.
Not the same as #3070
#3070 (closed) was the end-of-turn model timing out under CPU pressure, resolved by moving to a larger instance. Here there is no timeout and no CancelledError — the prediction is emitted, after the turn has already flushed, with null fields. That issue was also on the local turn_detector plugin; this is the hosted inference.TurnDetector() path.
Impact
In a voice pipeline where users produce short utterances with natural mid-sentence pauses, the LLM receives fragmented input and one of the fragments has bypassed turn detection. In my case the agent responded to "No. Date" before "needed now." had arrived.
Expected Behavior
Either the late transcript is merged into the already-committed turn, or it is genuinely skipped as the log message states — a turn should not commit with end_of_turn_probability: null and unlikely_threshold: null.
A single continuous utterance should reach the LLM as one conversation item, not split across two turns where the second bypassed turn detection entirely.
Reproduction Steps
Create a project from agent-starter-python (unmodified template).
Run uv run src/agent.py console.
Speak a sentence with a pause of roughly one second mid-phrase, so VAD commits the turn before STT has finalised the trailing words. Example: "No. Date … needed now."
Watch the debug log for transcript arrives after turn has been committed, immediately followed by an eot prediction with probability: null.
Observed on multiple occasions across two sessions. Reproduces with the template's default ai_coustics audio enhancement both enabled and disabled — the enhancement layer is not the cause.
The only deviation from the stock template in my runs was commenting out the room_options block to disable enhancement for the control test.
Operating System
Windows 11
Models Used
STT: deepgram/nova-3 (language="multi") via inference.STT | LLM: google/gemma-4-31b-it via inference.LLM | TTS: cartesia/sonic-3 via inference.TTS | Turn detection: inference.TurnDetector() — hosted, reports "model": "turn-detector-v1"
Package Versions
livekit 1.1.13
livekit-agents 1.6.5
livekit-api 1.2.0
livekit-blingfire 1.1.0
livekit-local-inference 0.2.6
livekit-plugins-ai-coustics 0.3.0
livekit-protocol 1.1.19
Python 3.14.5
Session/Room/Call IDs
N/A - console mode, no Cloud session
Proposed Solution
Resolve the race in one direction rather than both: either merge the late transcript into the already-committed turn, or genuinely skip it as the "skipping eot prediction" log line claims. A turn should never commit with end_of_turn_probability and unlikely_threshold both null. Note that the warning's suggestion to raise min_delay reduces how often the race occurs but does not fix either problem — and it increases response latency, which is costly in telephony.
Additional Context
Config runs entirely through LiveKit's hosted inference gateway (inference.LLM / STT / TTS / TurnDetector); no third-party model keys. Distinct from #3070, which was an EOT model timeout under CPU pressure on the local turn_detector plugin.
Screenshots and Recordings
No response
This is expected behavior. The late transcript could still show up as the same turn if there is no agent speech played. An user turn could have several chunks naturally, and for LLM, they are not different from STT sending them before committing the turn.
We can't retroactively change the history here because the agent might have already responded, and we need to surface late STT problems in case users want to tune STT settings or switch STT for better experience.
If your concern is more about empty values from the newly committed turn from late STT transcript, we can find other ways to mark the source clearly so you can filter them out accordingly in your code.
That makes sense - thanks for the detail on why the history can't be rewritten. My concern is exactly the filtering case you mentioned: right now the late-committed turn arrives with end_of_turn_probability: null and unlikely_threshold: null, which is hard to distinguish downstream from other null cases. If you're open to marking the source explicitly on these late-STT commits, that would let consumers filter them cleanly. Happy to open a PR for that if it'd be useful.
A related, deterministic variant of this split, for anyone using a non-streaming (batch) STT through
stt.StreamAdapter with turn_detection="stt".
Root cause
StreamAdapterWrapper._run in livekit-agents 1.8.4 (livekit/agents/stt/stream_adapter.py) sends
END_OF_SPEECH first and only then calls recognize() on the clip:
- L130-139: on the VAD's
END_OF_SPEECH, it sendsSpeechEvent(END_OF_SPEECH, speech_end_time=...). - L141-146: then it awaits
self._wrapped_stt.recognize(...)for that clip. - L153-163: only after that does it send the clip's
FINAL_TRANSCRIPT.
In "stt" turn detection, AudioRecognition._process_stt_event (voice/audio_recognition.py, 1.8.4 L1333-1376)
treats that END_OF_SPEECH as the end of the turn. It sets _user_turn_committed = True and runs EOU detection,
which commits once min_delay has passed since speech_end_time (L1730-1736). With a batch STT, recognize()
for the last clip is often still in flight at that moment. So the turn commits without the last clip's text. That
text then arrives as a FINAL_TRANSCRIPT after the commit and becomes a second user turn.
This is not a race that depends on network timing alone: the adapter's event order guarantees END_OF_SPEECH
before the last clip's text, every time. Whether the turn splits depends only on whether recognize() takes
longer than what is left of min_delay.
Still present in 1.8.8: stt/stream_adapter.py is byte-identical between 1.8.4, 1.8.8 and main (checked
today). In 1.8.8 the audio_recognition.py code paths below are unchanged; only line numbers shift by about +11.
Numbers from production (one week, batch STT through StreamAdapter, "stt" turn detection)
- 122 utterances split into two turns this way.
- The late text arrived 0.06 s to 1.56 s after the commit. Median 0.57 s.
Raising min_delay past about 1.6 s would hide most of these, but adds that latency to every turn.
The fix we use (a subclass of StreamAdapter)
Send the clip's FINAL_TRANSCRIPT first, then END_OF_SPEECH, with a cap so a slow provider cannot hold the
turn open forever:
- Read the VAD stream in a task that never blocks on
recognize(), and recognize closed clips in order in a second task. That way new speech is still seen while an earlier clip is at the STT. - Send
END_OF_SPEECHonly when all of these hold:- the user is silent (the latest VAD clip has closed and no new one has started);
- every closed clip's text is in, or a cap (we use 1.5 s) has passed since the latest clip closed;
- some text arrived since the last
END_OF_SPEECH(one with no text commits nothing; see below); min_delayhas already passed since the latestspeech_end_time(see the next section for why).
- Text that arrives after a capped
END_OF_SPEECHgets its ownEND_OF_SPEECH, so it still commits.
Turns whose text is in before min_delay runs out commit no later than before.
The _user_turn_committed interaction
Moving END_OF_SPEECH after the text is not enough by itself. If it is sent before min_delay has passed,
_run_eou_detection sleeps out the rest of the delay (1.8.4 L1730-1736). If the user resumes in that window, the
STT START_OF_SPEECH handler (L1378-1393) cancels _end_of_turn_task, but does not reset
_user_turn_committed. It is only cleared at the end of _bounce_eou_task (L1822) or in _clear_user_turn
(L1014), and the cancelled task never reaches L1822.
The turn is then "half-committed": _user_turn_committed stays True while the user is speaking again. In that
state a later VAD END_OF_SPEECH runs EOU detection by itself (L1461-1465), and new final transcripts take the
preemptive-generation path (L1262). An END_OF_SPEECH with no text (L1520, no transcript, early return) leaves
the same state.
So our adapter holds END_OF_SPEECH until min_delay has passed since speech_end_time. Then LiveKit commits
the moment it gets the event, and there is no window for this to happen.
Question for maintainers: should the STT START_OF_SPEECH branch reset _user_turn_committed = False when it
cancels _end_of_turn_task? That looks like the intended invariant per the comment on L275 ("true if user turn
ended but EOU task not done").
Minimal repro (no network, no room)
Shows the event order from the stock StreamAdapter with a batch STT that takes 0.5 s.
import asyncio
import time
from types import SimpleNamespace
from livekit import rtc
from livekit.agents import stt, vad
from livekit.agents.language import LanguageCode
class SlowBatchStt(stt.STT):
def __init__(self) -> None:
super().__init__(capabilities=stt.STTCapabilities(streaming=False, interim_results=False))
async def _recognize_impl(self, buffer, *, language=None, conn_options=None):
await asyncio.sleep(0.5) # a typical batch STT round trip
return stt.SpeechEvent(
type=stt.SpeechEventType.FINAL_TRANSCRIPT,
alternatives=[stt.SpeechData(language=LanguageCode("en"), text="last words")],
)
class OneClipVad:
"""A VAD stream that reports one clip: speech start, then speech end."""
def __init__(self) -> None:
self._q: asyncio.Queue = asyncio.Queue()
for kind in (vad.VADEventType.START_OF_SPEECH, vad.VADEventType.END_OF_SPEECH):
self._q.put_nowait(
vad.VADEvent(type=kind, samples_index=0, timestamp=0.0, speech_duration=0.5,
silence_duration=0.25, frames=[rtc.AudioFrame.create(16000, 1, 160)])
)
def __aiter__(self):
return self
async def __anext__(self):
return await self._q.get()
def push_frame(self, frame): ...
def flush(self): ...
def end_input(self): ...
async def aclose(self): ...
async def main() -> None:
adapter = stt.StreamAdapter(stt=SlowBatchStt(), vad=SimpleNamespace(stream=OneClipVad))
stream = adapter.stream()
t0 = time.monotonic()
async def read() -> None:
async for ev in stream:
print(f"{time.monotonic() - t0:.2f}s {ev.type.name}")
reader = asyncio.create_task(read())
await asyncio.sleep(1.0)
await stream.aclose()
reader.cancel()
asyncio.run(main())
Output on 1.8.4 (the adapter file is identical in 1.8.8):
0.00s START_OF_SPEECH
0.00s END_OF_SPEECH
0.50s FINAL_TRANSCRIPT
With turn_detection="stt" and min_delay 0.5 s, the session counts the delay from speech_end_time (0.25 s
before the END_OF_SPEECH), so it commits about 0.25 s after the event, before the text at 0.50 s. The text then
becomes a second turn. Expected order for a batch STT: START_OF_SPEECH, FINAL_TRANSCRIPT, END_OF_SPEECH.
Reading the code, this answers the open question on #6516 about the two variants.
Both variants are the same branch. _on_missing_eot_prediction() runs only when the trigger is stt and no prediction future is in flight:
https://github.com/livekit/agents/blob/dbc38dfbc113a2e06d36feb1278e543af3585ea9/livekit-agents/livekit/agents/voice/audio_recognition.py#L1395-L1398
With a flushed detector, it logs the transcript arrives after turn has been committed WARNING the first time and stt transcript arrived after a turn flush, skipping eot prediction at debug after that:
https://github.com/livekit/agents/blob/dbc38dfbc113a2e06d36feb1278e543af3585ea9/livekit-agents/livekit/agents/voice/audio_recognition.py#L1331-L1343
So in both of your logs _turn_detector_prediction_fut was None and _turn_detector_flushed was True. A late final with a prediction still pending would log neither line. Links are to 1.6.5, your version. Main has the same code:
https://github.com/livekit/agents/blob/0f3af69338cfbc8552b7852a5d6b537a64f8e477/livekit-agents/livekit/agents/voice/audio_recognition.py#L1610-L1622
https://github.com/livekit/agents/blob/0f3af69338cfbc8552b7852a5d6b537a64f8e477/livekit-agents/livekit/agents/voice/audio_recognition.py#L1719-L1722
For the marker idea above, that branch is the only place that knows a commit came from a late transcript. _EndOfTurnInfo has no field to carry it yet:
https://github.com/livekit/agents/blob/0f3af69338cfbc8552b7852a5d6b537a64f8e477/livekit-agents/livekit/agents/voice/audio_recognition.py#L71-L83