[Ops] Stream recording audio to disk instead of buffering whole sessions in RAM #82
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
PerUserPCMSink(bot/questboard_bot/cogs/recording.py:54) accumulates decoded 48kHz stereo PCM per user inio.BytesIObuffers (recording.py:75, allocated inwrite()atrecording.py:103). Silence is padded in so each speaker's buffer grows toward full session length regardless of how much they talk (recording.py:104-113). Buffers are only flushed at stop, wherebuf.getvalue()(recording.py:555) copies the entire buffer before writing the WAV (recording.py:556), doubling peak memory.Current behavior
48kHz × 2ch × 2 bytes ≈ 675 MB/hour/speaker. A 5-person, 6-hour session ≈ 20 GB resident — the bot OOMs long before the
max_recording_hours: int = 6cap (bot/questboard_bot/config.py:36) ever fires. A crash mid-recording also loses all audio, since nothing touches disk until stop.Fix / Spec
write(), stream each user's PCM incrementally to an on-disk WAV instead ofBytesIO:wave.Wave_writefor them in the session directory and write silence frames to align with session start (reusing the existing padding logic atrecording.py:104-113).writeframesthe packet data. DTX silence packets keep writing their one 20ms silence frame.getvalue(), no full-buffer copy anywhere._buffersdict /audio_dataaccessor (recording.py:172-173) or repoint them at the on-disk files, updating all consumers in the stop/upload path.Acceptance criteria
buf.getvalue()on session audio is gone).References
bot/questboard_bot/cogs/recording.py:54-173(sink, buffers, write path)bot/questboard_bot/cogs/recording.py:555-556(stop-path full copy)bot/questboard_bot/config.py:36(max_recording_hours)Filed from the July 2026 full-project review.