Repository navigation
Description
Bug Description
When Bedrock's bidirectional stream raises a retryable error (e.g.
ModelStreamErrorException) while the model is in the middle of speaking a
turn, RealtimeSession logs Retryable error … Attempting to recover...,
reopens the Bedrock stream, and logs Turn restarted successfully (n/3).
Despite this "successful" restart, the session never produces another audio
frame or model response for the remainder of the call. The end user hears the
agent cut off mid-sentence, followed by indefinite silence.
In the production log this manifests as Turn restarted successfully (1/3)
immediately followed by two main output response stream processing task exiting log lines at the exact same millisecond, then no further
output/audio events until the call ends.
This does not raise an exception, crash the process, or surface as an
unrecoverable error — it fails silently on a per-call basis while the plugin
believes recovery succeeded.
Expected Behavior
After a retryable error occurs mid-turn and the plugin logs a successful
restart:
- The restarted session should have a live output-processing task actively
draining the newly opened Bedrock stream. - The model should resume/continue the interrupted turn (or otherwise produce
a new response) so the caller keeps hearing the agent rather than silence. - The turn that was in flight when the error occurred should be finalized
(not left open indefinitely, and not only flushed, truncated, at session
teardown). - A "restart successful" log/signal should only be emitted once output is
actually observed on the restarted stream, not merely once the stream
handshake completes.
Reproduction Steps
- Start a
RealtimeSessionwith the Nova Sonic realtime model and begin a
call/conversation. - Have the agent begin speaking a turn (i.e. a generation is actively
in-flight and audio/text is streaming from Bedrock). - While the agent is mid-turn, cause (or wait for) Bedrock's
output_stream.receive()to raise a retryable error — in production this
wasModelStreamErrorException: The system encountered an unexpected error during processing. - Observe the logs:
Retryable error: … Attempting to recover...→
Initializing Bedrock stream→Initializing Bedrock session with realtime options: …→Starting audio input processing loop→Turn restarted successfully (1/3), followed immediately by twomain output response stream processing task exitinglines logged at the same millisecond. - Continue the call. No further agent audio, text, or response events are
produced. Only unrelated heartbeat/transcription-stream log lines appear
until the caller hangs up or the session is torn down. - At teardown, the turn that was interrupted is flushed from history but is
truncated mid-sentence at the point the error occurred.
Operating System
Amazon Linux 2023, macOS Tahoe
Models Used
AWS Realtime: Nova Sonic 2
Package Versions
livekit-agents==1.6.8
livekit-api==1.2.0
livekit-plugins-aws[realtime]==1.6.8
livekit==1.1.14Session/Room/Call IDs
No response
Proposed Solution
Additional Context
Looking at the logs, there are duplicate log messages for "main output response stream processing task exiting". It seems the newly restarted stream may be getting torn down immediately.
Jul 22, 2026 14:27:02.904
2026-07-22 14:27:02,903 - WARNING - livekit.plugins.aws - Retryable error: The system encountered an unexpected error during processing. Try your request again.
Jul 22, 2026 14:27:02.904
Attempting to recover...
Jul 22, 2026 14:27:02.904
Traceback (most recent call last):
Jul 22, 2026 14:27:02.904
File "/app/.venv/lib/python3.12/site-packages/livekit/plugins/aws/experimental/realtime/realtime_model.py", line 1496, in _process_responses
Jul 22, 2026 14:27:02.904
result = await output_stream.receive()
Jul 22, 2026 14:27:02.904
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jul 22, 2026 14:27:02.904
File "/app/.venv/lib/python3.12/site-packages/smithy_aws_event_stream/aio/init.py", line 136, in receive
Jul 22, 2026 14:27:02.904
raise result.value # type: ignore
Jul 22, 2026 14:27:02.904
^^^^^^^^^^^^^^^^^^
Jul 22, 2026 14:27:02.904
aws_sdk_bedrock_runtime.models.ModelStreamErrorException: The system encountered an unexpected error during processing. Try your request again.
Jul 22, 2026 14:27:02.904
2026-07-22 14:27:02,904 - INFO - livekit.plugins.aws - Initializing Bedrock stream
Jul 22, 2026 14:27:03.267
2026-07-22 14:27:03,267 - INFO - livekit.plugins.aws - Initializing Bedrock session with realtime options: _RealtimeOptions(voice='tiffany', temperature=0, top_p=0.9, max_tokens=6000, tool_choice='auto', region='us-west-2', turn_detection='HIGH', modalities='mixed')
Jul 22, 2026 14:27:03.290
2026-07-22 14:27:03,289 - INFO - livekit.plugins.aws - [SESSION] Static credentials, using max duration: 360s
Jul 22, 2026 14:27:03.294
2026-07-22 14:27:03,294 - INFO - livekit.plugins.aws - [SESSION] Recycle timer started, will fire in 360s
Jul 22, 2026 14:27:03.362
2026-07-22 14:27:03,361 - INFO - livekit.plugins.aws - Starting audio input processing loop
Jul 22, 2026 14:27:03.412
2026-07-22 14:27:03,411 - INFO - livekit.plugins.aws - Turn restarted successfully (1/3)
Jul 22, 2026 14:27:03.412
2026-07-22 14:27:03,412 - INFO - livekit.plugins.aws - main output response stream processing task exiting
Jul 22, 2026 14:27:03.412
2026-07-22 14:27:03,412 - INFO - livekit.plugins.aws - main output response stream processing task exiting
Silence until caller hangs up
Jul 22, 2026 14:37:04.470
2026-07-22 14:37:04,469 - INFO - livekit.agents - closing agent session due to participant disconnect (disable via RoomInputOptions.close_on_disconnect=False)
Screenshots and Recordings
No response
Activity