Skip to content

fix(recordings): stop captures that start late and handle system stops - #54

Merged
Quost merged 2 commits into
mainfrom
fix/recordings-stream-lifecycle
Nov 24, 2026
Merged

Quost merged 2 commits into
mainfrom
fix/recordings-stream-lifecycle

Conversation

@Quost

@Quost Quost commented Nov 23, 2026

Copy link
Copy Markdown
Owner

What changes

Lifecycle fixes for the three ScreenCaptureKit captures (screen recorder, meeting recordings, live captions), found in the codebase audit.

  • A capture could keep running forever. Recordings and live captions assigned stream = s after await s.startCapture(). If you pressed Stop while the capture was still starting, stop() saw no stream and stopped nothing. The stream was then assigned and kept capturing system audio, with the screen-recording indicator on. Now, once the capture has started, they check the recording is still the same one (recordingID in Recordings, a generation counter in Live Captions). If it isn't, they stop the stream instead of keeping it.

  • Live Captions restart race. restart() (stop + start) while a previous begin() was still waiting (model download, permission) could start two engines. Every await in begin() now bails out if the generation changed, and shuts down an engine or stream that arrives late.

  • The app now notices when macOS stops a capture. All three SCStreams had delegate: nil, so when a display was disconnected or the permission revoked, the app never found out. The recorder stayed "recording", the .mov was never finished and the temp file was lost. A small StreamStopDelegate now calls the normal stop path on the main actor:

    • The screen recorder finishes and saves the file.
    • Recordings stop and get processed.
    • Captions show the reason.

    A HUD says "Recording stopped: the screen or the permission changed."

  • Recorder stop() no longer clears the stream, sink or audio files of a new recording started while the previous one was still finishing. It only clears them if they are the same objects, and it captures started and the audio files before its Task.

Notes for review

Checklist

  • Builds with ./build.sh and I tried the change in the app. (CI builds it. Worth a manual try: start then stop quickly, unplug an external display while recording)
  • swift test passes (CI)
  • Every new UI string uses L("…") with en, de, es and zh
  • No telemetry, no new network calls and no new dependencies

🤖 Generated with Claude Code

…tem stops

Co-Authored-By: Claude Opus 5.5 <[email protected]>

A stop() during a pending startCapture() left system-audio capture running forever (Recordings, Live
Captions). Live Captions now uses a generation counter so restart() cannot start two engines.
SCStream now has a delegate so a vanished display or revoked permission finishes the recording and
saves the file. ScreenRecorder.stop() no longer clears the stream/sink or audio files of a recording
started in the meantime.
@Quost
Quost force-pushed the fix/recordings-stream-lifecycle branch from 9bfa439 to bb066c2 Compare November 24, 2026 00:56
@Quost Quost changed the title fix(recording): stop captures that start late and handle system stops fix(recordings): stop captures that start late and handle system stops Nov 24, 2026
@Quost
Quost merged commit 69a7be1 into main Nov 24, 2026
12 checks passed
@Quost
Quost deleted the fix/recordings-stream-lifecycle branch November 24, 2026 04:52
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.

1 participant