← Back to Pull requests

fix(vad): ignore empty audio chunks instead of crashing #854

Merged
CJstate merged 3 files (58 lines) on Dec 02, 2026 21:25 UTC
View on GitHub
CJstate CJstate commented on Nov 19, 2026 09:13 UTC
Author

Hardening: VADHandler.process now drops a zero-length PCM chunk instead of
crashing the VAD thread.

Before this change an empty chunk reached int2float, whose .max() raises
ValueError: zero-size array to reduction operation maximum which has no
identity
. No current producer sends one: every VAD input goes through
append_pcm (api/openai_realtime/handlers/audio.py), which only forwards full
512-sample chunks. So this is defensive, not a fix for an observed crash.

Changes:

  • VAD/vad_handler.py: the fix. Return early on an empty chunk, before the

  • chunk/sample counters and the VAD model call.
  • utils/utils.py: defence in depth. np.abs(sound).max(initial=0) makes

  • int2float return an empty float32 array for empty input. Non-empty input is
    unchanged (abs_max is still the true peak).
  • tests/test_int2float_empty.py: covers both. Both tests fail on main and

  • pass with this change.

    Out of scope: an odd-length buffer still raises in np.frombuffer; no current
    producer sends one.

    Validation:

  • pytest tests/test_int2float_empty.py tests/test_vad_iterator.py tests/test_vad_session_reset.py tests/test_vad_model_state.py tests/test_vad_confident_turn_opening.py tests/test_speculative_turns.py: 156 passed (PR merged with current main)
  • Diff: 58 lines (+56 / -2) across 3 files Reviewer: andimarafioti Review duration: 19451m
    All Vouch review confidence checks passed
    Residual risk 0.11 = Change Risk (0.35) × (1 − Review Confidence (0.69)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.35 · 58 lines diff across 3 files
    0.35
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.35 · 1 substantive comment(s)
    0.35
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    69%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.244
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    3 items
    1AbdullahButt 1AbdullahButt commented on Nov 25, 2026 17:06 UTC
    Reviewer

    Looks correct to me. The guard in VADHandler.process is in the right place, and the int2float change is harmless.

    I ran this in Docker (python:3.11, CPU torch): tests/test_int2float_empty.py, tests/test_vad_iterator.py, tests/test_vad_session_reset.py, tests/test_vad_model_state.py, tests/test_vad_confident_turn_opening.py and tests/test_speculative_turns.py. All 139 pass on the PR head.

    Two notes, neither blocking.

    First, the size check at VAD/vad_handler.py:630 now covers the only caller of int2float. So the max(initial=0) change at utils/utils.py:133 is purely defensive. It doesn't hurt, but the PR text describes it as the fix.

    Second, I couldn't find a path that sends an empty chunk today. The realtime transport splits audio in append_pcm (api/openai_realtime/handlers/audio.py:329-336), and that only forwards full 512-sample chunks. Everything shorter stays in audio_remainder. If you have a concrete trigger (a client, or the local audio streamer), naming it in the description would help a reviewer judge whether this is a bug fix or hardening. If the goal is hardening, an odd-length chunk is the next thing that would crash the same line: np.frombuffer(b"\x00", dtype=np.int16) raises ValueError. The realtime path never produces one, because its chunks are always CHUNK_SIZE_BYTES. Any other producer could.

    andimarafioti andimarafioti approved these changes on Dec 02, 2026 21:25 UTC
    Approved Reviewer
    Reviewers
    Assignees
    CJstate CJstate
    Labels
    risk: low confidence: 69% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 35.3% (MEDIUM) · Higher = larger blast radius
    35.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 69% · Lower = rushed or shallow review
    69%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 10.9% · Safe to merge
    10.9%