← Back to Pull requests

Bound HTTP STT windows while preserving long user turns #723

Merged
andimarafioti merged 10 files (745 lines) on Oct 19, 2026 11:38 UTC
View on GitHub
andimarafioti andimarafioti commented on Oct 15, 2026 14:09 UTC
Author

Fixes #655.

Long or repeatedly reopened user turns currently submit cumulative WAVs to the HTTP STT backend. Qwen3-ASR served by vLLM can reject those uploads at its configurable duration/file-size limits; progressive updates also repeatedly decode the completed prefix.

Add opt-in --openai_stt_max_window_s 120 (also available in configured STT blocks). Completed windows retain their text across revisions, and the tail remains revisable. VAD exposes a backend-independent cadence for cumulative progressive audio snapshots, including when live captions are disabled. The current pipeline enables that capability for this HTTP backend; downstream STT owns slicing and caching. The final transcript still uses the existing conversational-turn and response-admission path. Leaving the option unset preserves current uploads.

Cuts select the quietest 100 ms frame midpoint in the five seconds before the cap. They remain bounded without silence, cover every sample, and use no overlap or text deduplication. This follows the investigated two-minute direction without requiring unavailable timestamps. Changed audio/language invalidates cached text; existing cancellation/session fences guard commits and outputs. Known HTTP duration/file-size rejections now provide fixed, sanitized guidance.

The VAD snapshot contract documents the input-sample cadence, cumulative audio, continued capture, and final-prefix caveat. Held short fragments can be added only at finalization, so consumers must handle changed audio rather than assume every snapshot is an exact final prefix. The existing snapshot test now lives in a VAD test module; backend-specific upload/cache assertions stay in the HTTP STT tests.

