Run managed daemon processes at background priority on macOS (#54401)

## What changed

- Launch managed processes through `taskpolicy -b` on macOS when a five-second probe succeeds, preserving the managed process PID. Fall back to direct launch if the probe fails or times out.
- Increase the macOS startup timeout from 10 to 30 seconds to accommodate background CPU and I/O scheduling, and serialize daemon startup test fixtures on macOS.
- Use the shared background command helper and retain `CREATE_NO_WINDOW` alongside Windows detachment flags.

## Testing

Add macOS tests for PID preservation, background priority when available, and direct-launch fallback after a probe timeout.

GitOrigin-RevId: ab3328e2e8f62218ac9602e4172563c00056875b
This commit is contained in:
Benjamin Carlsson
2026-10-15 20:00:15 +00:00
committed by copyberry
parent aabf13307a
commit 97ebf2d94d
7 changed files with 177 additions and 16 deletions
+8
View File
@@ -8,6 +8,9 @@ use std::fs;
use std::process::Command;
use std::time::Duration;
#[cfg(target_os = "macos")]
static DAEMON_STARTUP_SERIAL: tokio::sync::Semaphore = tokio::sync::Semaphore::const_new(1);
#[tokio::test]
#[cfg(unix)]
async fn auto_daemon_start_attaches_to_shared_server() -> Result<()> {
@@ -152,6 +155,11 @@ async fn bedrock_onboarding_leaves_a_running_daemon_untouched() -> Result<()> {
}
async fn daemon_startup(command: &str) -> Result<()> {
// Background QoS is intentionally allowed to reduce throughput. Avoid
// making many independent daemon fixtures compete during this test binary.
#[cfg(target_os = "macos")]
let _serial = DAEMON_STARTUP_SERIAL.acquire().await?;
#[cfg(windows)]
let elevated = codex_app_server_daemon::is_elevated()?;
#[cfg(not(windows))]