Repository navigation
fix(codec): stream all streamable Blobs, not just files ≥500 MB - #51
Merged
Merged
Conversation
A 45.5 MB MP3 (a long recording) failed at [decoding-studio-audio] with "Array buffer allocation failed" / "Unable to decode audio data". Root cause: the resolver only used the memory-safe streaming decoder above a 500 MB *file-size* gate. A long MP3 stays below that gate but expands to ~1 GB of PCM, OOMing the whole-file decodeAudioData + ffmpeg.wasm paths. Route by capability instead of size: any Blob that sniffs as mp3/mp4/wav streams regardless of size; ArrayBuffer sources and non-streamable containers (ogg/flac/opus) keep the whole-file path. Streaming failures on sub-ceiling files fall back to whole-file; the streaming reason is chained into the combined error. STREAMING_THRESHOLD is repurposed as the fallback ceiling. Verified: a 30-min MP3 decodes via streaming (1800s, 39.7M samples); new routing tests assert streamable Blobs emit sub-progress (streaming) while ArrayBuffer sources don't (whole-file). All 36 codec browser tests green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Audio decode routing in
codec/index.tsis now capability-based instead of size-based:Blob/Filethat sniffs as mp3 / mp4 / wav → streaming decoder, regardless of file size.ArrayBuffersources and non-streamable containers (ogg/flac/opus) → whole-file path (decodeAudioData→ ffmpeg.wasm), unchanged.STREAMING_THRESHOLDis repurposed from "stream above this" to "fallback ceiling."Only one production file changed.
Why
A tester hit a hard failure at
[decoding-studio-audio]with a 45.5 MB MP3:Root cause: the resolver only routed to the memory-safe streaming decoder above a 500 MB file-size gate. A long MP3 stays below that gate but expands ~10–25× when decoded — a ~40 min file becomes ~1 GB of PCM, OOMing both whole-file backends. Compressed file size is the wrong proxy; duration drives memory. Streaming reads in 4 MiB batches and keeps memory bounded.
Reviewer notes
AudioDecoder) instead ofdecodeAudioData. Those decoders were already exercised by the ≥500 MB path and have browser tests, but this is the main risk surface.Blob/File(or aBlob|ArrayBufferunion the new logic handles); no caller changes needed.runStreamingDecodestill sniffs internally (trivial 16-byte re-read) to preserve theforceBackend: "streaming""not streamable" error.Testing
tsc --noEmitclean.ArrayBuffersource emits only 0/1 (proves whole-file path). Both rely on the fact streaming and whole-file both reportbackend: "webcodecs", so progress shape is the distinguishing signal.🤖 Generated with Claude Code