Fix OOM crash on file send: lazy chunk reads, single transmitter session, correct modem profile - #13
Merged
Conversation
…n, correct modem profile/timeout Agent-Logs-Url: https://github.com/melbinjp/audio_data_transfer/sessions/cbfb09ec-6398-45b5-9ce5-40f3b5e7dc5e Co-authored-by: melbinjp <91303803+melbinjp@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
melbinjp
April 10, 2026 15:06
View session
melbinjp
marked this pull request as ready for review
April 10, 2026 15:07
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.
Sending any non-trivial file caused an immediate out-of-memory crash, followed by transmission timeouts on every frame even if memory was sufficient.
Root causes & fixes
1. OOM — full file loaded into memory before transmission (
sender-sm.ts)file.arrayBuffer()was called on the entire file upfront. Replaced with per-frame lazy reads:Peak memory is now O(1 frame) regardless of file size.
2. Timeout — wrong modem profile made every frame exceed the deadline (
quiet-modem.ts)audible-fsk-robustruns at 250 samples/symbol (~50 bytes/sec), so a single 4096-byte application frame takes ~81 s of audio — well over the 30 sSEND_TIMEOUT_MS. Switched toaudible-fsk(50 samples/symbol, ~250 bytes/sec, ~16 s/frame) and raised the timeout to 60 s for a 3.7× margin.3. Transmitter churn — new
ScriptProcessorNodecreated per frame (quiet-modem.ts,sender-sm.ts)Added
TransmitterSession: oneQuiet.transmitteris created for the whole transfer and reused across all frames via a mutableonFinishRefcallback. The node is destroyed once after the final frame.Supporting changes (
framing.ts)PAYLOAD_SIZEexported sosender-sm.tscan compute frame counts fromfile.sizewithout reading file contents.createFileDataFrameFromPayload()added — accepts an already-sliced buffer instead of requiring the full file.