mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Reuse config server discovery when loading managed policy (#63473)
## Why CLI login and interactive TUI startup could look up the same config server's OAuth metadata again when loading managed policy, even after resolving it for sign-in. ## What changed - Carry the resolved config server settings in memory from sign-in to policy loading and through TUI startup and worktree setup. Reuse them only when the configured server, outbound proxy policy, and system proxy fallback setting match. - Rediscover anonymous servers after onboarding so the TUI can pick up a newly enabled OAuth requirement. - Use discovered OAuth settings to classify app-server startup errors as config server errors when applicable. ## Testing Add a regression test that blocks discovery requests and checks reuse for matching OAuth and anonymous resolutions, as well as cache misses when the server or either proxy setting changes. GitOrigin-RevId: 28b5c8ffdb80db09dd8bbae3c1e187189ea393bf
This commit is contained in:
@@ -17,11 +17,20 @@ use codex_utils_cli::CliConfigOverrides;
|
||||
pub async fn load_config(
|
||||
config_overrides: &CliConfigOverrides,
|
||||
loader_overrides: LoaderOverrides,
|
||||
) -> Result<Config> {
|
||||
load_config_with_resolution(config_overrides, loader_overrides, /*resolution*/ None).await
|
||||
}
|
||||
|
||||
pub(crate) async fn load_config_with_resolution(
|
||||
config_overrides: &CliConfigOverrides,
|
||||
loader_overrides: LoaderOverrides,
|
||||
resolution: Option<&codex_config::ConfigServerResolution>,
|
||||
) -> Result<Config> {
|
||||
let mut config = config_builder(
|
||||
config_overrides,
|
||||
loader_overrides,
|
||||
ConfigOverrides::default(),
|
||||
resolution,
|
||||
)
|
||||
.await?
|
||||
.build()
|
||||
@@ -36,6 +45,7 @@ pub async fn config_builder(
|
||||
config_overrides: &CliConfigOverrides,
|
||||
loader_overrides: LoaderOverrides,
|
||||
harness_overrides: ConfigOverrides,
|
||||
resolution: Option<&codex_config::ConfigServerResolution>,
|
||||
) -> Result<ConfigBuilder> {
|
||||
let network_policy = EmbeddedNetworkPolicy::load(&loader_overrides).await;
|
||||
let cli_overrides = config_overrides
|
||||
@@ -66,6 +76,7 @@ pub async fn config_builder(
|
||||
),
|
||||
bootstrap_config.config_layer_stack.requirements_toml(),
|
||||
/*enable_codex_api_key_env*/ false,
|
||||
resolution,
|
||||
)
|
||||
.await
|
||||
.context("failed to initialize cloud configuration authentication")?;
|
||||
|
||||
@@ -649,6 +649,7 @@ async fn load_config(
|
||||
&root_config_overrides,
|
||||
LoaderOverrides::default(),
|
||||
overrides,
|
||||
/*resolution*/ None,
|
||||
)
|
||||
.await?
|
||||
.build()
|
||||
|
||||
@@ -187,10 +187,16 @@ async fn sign_in_to_config_server_and_reload_config(
|
||||
.await;
|
||||
let bootstrap_auth = network.bind_bootstrap_auth(config.auth_config());
|
||||
let auth_route_config = bootstrap_auth.auth_route_config.clone();
|
||||
codex_cloud_config::ensure_config_server_login(bootstrap_auth, requirements, method).await?;
|
||||
*config = crate::cloud_config::load_config(cli_config_overrides, Default::default())
|
||||
.await
|
||||
.map_err(|error| std::io::Error::other(format!("{error:#}")))?;
|
||||
let resolution =
|
||||
codex_cloud_config::ensure_config_server_login(bootstrap_auth, requirements, method)
|
||||
.await?;
|
||||
*config = crate::cloud_config::load_config_with_resolution(
|
||||
cli_config_overrides,
|
||||
Default::default(),
|
||||
resolution.as_ref(),
|
||||
)
|
||||
.await
|
||||
.map_err(|error| std::io::Error::other(format!("{error:#}")))?;
|
||||
network.activate(config);
|
||||
config.application_auth_route_config = Some(auth_route_config);
|
||||
Ok(())
|
||||
@@ -592,8 +598,8 @@ async fn logout_config_server(
|
||||
)
|
||||
.await?
|
||||
{
|
||||
Some(manager) => manager.logout().await,
|
||||
None => Ok(false),
|
||||
Some((_, Some(manager))) => manager.logout().await,
|
||||
Some((_, None)) | None => Ok(false),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ impl MarketplaceCli {
|
||||
&config_overrides,
|
||||
LoaderOverrides::default(),
|
||||
ConfigOverrides::default(),
|
||||
/*resolution*/ None,
|
||||
)
|
||||
.await?;
|
||||
let config = builder.clone().build().await?;
|
||||
|
||||
@@ -773,6 +773,7 @@ async fn load_plugin_command_context(
|
||||
overrides,
|
||||
LoaderOverrides::default(),
|
||||
ConfigOverrides::default(),
|
||||
/*resolution*/ None,
|
||||
)
|
||||
.await?
|
||||
.build()
|
||||
|
||||
Reference in New Issue
Block a user