Skip to content

Fix OOM crash on file send: lazy chunk reads, single transmitter session, correct modem profile - #13

Merged
melbinjp merged 1 commit into
mainfrom
copilot/plan-audio-data-transfer-implementation
Apr 10, 2026
Merged

Fix OOM crash on file send: lazy chunk reads, single transmitter session, correct modem profile#13
melbinjp merged 1 commit into
mainfrom
copilot/plan-audio-data-transfer-implementation

Conversation

Copilot AI commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

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:

// Before: entire file in RAM
const fileBuffer = await this.file.arrayBuffer();

// After: one 4 KB slice at a time
const chunkBuffer = await this.file.slice(start, end).arrayBuffer();

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-robust runs at 250 samples/symbol (~50 bytes/sec), so a single 4096-byte application frame takes ~81 s of audio — well over the 30 s SEND_TIMEOUT_MS. Switched to audible-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 ScriptProcessorNode created per frame (quiet-modem.ts, sender-sm.ts)

Added TransmitterSession: one Quiet.transmitter is created for the whole transfer and reused across all frames via a mutable onFinishRef callback. The node is destroyed once after the final frame.

Supporting changes (framing.ts)

  • PAYLOAD_SIZE exported so sender-sm.ts can compute frame counts from file.size without reading file contents.
  • createFileDataFrameFromPayload() added — accepts an already-sliced buffer instead of requiring the full file.

…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>
@melbinjp
melbinjp marked this pull request as ready for review April 10, 2026 15:07
@melbinjp
melbinjp merged commit 1b7207d into main Apr 10, 2026
1 check passed
@melbinjp
melbinjp deleted the copilot/plan-audio-data-transfer-implementation branch April 10, 2026 15:07
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