From 09984ca85d8430c8777fbe7e0833b05894c0eec1 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Tue, 1 Dec 2026 16:47:12 +0000 Subject: [PATCH] Fix app-server daemon startup with BusyBox `ps` (#65043) ## Why BusyBox `ps` can reject the arguments Codex uses to read a process start time. That failure prevents the managed app-server daemon and updater from starting even when Linux can identify both processes through `/proc`. ## What changed On Linux, allow startup to proceed when the `ps` lookup fails and `/proc` identifies a live process. Store that identity in the PID record with an empty legacy start timestamp. ## Testing Add a Linux CLI regression test that substitutes a failing `ps`, checks both PID records for a process identity and an empty legacy timestamp, and verifies that `daemon version` reports the daemon running and `daemon stop` stops it. GitOrigin-RevId: fc82e0e32a62ffbb1dc1683403757f3ab109000a --- .../src/backend/pid_start.rs | 19 +++++---- codex-rs/cli/tests/app_server_daemon.rs | 39 +++++++++++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/codex-rs/app-server-daemon/src/backend/pid_start.rs b/codex-rs/app-server-daemon/src/backend/pid_start.rs index e6a3998a05..b130803ce3 100644 --- a/codex-rs/app-server-daemon/src/backend/pid_start.rs +++ b/codex-rs/app-server-daemon/src/backend/pid_start.rs @@ -241,18 +241,23 @@ impl PidBackend { crate::diagnostics::event("process_spawned", serde_json::json!({ "pid": pid })); let started = std::time::Instant::now(); let record = async { - let process_start_time = read_process_start_time(pid).await?; + let start_time = read_process_start_time(pid).await; #[cfg(any(target_os = "linux", target_os = "macos"))] - let process_identity = super::identity::read_process_details(pid) - .await - .ok() - .map(|(_, identity)| identity); + let details = super::identity::read_process_details(pid).await.ok(); #[cfg(not(any(target_os = "linux", target_os = "macos")))] - let process_identity = None; + let details = None; + // BusyBox ps may reject our arguments. Only a live /proc identity + // can substitute for the legacy timestamp, which ps never returns empty. + let process_start_time = + if cfg!(target_os = "linux") && matches!(details, Some((false, _))) { + start_time.unwrap_or_default() + } else { + start_time? + }; anyhow::Ok(PidRecord { pid, process_start_time, - process_identity, + process_identity: details.map(|(_, identity)| identity), executable_identity: launched_identity, }) } diff --git a/codex-rs/cli/tests/app_server_daemon.rs b/codex-rs/cli/tests/app_server_daemon.rs index 9739587cdb..b8e31eaec9 100644 --- a/codex-rs/cli/tests/app_server_daemon.rs +++ b/codex-rs/cli/tests/app_server_daemon.rs @@ -467,6 +467,45 @@ fn wall_clock_shift_keeps_server_and_updater_managed() -> Result<()> { Ok(()) } +#[cfg(target_os = "linux")] +#[test] +fn managed_daemon_and_updater_start_with_busybox_ps() -> Result<()> { + let daemon = TestDaemon::new()?; + // Simulate BusyBox rejecting the ps arguments, only for these CLI processes. + std::os::unix::fs::symlink("/bin/false", daemon.home.path().join("ps"))?; + let path = std::env::join_paths(std::iter::once(daemon.home.path().to_owned()).chain( + std::env::split_paths(&std::env::var_os("PATH").unwrap_or_default()), + ))?; + for (action, expected) in [ + ("start", "started"), + ("version", "running"), + ("stop", "stopped"), + ] { + let output = daemon + .command() + .env("PATH", &path) + .args(["app-server", "daemon", action]) + .output()?; + ensure!( + output.status.success(), + "daemon {action} failed: {}", + String::from_utf8_lossy(&output.stderr) + ); + let response: Value = serde_json::from_slice(&output.stdout)?; + assert_eq!(response["status"], expected); + if action == "start" { + for name in ["app-server.pid", "app-server-updater.pid"] { + let record = + std::fs::read(daemon.home.path().join("app-server-daemon").join(name))?; + let record: Value = serde_json::from_slice(&record)?; + assert_eq!(record["processStartTime"], ""); + assert!(record["processIdentity"].is_object()); + } + } + } + Ok(()) +} + #[test] fn managed_start_keeps_updater_on_marker_mismatch_but_stops_it_for_pin() -> Result<()> { let daemon = TestDaemon::new()?;