Use server authentication for explicit remote session commands (#49624)

## Why

Session commands with `--remote` should use the selected server's authentication and execution environment, even when the caller has workload identity configured and cannot read its identity token.

## What changed

Connect `queue`, `archive`, `unarchive`, and `delete` directly to the explicit remote app server after validating configuration. Skip caller credential and runtime initialization, use remote thread parameters, and preserve the caller's working-directory override.

## Testing

Add end-to-end coverage with an unreadable caller identity token to verify queued turns use the server's API key and remote archive, unarchive, and deletion operate on the selected server. Add configuration-validation coverage for all four commands and `--no-daemon` rejection coverage for remote unarchive and delete.

GitOrigin-RevId: 5da7abbb40506cd754a8863e1a9d8fad9b1f09a9
This commit is contained in:
cooper-oai
2026-09-30 13:16:08 +00:00
committed by copyberry
parent 92bc601ad6
commit 7219fd735b
5 changed files with 316 additions and 2 deletions
@@ -2,6 +2,8 @@
//!
//! The CLI commands are thin app-server clients: resolve a user-provided UUID or exact session
//! name, then call the corresponding app-server RPC.
//! Explicit remote session commands, including queue, leave authentication and execution to
//! the selected server without initializing the caller's credentials or runtime.
use std::io::IsTerminal;
use std::io::Write;
@@ -11,6 +13,7 @@ use std::sync::Arc;
use crate::Cli;
use crate::app_server_session::AppServerSession;
use crate::app_server_session::ThreadParamsMode;
use crate::legacy_core::config::ConfigBuilder;
use crate::legacy_core::config::ConfigOverrides;
use crate::legacy_core::config::load_config_toml_with_layer_stack;
@@ -247,6 +250,25 @@ pub(super) async fn start_app_server_for_session_command(
launch_loader_overrides.user_config_profile = Some(profile_v2.clone());
}
if let Some(endpoint) = explicit_remote_endpoint {
// Validate config before connecting, but leave authentication and execution
// to the selected server even when this caller has workload identity set.
launch_loader_overrides.ignore_login_requirements = true;
ConfigBuilder::default()
.codex_home(codex_home)
.cli_overrides(cli_kv_overrides)
.loader_overrides(launch_loader_overrides)
.strict_config(strict_config)
.build()
.await
.wrap_err("failed to load config.toml")?;
return Ok(AppServerSession::new(
super::connect_remote_app_server(endpoint).await?,
ThreadParamsMode::Remote,
)
.with_remote_cwd_override(cli.cwd.clone()));
}
let workload_identity_selected = codex_login::is_workload_identity_selected();
let reuse_implicit_local_daemon = !cli.no_daemon
&& !workload_identity_selected