Scope excludes streaming transports (#536/#537), aligners, global inference scheduling, and a total VAD-memory cap. Quiet points are not guaranteed word boundaries; recognition errors and server backlogs remain possible.

Validation performed locally:

  • Original failure and correction through an actual multipart HTTP server with a deliberately small request limit; exact PCM sample coverage and complete assembled transcript.

  • Regression cases for 601-second input, repeated reopenings, continuous speech, captions disabled, changed language/audio, middle-window failure, cancellation/late completion, session reuse, turn identity, and configuration wiring.

  • Minimal test relocation: 42 lines added in the VAD test module versus 45 removed from the OpenAI test module, reusing the existing VAD helpers. Original VAD assertions are preserved; the removed OpenAI-consumer assertions are already covered by the existing background-window test. No new fixture or additional cases. 106 focused VAD/configuration/HTTP-window tests passed on the documentation/help trim, and Ruff lint/format and whitespace checks pass. Full-suite results for the final commit are supplied separately by the CI matrix below.

  • GitHub CI runs the stock Agents SDK WebSocket/WebRTC compatibility, packaging, and Linux/macOS ARM64 installation checks in addition to lint, types, and the complete Python suite.

  • Actual Qwen3-ASR-1.7B BF16 recognition comparison: 19m27s of real speech, three speakers, 3,046 normalized reference words, 86 distinct inference calls. Pooled WER: fixed 30s 0.89%, fixed 60s 0.69%, fixed 120s 0.66%, fixed 240s/uncut 0.59%, quiet-cut 120s 0.53%. Only two word edits separate quiet 120s from uncut; this is a small English audiobook pilot, not an optimality claim. Quiet cuts helped two speakers and did not help the harder recording.

  • - Settings: MLX Audio 0.4.7, greedy English decoding, independent requests without carried text, and no internal model chunking. WER used Whisper's English normalizer and spelling map, checked with jiwer 4.0.0.
    - Model mlx-community/Qwen3-ASR-1.7B-bf16@e1f6c266914abc5a46e8756e02580f834a6cf8a7. Dataset mirror ilyakam/librispeech-long@a5bb3ef1a678743ef6c6d1014f8f731d8c56c5e7 (LibriSpeech-Long). Test IDs: 1089-134686-0000 through 0002 joined in order (11m41s, the longest input), 1188-133604-0000, and test-other 1688-142285-0000.
    - This pilot does not describe recognition quality on vLLM. vLLM 0.28.0 splits Qwen3-ASR audio longer than 30 s into chunks itself (max_audio_clip_s is the model's chunk_length, which is 30). On vLLM, the client cap therefore bounds request size and repeated work, not the recognition chunk length.
  • Production HTTP handler replay against the real local Qwen model: the 701.2s recording used six requests of 116.05/119.45/117.55/117.95/117.85/112.35s, byte-exact decoded PCM coverage, no background captions, one complete final transcript; WER 5/1,820 = 0.275%. Local MLX implementation, not vLLM.

  • Controlled actual-handler work comparison at 60/180/601s and 1/4 concurrent users: at 601s with 120s cumulative caption snapshots, submitted audio per user dropped from 2,401s to 675.25s; outstanding final audio from 601s to 25.75s. With captions disabled, bounded processing submitted exactly 601s. These use a deterministic operation stub and measure audio work/routing, not model throughput or latency.
  • Compatibility assessment uses OpenAI's multipart transcription contract, vLLM 0.28 service limits, and duration validation. No Realtime event, WebRTC/RTP, codec, or item-identity change. Local browser checks supplement source inspection; tests alone are not protocol proof.

    Deployment vLLM throughput and speech-paced end-of-turn latency are unverified. The measured improvement is bounded upload size and less repeated completed audio; no production latency or capacity claim is made. Total VAD audio memory remains cumulative.

    Fresh independent review of the documentation trim recommended approve, with no actionable blockers or approval-blocking evidence gaps. It found the remaining guide additions useful and proportionate, and confirmed changes were limited to prose, docstrings/comments, and help metadata. The reviewer independently passed 138 tests with four loopback HTTP tests deselected; the implementing-agent 106-test run above included loopback. No new tests, fixtures, runtime logic, or protocol behavior were added.

    CI for the documentation trim passed all 17 jobs, including full Python 3.11–3.14 tests, Linux/macOS installation, lint, types, packaging, and Agents SDK compatibility. These are CI results, separate from the local checks above.

    Diff: 745 lines (+722 / -23) across 10 files Reviewer: jackboyla Review duration: 5608m
    All Vouch review confidence checks passed
    Residual risk 0.12 = Change Risk (0.61) × (1 − Review Confidence (0.80)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.61 · 745 lines diff across 10 files
    0.61
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.69 · 4 substantive comment(s)
    0.69
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    79%
    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.396
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    7 items
    andimarafioti andimarafioti commented on Oct 15, 2026 18:23 UTC
    Author

    @jackboyla do you want to review this one?

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 15, 2026 18:26 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟢 Approval recommended

    No blocking issues were identified in windowing, cache invalidation, configuration wiring, or cancellation and session safeguards.

    0 open findings

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    Adds opt-in bounded HTTP transcription windows to handle long user turns without changing conversational boundaries or default uploads.

    Changes:

  • Retains completed-window transcripts while keeping the tail revisable.

  • Adds internal VAD snapshots, configuration wiring, and sanitized backend rejection guidance.

  • Documents limitations and adds windowing, lifecycle, HTTP, and configuration regression tests.
  • | File | Description |
    | ---- | ----------- |
    | tests/​test_openai_stt_windows.py | Tests bounded requests, transcript preservation, and lifecycle safeguards. |
    | tests/​test_openai_stt_handler.py | Tests sanitized backend rejection messages. |
    | tests/​test_backend_registry.py | Tests window configuration wiring. |
    | src/​speech_to_speech/​VAD/​vad_handler.py | Supplies internal snapshots independently of captions. |
    | src/​speech_to_speech/​STT/​openai_compatible_handler.py | Implements bounded windows, prefix caching, and rejection guidance. |
    | src/​speech_to_speech/​s2s_pipeline.py | Connects window settings to VAD and STT. |
    | src/​speech_to_speech/​arguments_classes/​openai_stt_arguments.py | Adds the optional window-duration argument. |
    | docs/​openai-compatible-stt.md | Explains configuration, behavior, and limitations. |
    </details>

    🧠 Review effort: Balanced

    ---

    💡 <a href="/huggingface/speech-to-speech/new/main?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>

    jackboyla jackboyla commented on Oct 16, 2026 07:44 UTC
    Contributor

    @jackboyla do you want to review this one?

    taking a look now 👀

    jackboyla jackboyla commented on code on Oct 16, 2026 08:04 UTC
    Code Review
    src/speech_to_speech/STT/openai_compatible_handler.py:1
    @@ -413,6 +464,105 @@ def _run_request(self, request: _TranscriptionRequest) -> None:
                     elapsed,
                 )
     
    +    def _transcribe_audio(
    +        self, request: _TranscriptionRequest, audio: np.ndarray, selected: str | None = None
    +    ) -> HttpTranscriptionResult:
    +        if selected is None:
    +            operation = self._make_operation(audio)
    +        else:
    +            operation = self._make_operation(
    +                audio, language=None if selected == "auto" else selected, use_setup_language=False
    +            )
    +        with self._request_lock:
    +            request.operation = operation
    +            if not self._request_is_current(request):
    +                operation.cancel("superseded")
    +                raise TranscriptionRequestCancelled("superseded")
    +        return operation.run(cancel_check=lambda: not self._request_is_current(request))
    +
    +    @staticmethod
    +    def _audio_fingerprint(audio: np.ndarray) -> bytes:
    +        return hashlib.sha256(memoryview(np.ascontiguousarray(audio)).cast("B")).digest()

    nit: keeps mypy happy on py310 and py311 with the same hashes

            return hashlib.sha256(np.ascontiguousarray(audio).data.cast("B")).digest()
    

    jackboyla jackboyla approved these changes on Oct 16, 2026 15:41 UTC
    Approved Reviewer

    Approved these changes.

    jackboyla jackboyla commented on Oct 16, 2026 15:43 UTC
    Contributor

    looks sound in the normal pipeline. i don't have any issues apart from the nit above

    92 stt tests and both type targets pass with the suggestion

    Reviewers
    Assignees
    andimarafioti andimarafioti
    Labels
    risk: low confidence: 79.9% 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: 60.8% (MEDIUM) · Higher = larger blast radius
    60.8%
    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: 79.9% · Lower = rushed or shallow review
    79.9%
    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: 12.2% · Safe to merge
    12.2%