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
This commit is contained in:
Eric Traut
2026-12-01 17:52:27 +00:00
committed by copyberry
parent 51f546979e
commit 09984ca85d
2 changed files with 51 additions and 7 deletions
@@ -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,
})
}
+39
View File
@@ -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()?;