fix: replace assert with runtime guard in tts_tool streaming playback - #80910
Open
JonthanaHanh wants to merge 1 commit into
Open
JonthanaHanh wants to merge 1 commit into
JonthanaHanh wants to merge 1 commit into
Conversation
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.
Contributor
|
This was generated by AI during triage. Summary: Problems:
Solution: Checked against |
2 tasks
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Two
assertstatements instream_tts_to_speaker()inner functions (_playback_workerand_enqueue_audio) would be stripped bypython -O, silently removing invariant checks.Changes
tools/tts_tool.py:3597—_playback_worker():assert streamer is not None→if streamer is None: returntools/tts_tool.py:3704—_enqueue_audio():assert streamer is not None→if streamer is None: returnWhy
assertis stripped bypython -O. If a future refactor breaks the invariant thatstreameris non-None when these functions run, the code would crash with a confusingAttributeErrorinstead of a clear guard. The early-return pattern is consistent with the rest of the codebase.