mirror of
https://github.com/openai/codex.git
synced 2026-12-05 01:00:54 +00:00
Preserve the CLI MXC preference in executor config reads (#51525)
## Why Executor config reads omitted the startup `features.prefer_mxc` override, so clients could not see the CLI sandbox preference. ## What changed - Include the explicit CLI `features.prefer_mxc` value in `environmentConfig/read` as a `session-flags` layer, above project config and below legacy managed file and MDM config. - Retain only this preference from startup overrides. - Expose `windows_mxc_allowed_by_config` to share MXC eligibility checks after callers resolve the active permission profile. ## Testing Add CLI and remote executor coverage for preference propagation and filtering, plus a unit test verifying that both legacy managed config sources retain precedence. GitOrigin-RevId: 5ac6f5257f1e807c2f197dcf5dcb2385cedca0ea
This commit is contained in:
@@ -174,12 +174,21 @@ impl ExecServerCommand {
|
||||
.codex_self_exe
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow::anyhow!("Codex executable path is not configured"))?;
|
||||
let runtime_paths = ExecServerRuntimeOptions::new(
|
||||
let mut runtime_paths = ExecServerRuntimeOptions::new(
|
||||
codex_self_exe,
|
||||
arg0_paths.codex_linux_sandbox_exe.clone(),
|
||||
)?
|
||||
.with_linux_sandbox_pid_namespace(self.linux_sandbox_pid_namespace)
|
||||
.with_proxy_private_ips_via_upstream(self.proxy_private_ips_via_upstream);
|
||||
// Config loading below owns error handling (non-strict stdio can proceed
|
||||
// without config). Never retain other startup flags in the executor.
|
||||
if let Ok(overrides) = root_config_overrides.parse_overrides() {
|
||||
let cli_flags = codex_config::build_cli_overrides_layer(&overrides);
|
||||
runtime_paths.prefer_mxc = cli_flags
|
||||
.get("features")
|
||||
.and_then(|features| features.get("prefer_mxc"))
|
||||
.and_then(toml::Value::as_bool);
|
||||
}
|
||||
if let Some(base_url) = self.remote.take() {
|
||||
let environment_id = self.environment_id.take().ok_or_else(|| {
|
||||
anyhow::anyhow!("--environment-id is required when --remote is set")
|
||||
|
||||
@@ -97,6 +97,75 @@ fn local_exec_server_ignores_invalid_config_without_strict_config() -> Result<()
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Real global CLI flags must reach executor config reads; unrelated startup flags stay private.
|
||||
#[tokio::test]
|
||||
async fn local_exec_server_projects_global_mxc_preference() -> Result<()> {
|
||||
let home = TempDir::new()?;
|
||||
let cwd = url::Url::from_directory_path(home.path())
|
||||
.map_err(|()| anyhow::anyhow!("could not convert home to file URL"))?;
|
||||
let mut child = tokio::process::Command::new(codex_utils_cargo_bin::cargo_bin("codex")?)
|
||||
.env("CODEX_HOME", home.path())
|
||||
.args([
|
||||
"-c",
|
||||
"features.prefer_mxc=true",
|
||||
"-c",
|
||||
"model='private-startup-model'",
|
||||
"exec-server",
|
||||
"--listen",
|
||||
"stdio",
|
||||
])
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.kill_on_drop(true)
|
||||
.spawn()?;
|
||||
let mut stdin = child.stdin.take().context("exec-server stdin")?;
|
||||
let mut stdout = BufReader::new(child.stdout.take().context("exec-server stdout")?);
|
||||
let result = tokio::time::timeout(Duration::from_secs(30), async {
|
||||
send_json_line(
|
||||
&mut stdin,
|
||||
&serde_json::json!({"id": 1, "method": "initialize",
|
||||
"params": {"clientName": "mxc-test", "resumeSessionId": null}}),
|
||||
)
|
||||
.await?;
|
||||
wait_for_response(&mut stdout, /*expected_id*/ 1).await?;
|
||||
send_json_line(
|
||||
&mut stdin,
|
||||
&serde_json::json!({"method": "initialized", "params": {}}),
|
||||
)
|
||||
.await?;
|
||||
send_json_line(
|
||||
&mut stdin,
|
||||
&serde_json::json!({"id": 2, "method": "environmentConfig/read", "params": {
|
||||
"cwd": cwd, "configPaths": [["features", "prefer_mxc"], ["model"]],
|
||||
"requirementsPaths": []
|
||||
}}),
|
||||
)
|
||||
.await?;
|
||||
wait_for_response(&mut stdout, /*expected_id*/ 2).await
|
||||
})
|
||||
.await
|
||||
.context("executor CLI config read timed out")??;
|
||||
let layers = result["result"]["config"]["layers"]
|
||||
.as_array()
|
||||
.context("config layers")?;
|
||||
let session = layers
|
||||
.iter()
|
||||
.find(|l| l["source"] == "session-flags")
|
||||
.context("session flags")?;
|
||||
let value: toml::Value = toml::from_str(session["toml"].as_str().context("session TOML")?)?;
|
||||
assert_eq!(
|
||||
value,
|
||||
toml::Value::Table(toml::toml! { [features] prefer_mxc = true })
|
||||
);
|
||||
drop(stdin);
|
||||
assert!(
|
||||
tokio::time::timeout(Duration::from_secs(30), child.wait())
|
||||
.await??
|
||||
.success()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The standalone exec-server accepts an explicit per-connection concurrency limit.
|
||||
#[test]
|
||||
fn local_exec_server_accepts_concurrent_requests_flag() -> Result<()> {
|
||||
@@ -617,7 +686,7 @@ fn local_exec_server_exits_successfully_on_sigterm() -> Result<()> {
|
||||
async fn wait_for_response(
|
||||
stdout: &mut (impl tokio::io::AsyncBufRead + Unpin),
|
||||
expected_id: i64,
|
||||
) -> Result<()> {
|
||||
) -> Result<serde_json::Value> {
|
||||
loop {
|
||||
let mut line = String::new();
|
||||
if stdout.read_line(&mut line).await? == 0 {
|
||||
@@ -629,7 +698,7 @@ async fn wait_for_response(
|
||||
message.get("error").is_none(),
|
||||
"exec-server request {expected_id} failed: {message}"
|
||||
);
|
||||
return Ok(());
|
||||
return Ok(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user