Skip to content

fix(realtime): send TEXT frames and valid guardrail session.update#28848

Merged
mateo-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_fix_realtime_streaming_protocol
May 26, 2026
Merged

fix(realtime): send TEXT frames and valid guardrail session.update#28848
mateo-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_fix_realtime_streaming_protocol

Conversation

@Sameerlite

@Sameerlite Sameerlite commented May 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Decode backend WebSocket recv(decode=False) bytes to str before send_text, so proxy clients receive OP_TEXT JSON events (fixes LiveKit / openai-python clients silently missing server events).
  • Include turn_detection.type: server_vad in guardrail-injected session.update for GA Realtime upstreams (fixes Missing required parameter: session.audio.input.turn_detection.type).
image Fixes LIT-3288

Decode backend recv bytes before send_text so clients receive OP_TEXT JSON
events. Include turn_detection.type server_vad in injected session.update.

Co-authored-by: Cursor <[email protected]>
@greptile-apps

greptile-apps Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes two realtime proxy forwarding bugs in RealTimeStreaming: backend bytes frames are now UTF-8 decoded to str before send_text (fixing silent event drops on LiveKit/openai-python clients), and guardrail-injected session.update messages now include type: server_vad in turn_detection for both GA and beta protocol shapes (fixing the upstream validation error Missing required parameter: session.audio.input.turn_detection.type).

  • Binary-to-text decode (backend_to_client_send_messages): bytes from recv(decode=False) are decoded with UTF-8; non-UTF-8 frames are logged and skipped via continue, keeping the forwarding loop alive.
  • _make_disable_auto_response_message: A shared turn_detection dict with type: server_vad and create_response: false is now injected into both the GA (session.audio.input.turn_detection) and beta (flat turn_detection) message shapes.
  • Tests: Updated assertions for the new session shape; two new @pytest.mark.asyncio tests cover the string-delivery and binary-skip paths using only mocks.

Confidence Score: 5/5

Safe to merge — both fixes are localized, the decode path preserves the loop on failure, and the updated session shape satisfies the GA upstream validation requirement.

The bytes-to-str decode is narrowly scoped to the forwarding loop and handles the error case correctly with continue. The turn_detection fix adds the field the GA upstream already requires, so it cannot regress callers that were already failing. New tests cover the exact behavioral changes introduced and use only mocks.

No files require special attention.

Important Files Changed

Filename Overview
litellm/litellm_core_utils/realtime_streaming.py Two targeted fixes: bytes-to-str decoding before send_text and adding required type: server_vad to guardrail-injected turn_detection; both paths are exercised before downstream handlers
tests/test_litellm/litellm_core_utils/test_realtime_streaming.py Existing session-shape tests updated to assert the new type: server_vad field; two new async tests added for str-delivery and non-UTF-8 binary skip behavior, all using only mocks (no real network calls)

Reviews (2): Last reviewed commit: "fix(realtime): skip non-UTF-8 backend bi..." | Re-trigger Greptile

Comment thread litellm/litellm_core_utils/realtime_streaming.py Outdated
@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Avoid terminating the forwarding loop on UnicodeDecodeError when the
backend sends unexpected binary payloads.

Co-authored-by: Cursor <[email protected]>
@Sameerlite

Copy link
Copy Markdown
Collaborator Author

@greptileai

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; thanks!

@mateo-berri mateo-berri merged commit 79a4909 into litellm_internal_staging May 26, 2026
117 of 119 checks passed
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…erriAI#28848)

* fix(realtime): send TEXT frames and valid guardrail session.update

Decode backend recv bytes before send_text so clients receive OP_TEXT JSON
events. Include turn_detection.type server_vad in injected session.update.

Co-authored-by: Cursor <[email protected]>

* fix(realtime): skip non-UTF-8 backend binary frames

Avoid terminating the forwarding loop on UnicodeDecodeError when the
backend sends unexpected binary payloads.

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants