Skip to content

fix(macos): keep the GUI server out of App Nap as well - #921

Merged
srperens merged 1 commit into
Eyevinn:mainfrom
wagenet:wagenet/gui-app-nap
Oct 19, 2026
Merged

srperens merged 1 commit into
Eyevinn:mainfrom
wagenet:wagenet/gui-app-nap

Conversation

@wagenet

@wagenet wagenet commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

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 with video 0 has run dry. Throughout, the pipeline reports Playing.

#735 already opts headless mode out of App Nap with an NSProcessInfo activity 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 in main() before the headless/GUI dispatch, so both modes get it.

Evidence

  • Production: a meeting on a GUI-mode server showed exactly the symptoms above: "no video" errors on both occupied inputs a few seconds apart, 37 gaps of digital silence in the program audio, and queue-level warnings on the vision mixer's meter and overlay queues and the audio mixer's aux queues. It stalled again later with no publishers connected at all. Checked shortly afterwards (the thread priorities during the meeting itself were not captured), ps -M showed all 174 threads of that process at priority 4T, and its log has no App Nap opt-out line.
  • Repro: the production flow (5 WHIP inputs → GPU vision mixer → videoenc → program/multiview/5 return WHEPs and a recorder) with 5 headless Chrome publishers, 7 WHEP viewers, and one publisher reloading every ~35 s. Frozen seconds are counted per viewer from getVideoPlaybackQuality(); silence gaps are 20 ms windows below -85 dBFS in the recorder's audio.
arm threads frozen s per viewer (pgm, mv, 5 returns) silence gaps "no video" / "run dry"
headless, taskpolicy -b 4T 0 0 0
GUI hidden, without fix (run 1) 4T, 3 s after hiding 15–18 9, up to 1.34 s yes
GUI hidden, without fix (run 2) 4T, 36 s after hiding 1–4 0 1
GUI hidden, without fix (run 3) 4T, 40 s after hiding 7–10 7, up to 3.6 s 3
GUI hidden, with fix (run 1) 31T after 60 s hidden 0 0 0
GUI hidden, with fix (run 2) 31T after 60 s hidden 0 0 0

The taskpolicy -b arm 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 (main plus open PRs such as #919, which late-joining publishers need), with and without this commit cherry-picked. The PR itself is based on main.

Related Issue

Follows #735.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • I have run cargo fmt --all
  • I have run cargo clippy --workspace --all-targets -- -D warnings (pre-commit hook)
  • I have run cargo test --workspace: only macos_app_nap_test was run, see below
  • I have updated documentation as needed (module doc in macos_app_nap.rs)
  • I have added tests for new functionality

Tests run

  • cargo test --test macos_app_nap_test on macOS: headless_entry_takes_the_activity_assertion and the new gui_mode_takes_the_activity_assertion pass.
  • Revert check: with main.rs restored to upstream/main, gui_mode_takes_the_activity_assertion fails 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.
  • The GUI wiring test spawns the server without --headless and kills it as soon as the marker is logged. On Linux and Windows the file is cfg'd out. The macOS CI runner has not run it yet; add ci:macos to exercise it there.

🤖 Generated with Claude Code

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>
@wagenet
wagenet marked this pull request as ready for review September 30, 2026 05:17
@srperens srperens mentioned this pull request Sep 30, 2026

@srperens srperens left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Add the ci:macos label. The macOS job runs cargo test --package strom --features efp,nvidia (.github/workflows/ci.yml:695), which would build and run gui_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

wagenet added a commit to wagenet/strom that referenced this pull request Oct 9, 2026
@srperens
srperens merged commit 4e7396d into Eyevinn:main Oct 19, 2026
9 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