Expose TTS fallback controls and activation events (LKINF-495) - #7185
Expose TTS fallback controls and activation events (LKINF-495)#7185russellmartin-livekit wants to merge 1 commit into
Conversation
e42ebb2 to
e7a7dda
Compare
b1e0a4e to
11335c2
Compare
11335c2 to
c0749e8
Compare
6f2865d to
8cf9590
Compare
| def _normalize_fallback_type(fallback_type: object) -> FallbackType: | ||
| if isinstance(fallback_type, str) and fallback_type in _FALLBACK_TYPES: | ||
| return cast(FallbackType, fallback_type) | ||
| return "unknown" |
There was a problem hiding this comment.
🟡 Malformed fallback notices emit events
A missing or non-string fallback_type becomes unknown instead of failing validation. Listeners receive an event when every other field is valid.
Learn more
Unknown string values represent future gateway enum members and can safely map to unknown. Missing values and non-string values are structurally invalid, but this helper maps those values to the same valid enum member. Pydantic therefore cannot reject the notice when its other fields are valid.
Example: A notice containing valid session_id, provider, model, voice, and cause fields but no fallback_type emits FallbackActivatedEvent(fallback_type="unknown"). The notice must instead be ignored while subsequent audio continues.
Recommended fix: Preserve validation failure for missing and non-string values while mapping only unrecognized strings to unknown. Add test cases for an absent value and a non-string value with all other required fields present.
Was this helpful? React with 👍 or 👎 to provide feedback.
8cf9590 to
6a0149e
Compare
| except ValidationError as e: | ||
| logger.warning( | ||
| "ignoring invalid fallback activation notice", | ||
| extra={"session_id": data.get("session_id"), "error": str(e)}, |
Summary
disable_system_default_fallbackand serialize opt-out even without customer fallback modelsfallback_activatedevent for regular and system-default fallback outputunknownTesting
uv run pytest tests/test_inference_tts_fallback.py tests/test_inference_tts_alignment.pyuv run ruff check livekit-agents/livekit/agents/inference/tts.py livekit-agents/livekit/agents/inference/__init__.py tests/test_inference_tts_fallback.py tests/test_inference_tts_alignment.pyuv run ruff format --check livekit-agents/livekit/agents/inference/tts.py livekit-agents/livekit/agents/inference/__init__.py tests/test_inference_tts_fallback.py tests/test_inference_tts_alignment.pyuv run --group typing mypy -p livekit.agentsCoordinated PRs
LKINF-495