Repository navigation
fix(macos): keep the GUI server out of App Nap as well - #921
Conversation
The NSProcessInfo activity assertion was only taken in headless mode, on the belief that a window keeps the app out of App Nap. It does only while the window is visible. With the Strom window hidden or covered, macOS App-Naps the GUI process: every thread drops to scheduling priority 4 and timers are coalesced, so live mixers miss their deadlines in bursts. Video freezes on every output at once, the audio mix drops to digital silence, and WHIP inputs report "produced no video while its audio is still flowing", all while the pipeline reports Playing. Take the assertion in main() before the headless/GUI dispatch, and guard the GUI path with a wiring test alongside the headless one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
srperens
left a comment
There was a problem hiding this comment.
Verdict: Comment. The move is correct and minimal. But the diff changes only macOS behaviour, and this repo's CI has not yet compiled or run the new macOS-only test at this head.
Needs the maintainer
- Add the
ci:macoslabel. The macOS job runscargo test --package strom --features efp,nvidia(.github/workflows/ci.yml:695), which would build and rungui_mode_takes_the_activity_assertion. On Linux the test file compiles to nothing (backend/tests/macos_app_nap_test.rs:15—#![cfg(target_os = "macos")]). So none of the green checks exercise any part of this PR.
Claims
| Claim | Verdict | Evidence |
|---|---|---|
| Both launch modes now take the assertion | CONFIRMED |
The call sits in main() before the dispatch: backend/src/main.rs:466 — strom::macos_app_nap::hold_activity_for_process_lifetime();. Both run_headless_entry call sites come after it (:480 for GUI-enabled builds, :492 for no-gui), and the old call inside run_headless_entry is removed, so headless still takes it exactly once. |
| Headless still takes it before the CFRunLoop starts | CONFIRMED |
It now runs even earlier, before run_headless_entry reaches gstreamer::macos_main. |
| The GUI test's anchor is logged before the call | CONFIRMED |
backend/src/main.rs:458 — info!("Starting Strom backend server with GUI..."); precedes :466. The test grants 500 ms after seeing it, and it refuses to pass when neither anchor line appears. |
| Non-macOS builds are unaffected | CONFIRMED |
backend/src/macos_app_nap.rs:44 — pub fn hold_activity_for_process_lifetime() {} |
Taking the assertion before winit/eframe creates NSApplication is safe |
EXTERNAL |
This assumes NSProcessInfo needs no NSApp. #735 already relied on the same thing for headless, and the author ran the GUI trials. |
| The new test fails on revert | UNVERIFIED |
The author reports it on macOS. It cannot run in this repo's CI without the label. |
Diagnosis: This is the right layer. #735's premise (the window keeps GUI mode awake) holds only while the window is visible. The call now runs once, process-wide, before either mode starts. Coverage is ABSOLUTE for the "call missing from a launch path" failure. The author's own taskpolicy -b arm shows that the priority band alone did not cause the stalls. The fix sets LatencyCritical, which also opts out of timer coalescing, so it covers the mechanism the author suspects without having isolated it. That is fine, because the assertion was already in production for headless.
Radius: LOCAL. One call moves up about 250 lines in main.rs. It adds no new object lifetime: the token was already leaked deliberately for the process lifetime. On Linux and Windows the call is a no-op.
Overlaps: No open PR or issue owns this decision. #879 adds about 140 lines to main() just above this call (hunk @@ -434,6 +437,139 @@). That is likely a textual conflict for whichever lands second, but it is not a design overlap.
Tests & CI: At a9e78fa, Check (Linux), both Linux builds, WASM and API Contract are green. Build (macOS) and Build (Windows) show skipping, and the PR has no labels.
Confidence: HIGH
Description
On macOS, a GUI-mode Strom whose window is hidden or covered gets App-Napped. Every thread drops to scheduling priority 4 (efficiency cores) and timers are coalesced. Live mixers then miss their deadlines in bursts. Video freezes on every output at once, the audio mix drops to digital silence, WHIP inputs report
slot N has produced no video … while its audio is still flowing, and the recorder ends its video track withvideo 0 has run dry. Throughout, the pipeline reportsPlaying.#735 already opts headless mode out of App Nap with an
NSProcessInfoactivity assertion. GUI mode was left out on the assumption that its window prevents App Nap, which holds only while the window is visible. This PR takes the same assertion inmain()before the headless/GUI dispatch, so both modes get it.Evidence
ps -Mshowed all 174 threads of that process at priority4T, and its log has noApp Nap opt-outline.getVideoPlaybackQuality(); silence gaps are 20 ms windows below -85 dBFS in the recorder's audio.taskpolicy -bThe
taskpolicy -barm holds the process at priority 4 and stays clean, so the priority band alone does not cause the stalls in this flow. The difference is App Nap's other throttling, most likely timer coalescing delaying GStreamer's clock waits. I have not isolated that part.Severity varies from run to run. All 3 unfixed runs froze, and neither fixed run did. Both arms ran the same integration branch (
mainplus open PRs such as #919, which late-joining publishers need), with and without this commit cherry-picked. The PR itself is based onmain.Related Issue
Follows #735.
Type of Change
Checklist
cargo fmt --allcargo clippy --workspace --all-targets -- -D warnings(pre-commit hook)cargo test --workspace: onlymacos_app_nap_testwas run, see belowmacos_app_nap.rs)Tests run
cargo test --test macos_app_nap_teston macOS:headless_entry_takes_the_activity_assertionand the newgui_mode_takes_the_activity_assertionpass.main.rsrestored toupstream/main,gui_mode_takes_the_activity_assertionfails and the headless test still passes.server_is_not_demoted_to_background_qos(ignored, opt-in) was not run. The hidden-GUI trials above are the behavioural check.--headlessand kills it as soon as the marker is logged. On Linux and Windows the file iscfg'd out. The macOS CI runner has not run it yet; addci:macosto exercise it there.🤖 Generated with Claude Code