Infinite samples raise OverflowError instead of being clipped
The finding
_clip guards against NaN but not ±inf. For sample = float('inf') (or -inf, or any value large enough that sample * 32767.0 overflows to inf), round(...) raises OverflowError: cannot convert float infinity to integer. This happens before max/min can clamp the value. A single bad sample, such as one produced by a gain or normalisation divide-by-near-zero upstream, will abort rendering of the whole echo audio buffer instead of being saturated to full scale. That defeats the purpose of a clipping helper.
1| """Speech from argus-echo: the :class:`~argus_scout.channels.base.Synthesiser` voice channels play from.
2|
3| ::
4|
5| services:
6| echo:
7| url: http://echo:8000 # an engine's root (Miso, XTTS-v2 or Qwen3-TTS: the same contract)
8| voice_clone_id: <CLONE_ID> # or speaker: <SPEAKER>; neither means the engine's default
9| language: en
10| format: pcm_s16le # what voice channels get: pcm_s16le, or wav
11|
12| **The contract.** argus-echo's engines share one HTTP contract (``argus_echo.contract`` and echo's
13| ``docs/api.md``), which this module follows exactly. It is re-implemented here rather than imported: it is a
14| handful of field and header names, argus-echo isn't published to PyPI, and echo's own README says clients share
15| the contract, not code. The parts scout uses:
16| The work pack
Recommendation. Handle non-finite values before rounding. For example: if math.isnan(sample): return 0, then if math.isinf(sample): return 32767 if sample > 0 else -32768. Alternatively, clamp the float first: s = max(-1.0, min(1.0, sample)); return max(-32768, min(32767, round(s * 32767.0))).
Acceptance criteria
- Address: Infinite samples raise OverflowError instead of being clipped
- Keep the change scoped to the cited file/symbols unless impact requires otherwise
- Handle non-finite values before rounding. For example:
if math.isnan(sample): return 0, thenif math.isinf(sample): return 32767 if sample > 0 else -32768. Alternatively, clamp the float first: `s = max(-1.0, min(1.0, sample)); return m - Re-check
src/argus_scout/channels/echo.pyafter the fix
Status
- claimed
- resolved
The fix
9950a85166 fix: echo clips infinite float samples instead of raising OverflowError.
@@ -149,7 +149,8 @@ def build_request(cfg: EchoConfig, text: str) -> dict[str, Any]: def _clip(sample: float) -> int: if math.isnan(sample): return 0- return max(-32768, min(32767, round(sample * 32767.0)))+ # Clamp before scaling: an infinite (or huge) sample saturates instead of overflowing round().+ return max(-32768, min(32767, round(max(-1.0, min(1.0, sample)) * 32767.0))) def to_s16le(data: bytes, audio_format: str) -> bytes:@@ -422,3 +422,14 @@ async def test_a_refused_clone_is_reported_not_recorded_and_never_retried(): assert result.get("face").status == "skipped" and result.ok assert store.list_deliveries(f"report:{report.id}") == [] assert (await RedeliveryJob(store, disp, DeliveryConfig(), clock=lambda: T0)()).reports == []+++def test_infinite_and_huge_float_samples_saturate():+ floats = array.array("f", [math.inf, -math.inf, 3.4e38, math.nan, 0.5])+ if sys.byteorder == "big":+ floats.byteswap()+ ints = array.array("h")+ ints.frombytes(to_s16le(floats.tobytes(), "pcm_f32le"))+ if sys.byteorder == "big":+ ints.byteswap()+ assert list(ints) == [32767, -32767, 32767, 0, 16384]How it was judged
Proven 1 test(s) fail on dev and pass with the fix: tests/test_echo.py::test_infinite_and_huge_float_samples_saturate
Judged 24 Nov 2026, 04:48 UTC against dev at d0c0f66.
| Test | on dev | dev + patch |
|---|---|---|
tests/test_echo.py::test_infinite_and_huge_float_samples_saturate | failed | passed |
The other 17 tests in the run (17 with the same result on both trees)
tests/test_echo.py::test_a_cold_model_gets_the_load_timeout | passed | passed |
tests/test_echo.py::test_a_refused_clone_is_reported_not_recorded_and_never_retried | passed | passed |
tests/test_echo.py::test_build_dispatcher_picks_echo_when_configured | passed | passed |
tests/test_echo.py::test_build_request_and_stream_format | passed | passed |
tests/test_echo.py::test_echo_config_and_the_echo_url_break | passed | passed |
tests/test_echo.py::test_echo_down_still_delivers_text_and_records_the_failure | passed | passed |
tests/test_echo.py::test_echo_output_feeds_the_snapcast_and_mask_conversion[pcm_s16le] | passed | passed |
tests/test_echo.py::test_echo_output_feeds_the_snapcast_and_mask_conversion[wav] | passed | passed |
tests/test_echo.py::test_every_reserved_request_field_has_its_own_key | passed | passed |
tests/test_echo.py::test_mask_refuses_a_cloned_voice_unless_allowed | passed | passed |
tests/test_echo.py::test_no_gpu_lease_is_taken_around_synthesis | passed | passed |
tests/test_echo.py::test_one_synthesis_for_every_voice_channel | passed | passed |
tests/test_echo.py::test_request_and_response_follow_the_contract | passed | passed |
tests/test_echo.py::test_speech_from_a_clone_is_marked_cloned | passed | passed |
tests/test_echo.py::test_speed_is_a_key_and_reaches_the_request | passed | passed |
tests/test_echo.py::test_unready_or_refusing_echo_raises_a_typed_error | passed | passed |
tests/test_echo.py::test_wav_output_and_s16_input | passed | passed |