fix: guard RTF division in debug log for zero-duration audio - #668
Open
Archlie wants to merge 2 commits into
Open
fix: guard RTF division in debug log for zero-duration audio#668Archlie wants to merge 2 commits into
Archlie wants to merge 2 commits into
Conversation
The debug log line in audio_file_dependency eagerly evaluates elapsed / audio.duration inside an f-string, so a well-formed but zero-duration audio file (empty sample array) raised ZeroDivisionError, turning a 200 into a 500 even when debug logging was disabled. Guard the division with audio.duration > 0 and log RTF as n/a for zero-duration files, restoring the pre-0.9.0 behavior of returning an empty transcription.
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.
Fixes #667
Problem
Uploading a well-formed but zero-duration audio file (e.g. a header-only WAV with 0 samples) to
POST /v1/audio/transcriptionsreturns HTTP 500 instead of the pre-0.9.0 clean200with empty text.Root cause: the RTF debug log line in
audio_file_dependencyuses an eager f-string:Because f-strings evaluate eagerly,
elapsed / audio.durationruns even when debug logging is disabled (log_leveldoes not mitigate it).audio.duration == 0is reachable: a well-formed container that decodes to an empty sample array makesdecode_audio()succeed (so theav.error.*handlers don't fire) and returns a zero-length result. TheZeroDivisionErroris then caught by the genericexcept Exceptionhandler, which turns it into a 500.Fix
Guard the division with
audio.duration > 0. Zero-duration uploads now flow through to the normal empty-transcription path, restoring the pre-rc behavior; normal files still log RTF as before.Test
Added
tests/dependencies_test.pywith a mock-based regression test that feeds a zero-duration sample array throughaudio_file_dependencyand asserts no crash andduration == 0.0.