Skip to content

fix: avoid blocking audio format probes - #10055

Open
zzz27578 wants to merge 1 commit into
AstrBotDevs:masterfrom
zzz27578:fix/nonblocking-audio-probe
Open

fix: avoid blocking audio format probes#10055
zzz27578 wants to merge 1 commit into
AstrBotDevs:masterfrom
zzz27578:fix/nonblocking-audio-probe

Conversation

@zzz27578

@zzz27578 zzz27578 commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • run the synchronous audio magic-byte probe in asyncio.to_thread so audio conversion does not block the event loop
  • preserve the no-op fast path for Ogg Opus input requested as Ogg
  • add regression coverage for the asynchronous probe and Ogg/Opus fast path

Context

Follow-up to #9329. The current master includes the file-content check from #9612, but the probe still performs synchronous file I/O inside convert_audio_format, and Ogg Opus files are needlessly re-encoded when Ogg output is requested. This PR keeps the correctness fix on the latest master while addressing those remaining cases.

Validation

Per request, local tests were not run.

Summary by Sourcery

Keep audio conversion responsive by offloading format probes and preserving compatible Ogg Opus inputs.

Bug Fixes:

  • Prevent synchronous audio format detection from blocking the asyncio event loop.
  • Avoid unnecessary re-encoding when Ogg Opus input is requested as Ogg.

Tests:

  • Add regression coverage for asynchronous audio probing and the Ogg Opus no-op path.

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@kilisamemarisaaa kilisamemarisaaa left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Independent validation at e871599 on Windows:

  • pytest tests/test_media_utils.py -q: 55 passed (one audioop deprecation warning).
  • Ruff check and format --check on both changed files: passed.
  • Added a local diagnostic wrapper around the real _get_audio_magic_type recording threading.get_ident(), without replacing asyncio.to_thread. The off-loop-thread assertion fails on base 7ec39bd and the off-loop-thread assertion passes on this head (1 test). The wrapper still invokes the original detector on a WAV fixture.

This confirms actual thread offloading in addition to the new mocked-call unit test. The existing Ogg/Opus no-subprocess regression also passes as part of the 55 tests. Scope: media utility tests and the probe thread boundary, not a full-suite/real-codec integration run or a claim that every filesystem operation in the helper is asynchronous.

@zzz27578

Copy link
Copy Markdown
Contributor Author

@kilisamemarisaaa Thanks for the independent validation. The targeted media tests and Ruff checks passing, together with the real thread-ID check, confirm that the magic-byte probe is actually offloaded from the event-loop thread and that the Ogg/Opus fast path remains intact. No code changes are needed from this review.

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