Skip to content

fix: replace assert with runtime guard in tts_tool streaming playback - #80910

Open
JonthanaHanh wants to merge 1 commit into
NousResearch:mainfrom
JonthanaHanh:fix/assert-in-tts-tool
Open

JonthanaHanh wants to merge 1 commit into
NousResearch:mainfrom
JonthanaHanh:fix/assert-in-tts-tool

Conversation

@JonthanaHanh

Copy link
Copy Markdown
Contributor

Summary

Two assert statements in stream_tts_to_speaker() inner functions (_playback_worker and _enqueue_audio) would be stripped by python -O, silently removing invariant checks.

Changes

  • tools/tts_tool.py:3597 — _playback_worker(): assert streamer is not None → if streamer is None: return
  • tools/tts_tool.py:3704 — _enqueue_audio(): assert streamer is not None → if streamer is None: return

Why

assert is stripped by python -O. If a future refactor breaks the invariant that streamer is non-None when these functions run, the code would crash with a confusing AttributeError instead of a clear guard. The early-return pattern is consistent with the rest of the codebase.

Two assert statements in stream_tts_to_speaker() inner functions
(_playback_worker and _enqueue_audio) would crash under python -O
which strips assert statements. Replace with early-return guards
consistent with the rest of the codebase.

assert is stripped by python -O, silently removing invariant checks.
The assertions were already safe in practice (thread only starts when
streamer is not None), but future refactors could break the invariant,
leading to confusing AttributeError instead of a clear guard.
@alt-glitch alt-glitch added type/bug Something isn't working tool/tts Text-to-speech and transcription P3 Low — cosmetic, nice to have labels Aug 7, 2026
@spfcraze

spfcraze commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

This was generated by AI during triage.

Summary:
The new guard in _enqueue_audio returns before the function's existing try/except, so the failure this PR hardens against — streamer None under python -O — now drops a sentence with no log line where the pre-change code logged one.

Problems:

  • The new if streamer is None: return in tools/tts_tool.py (replacing the assert at line 3704) sits above the try block whose except Exception at line 3707 logs Streaming TTS synthesis failed: %s (line 3708). The pre-change code, with the assert stripped under python -O, would reach streamer.stream(...) -> AttributeError -> that except -> the warning; the guard returns before that path.
  • The diff adds no logging of its own (no logger token appears), so nothing records the dropped sentence — _speak_sentence has already displayed it and marked it spoken.

Solution:
Log in the guard before returning, matching the function's other failure paths: if streamer is None: logger.warning("Streaming TTS: streamer is None, dropping sentence"); return.


Checked against 8f03e89 — the PR head when this was written — and e5e96e8, main at the same moment.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low — cosmetic, nice to have tool/tts Text-to-speech and transcription type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants