-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
fix(realtime): bound Vertex credential resolution and make realtime failures loud #37604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mateo-berri
merged 3 commits into
litellm_internal_staging
from
litellm_lit5867_realtime_silent_hang
Aug 20, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """Loud-failure helpers for the realtime WebSocket paths. | ||
|
|
||
| A realtime caller that only gets a bare close frame has nothing to act on, so | ||
| every failure surfaces as an OpenAI-style ``error`` event plus a close frame | ||
| whose reason names the failure. Close reasons are capped at | ||
| ``WEBSOCKET_CLOSE_REASON_MAX_BYTES``: RFC 6455 control frames carry at most 125 | ||
| bytes, two of which hold the status code, and a longer reason makes the close | ||
| frame itself fail, which is how a loud failure turns back into a silent one. | ||
| """ | ||
|
|
||
| import json | ||
| from typing import Final | ||
|
|
||
| from litellm.types.realtime import RealtimeErrorDetail, RealtimeErrorEvent | ||
|
|
||
| WEBSOCKET_CLOSE_REASON_MAX_BYTES: Final = 123 | ||
|
|
||
|
|
||
| def realtime_error_event(message: str, error_type: str) -> str: | ||
| detail: Final[RealtimeErrorDetail] = {"type": error_type, "message": message} | ||
| event: Final[RealtimeErrorEvent] = {"type": "error", "error": detail} | ||
| return json.dumps(event) | ||
|
|
||
|
|
||
| def websocket_close_reason(message: str, fallback: str) -> str: | ||
| encoded: Final = message.encode("utf-8") | ||
| if not encoded: | ||
| return fallback | ||
| if len(encoded) <= WEBSOCKET_CLOSE_REASON_MAX_BYTES: | ||
| return message | ||
| return encoded[:WEBSOCKET_CLOSE_REASON_MAX_BYTES].decode("utf-8", errors="ignore") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tests/test_litellm/litellm_core_utils/test_realtime_errors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import json | ||
| import os | ||
| import sys | ||
|
|
||
| sys.path.insert(0, os.path.abspath("../../..")) | ||
|
|
||
| from litellm.litellm_core_utils.realtime_errors import ( | ||
| WEBSOCKET_CLOSE_REASON_MAX_BYTES, | ||
| realtime_error_event, | ||
| websocket_close_reason, | ||
| ) | ||
|
|
||
|
|
||
| def test_realtime_error_event_shape(): | ||
| event = json.loads(realtime_error_event("token refresh failed", error_type="server_error")) | ||
|
|
||
| assert event == { | ||
| "type": "error", | ||
| "error": {"type": "server_error", "message": "token refresh failed"}, | ||
| } | ||
|
|
||
|
|
||
| def test_websocket_close_reason_keeps_short_messages_intact(): | ||
| assert websocket_close_reason("boom", fallback="Internal server error") == "boom" | ||
|
|
||
|
|
||
| def test_websocket_close_reason_falls_back_on_empty_message(): | ||
| assert websocket_close_reason("", fallback="Internal server error") == "Internal server error" | ||
|
|
||
|
|
||
| def test_websocket_close_reason_truncates_long_ascii_message(): | ||
| reason = websocket_close_reason("x" * 500, fallback="Internal server error") | ||
|
|
||
| assert len(reason.encode("utf-8")) <= WEBSOCKET_CLOSE_REASON_MAX_BYTES | ||
| assert reason == "x" * WEBSOCKET_CLOSE_REASON_MAX_BYTES | ||
|
|
||
|
|
||
| def test_websocket_close_reason_truncates_multibyte_message_by_bytes(): | ||
| """A close frame carries at most 123 bytes of reason, not 123 characters: | ||
| truncating by characters lets a multibyte message overflow the control | ||
| frame, which makes the close itself fail and leaves the caller with a bare | ||
| abnormal closure and no reason at all.""" | ||
| reason = websocket_close_reason("あ" * 200, fallback="Internal server error") | ||
|
|
||
| assert len(reason.encode("utf-8")) <= WEBSOCKET_CLOSE_REASON_MAX_BYTES | ||
| assert reason == "あ" * (WEBSOCKET_CLOSE_REASON_MAX_BYTES // 3) | ||
| assert "�" not in reason |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Low: Internal exception disclosure
When realtime routing or backend setup fails, an authenticated caller now receives the raw exception text.
_redact_stringremoves recognized credential patterns, but leaves details such as GCP project IDs, private upstream hostnames, and filesystem paths; the same issue occurs inlitellm/llms/custom_httpx/llm_http_handler.py:5982. Return a fixed public error message for unexpected exceptions, whitelist specific safe messages such as the credential timeout, and retain the full exception only in server logs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
llm_http_handler already sent this redacted text before the PR. Clamping the proxy to a fixed string restores the opaque failure this fix removes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detail. I can't automatically confirm this is safe to dismiss, so I'm leaving the thread open for a maintainer to make the call.