BigPizzaV3/CodexPlusPlus · error · anyhow::Error

macOS app did not exit before debug relaunch

Error message

macOS app did not exit before debug relaunch: {}

What it means

Before a debug relaunch on macOS, the launcher asks the running app to quit (via a cleanup command) and then polls `is_macos_app_running` until a deadline (MACOS_DEBUG_TAKEOVER_WAIT_MS). If the app process is still alive after the timeout, relaunching would collide with the old instance, so the takeover is aborted with the app directory in the message.

Solutions

  1. Manually quit the running macOS app (Cmd+Q or `pkill` its process) and retry the debug relaunch
  2. Increase MACOS_DEBUG_TAKEOVER_WAIT_MS to give slow shutdowns more time
  3. Investigate why the cleanup command did not terminate the app (check run_macos_cleanup_command output/logs)

Example fix

// before
const MACOS_DEBUG_TAKEOVER_WAIT_MS: u64 = 5_000;
// after
const MACOS_DEBUG_TAKEOVER_WAIT_MS: u64 = 30_000;
Defensive patterns

Strategy: retry

Validate before calling

// before relaunch, confirm the app is gone
if is_macos_app_running(app_dir).await {
    eprintln!("app still running; quit it manually before debug relaunch");
}

Try / catch

loop {
    match quit_macos_app_and_wait(app_dir).await {
        Ok(()) => break,
        Err(e) if e.to_string().contains("did not exit") => {
            attempt_force_quit(app_dir)?;
            continue; // bounded retries
        }
        Err(e) => return Err(e),
    }
}

Prevention

When it happens

Trigger: Running the debug relaunch/takeover flow while the previously launched macOS app bundle at `app_dir` refuses to exit or takes longer than MACOS_DEBUG_TAKEOVER_WAIT_MS to terminate.

Common situations: App showing a quit-confirmation dialog or being stuck; app hung/crashed without exiting; another user/session running the same bundle; cleanup AppleScript/kill command failing silently; very short takeover wait timeout on a slow machine.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/ffc8760c4bf90461. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/launcher.rs:3069

        return Ok(());
    };
    let _ = Command::new(executable)
        .args(&command[1..])
        .stdout(Stdio::null())
        .stderr(Stdio::null())
        .status()
        .await
        .with_context(|| format!("failed to request macOS app quit for {}", app_dir.display()))?;
    Ok(())
}

async fn quit_macos_app_and_wait(app_dir: &Path) -> anyhow::Result<()> {
    run_macos_cleanup_command(app_dir, MacosCleanupPolicy::QuitIfNotPreviouslyRunning).await?;
    let deadline = tokio::time::Instant::now()
        + std::time::Duration::from_millis(MACOS_DEBUG_TAKEOVER_WAIT_MS);
    while is_macos_app_running(app_dir).await {
        if tokio::time::Instant::now() >= deadline {
            anyhow::bail!(
                "macOS app did not exit before debug relaunch: {}",
                app_dir.display()
            );
        }
        tokio::time::sleep(std::time::Duration::from_millis(
            MACOS_DEBUG_TAKEOVER_INTERVAL_MS,
        ))
        .await;
    }
    let _ = crate::diagnostic_log::append_diagnostic_log(
        "launcher.macos_existing_app_without_cdp_stopped",
        serde_json::json!({
            "app_dir": app_dir
        }),
    );
    Ok(())
}

View on GitHub (pinned to b1ed92e5e4)