Skip to content

fix(rtc): return no frames from AudioResampler.flush() when nothing is buffered - #938

Open
ANDROIDHASSAN wants to merge 1 commit into
livekit:mainfrom
ANDROIDHASSAN:fix/resampler-flush-empty
Open

ANDROIDHASSAN wants to merge 1 commit into
livekit:mainfrom
ANDROIDHASSAN:fix/resampler-flush-empty

Conversation

@ANDROIDHASSAN

Copy link
Copy Markdown
Contributor

Problem: AudioResampler.flush() returns [AudioFrame(samples_per_channel=0)] instead of [] when nothing is buffered, both on a fresh resampler and on a second flush. The docstring says "The list may be empty if no output data remains". The FFI flush reply sets output_ptr to the (non-null) buffer address even when size is 0, so the if not output_ptr check never matches. push() gets ptr 0 for empty output, so it is not affected.

Callers that forward flushed frames, such as RecognizeStream.flush() in livekit-agents, then pass a 0-sample frame on to the provider.

Fix: check size instead of output_ptr. One line.

Tests: test_flush_with_nothing_buffered_returns_no_frames in tests/rtc/test_resampler.py. Run against livekit-rtc 1.2.1's FFI library:

  • on main it fails: Left contains one more item: rtc.AudioFrame(sample_rate=16000, num_channels=1, samples_per_channel=0, ...). A fresh flush and a second flush both return the empty frame.
  • with the fix it passes. A flush right after a push still returns the buffered tail.

ruff check and ruff format --check pass on both files. Includes a livekit-rtc patch changeset.

Scope: flush() still does not read the reply's error field the way push() does. That path can't be reached from a test, so it is left out. The non-null pointer for empty output comes from the Rust side; this change only makes the Python check match the length it actually reads.

…s buffered

The FFI flush reply carries a non-zero output_ptr with size 0 when the resampler has no data left, so the ptr check never matched and flush() returned one 0-sample frame. Check the size instead, as the docstring promises an empty list.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T14:14:04.970455Z 2814aae PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

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.

1 participant