fix(realtime): keep the proxy's realtime session gate off translation sessions

A key that opts out of a legacy callback guardrail now gets a working translation session, since the transcription-guardrail gate no longer sends a realtime session.update the translation upstream rejects
This commit is contained in:
mateo-berri 2026-10-28 18:02:26 -07:00
parent fb50c3d3ce
commit 5169f815c5
2 changed files with 33 additions and 2 deletions

View file

@ -1362,8 +1362,12 @@ class RealTimeStreaming:
return self._has_realtime_guardrails_for_event_hooks([GuardrailEventHooks.realtime_input_transcription])
def _should_disable_vad_auto_response(self) -> bool:
"""Transcription-only sessions have no assistant turn to gate and reject realtime session updates."""
return not self._is_transcription_session and self._has_audio_transcription_guardrails()
"""Transcription and translation sessions have no assistant turn to gate and reject realtime session updates."""
return (
not self._is_transcription_session
and not self._is_translation_session
and self._has_audio_transcription_guardrails()
)
async def run_realtime_guardrails(
self,

View file

@ -3402,6 +3402,33 @@ async def test_translation_rejects_applicable_guardrails_before_forwarding_audio
backend.send.assert_awaited_once_with(input_event)
@pytest.mark.asyncio
async def test_translation_for_a_key_opted_out_of_a_legacy_callback_guardrail_gets_no_realtime_session_gate(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setattr(litellm, "callbacks", [CustomGuardrail(guardrail_name="legacy-callback")])
session_update: Final = json.dumps({"type": "session.update", "session": {"audio": {"output": {"language": "es"}}}})
session_created: Final = {"type": "session.created", "session": {"type": "translation"}}
client: Final = _ga_client_ws()
client.receive_text = AsyncMock(side_effect=[session_update, ConnectionClosed(None, None)])
client.close = AsyncMock()
backend: Final = MagicMock()
backend.send = AsyncMock()
backend.recv = AsyncMock(side_effect=[json.dumps(session_created), ConnectionClosed(None, None)])
streaming: Final = RealTimeStreaming(
websocket=client,
backend_ws=backend,
logging_obj=_mock_logging(),
translation_session=True,
request_data={"litellm_metadata": {"user_api_key_metadata": {"disable_global_guardrails": True}}},
)
await streaming.bidirectional_forward()
assert tuple(call.args[0] for call in backend.send.await_args_list) == (session_update,)
assert session_created in tuple(json.loads(call.args[0]) for call in client.send_text.await_args_list)
@pytest.mark.asyncio
@pytest.mark.parametrize("retain_close", (False, True))
@pytest.mark.parametrize("reported_input,expected_input", [(None, 2.0), (0.0, 0.0), (0.25, 0.25)])