fix: avoid blocking audio writes#1613
Conversation
TTS responses were written synchronously from the async presentation pipeline, blocking concurrent requests. Offload byte writes to a worker thread and add a regression test that keeps the event loop responsive.
|
@Sanjays2402 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
Moves TTS response writes off the asyncio event loop so concurrent presentation requests are not stalled by synchronous file I/O.
Motivation and Context
Fixes #1603.
Screenshots
N/A
API Changes
Change Type
Testing Performed
Focused async regression test, Ruff check/format, and Python compilation pass.
Checklist
High-level PR Summary
This PR fixes a performance issue where synchronous file I/O operations for TTS audio responses were blocking the asyncio event loop, preventing concurrent presentation requests from being processed. The fix introduces a new utility function
write_bytesthat usesasyncio.to_threadto offload file writes to a thread pool, and replaces the blockingopen().write()call in the TTS chunk generation with this non-blocking alternative.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
surfsense_backend/app/utils/file_io.pysurfsense_backend/tests/unit/agents/video_presentation/test_file_io.pysurfsense_backend/app/agents/video_presentation/nodes.py