Repository navigation
fix(recording): stop and save a macOS recording when its capture source goes away - #4240
Open
richiemcilroy wants to merge 17 commits into
Open
richiemcilroy wants to merge 17 commits into
richiemcilroy wants to merge 17 commits into
Conversation
|
Sandchest reviewed Sandchest reviews every change for vulnerabilities an attacker could use · 2 credits · Review details |
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
… window-close check
Member
Author
|
@greptileai review |
Member
Author
|
@greptileai review |
Member
Author
|
@greptileai review |
Member
Author
|
@greptileai review |
Member
Author
|
@greptileai review |
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.

On macOS, a recording whose capture source goes away (the display sleeps or is unplugged, the lid closes on the recorded display, the recorded window closes, sharing is stopped from the menu bar) now stops on its own and is saved like a normal Stop. Before, a Studio recording kept counting while capturing nothing, and a stream that stopped with any other error could leave Stop, Pause and Quit stuck until a force quit (#3578).
Root cause
flowchart LR A[SCK didStopWithError -3815] --> B[screen pipeline ends cleanly] B --> C[mic, camera, system audio cancelled] B -.Studio: Ok never reported.-> D[session still Recording, timer counts] B -.Instant: Ok reported.-> E[session: 'Recording ended unexpectedly', upload aborted] F[SCK didStopWithError, other code] --> G[capturer still marked started] G --> H[Stop calls stop on a dead stream, fails] H --> I[Stop unconfirmed, Pause and Quit refused]SCStreamErrorNoCaptureSource(-3815) end the screen pipeline cleanly. On macOS the Studio track watcher (spawn_watcher,studio_recording.rs) only forwards errors, so a screen track that ends withOkbefore Stop never resolves the recording'sdone_fut. The session never learns that capture ended and keeps showing a live recording.done_futwithOk, but the session treats any completion before Stop as a failure (monitor_recording_failure,session.rs), so the recording is kept as failed files and its upload is aborted.didStopWithErrorcode the monitors inscreen_capture/macos.rsreturn an error without marking the capturer stopped. Stop then callsstopStreamon a stream that is already gone, getsFailed to stop a stream that is already stopped, and reports cleanup as unconfirmed: the stuck Stop/Pause/Quit state in macOS: sleep during Studio recording leaves controls in zombie state — pause/stop rejected, app refuses to quit #3578.What changed
studio_recording.rs: on macOS, when the required screen track ends cleanly before Stop, the watcher resolves the recording's completion withOk. The pipeline'sstoppingflag (already used on Windows and Linux) now exists on macOS too, so a Pause or Stop, which set it first, never counts as the source going away.session.rs: on macOS a completion that isOkbefore Stop means the source went away. The session runs the normal Stop (capture_source_lost), so Studio finalizes into an openable project and Instant finalizesoutput.mp4and queues its upload. Errors still take the existing failed-recording path.main_window.rs+ locales: after such a stop the main window shows the same warning prompt the low-storage stop uses, titled "Recording stopped": "Cap stopped recording because what it was capturing went away, for example the display went to sleep or the window closed. Everything recorded up to then was saved." Translated in all seven catalogs.screen_capture/macos.rs, closed window: a focused-window capture uses a window filter, and ScreenCaptureKit keeps that stream running after the window closes or its app quits; it just stops sending frames. The capture monitor now checks once a second whether the window server still lists the recorded window (a minimized, hidden or off-Space window is still listed). After two missed checks it reportsCaptureTargetLostand ends the pipeline cleanly, so the recording is stopped and saved as above. The watcher only arms when the stream really uses a window filter (the samecapturable_windowcheck start and restart use), which only happens in the Focused window capture style and never for a window excluded from recordings, which is recorded as a display crop; the default Screen region style records a display crop that keeps capturing real pixels after the window closes, so nothing is lost there.screen_capture/macos.rs: anydidStopWithErrormarks the capturer stopped before the monitor exits (video and system audio), because the delegate is only called once the stream has stopped. A real failure is still reported as a failure, but Stop now confirms and keeps the media.Sleep vs stop
System sleep already pauses a running Studio recording before the Mac sleeps, and stops and saves an Instant one (#3702,
power.rs). That stays. Display sleep, display unplug, lid close with an external display and window close do not go through the system power notification, and afterwards the target may not exist, so the recording is stopped and saved rather than paused.Callers checked
ActorHandle::done_fut(Studio): thesession.rsfailure monitor andapps/cli/src/record.rsfinalize. The CLI now finalizes a Studio recording when its display sleeps instead of waiting for the stop trigger, as it already did for Instant.Pipeline::stopping: set inPipeline::stopbefore any track stops, on every platform. The Windows and Linux watcher branch is untouched.Capturer::mark_stopped: only makesCapturer::stopa no-op for a stream that has already stopped.sleep_action/prepare_for_sleep: unchanged.Tests
macos_screen_capture_ending_before_stop_completes_the_recording,macos_pause_or_stop_does_not_complete_the_recording(studio_recording.rs).a_capture_that_ends_cleanly_before_stop_is_saved_not_failed(session.rs), new strings indialogs_surface_tests.rs.a_window_the_window_server_does_not_list_counts_as_closed,only_a_window_filter_is_watched_for_its_window_closing(screen_capture/macos.rs).real_app_recorded_window_closing_ends_the_recording_with_its_media(Instant reliability workflow, real app): records a TextEdit document window in Focused window style in both modes, opens it in a TextEdit instance of its own and ends only that instance (a scripted close needs Automation consent, which CI cannot give), and requires the recording to stop and save on its own with sealed media.real_app_display_sleep_ends_the_recording_with_its_media(Instant reliability workflow, real app,pmset displaysleepnow) now also requires both modes to stop and save on their own (recording finished, norecording pipeline failed).Proof
All on GitHub-hosted macOS 15 runners (Apple silicon), debug build of this branch, real ScreenCaptureKit with BlackHole as the audio device.
av-sync-checkon the finalized file. "Lost" closes the window mid-recording; "Stop" is a normal Stop. Offset is video minus audio, mean and standard deviation over 22 flash/click pairs; drift is the slope across the recording.A recording finalized after its window closed is within 2 ms of main's offset in both modes, and the logs show the source-lost stop with no pipeline failure.
pmset sleepnow(error 0xe00002e2). The sleep handling itself is unchanged and covered bysleep_pauses_running_studio_and_stops_every_live_instant_recording.

Confidence Score: 5/5
The PR appears safe to merge; the latest change fixes the early stop for excluded windows.Summary
macOS recordings now stop and save when their capture source disappears. The latest change keeps the window-close watcher off display crops.
All three previous threads are addressed. None supplied a comment number, so
previousFindingsis empty.Reviews (8) · Last reviewed commit: "fix(recording): only watch for a closed ..." · Reviewed by Greptile