mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
## 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
92 lines
3.3 KiB
Rust
92 lines
3.3 KiB
Rust
use anyhow::Context;
|
|
use anyhow::Result;
|
|
use codex_app_server::in_process::EmbeddedNetworkPolicy;
|
|
use codex_cloud_config::managed_config_bundle_loader_for_storage;
|
|
use codex_config::CloudConfigBundleLoader;
|
|
use codex_config::ConfigLoadOptions;
|
|
use codex_core::config::Config;
|
|
use codex_core::config::ConfigBuilder;
|
|
use codex_core::config::ConfigOverrides;
|
|
use codex_core::config::LoaderOverrides;
|
|
use codex_core::config::bootstrap_auth_config;
|
|
use codex_core::config::find_codex_home;
|
|
use codex_core::config::load_config_toml_with_layer_stack;
|
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
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()
|
|
.await
|
|
.context("failed to load configuration")?;
|
|
config.config_layer_stack.ensure_config_server_applied()?;
|
|
EmbeddedNetworkPolicy::default().activate(&mut config);
|
|
Ok(config)
|
|
}
|
|
|
|
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
|
|
.parse_overrides()
|
|
.map_err(anyhow::Error::msg)?;
|
|
let codex_home = find_codex_home().context("failed to resolve CODEX_HOME")?;
|
|
let cwd = match harness_overrides.cwd.as_deref() {
|
|
Some(cwd) => AbsolutePathBuf::relative_to_current_dir(cwd),
|
|
None => AbsolutePathBuf::current_dir(),
|
|
}
|
|
.context("failed to resolve current directory")?;
|
|
let bootstrap_config = load_config_toml_with_layer_stack(
|
|
codex_home.as_path(),
|
|
Some(&cwd),
|
|
cli_overrides.clone(),
|
|
ConfigLoadOptions {
|
|
loader_overrides: loader_overrides.clone(),
|
|
strict_config: false,
|
|
cloud_config_bundle: CloudConfigBundleLoader::default(),
|
|
},
|
|
)
|
|
.await
|
|
.context("failed to load bootstrap configuration")?;
|
|
let cloud_config_bundle = managed_config_bundle_loader_for_storage(
|
|
network_policy.bind_bootstrap_auth(
|
|
bootstrap_auth_config(codex_home.as_path(), &bootstrap_config)
|
|
.context("failed to resolve cloud configuration authentication")?,
|
|
),
|
|
bootstrap_config.config_layer_stack.requirements_toml(),
|
|
/*enable_codex_api_key_env*/ false,
|
|
resolution,
|
|
)
|
|
.await
|
|
.context("failed to initialize cloud configuration authentication")?;
|
|
|
|
Ok(ConfigBuilder::default()
|
|
.codex_home(codex_home.to_path_buf())
|
|
.cli_overrides(cli_overrides)
|
|
.loader_overrides(loader_overrides)
|
|
.harness_overrides(harness_overrides)
|
|
.cloud_config_bundle(cloud_config_bundle)
|
|
.fallback_cwd(Some(cwd.to_path_buf())))
|
|
}
|