Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions codex-rs/app-server-daemon/src/backend/pid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::time::Duration;
use anyhow::Context;
use anyhow::Result;
use anyhow::bail;
#[cfg(unix)]
use codex_app_server_transport::REMOTE_CONTROL_DISABLED_ENV_VAR;
use serde::Deserialize;
use serde::Serialize;
use tokio::fs;
Expand Down Expand Up @@ -164,6 +166,9 @@ impl PidBackend {
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::from(stderr_log.into_std().await));
if let Some((key, value)) = self.command_env() {
command.env(key, value);
}

#[cfg(unix)]
{
Expand Down Expand Up @@ -407,6 +412,19 @@ impl PidBackend {
}
}

#[cfg(unix)]
fn command_env(&self) -> Option<(&'static str, &'static str)> {
match self.command_kind {
PidCommandKind::AppServer {
remote_control_enabled: false,
} => Some((REMOTE_CONTROL_DISABLED_ENV_VAR, "1")),
PidCommandKind::AppServer {
remote_control_enabled: true,
}
| PidCommandKind::UpdateLoop => None,
}
}

fn terminate_process(&self, pid: u32) -> Result<()> {
match self.command_kind {
PidCommandKind::AppServer { .. } => terminate_process(pid),
Expand Down
20 changes: 20 additions & 0 deletions codex-rs/app-server-daemon/src/backend/pid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::time::Duration;
use pretty_assertions::assert_eq;
use tempfile::TempDir;

use codex_app_server_transport::REMOTE_CONTROL_DISABLED_ENV_VAR;

use super::PidBackend;
use super::PidCommandKind;
use super::PidFileState;
Expand Down Expand Up @@ -174,6 +176,24 @@ fn app_server_remote_control_uses_runtime_flag() {
);
}

#[test]
fn app_server_disabled_remote_control_uses_compatible_args_and_runtime_env() {
let backend = PidBackend::new(
"codex".into(),
"app-server.pid".into(),
/*remote_control_enabled*/ false,
);

assert_eq!(
backend.command_args(),
vec!["app-server", "--listen", "unix://"]
);
assert_eq!(
backend.command_env(),
Some((REMOTE_CONTROL_DISABLED_ENV_VAR, "1"))
);
}

#[tokio::test]
async fn read_stderr_log_tail_returns_recent_complete_lines() {
let temp_dir = TempDir::new().expect("temp dir");
Expand Down
10 changes: 10 additions & 0 deletions codex-rs/app-server-daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,16 @@ impl Daemon {
} else {
None
};
if info.is_some() {
match mode {
RemoteControlMode::Enabled => {
remote_control_client::enable_remote_control(&self.socket_path).await?;
}
RemoteControlMode::Disabled => {
remote_control_client::disable_remote_control(&self.socket_path).await?;
}
}
}
return Ok(self.remote_control_output(
already_remote_control_status(mode),
backend.map(|_| BackendKind::Pid),
Expand Down
Loading
Loading