Skip to content

Audio: keep PyAV decoding working on PyAV 19, and stop the tests needing an AMR encoder - #12295

Merged
danielhanchen merged 2 commits into
mainfrom
fix/amr-fixture-without-encoder
Sep 30, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix/amr-fixture-without-encoder

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Summary

PyAV 19.0.0 was released on 2026-09-29 at 17:46 UTC. Within 15 minutes, (Python 3.13, l-r) went red: five tests in test_llama_audio_attachment_container.py failed with UnknownCodecError: amr_nb. Underneath that is a product break that affects real users.

Two problems

1. Product: every PyAV decode fails on PyAV 19.

PyAV 19 removed the metadata_errors keyword from av.open(). Four call sites pass it, and each one now raises TypeError before reading anything:

  • studio/backend/routes/inference.py (chat audio attachments: wma, amr, m4a and the rest PyAV handles)
  • studio/backend/core/inference/stt_sidecar.py (speech to text)
  • studio/backend/utils/datasets/audio_decode.py (audio datasets in Studio)
  • unsloth/import_fixes.py (the library's torchcodec-free audio dataset fallback)

Who is exposed:

  • unsloth itself (av>=12.3.0) and Windows ARM64 Studio (av>=17.0.0) resolve to 19.0.0 today.
  • Other Studio installs pin av==15.1.0 and are not affected yet.

On main with PyAV 19, seven STT sidecar tests that decode through real PyAV fail too, alongside the five above.

2. Tests: the AMR fixture needs an encoder PyAV 19 no longer ships.

The 19.0.0 wheels still decode AMR-NB and AMR-WB but have no AMR encoder. _encode_amr() built its fixture with add_stream("amr_nb"), so the test failed before reaching the decoder it exists to check.

3. Tests: the WebM export check relied on AAC padding.

test_video_gallery.py::test_webm_export_keeps_the_audio_track asserted at least 48000 decoded samples after exporting a 1 s clip. PyAV 18 decoded that 1 s AAC fixture with its encoder padding (45056 samples at 44.1 kHz); PyAV 19 trims it to the true 44100. With the padding gone, a correct export decodes to 47983, and the flat floor fails. The exporter is unchanged and correct.

The test now compares against the decoded source's duration, allowing one 20 ms Opus frame (960 samples) for resampling and framing at the edges. A mute or truncated track still fails by a wide margin. test_video_gallery.py passes on PyAV 19.0.0, 18.1.0 and 15.1.0.

Changes

  • A small _av_open(av, source) helper at each site (_audio_av_open in import_fixes.py, which mirrors Studio's copy). It passes metadata_errors = "ignore" as before. If PyAV rejects that keyword by name, it retries without it; any other TypeError still propagates. The retry spells format = None, which is PyAV's default (probe the container), so test_text_io_encoding.py does not read it as Path.open().
  • tests/test_datasets_audio_fallback.py: the library/Studio drift check now covers the new helper pair as well.
  • The AMR fixture is now a stored 678-byte clip: the same 0.4 s 440 Hz tone, encoded once with PyAV 18.1.0. The decode tests keep exercising the real PyAV decoder on any version.
  • Three unit tests for the helper with a fake av:
    • retries when the keyword is rejected;
    • makes one call when it is accepted;
    • does not swallow an unrelated TypeError.

Testing

Studio audio, STT and text-encoding suites (tests/*audio*, tests/*stt*, tests/test_text_io_encoding.py):

PyAV main this branch
19.0.0 12 failures (5 AMR fixture, 7 STT sidecar decode) no failures beyond main's environment-only ones
15.1.0 passes passes
  • test_llama_audio_attachment_container.py: 61 passed on PyAV 19.0.0, 18.1.0 and 15.1.0.
  • tests/test_datasets_audio_fallback.py: 15 passed. Changing one character in only the library copy of the helper fails the drift check.
  • PyAV 19.0.0 decodes the stored clip (3360 samples at 8 kHz), and av.open(..., format = None) works on both 15.1.0 and 19.0.0.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-30T03:44:23.345495Z 01d6fe6 Manual request
ℹ️ 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.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 30, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 01d6fe6dff

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen danielhanchen self-assigned this Sep 30, 2026
@danielhanchen
danielhanchen merged commit 8c5e833 into main Sep 30, 2026
62 of 69 checks passed
@danielhanchen
danielhanchen deleted the fix/amr-fixture-without-encoder branch September 30, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant