Skip to content

fix: avoid blocking audio writes#1613

Merged
MODSetter merged 1 commit into
MODSetter:devfrom
Sanjays2402:fix/nonblocking-audio-write
Jul 19, 2026
Merged

fix: avoid blocking audio writes#1613
MODSetter merged 1 commit into
MODSetter:devfrom
Sanjays2402:fix/nonblocking-audio-write

Conversation

@Sanjays2402

@Sanjays2402 Sanjays2402 commented Jul 19, 2026

Copy link
Copy Markdown

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

  • This PR includes API changes

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation
  • Dependency/Build system
  • Breaking change
  • Other (specify):

Testing Performed

  • Tested locally
  • Manual/QA verification

Focused async regression test, Ruff check/format, and Python compilation pass.

Checklist

  • Follows project coding standards and conventions
  • Documentation updated as needed
  • Dependencies updated as needed
  • No lint/build errors or new warnings
  • All relevant tests are passing

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_bytes that uses asyncio.to_thread to offload file writes to a thread pool, and replaces the blocking open().write() call in the TTS chunk generation with this non-blocking alternative.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_backend/app/utils/file_io.py
2 surfsense_backend/tests/unit/agents/video_presentation/test_file_io.py
3 surfsense_backend/app/agents/video_presentation/nodes.py

Need help? Join our Discord

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.
@vercel

vercel Bot commented Jul 19, 2026

Copy link
Copy Markdown

@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.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 96dd5aa5-86ae-47da-9053-d2d2d78551b9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@MODSetter
MODSetter merged commit 2eed9b2 into MODSetter:dev Jul 19, 2026
1 of 3 checks passed
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