Repository navigation
fix(recording): keep macOS recordings intact through output storage stalls - #2566
Open
richiemcilroy wants to merge 4 commits into
Open
richiemcilroy wants to merge 4 commits into
richiemcilroy wants to merge 4 commits into
Conversation
…lbacks off the writer lock
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
Author
|
hey @greptileai, please re-review the PR |
This branch was successfully deployed
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.
Fixes #2366
When the recording volume stops accepting writes for a while (slow SD card, external or network drive), macOS Studio and Instant recordings lost every video frame and most audio for the length of the stall. This moves file writes for those outputs onto per-output writer threads with a bounded in-memory buffer, so capture and encoding keep running while storage catches up.
flowchart LR subgraph Before A1["ScreenCaptureKit frames"] --> B1["m4s encoder thread: VideoToolbox encode + DASH write + manifest fsync"] C1["mic / system audio"] --> D1["tokio worker (mux-audio): AAC encode + write()"] B1 -- "blocks in write()" --> V1[("output volume")] D1 -- "blocks in write()" --> V1 end subgraph After A2["ScreenCaptureKit frames"] --> B2["m4s encoder thread: VideoToolbox encode"] B2 -- "packets" --> Q2[["byte-budgeted queue"]] Q2 --> W2["mux-writer-video: DASH write, segment events, manifests"] C2["mic / system audio"] --> D2["tokio worker (mux-audio): AAC encode"] D2 -- "packets" --> Q3[["byte-budgeted queue"]] Q3 --> W3["mux-writer-audio"] W2 --> V2[("output volume")] W3 --> V2 endRoot cause
crates/enc-ffmpeg/src/mux/segmented_stream.rs:380, called fromcrates/recording/src/output_pipeline/macos_fragmented_m4s.rs:417), and every segment boundary also writesmanifest.jsonwith twofsyncs (segmented_stream.rs:29-42). While a write blocks, the sample buffers already handed to the encoder channel (macos_fragmented_m4s.rs:287, filled at:511) stay retained, the capture surface pool (queue depth 8,crates/recording/src/sources/screen_capture/macos.rs:240) runs dry, and capture stops delivering. That is the "Wall-clock-confirmed forward jump" in the issue log.FragmentedAudioMuxer::send_audio_frame(crates/recording/src/output_pipeline/ffmpeg.rs:235) writes the file inline (crates/enc-ffmpeg/src/mux/fragmented_audio.rs:100) from themux-audiotask (crates/recording/src/output_pipeline/core.rs:3380,:4037). Each stalled audio track pins one tokio worker, the source channels fill, and the sources drop frames ("dropping frames due to full channel" plus inserted silence). With few free workers the runtime itself stops making progress.Change
crates/enc-ffmpeg/src/mux/write_behind.rs: a writer thread per output owns theAVFormatContext. Encoders hand packets through the existingPacketSinktrait (newqueue_frame_to/flush_toon the H264, AAC and Opus encoders). Packets are written in production order, so the bytes on disk are the same as inline writing.manifest.jsonwrites run on the writer thread, including the initial manifest, so the first-frame path no longerfsyncs.write_behindflag onOggMuxerConfig,FragmentedAudioMuxerConfigandDashSegmentedAudioMuxerConfigdefaults to off and is set withcfg!(target_os = "macos")at the Studio and Instant call sites. Video usesSegmentedVideoEncoder::init_write_behindfrom the macOS-only M4S muxers. Windows and Linux keep the inline write path.OggMuxernow takesOggMuxerConfiginstead of().Results
Stalls were reproduced with a
DYLD_INSERT_LIBRARIESinterposer that blockswrite,pwrite,writev,fsync,F_FULLFSYNC, write-modeopenandrenameunder the recording directory, driving a synthetic pipeline: 3024x1964 NV12 at 60 fps through the real VideoToolbox encoder and M4S muxer (capture pool of 8 buffers), plus 48 kHz mic and system audio through the real audio muxers. Each class ran as interleaved pairs, with main as the baseline. The A/V offset is measured from flash and click markers in the output files and includes a constant 21 ms AAC priming offset.180 s with a 20 s stall every 60 s (4 runs each)
Stop 12.5 s into a 20 s stall (4 runs each)
15 s recordings, no stall (20 runs main, 19 this PR)
60 s recordings, no stall (12 runs each)

Confidence Score: 5/5
The PR appears safe to merge; no blocking issues remain.Summary
The PR moves macOS recording writes onto dedicated threads with bounded packet buffers. The latest changes address both earlier findings:
Both earlier threads were manually resolved by
richiemcilroywithout explanatory replies. The current code addresses their reported causes. Neither thread supplied a Comment number, so neither appears inpreviousFindings.No new actionable issues were found. Checks were based on code inspection; no builds or runtime tests were run.
Reviews (2) · Last reviewed commit: "fix(enc-ffmpeg): bound write-behind fina..." · Reviewed by Greptile