Skip to content

fix(vad): clamp cursor when resizing speech buffer - #7566

Open
gudcks0305 wants to merge 2 commits into
livekit:mainfrom
gudcks0305:codex/vad-shrink-buffer-cursor
Open

gudcks0305 wants to merge 2 commits into
livekit:mainfrom
gudcks0305:codex/vad-shrink-buffer-cursor

Conversation

@gudcks0305

@gudcks0305 gudcks0305 commented Oct 1, 2026 •

Copy link
Copy Markdown

Problem

Reducing max_buffered_speech or prefix_padding_duration while a VAD stream has buffered speech can shrink its sample array below its write cursor. The next speech event then raises ValueError: data length must be >= num_channels * samples_per_channel * sizeof(int16) and terminates the stream. Shrinking and immediately growing the buffer also leaves discarded samples counted as valid audio.

Change

Keep the cursor on the stream and clamp it when resizing the buffer, in both inference.VAD and the Silero plugin. Existing event emission, prefix retention, and reset paths use the same cursor. Add deterministic regressions for both options, buffer growth, shrink-then-grow, subsequent speech, and explicit reset.

Load the optional Silero plugin only for its fixture cases, so its absence does not prevent the bundled VAD regressions from running. Skip missing modules while allowing a general ImportError from a broken installed plugin to propagate.

Validation

  • Before the fix: 8 regression cases failed; 4 growth controls passed.
  • After the fix, with Silero installed: all 12 regression cases passed. They use synthetic PCM and mocked VAD predictions while exercising the real stream and rtc.AudioFrame buffer paths.
  • A process-local import-hook simulation of missing Silero: 6 bundled VAD cases passed and 6 Silero cases skipped. A simulated general ImportError propagated as 6 fixture errors with a nonzero exit status, while the 6 bundled cases still passed.
  • Related audio recognition, turn detection, and PCM buffer suites: 199 tests passed, including those regressions and local resampling tests.
  • Existing native VAD executor lifecycle test: passed.
  • Repository Ruff formatting/lint and focused mypy on both changed production modules: passed.

The local environment installed core Agents plus the Silero extra. Full --unit --audio_eot collection stopped at missing optional provider packages, and the project-wide type check was blocked by missing optional packages and typing stubs. Focused mypy checked the two changed production modules with --follow-imports=silent. No cloud/provider integration tests were run.

AI assistance was used to develop and test this change.

@gudcks0305
gudcks0305 requested a review from a team as a code owner October 1, 2026 09:47
@CLAassistant

CLAassistant commented Oct 1, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

This branch has not been deployed

No deployments
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.

2 participants