Skip to content

fix(recording): stop Linux system audio from silently recording the microphone - #4495

Merged
richiemcilroy merged 15 commits into
CapSoftware:mainfrom
kyzer1023:fix/linux-audio-only-system-audio-loss
Nov 27, 2026
Merged

richiemcilroy merged 15 commits into
CapSoftware:mainfrom
kyzer1023:fix/linux-audio-only-system-audio-loss

Conversation

@kyzer1023

@kyzer1023 kyzer1023 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Why

On Linux with PipeWire (pipewire-pulse), unloading or losing the default output sink during an Audio Only recording causes PipeWire to silently reroute the system-audio capture stream onto the default input source (the hardware microphone) while leaving the stream open without erroring. That silently records the user's microphone into system_audio.m4a, or hangs the system-audio track when no output .monitor exists.

What changed

  • Detect when Linux system-audio capture is no longer attached to a sink .monitor source (crates/recording/src/sources/screen_capture/linux.rs, crates/recording/src/feeds/microphone.rs, crates/recording/src/sources/microphone.rs), dropping samples from non-monitor sources instead of writing microphone audio to the system track.
  • When another output .monitor exists (or returns within the 3 s reconnect grace window), move the capture stream back onto the active output .monitor and keep the recording running.
  • When no output .monitor returns within the 3 s grace window during an Audio Only take, end the system-audio track cleanly and save the recording with the microphone track intact (crates/recording/src/studio_recording.rs, apps/desktop-gpui/src/session.rs). Screen recordings and PulseAudio error-stream paths are unchanged.
  • Added unit tests in crates/recording/src/sources/screen_capture/linux/audio_only_null_sink_tests.rs and system_audio_channel_tests.rs.

Verification

Verified on Linux Mint 22.3 (PipeWire 1.0.5 / pipewire-pulse, XFCE/X11) with Audio Only + system audio On + hardware mic default On and a 440 Hz tone routed into a temporary cap_id8_null sink:

  1. Null sink unloaded while hardware .monitor exists: PipeWire briefly parked system-audio stream #1561 on the hardware mic (1174); within ~1 s Cap moved #1561 onto alsa_output.pci-0000_00_1f.3.analog-stereo.monitor (1173). Recording finished Complete (system_audio.m4a: 33.893 s, 48 kHz 2 ch AAC, 440 Hz throughout; audio-input.m4a: 33.899 s room noise; last-5 s system-vs-mic correlation 0.0084).
  2. Null sink unloaded and reloaded within 3 s grace (39 ms gap): Stream #7740 recovered onto the recreated cap_id8_null.monitor (10805). Recording finished Complete (system_audio.m4a: 26.623 s; audio-input.m4a: 26.645 s; post-recovery system-vs-mic correlation -0.0005).
  3. No remaining output .monitor (module-always-sink unloaded + card switched to input:analog-stereo): PipeWire moved stream #12473 onto the hardware mic -> Cap logged System audio capture is not on an output monitor source_output=12473, waited the grace window (3.08 s), logged Audio-only system audio ended before Stop track=SystemAudio and stopped/saved the recording cleanly (status: "Complete", audioOnly: true). system_audio.m4a ended cleanly at 15.730 s (440 Hz only, no mic bleed) while audio-input.m4a kept 18.588 s of mic audio.

Confidence Score: 5/5 · The latest change appears safe to merge; no new blocking issue was found.RetriggerView in GreptileConfidence Score: 5/5

The latest change appears safe to merge; no new blocking issue was found.

Summary

This PR protects Linux system audio from microphone reroutes and saves Audio Only recordings when the output monitor stays unavailable.

  • Linux system audio stays on an output monitor when routing changes.
  • Audio Only takes end cleanly when their system-audio monitor stays gone.

Reviews (8) · Last reviewed commit: "fix: write the microphone finish_capture..." · Reviewed by Greptile

kyzer1023 and others added 2 commits November 23, 2026 16:20
Audio-only system audio now ends its own track after the reconnect grace,
and the take saves with the microphone still in it. A monitor that returns
during the grace keeps the take running. Screen recordings are unchanged.

Co-authored-by: Kyzer  <kyzer1023@users.noreply.github.com>
PipeWire moves a capture onto the default source when its monitor
disappears, and the stream stays open. Treat a source that is not a
sink .monitor as a system-audio loss: drop those samples, move the
stream back onto the current output monitor when one exists, and
otherwise end the track after the reconnect grace. A stream that
errors still follows the existing PulseAudio path.

Co-authored-by: Kyzer  <kyzer1023@users.noreply.github.com>
@kyzer1023

Copy link
Copy Markdown
Contributor Author

@greptileai

@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@kyzer1023 is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

kyzer1023 added a commit to kyzer1023/Cap that referenced this pull request Nov 23, 2026
Windows and macOS builds no longer reference the Linux capture gate.
System-audio samples stay staged until a later pactl read still sees a
sink monitor; a microphone reroute drops every unconfirmed chunk. A
closed pactl subscribe waits out its backoff instead of spinning, and
the null-sink reload test checks the post-reload tone.

Co-authored-by: Kyzer  <kyzer1023@users.noreply.github.com>
@kyzer1023

Copy link
Copy Markdown
Contributor Author

@greptileai

kyzer1023 added a commit to kyzer1023/Cap that referenced this pull request Nov 23, 2026
Route checks start when the system-audio stream starts, so the startup
observer can receive a sample before Lock. Delayed chunks captured on a
monitor stay queued for the next check, while audio from before a
microphone reroute is still dropped. Stop waits for the held samples
to reach the muxer before the feed is killed. The Linux-only capture
epoch, route grace, and stop flag no longer fail Windows or macOS clippy.
@kyzer1023

Copy link
Copy Markdown
Contributor Author

@greptileai

kyzer1023 added a commit to kyzer1023/Cap that referenced this pull request Nov 24, 2026
Keep the system-audio route watcher, staging cutoff, and stop flush
alongside the microphone delivery clock and enqueue failure log.
A monitor device cpal lists by name never builds a PulseInputRoute, so its staged samples were never released and system-audio startup timed out. Snapshot that source output and start the route watcher before the stream is reported ready.
kyzer1023 added a commit to kyzer1023/Cap that referenced this pull request Nov 25, 2026
@richiemcilroy

Copy link
Copy Markdown
Member

hey @greptileai, please re-review the PR

@richiemcilroy

Copy link
Copy Markdown
Member

hey @greptileai, please re-review the PR

@richiemcilroy

Copy link
Copy Markdown
Member

hey @greptileai, please re-review the PR

@richiemcilroy
richiemcilroy merged commit c9fafab into CapSoftware:main Nov 27, 2026
76 of 78 checks passed
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