Skip to content

fix: validate reference arguments in api_client instead of failing silently - #1319

Open
yuvrajnode wants to merge 1 commit into
fishaudio:mainfrom
yuvrajnode:fix/api-client-reference-validation
Open

fix: validate reference arguments in api_client instead of failing silently#1319
yuvrajnode wants to merge 1 commit into
fishaudio:mainfrom
yuvrajnode:fix/api-client-reference-validation

Conversation

@yuvrajnode

@yuvrajnode yuvrajnode commented Aug 6, 2026

Copy link
Copy Markdown

The __main__ block of tools/api_client.py builds the references list in a way that discards bad input without telling the user.

Two silent failures

1. A missing reference audio becomes empty audio. audio_to_bytes() returns None when the path does not exist, and the result was coerced with audio=ref_audio if ref_audio is not None else b"". A typo in --reference_audio is therefore sent to the server as an empty reference, which fails later with an unrelated decode error rather than pointing at the bad path.

2. Mismatched counts are truncated. zip(ref_texts, byte_audios) stops at the shorter sequence. --reference_audio and --reference_text are separate nargs="+" options, so passing three audios and two texts silently drops the third reference.

input before after
typo in --reference_audio reference sent with audio=b"" Reference audio file not found: typo.wav
3 audios, 2 texts 1 reference silently dropped explicit count-mismatch error
2 audios, 2 texts 2 references 2 references (unchanged)
no references / --reference_id unchanged unchanged

Fix

Fail fast: report a missing reference audio by path, and require the two options to have matching lengths. With those checks in place the None coercion is unreachable, so references builds directly from the validated values.

Behavior is unchanged when the arguments are correct, when --reference_id is used, and when no references are passed at all.

The repo has no test suite, so I kept this to the behavioral fix rather than introducing pytest as a new dependency.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…lently

The `__main__` block of tools/api_client.py built the `references` list in
a way that discarded bad input without telling the user:

1. `audio_to_bytes()` returns None when the path does not exist, and the
   result was coerced with `audio=ref_audio if ref_audio is not None else b""`.
   A typo in --reference_audio therefore became an empty reference audio and
   was sent to the server, which fails later with an unrelated decode error.

2. `zip(ref_texts, byte_audios)` truncates to the shorter sequence.
   --reference_audio and --reference_text are separate `nargs="+"` options,
   so passing three audios and two texts silently dropped the third
   reference instead of reporting the mismatch.

Both are easy to hit from the command line and neither produced any warning.

Fail fast instead: report a missing reference audio by path, and require the
two options to have matching lengths. With those checks in place the None
coercion is no longer reachable, so `references` builds directly from the
validated values.

Behavior is unchanged when the arguments are correct, and when
--reference_id is used or no references are passed at all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant