mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Support the app-server daemon on Windows (#42405)
## Why The managed app-server daemon and automatic TUI attachment were limited to Unix, so Windows users could not share a background server across Codex sessions. ## What changed - Enable daemon lifecycle commands, `codex agents` startup, and AF_UNIX daemon discovery on Windows. - Require Windows daemons to start non-elevated and verify the discovered socket directory and peer before connecting. - Preflight detached process support, preserve path-based environment settings, and keep daemon processes out of the launching project's working directory. - Fall back to an embedded server when an implicitly discovered daemon cannot connect, while preserving errors for explicit remote endpoints and bypassing daemon reuse when `CODEX_EXEC_SERVER_URL` is set. ## Testing Add coverage for Windows launch restrictions and socket validation, implicit connection fallback, executor selection, daemon discovery, and the agents dashboard startup result. GitOrigin-RevId: e7fd63cf8690bcca8b5155266416f31f2f792aa2
This commit is contained in:
@@ -56,14 +56,14 @@ impl App {
|
||||
subtitle: Some(
|
||||
if workload_identity_selected {
|
||||
"The agents dashboard is unavailable while workload identity is active."
|
||||
} else if cfg!(unix) {
|
||||
} else if cfg!(any(unix, windows)) {
|
||||
"This session isn’t connected to a shared background server."
|
||||
} else {
|
||||
"Connect to a remote background server to use the agents dashboard."
|
||||
}
|
||||
.to_string(),
|
||||
),
|
||||
footer_note: (cfg!(unix) && !workload_identity_selected).then(|| {
|
||||
footer_note: (cfg!(any(unix, windows)) && !workload_identity_selected).then(|| {
|
||||
Line::from(
|
||||
"Starting a background server will not interrupt or move this session."
|
||||
.dim(),
|
||||
@@ -71,7 +71,7 @@ impl App {
|
||||
}),
|
||||
footer_hint: Some(standard_popup_hint_line_for_keymap(&self.keymap.list)),
|
||||
items: [
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(unix, windows))]
|
||||
(!workload_identity_selected).then(|| SelectionItem {
|
||||
name: "Start background server".to_string(),
|
||||
description: Some(
|
||||
@@ -737,7 +737,7 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(unix, windows))]
|
||||
pub(super) fn start_agents_daemon(&self) {
|
||||
let app_event_tx = self.app_event_tx.clone();
|
||||
tokio::spawn(async move {
|
||||
@@ -746,9 +746,19 @@ impl App {
|
||||
std::env::current_exe().map_err(|error| error.to_string())?;
|
||||
let executable = if current_executable
|
||||
.file_stem()
|
||||
.is_some_and(|name| name == "codex-tui")
|
||||
{
|
||||
current_executable.with_file_name("codex")
|
||||
.and_then(std::ffi::OsStr::to_str)
|
||||
.is_some_and(|name| {
|
||||
if cfg!(windows) {
|
||||
name.eq_ignore_ascii_case("codex-tui")
|
||||
} else {
|
||||
name == "codex-tui"
|
||||
}
|
||||
}) {
|
||||
current_executable.with_file_name(if cfg!(windows) {
|
||||
"codex.exe"
|
||||
} else {
|
||||
"codex"
|
||||
})
|
||||
} else {
|
||||
current_executable
|
||||
};
|
||||
|
||||
@@ -606,7 +606,7 @@ async fn shared_overview_shows_only_root_sessions() {
|
||||
assert!(app.last_rendered_history_tail.is_some());
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(unix, windows))]
|
||||
#[tokio::test]
|
||||
async fn embedded_sessions_offer_to_start_a_background_server_without_migrating() {
|
||||
let mut app = make_test_app().await;
|
||||
@@ -625,6 +625,47 @@ async fn embedded_sessions_offer_to_start_a_background_server_without_migrating(
|
||||
app_server.shutdown().await.expect("shutdown app server");
|
||||
}
|
||||
|
||||
#[cfg(any(unix, windows))]
|
||||
#[tokio::test]
|
||||
async fn daemon_start_result_snapshots() -> Result<()> {
|
||||
let (mut app, mut app_event_rx, _op_rx) =
|
||||
crate::app::tests::make_test_app_with_channels().await;
|
||||
let mut app_server =
|
||||
crate::start_embedded_app_server_for_picker(app.chat_widget.config_ref()).await?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
|
||||
for (name, result) in [
|
||||
("agents_daemon_started", Ok(())),
|
||||
(
|
||||
"agents_daemon_start_failed",
|
||||
Err("The host does not allow detached processes".to_string()),
|
||||
),
|
||||
] {
|
||||
app.handle_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
AppEvent::AgentsDaemonStarted { result },
|
||||
)
|
||||
.await?;
|
||||
let cell = match app_event_rx.try_recv()? {
|
||||
AppEvent::InsertHistoryCell(cell) => cell,
|
||||
other => panic!("expected daemon result history, got {other:?}"),
|
||||
};
|
||||
let rendered = cell
|
||||
.display_lines(/*width*/ 80)
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
insta::with_settings!({snapshot_path => "../snapshots"}, {
|
||||
insta::assert_snapshot!(name, rendered);
|
||||
});
|
||||
}
|
||||
|
||||
app_server.shutdown().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn filtered_dashboard_actions_use_configured_shortcuts() {
|
||||
let mut app = make_test_app().await;
|
||||
|
||||
@@ -2637,11 +2637,11 @@ impl App {
|
||||
self.stop_agents_overview_thread(app_server, thread_id)
|
||||
.await;
|
||||
}
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(unix, windows))]
|
||||
AppEvent::StartAgentsDaemon => {
|
||||
self.start_agents_daemon();
|
||||
}
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(unix, windows))]
|
||||
AppEvent::AgentsDaemonStarted { result } => match result {
|
||||
Ok(()) => self.chat_widget.add_info_message(
|
||||
"Background server started. Run `codex agents` in another terminal; this session remains unchanged."
|
||||
|
||||
@@ -36,14 +36,9 @@ pub(super) async fn reconnect(
|
||||
presentation: ReconnectPresentation,
|
||||
) -> Result<Reconnected> {
|
||||
let mode = target.thread_params_mode();
|
||||
let endpoint = match target {
|
||||
AppServerTarget::Remote { endpoint } | AppServerTarget::LocalDaemon { endpoint } => {
|
||||
endpoint
|
||||
}
|
||||
AppServerTarget::Embedded => {
|
||||
color_eyre::eyre::bail!("in-process sessions have no connection to restore")
|
||||
}
|
||||
};
|
||||
if matches!(target, AppServerTarget::Embedded) {
|
||||
color_eyre::eyre::bail!("in-process sessions have no connection to restore");
|
||||
}
|
||||
if let ThreadToolTransport::Mcp(server) = &task_tools {
|
||||
server.suspend();
|
||||
}
|
||||
@@ -58,7 +53,7 @@ pub(super) async fn reconnect(
|
||||
for delay in [0, 1, 2, 4, 8] {
|
||||
let attempt = async {
|
||||
tokio::time::sleep(Duration::from_secs(delay)).await;
|
||||
let client = crate::connect_remote_app_server(endpoint.clone()).await?;
|
||||
let client = crate::app_server_connection::connect(&target).await?;
|
||||
let mut session = AppServerSession::new(client, mode)
|
||||
.with_startup_config(&config)
|
||||
.with_remote_cwd_override(remote_cwd.clone())
|
||||
|
||||
@@ -5510,7 +5510,7 @@ async fn make_test_app() -> App {
|
||||
}
|
||||
}
|
||||
|
||||
async fn make_test_app_with_channels() -> (
|
||||
pub(super) async fn make_test_app_with_channels() -> (
|
||||
App,
|
||||
tokio::sync::mpsc::UnboundedReceiver<AppEvent>,
|
||||
tokio::sync::mpsc::UnboundedReceiver<Op>,
|
||||
|
||||
@@ -270,10 +270,10 @@ pub(crate) enum AppEvent {
|
||||
thread_id: ThreadId,
|
||||
},
|
||||
/// Start the shared app-server daemon without moving the current embedded session.
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(unix, windows))]
|
||||
StartAgentsDaemon,
|
||||
/// Report whether starting the shared app-server daemon succeeded.
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(unix, windows))]
|
||||
AgentsDaemonStarted {
|
||||
result: Result<(), String>,
|
||||
},
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
//! Applies the selected server's socket policy on initial connections and reconnects.
|
||||
|
||||
use crate::AppServerTarget;
|
||||
#[cfg(windows)]
|
||||
use crate::DEFAULT_IN_PROCESS_CHANNEL_CAPACITY;
|
||||
use crate::connect_remote_app_server;
|
||||
use codex_app_server_client::AppServerClient;
|
||||
#[cfg(windows)]
|
||||
use codex_app_server_client::RemoteAppServerClient;
|
||||
#[cfg(windows)]
|
||||
use codex_app_server_client::RemoteAppServerConnectArgs;
|
||||
#[cfg(windows)]
|
||||
use codex_app_server_client::RemoteAppServerEndpoint;
|
||||
#[cfg(windows)]
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
|
||||
pub(crate) async fn connect(target: &AppServerTarget) -> color_eyre::Result<AppServerClient> {
|
||||
match target {
|
||||
AppServerTarget::Embedded => {
|
||||
color_eyre::eyre::bail!("embedded sessions have no remote connection")
|
||||
}
|
||||
#[cfg(windows)]
|
||||
AppServerTarget::LocalDaemon {
|
||||
endpoint: RemoteAppServerEndpoint::UnixSocket { socket_path },
|
||||
} => {
|
||||
// Revalidate at the real connection, not just the earlier discovery probe.
|
||||
let (socket_path, _directory) =
|
||||
codex_uds::validate_private_socket_path(socket_path.as_path())?;
|
||||
let app_server =
|
||||
RemoteAppServerClient::connect_local_daemon(RemoteAppServerConnectArgs {
|
||||
endpoint: RemoteAppServerEndpoint::UnixSocket {
|
||||
socket_path: AbsolutePathBuf::from_absolute_path_checked(socket_path)?,
|
||||
},
|
||||
client_name: "codex-tui".to_string(),
|
||||
client_version: env!("CARGO_PKG_VERSION").to_string(),
|
||||
experimental_api: true,
|
||||
mcp_server_openai_form_elicitation: false,
|
||||
opt_out_notification_methods: Vec::new(),
|
||||
channel_capacity: DEFAULT_IN_PROCESS_CHANNEL_CAPACITY,
|
||||
})
|
||||
.await?;
|
||||
Ok(AppServerClient::Remote(app_server))
|
||||
}
|
||||
AppServerTarget::LocalDaemon { endpoint } | AppServerTarget::Remote { endpoint } => {
|
||||
connect_remote_app_server(endpoint.clone()).await
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
//! Implicit daemon discovery is opportunistic; explicit endpoints remain authoritative.
|
||||
|
||||
use super::*;
|
||||
use crate::legacy_core::config::ConfigBuilder;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[cfg(windows)]
|
||||
#[tokio::test]
|
||||
async fn daemon_connection_rejects_unprotected_socket_before_handshake() -> color_eyre::Result<()> {
|
||||
let home = TempDir::new()?;
|
||||
let parent = home.path().join("control");
|
||||
std::fs::create_dir(&parent)?;
|
||||
let socket_path = AbsolutePathBuf::from_absolute_path_checked(parent.join("server.sock"))?;
|
||||
let mut listener = codex_uds::UnixListener::bind(socket_path.as_path()).await?;
|
||||
let target = AppServerTarget::LocalDaemon {
|
||||
endpoint: RemoteAppServerEndpoint::UnixSocket { socket_path },
|
||||
};
|
||||
tokio::select! {
|
||||
result = app_server_connection::connect(&target) => assert!(result.is_err()),
|
||||
_ = listener.accept() => panic!("unprotected listener must not receive a connection"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn daemon_startup_falls_back_only_for_implicit_endpoints() -> color_eyre::Result<()> {
|
||||
for scenario in ["missing socket", "failed handshake", "explicit endpoint"] {
|
||||
let home = TempDir::new()?;
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(home.path().to_path_buf())
|
||||
.build()
|
||||
.await?;
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?;
|
||||
let endpoint = if scenario == "missing socket" {
|
||||
RemoteAppServerEndpoint::UnixSocket {
|
||||
socket_path: AbsolutePathBuf::from_absolute_path_checked(
|
||||
home.path().join("gone.sock"),
|
||||
)?,
|
||||
}
|
||||
} else {
|
||||
RemoteAppServerEndpoint::WebSocket {
|
||||
websocket_url: format!("ws://{}", listener.local_addr()?),
|
||||
auth_token: None,
|
||||
}
|
||||
};
|
||||
let reject_handshake = tokio::spawn(async move {
|
||||
let _ = listener.accept().await;
|
||||
});
|
||||
let mut target = if scenario == "explicit endpoint" {
|
||||
AppServerTarget::Remote { endpoint }
|
||||
} else {
|
||||
AppServerTarget::LocalDaemon { endpoint }
|
||||
};
|
||||
let original_target = target.clone();
|
||||
let mut state_db = None;
|
||||
let result = start_app_server(
|
||||
&mut target,
|
||||
Arg0DispatchPaths::default(),
|
||||
config,
|
||||
Vec::new(),
|
||||
LoaderOverrides::default(),
|
||||
/*strict_config*/ false,
|
||||
CloudConfigBundleLoader::default(),
|
||||
codex_feedback::CodexFeedback::new(),
|
||||
/*log_db*/ None,
|
||||
&mut state_db,
|
||||
Arc::new(EnvironmentManager::default_for_tests()),
|
||||
)
|
||||
.await;
|
||||
reject_handshake.abort();
|
||||
if scenario == "explicit endpoint" {
|
||||
assert!(result.is_err());
|
||||
assert_eq!(target, original_target);
|
||||
assert!(state_db.is_none());
|
||||
} else {
|
||||
let server = AppServerSession::new(result?, target.thread_params_mode());
|
||||
assert!(server.uses_embedded_app_server());
|
||||
assert_eq!(target, AppServerTarget::Embedded);
|
||||
assert!(state_db.is_some());
|
||||
server.shutdown().await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
+120
-41
@@ -104,6 +104,7 @@ mod app_event;
|
||||
mod app_event_sender;
|
||||
mod app_info;
|
||||
mod app_server_approval_conversions;
|
||||
mod app_server_connection;
|
||||
mod app_server_session;
|
||||
mod approval_events;
|
||||
mod ascii_animation;
|
||||
@@ -249,7 +250,6 @@ pub use public_widgets::composer_input::ComposerInput;
|
||||
const TUI_LOG_FILE_NAME: &str = "codex-tui.log";
|
||||
const INTERACTIVE_OTEL_SHUTDOWN_TIMEOUT: Duration = Duration::from_millis(/*millis*/ 500);
|
||||
|
||||
#[cfg(unix)]
|
||||
const AUTO_CONNECT_DAEMON_CONNECT_TIMEOUT: std::time::Duration =
|
||||
std::time::Duration::from_millis(50);
|
||||
|
||||
@@ -444,16 +444,28 @@ async fn connect_remote_app_server(
|
||||
Ok(AppServerClient::Remote(app_server))
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
async fn maybe_probe_default_daemon_socket(codex_home: &Path) -> Option<AbsolutePathBuf> {
|
||||
let socket_path = codex_app_server_client::app_server_control_socket_path(codex_home).ok()?;
|
||||
#[cfg(windows)]
|
||||
let (validated_path, _directory) =
|
||||
codex_uds::validate_private_socket_path(socket_path.as_path()).ok()?;
|
||||
#[cfg(windows)]
|
||||
let validated_path = AbsolutePathBuf::from_absolute_path_checked(validated_path).ok()?;
|
||||
#[cfg(windows)]
|
||||
let probe_path = validated_path.as_path();
|
||||
#[cfg(not(windows))]
|
||||
let probe_path = socket_path.as_path();
|
||||
match tokio::time::timeout(
|
||||
AUTO_CONNECT_DAEMON_CONNECT_TIMEOUT,
|
||||
tokio::net::UnixStream::connect(socket_path.as_path()),
|
||||
codex_uds::UnixStream::connect(probe_path),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(Ok(_stream)) => Some(socket_path),
|
||||
Ok(Ok(_stream)) => {
|
||||
#[cfg(windows)]
|
||||
_stream.ensure_non_elevated_peer().ok()?;
|
||||
Some(socket_path)
|
||||
}
|
||||
Ok(Err(err)) => {
|
||||
tracing::debug!(%err, socket_path = %socket_path.display(), "skipping default app-server daemon socket");
|
||||
None
|
||||
@@ -469,14 +481,9 @@ async fn maybe_probe_default_daemon_socket(codex_home: &Path) -> Option<Absolute
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
async fn maybe_probe_default_daemon_socket(_codex_home: &Path) -> Option<AbsolutePathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn start_app_server(
|
||||
target: &AppServerTarget,
|
||||
target: &mut AppServerTarget,
|
||||
arg0_paths: Arg0DispatchPaths,
|
||||
config: Config,
|
||||
cli_kv_overrides: Vec<(String, toml::Value)>,
|
||||
@@ -485,28 +492,39 @@ async fn start_app_server(
|
||||
cloud_config_bundle: CloudConfigBundleLoader,
|
||||
feedback: codex_feedback::CodexFeedback,
|
||||
log_db: Option<log_db::LogDbLayer>,
|
||||
state_db: Option<StateDbHandle>,
|
||||
state_db: &mut Option<StateDbHandle>,
|
||||
environment_manager: Arc<EnvironmentManager>,
|
||||
) -> color_eyre::Result<AppServerClient> {
|
||||
match target {
|
||||
AppServerTarget::Embedded => start_embedded_app_server(
|
||||
arg0_paths,
|
||||
config,
|
||||
cli_kv_overrides,
|
||||
loader_overrides,
|
||||
strict_config,
|
||||
cloud_config_bundle,
|
||||
feedback,
|
||||
log_db,
|
||||
state_db,
|
||||
environment_manager,
|
||||
)
|
||||
.await
|
||||
.map(AppServerClient::InProcess),
|
||||
AppServerTarget::LocalDaemon { endpoint } | AppServerTarget::Remote { endpoint } => {
|
||||
connect_remote_app_server(endpoint.clone()).await
|
||||
let connection = if matches!(target, AppServerTarget::Embedded) {
|
||||
None
|
||||
} else {
|
||||
Some(app_server_connection::connect(target).await)
|
||||
};
|
||||
if let Some(connection) = connection {
|
||||
match connection {
|
||||
Ok(app_server) => return Ok(app_server),
|
||||
Err(err) if matches!(target, AppServerTarget::LocalDaemon { .. }) => {
|
||||
tracing::debug!(%err, "local daemon connection failed; starting embedded app server");
|
||||
*target = AppServerTarget::Embedded;
|
||||
*state_db = init_state_db_for_app_server_target(&config, target).await?;
|
||||
}
|
||||
Err(err) => return Err(err),
|
||||
}
|
||||
}
|
||||
start_embedded_app_server(
|
||||
arg0_paths,
|
||||
config,
|
||||
cli_kv_overrides,
|
||||
loader_overrides,
|
||||
strict_config,
|
||||
cloud_config_bundle,
|
||||
feedback,
|
||||
log_db,
|
||||
state_db.clone(),
|
||||
environment_manager,
|
||||
)
|
||||
.await
|
||||
.map(AppServerClient::InProcess)
|
||||
}
|
||||
|
||||
pub(crate) async fn start_app_server_for_picker(
|
||||
@@ -515,8 +533,10 @@ pub(crate) async fn start_app_server_for_picker(
|
||||
state_db: Option<StateDbHandle>,
|
||||
environment_manager: Arc<EnvironmentManager>,
|
||||
) -> color_eyre::Result<AppServerSession> {
|
||||
let mut target = target.clone();
|
||||
let mut state_db = state_db;
|
||||
let app_server = start_app_server(
|
||||
target,
|
||||
&mut target,
|
||||
Arg0DispatchPaths::default(),
|
||||
config.clone(),
|
||||
Vec::new(),
|
||||
@@ -525,7 +545,7 @@ pub(crate) async fn start_app_server_for_picker(
|
||||
CloudConfigBundleLoader::default(),
|
||||
codex_feedback::CodexFeedback::new(),
|
||||
/*log_db*/ None,
|
||||
state_db,
|
||||
&mut state_db,
|
||||
environment_manager,
|
||||
)
|
||||
.await?;
|
||||
@@ -864,6 +884,7 @@ fn app_server_target_for_launch(
|
||||
default_daemon_socket: Option<AbsolutePathBuf>,
|
||||
can_reuse_implicit_local_daemon: bool,
|
||||
workload_identity_selected: bool,
|
||||
exec_server_url: Option<&std::ffi::OsStr>,
|
||||
) -> std::io::Result<AppServerTarget> {
|
||||
if workload_identity_selected {
|
||||
if explicit_remote_endpoint.is_some() {
|
||||
@@ -876,7 +897,8 @@ fn app_server_target_for_launch(
|
||||
}
|
||||
Ok(match explicit_remote_endpoint {
|
||||
Some(endpoint) => AppServerTarget::Remote { endpoint },
|
||||
None if can_reuse_implicit_local_daemon => {
|
||||
// A shared daemon cannot adopt this invocation's executor selection.
|
||||
None if can_reuse_implicit_local_daemon && exec_server_url.is_none() => {
|
||||
default_daemon_socket.map_or(AppServerTarget::Embedded, |socket_path| {
|
||||
AppServerTarget::LocalDaemon {
|
||||
endpoint: RemoteAppServerEndpoint::UnixSocket { socket_path },
|
||||
@@ -970,7 +992,7 @@ async fn run_ratatui_app(
|
||||
arg0_paths: Arg0DispatchPaths,
|
||||
loader_overrides: LoaderOverrides,
|
||||
strict_config: bool,
|
||||
app_server_target: AppServerTarget,
|
||||
mut app_server_target: AppServerTarget,
|
||||
remote_cwd_override: Option<PathBuf>,
|
||||
initial_config: Config,
|
||||
manually_selected_oss_provider: Option<String>,
|
||||
@@ -979,7 +1001,7 @@ async fn run_ratatui_app(
|
||||
mut cloud_config_bundle: CloudConfigBundleLoader,
|
||||
feedback: codex_feedback::CodexFeedback,
|
||||
log_db: Option<log_db::LogDbLayer>,
|
||||
state_db: Option<StateDbHandle>,
|
||||
mut state_db: Option<StateDbHandle>,
|
||||
environment_manager: Arc<EnvironmentManager>,
|
||||
startup_draft: startup_draft::StartupDraft,
|
||||
) -> color_eyre::Result<AppExitInfo> {
|
||||
@@ -1032,7 +1054,7 @@ async fn run_ratatui_app(
|
||||
.run_until(
|
||||
&mut tui,
|
||||
start_app_server(
|
||||
&app_server_target,
|
||||
&mut app_server_target,
|
||||
arg0_paths.clone(),
|
||||
initial_config.clone(),
|
||||
cli_kv_overrides.clone(),
|
||||
@@ -1041,7 +1063,7 @@ async fn run_ratatui_app(
|
||||
cloud_config_bundle.clone(),
|
||||
feedback.clone(),
|
||||
log_db.clone(),
|
||||
state_db.clone(),
|
||||
&mut state_db,
|
||||
environment_manager.clone(),
|
||||
),
|
||||
)
|
||||
@@ -1639,7 +1661,7 @@ async fn run_ratatui_app(
|
||||
.run_until(
|
||||
&mut tui,
|
||||
start_app_server(
|
||||
&app_server_target,
|
||||
&mut app_server_target,
|
||||
arg0_paths,
|
||||
config.clone(),
|
||||
cli_kv_overrides.clone(),
|
||||
@@ -1648,7 +1670,7 @@ async fn run_ratatui_app(
|
||||
cloud_config_bundle.clone(),
|
||||
feedback.clone(),
|
||||
log_db.clone(),
|
||||
state_db.clone(),
|
||||
&mut state_db,
|
||||
environment_manager.clone(),
|
||||
),
|
||||
)
|
||||
@@ -1978,6 +2000,10 @@ fn should_show_bedrock_setup_wizard(
|
||||
.is_login_method_allowed(ForcedLoginMethod::Api)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "daemon_startup_tests.rs"]
|
||||
mod daemon_startup_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -2624,18 +2650,48 @@ requires_openai_auth = {requires_openai_auth}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn default_daemon_auto_connect_probes_socket_only() -> color_eyre::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let socket_path =
|
||||
codex_app_server_client::app_server_control_socket_path(codex_home.path())?;
|
||||
std::fs::create_dir_all(socket_path.as_path().parent().expect("socket parent"))?;
|
||||
let _listener = tokio::net::UnixListener::bind(socket_path.as_path())?;
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let parent = socket_path.as_path().parent().expect("socket parent");
|
||||
std::fs::create_dir_all(parent)?;
|
||||
let listener = codex_uds::UnixListener::bind(socket_path.as_path()).await?;
|
||||
assert!(
|
||||
maybe_probe_default_daemon_socket(codex_home.path())
|
||||
.await
|
||||
.is_none()
|
||||
);
|
||||
drop(listener);
|
||||
std::fs::remove_dir_all(parent)?;
|
||||
}
|
||||
codex_uds::prepare_private_socket_directory(
|
||||
socket_path.as_path().parent().expect("socket parent"),
|
||||
)
|
||||
.await?;
|
||||
let _listener = codex_uds::UnixListener::bind(socket_path.as_path()).await?;
|
||||
|
||||
let expected = Some(socket_path);
|
||||
#[cfg(windows)]
|
||||
let expected = {
|
||||
// Existing Windows CI may run elevated; an elevated listener must
|
||||
// never be selected implicitly, even when its directory is private.
|
||||
let output = std::process::Command::new("powershell.exe")
|
||||
.args(["-NoProfile", "-NonInteractive", "-Command", "([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)"])
|
||||
.output()?;
|
||||
assert!(output.status.success());
|
||||
match String::from_utf8(output.stdout)?.trim() {
|
||||
"True" => None,
|
||||
"False" => expected,
|
||||
other => panic!("unexpected elevation result: {other}"),
|
||||
}
|
||||
};
|
||||
assert_eq!(
|
||||
maybe_probe_default_daemon_socket(codex_home.path()).await,
|
||||
Some(socket_path)
|
||||
expected
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@@ -2649,6 +2705,7 @@ requires_openai_auth = {requires_openai_auth}
|
||||
Some(socket_path.clone()),
|
||||
/*can_reuse_implicit_local_daemon*/ true,
|
||||
/*workload_identity_selected*/ false,
|
||||
/*exec_server_url*/ None,
|
||||
)?;
|
||||
|
||||
assert_eq!(
|
||||
@@ -2662,6 +2719,24 @@ requires_openai_auth = {requires_openai_auth}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_server_target_for_launch_preserves_executor_selection() -> color_eyre::Result<()> {
|
||||
let socket_path = AbsolutePathBuf::relative_to_current_dir("codex.sock")?;
|
||||
for executor in ["none", "ws://127.0.0.1:4501"] {
|
||||
assert_eq!(
|
||||
app_server_target_for_launch(
|
||||
/*explicit_remote_endpoint*/ None,
|
||||
Some(socket_path.clone()),
|
||||
/*can_reuse_implicit_local_daemon*/ true,
|
||||
/*workload_identity_selected*/ false,
|
||||
Some(std::ffi::OsStr::new(executor)),
|
||||
)?,
|
||||
AppServerTarget::Embedded,
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_server_target_for_launch_prefers_explicit_remote_endpoint() -> color_eyre::Result<()> {
|
||||
let explicit_endpoint = RemoteAppServerEndpoint::UnixSocket {
|
||||
@@ -2672,6 +2747,7 @@ requires_openai_auth = {requires_openai_auth}
|
||||
Some(AbsolutePathBuf::relative_to_current_dir("default.sock")?),
|
||||
/*can_reuse_implicit_local_daemon*/ false,
|
||||
/*workload_identity_selected*/ false,
|
||||
Some(std::ffi::OsStr::new("none")),
|
||||
)?;
|
||||
|
||||
assert_eq!(
|
||||
@@ -2694,6 +2770,7 @@ requires_openai_auth = {requires_openai_auth}
|
||||
Some(socket_path),
|
||||
/*can_reuse_implicit_local_daemon*/ false,
|
||||
/*workload_identity_selected*/ false,
|
||||
/*exec_server_url*/ None,
|
||||
)?;
|
||||
|
||||
assert_eq!(target, AppServerTarget::Embedded);
|
||||
@@ -2709,6 +2786,7 @@ requires_openai_auth = {requires_openai_auth}
|
||||
Some(default_socket),
|
||||
/*can_reuse_implicit_local_daemon*/ true,
|
||||
/*workload_identity_selected*/ true,
|
||||
/*exec_server_url*/ None,
|
||||
)?,
|
||||
AppServerTarget::Embedded
|
||||
);
|
||||
@@ -2721,6 +2799,7 @@ requires_openai_auth = {requires_openai_auth}
|
||||
/*default_daemon_socket*/ None,
|
||||
/*can_reuse_implicit_local_daemon*/ false,
|
||||
/*workload_identity_selected*/ true,
|
||||
/*exec_server_url*/ None,
|
||||
)
|
||||
.expect_err("remote hosts must own workload identity");
|
||||
assert_eq!(
|
||||
|
||||
@@ -350,11 +350,12 @@ pub(super) async fn start_app_server_for_session_command(
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let app_server_target = super::app_server_target_for_launch(
|
||||
let mut app_server_target = super::app_server_target_for_launch(
|
||||
explicit_remote_endpoint,
|
||||
default_daemon,
|
||||
reuse_implicit_local_daemon,
|
||||
workload_identity_selected,
|
||||
std::env::var_os(codex_exec_server::CODEX_EXEC_SERVER_URL_ENV_VAR).as_deref(),
|
||||
)?;
|
||||
let remote_cwd_override = cli
|
||||
.cwd
|
||||
@@ -446,11 +447,11 @@ pub(super) async fn start_app_server_for_session_command(
|
||||
.build(Some(local_runtime_paths), config.http_client_factory())
|
||||
.wrap_err("failed to initialize environment manager")?,
|
||||
);
|
||||
let state_db = super::init_state_db_for_app_server_target(&config, &app_server_target)
|
||||
let mut state_db = super::init_state_db_for_app_server_target(&config, &app_server_target)
|
||||
.await
|
||||
.wrap_err("failed to initialize state database")?;
|
||||
let app_server = super::start_app_server(
|
||||
&app_server_target,
|
||||
&mut app_server_target,
|
||||
arg0_paths,
|
||||
config,
|
||||
cli_kv_overrides,
|
||||
@@ -459,7 +460,7 @@ pub(super) async fn start_app_server_for_session_command(
|
||||
cloud_config_bundle,
|
||||
codex_feedback::CodexFeedback::new(),
|
||||
/*log_db*/ None,
|
||||
state_db,
|
||||
&mut state_db,
|
||||
environment_manager,
|
||||
)
|
||||
.await?;
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
---
|
||||
source: tui/src/app/agents_overview_tests.rs
|
||||
assertion_line: 401
|
||||
expression: rendered
|
||||
---
|
||||
■ Failed to start the background server: The host does not allow detached processes
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
---
|
||||
source: tui/src/app/agents_overview_tests.rs
|
||||
assertion_line: 401
|
||||
expression: rendered
|
||||
---
|
||||
• Background server started. Run `codex agents` in another terminal; this session remains unchanged.
|
||||
@@ -73,6 +73,7 @@ pub(super) async fn run_main_inner(
|
||||
/*default_daemon_socket*/ None,
|
||||
/*can_reuse_implicit_local_daemon*/ false,
|
||||
workload_identity_selected,
|
||||
std::env::var_os(codex_exec_server::CODEX_EXEC_SERVER_URL_ENV_VAR).as_deref(),
|
||||
)?;
|
||||
let validation_environment_manager =
|
||||
if should_load_configured_environments(&loader_overrides, &validation_target) {
|
||||
@@ -187,6 +188,7 @@ pub(super) async fn run_main_inner(
|
||||
default_daemon,
|
||||
reuse_implicit_local_daemon,
|
||||
workload_identity_selected,
|
||||
std::env::var_os(codex_exec_server::CODEX_EXEC_SERVER_URL_ENV_VAR).as_deref(),
|
||||
)?;
|
||||
let remote_cwd_override = cli
|
||||
.cwd
|
||||
|
||||
Reference in New Issue
Block a user