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:
@@ -116,15 +116,18 @@ async fn read_startup_config(
|
||||
Ok(config) => config,
|
||||
// Recovery retains local credential settings when cloud policy is unavailable.
|
||||
Err(_) if sign_out => loaded.bootstrap.clone(),
|
||||
Err(error)
|
||||
if manager
|
||||
.current_managed_config_loader()
|
||||
.config_server()
|
||||
.is_some_and(|server| server.oauth.is_some()) =>
|
||||
{
|
||||
return Err(config_server_error(error));
|
||||
Err(error) => {
|
||||
let loader = manager.current_managed_config_loader();
|
||||
let server = loader
|
||||
.config_server_resolution()
|
||||
.map(|resolution| &resolution.resolved)
|
||||
.or_else(|| loader.config_server());
|
||||
return Err(if server.is_some_and(|server| server.oauth.is_some()) {
|
||||
config_server_error(error)
|
||||
} else {
|
||||
startup_error(error)
|
||||
});
|
||||
}
|
||||
Err(error) => return Err(startup_error(error)),
|
||||
};
|
||||
let config = if sign_out {
|
||||
// Preserve local credential authority while using the effective HTTP route.
|
||||
|
||||
@@ -47,6 +47,7 @@ async fn discover_session(
|
||||
bootstrap.config_layer_stack.requirements_toml(),
|
||||
)
|
||||
.await
|
||||
.map(|session| session.and_then(|(_, manager)| manager))
|
||||
.map_err(|_| config_server_login_failed("Could not initialize configuration server sign-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()
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::service::CLOUD_CONFIG_BUNDLE_TIMEOUT;
|
||||
use crate::service::CloudConfigBundleService;
|
||||
use codex_config::CloudConfigBundleLoader;
|
||||
use codex_config::ConfigRequirementsToml;
|
||||
use codex_config::ConfigServerResolution;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_login::AuthConfig;
|
||||
use codex_login::AuthManager;
|
||||
@@ -24,12 +25,13 @@ const CONFIG_SERVER_LOGIN_FAILURE: &str =
|
||||
pub async fn managed_config_auth_manager(
|
||||
auth: AuthConfig,
|
||||
requirements: &ConfigRequirementsToml,
|
||||
) -> std::io::Result<Option<OAuthSessionManager>> {
|
||||
) -> std::io::Result<Option<(ConfigServerResolution, Option<OAuthSessionManager>)>> {
|
||||
let Some(service_config) = requirements.config_server.as_ref() else {
|
||||
return Ok(None);
|
||||
};
|
||||
crate::config_server_auth_manager(service_config, auth.codex_home, &auth.auth_route_config)
|
||||
.await
|
||||
.map(Some)
|
||||
}
|
||||
|
||||
/// How to sign in when the config server has no saved OAuth grant.
|
||||
@@ -43,11 +45,14 @@ pub async fn ensure_config_server_login(
|
||||
auth: AuthConfig,
|
||||
requirements: &ConfigRequirementsToml,
|
||||
method: ConfigServerLoginMethod,
|
||||
) -> std::io::Result<()> {
|
||||
let Some(manager) = managed_config_auth_manager(auth, requirements).await? else {
|
||||
return Ok(());
|
||||
) -> std::io::Result<Option<ConfigServerResolution>> {
|
||||
let Some((resolution, manager)) = managed_config_auth_manager(auth, requirements).await? else {
|
||||
return Ok(None);
|
||||
};
|
||||
ensure_config_server_login_with_manager(&manager, method).await
|
||||
if let Some(manager) = manager {
|
||||
ensure_config_server_login_with_manager(&manager, method).await?;
|
||||
}
|
||||
Ok(Some(resolution))
|
||||
}
|
||||
|
||||
pub(crate) async fn ensure_config_server_login_with_manager(
|
||||
@@ -88,6 +93,7 @@ pub async fn managed_config_bundle_loader(
|
||||
service_config.clone(),
|
||||
codex_home,
|
||||
&codex_login::AuthRouteConfig::from_http_client_factory(factory),
|
||||
/*previous*/ None,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@@ -109,12 +115,14 @@ pub async fn managed_config_bundle_loader_for_storage(
|
||||
auth_config: AuthConfig,
|
||||
requirements: &ConfigRequirementsToml,
|
||||
enable_codex_api_key_env: bool,
|
||||
resolution: Option<&ConfigServerResolution>,
|
||||
) -> std::io::Result<CloudConfigBundleLoader> {
|
||||
if let Some(service_config) = requirements.config_server.as_ref() {
|
||||
return Ok(crate::config_server_bundle_loader(
|
||||
service_config.clone(),
|
||||
auth_config.codex_home,
|
||||
&auth_config.auth_route_config,
|
||||
resolution,
|
||||
)
|
||||
.await);
|
||||
}
|
||||
@@ -205,6 +213,7 @@ pub async fn managed_config_bundle_loader_for_auth(
|
||||
config,
|
||||
requirements,
|
||||
/*enable_codex_api_key_env*/ false,
|
||||
/*resolution*/ None,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use codex_config::CloudConfigBundleLoader;
|
||||
use codex_config::CloudConfigBundlePolicy;
|
||||
use codex_config::CloudConfigBundleSnapshot;
|
||||
use codex_config::ConfigServer;
|
||||
use codex_config::ConfigServerResolution;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_keyring_store::DefaultKeyringStore;
|
||||
use codex_login::AuthRouteConfig;
|
||||
@@ -37,20 +38,18 @@ pub async fn config_server_bundle_loader(
|
||||
config: ConfigServer,
|
||||
codex_home: PathBuf,
|
||||
routes: &AuthRouteConfig,
|
||||
previous: Option<&ConfigServerResolution>,
|
||||
) -> CloudConfigBundleLoader {
|
||||
let service = create_config_server_service(&config, &codex_home, routes).await;
|
||||
|
||||
let loader = match service {
|
||||
Ok(service) => {
|
||||
match create_config_server_service(&config, &codex_home, routes, previous).await {
|
||||
Ok((service, resolution)) => {
|
||||
let (loader, _) = managed_config_bundle_loader_for_service(service);
|
||||
loader
|
||||
loader.with_config_server_resolution(resolution)
|
||||
}
|
||||
Err(error) => {
|
||||
config_server_loader_after_failure(config.clone(), codex_home, routes.clone(), error)
|
||||
.with_config_server(config)
|
||||
}
|
||||
};
|
||||
|
||||
loader.with_config_server(config)
|
||||
}
|
||||
}
|
||||
|
||||
/// Git must apply the same policy as Codex without opening the OS keyring.
|
||||
@@ -60,7 +59,9 @@ pub async fn anonymous_config_server_bundle_loader(
|
||||
codex_home: PathBuf,
|
||||
routes: &AuthRouteConfig,
|
||||
) -> std::io::Result<CloudConfigBundleLoader> {
|
||||
let resolved = resolve_config_server(config, routes).await?;
|
||||
let resolved = resolve_config_server(config, routes, /*previous*/ None)
|
||||
.await?
|
||||
.resolved;
|
||||
if resolved.oauth.is_some() {
|
||||
return Err(std::io::Error::other(
|
||||
"Git cannot verify Codex workspace policy using a protected login",
|
||||
@@ -76,8 +77,15 @@ async fn create_config_server_service(
|
||||
config: &ConfigServer,
|
||||
codex_home: &Path,
|
||||
routes: &AuthRouteConfig,
|
||||
) -> Result<CloudConfigBundleService<ConfigServerSource>, CloudConfigBundleLoadError> {
|
||||
let resolved = resolve_config_server(config, routes)
|
||||
previous: Option<&ConfigServerResolution>,
|
||||
) -> Result<
|
||||
(
|
||||
CloudConfigBundleService<ConfigServerSource>,
|
||||
ConfigServerResolution,
|
||||
),
|
||||
CloudConfigBundleLoadError,
|
||||
> {
|
||||
let resolution = resolve_config_server(config, routes, previous)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
CloudConfigBundleLoadError::new(
|
||||
@@ -87,7 +95,8 @@ async fn create_config_server_service(
|
||||
)
|
||||
})?;
|
||||
|
||||
config_server_service(resolved, codex_home, routes)
|
||||
let service = config_server_service(resolution.resolved.clone(), codex_home, routes)?;
|
||||
Ok((service, resolution))
|
||||
}
|
||||
|
||||
fn config_server_service(
|
||||
@@ -134,8 +143,13 @@ fn config_server_loader_after_failure(
|
||||
None => {
|
||||
initialized
|
||||
.get_or_try_init(|| async move {
|
||||
let mut service =
|
||||
create_config_server_service(&config, &codex_home, &routes).await?;
|
||||
let (mut service, _) = create_config_server_service(
|
||||
&config,
|
||||
&codex_home,
|
||||
&routes,
|
||||
/*previous*/ None,
|
||||
)
|
||||
.await?;
|
||||
service.policy = policy;
|
||||
let (loader, _) = managed_config_bundle_loader_for_service(service);
|
||||
Ok(loader)
|
||||
@@ -167,10 +181,12 @@ pub async fn config_server_auth_manager(
|
||||
service_config: &ConfigServer,
|
||||
codex_home: PathBuf,
|
||||
routes: &AuthRouteConfig,
|
||||
) -> std::io::Result<Option<OAuthSessionManager>> {
|
||||
let resolved = resolve_config_server(service_config, routes).await?;
|
||||
let factory = config_server_http_client_factory(&resolved, routes);
|
||||
oauth_session_manager(resolved.oauth.as_deref(), codex_home, &factory)
|
||||
) -> std::io::Result<(ConfigServerResolution, Option<OAuthSessionManager>)> {
|
||||
let resolution = resolve_config_server(service_config, routes, /*previous*/ None).await?;
|
||||
let factory = config_server_http_client_factory(&resolution.resolved, routes);
|
||||
let manager =
|
||||
oauth_session_manager(resolution.resolved.oauth.as_deref(), codex_home, &factory)?;
|
||||
Ok((resolution, manager))
|
||||
}
|
||||
|
||||
fn config_server_http_client_factory(
|
||||
|
||||
@@ -118,6 +118,65 @@ async fn device_endpoint_failure_points_to_config_server_oauth() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn policy_reload_reuses_discovery_only_for_the_same_config_server() {
|
||||
let home = tempdir().unwrap();
|
||||
let mut auth = codex_core::config::Config::load_default_with_cli_overrides_for_codex_home(
|
||||
home.path().into(),
|
||||
vec![],
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.auth_config();
|
||||
// Any attempt to rediscover metadata during reload will fail.
|
||||
let default = HttpClientFactory::new(codex_http_client::OutboundProxyPolicy::ReqwestDefault);
|
||||
let blocked = default
|
||||
.clone()
|
||||
.with_network_policy(codex_http_client::NetworkPolicyController::default().policy());
|
||||
auth.auth_route_config = AuthRouteConfig::from_http_client_factory(blocked);
|
||||
let base_url = "https://config.example";
|
||||
let server = |url: &str| ConfigServer {
|
||||
base_url: url.into(),
|
||||
oauth: None,
|
||||
};
|
||||
let requirements = codex_config::ConfigRequirementsToml {
|
||||
config_server: Some(server(base_url)),
|
||||
..Default::default()
|
||||
};
|
||||
let oauth = Box::new(oauth_config("https://login.example"));
|
||||
let system = HttpClientFactory::new(codex_http_client::OutboundProxyPolicy::RespectSystemProxy);
|
||||
let fallback = default.clone().with_system_proxy_fallback();
|
||||
for (previous_url, discovered_oauth, factory, reuse) in [
|
||||
(base_url, Some(oauth.clone()), &default, true),
|
||||
(base_url, None, &default, true),
|
||||
("https://other.example", None, &default, false),
|
||||
(base_url, Some(oauth), &system, false),
|
||||
(base_url, None, &fallback, false),
|
||||
] {
|
||||
let previous = ConfigServerResolution {
|
||||
outbound_proxy_policy: factory.outbound_proxy_policy(),
|
||||
system_proxy_fallback: factory.allows_system_proxy_fallback(),
|
||||
configured: server(previous_url),
|
||||
resolved: ConfigServer {
|
||||
oauth: discovered_oauth,
|
||||
..server(previous_url)
|
||||
},
|
||||
};
|
||||
let loader = crate::managed_config_bundle_loader_for_storage(
|
||||
auth.clone(),
|
||||
&requirements,
|
||||
/*enable_codex_api_key_env*/ false,
|
||||
Some(&previous),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
loader.config_server_resolution(),
|
||||
reuse.then_some(&previous)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn policy_fetch_uses_replacement_config_server_credentials() {
|
||||
let server = MockServer::start().await;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//! Explicit OAuth settings take precedence, and discovered settings stay in memory.
|
||||
|
||||
use codex_config::ConfigServer;
|
||||
use codex_config::ConfigServerResolution;
|
||||
use codex_exec_server::RouteAwareHttpClient;
|
||||
use codex_login::AuthRouteConfig;
|
||||
use codex_login::OAuthSessionConfig;
|
||||
@@ -16,8 +17,23 @@ const DISCOVERY_TIMEOUT: Duration = Duration::from_secs(5);
|
||||
pub(crate) async fn resolve_config_server(
|
||||
config: &ConfigServer,
|
||||
routes: &AuthRouteConfig,
|
||||
) -> io::Result<ConfigServer> {
|
||||
previous: Option<&ConfigServerResolution>,
|
||||
) -> io::Result<ConfigServerResolution> {
|
||||
config.validated_base_url().map_err(io::Error::other)?;
|
||||
let factory = routes.bootstrap_http_client_factory();
|
||||
let outbound_proxy_policy = factory.outbound_proxy_policy();
|
||||
let system_proxy_fallback = factory.allows_system_proxy_fallback();
|
||||
if let Some(previous) = previous
|
||||
&& previous.configured == *config
|
||||
&& previous.outbound_proxy_policy == outbound_proxy_policy
|
||||
&& previous.system_proxy_fallback == system_proxy_fallback
|
||||
{
|
||||
previous
|
||||
.resolved
|
||||
.validated_base_url()
|
||||
.map_err(io::Error::other)?;
|
||||
return Ok(previous.clone());
|
||||
}
|
||||
let mut resolved = config.clone();
|
||||
|
||||
if config.oauth.is_none()
|
||||
@@ -27,7 +43,12 @@ pub(crate) async fn resolve_config_server(
|
||||
resolved.validated_base_url().map_err(io::Error::other)?;
|
||||
}
|
||||
|
||||
Ok(resolved)
|
||||
Ok(ConfigServerResolution {
|
||||
outbound_proxy_policy,
|
||||
system_proxy_fallback,
|
||||
configured: config.clone(),
|
||||
resolved,
|
||||
})
|
||||
}
|
||||
|
||||
async fn discover_oauth(
|
||||
|
||||
@@ -120,7 +120,10 @@ async fn preserves_explicit_oauth_without_discovery() {
|
||||
oauth: Some(Box::new(explicit_oauth)),
|
||||
};
|
||||
assert_eq!(
|
||||
resolve_config_server(&config, &routes).await.unwrap(),
|
||||
resolve_config_server(&config, &routes, /*previous*/ None)
|
||||
.await
|
||||
.unwrap()
|
||||
.resolved,
|
||||
config
|
||||
);
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
|
||||
@@ -428,6 +428,7 @@ pub struct CloudConfigBundleLoader {
|
||||
snapshot_getter: Option<Arc<CloudConfigBundleSnapshotGetter>>,
|
||||
ema_policy: Option<CloudConfigBundlePolicy>,
|
||||
config_server: Option<crate::ConfigServer>,
|
||||
config_server_resolution: Option<Arc<crate::ConfigServerResolution>>,
|
||||
}
|
||||
|
||||
impl CloudConfigBundleLoader {
|
||||
@@ -454,6 +455,7 @@ impl CloudConfigBundleLoader {
|
||||
snapshot_getter: None,
|
||||
ema_policy: None,
|
||||
config_server: None,
|
||||
config_server_resolution: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,9 +505,24 @@ impl CloudConfigBundleLoader {
|
||||
|
||||
pub fn with_config_server(mut self, service_config: crate::ConfigServer) -> Self {
|
||||
self.config_server = Some(service_config);
|
||||
self.config_server_resolution = None;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_config_server_resolution(
|
||||
mut self,
|
||||
resolution: crate::ConfigServerResolution,
|
||||
) -> Self {
|
||||
self.config_server = Some(resolution.configured.clone());
|
||||
self.config_server_resolution = Some(Arc::new(resolution));
|
||||
self
|
||||
}
|
||||
|
||||
/// Successful discovery, including anonymous configuration, for the retained loader.
|
||||
pub fn config_server_resolution(&self) -> Option<&crate::ConfigServerResolution> {
|
||||
self.config_server_resolution.as_deref()
|
||||
}
|
||||
|
||||
pub fn config_server(&self) -> Option<&crate::ConfigServer> {
|
||||
self.config_server.as_ref()
|
||||
}
|
||||
|
||||
@@ -15,6 +15,15 @@ pub struct ConfigServer {
|
||||
pub oauth: Option<Box<ConfigServerOAuth>>,
|
||||
}
|
||||
|
||||
/// Successful runtime resolution, kept separate from administrator requirements.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct ConfigServerResolution {
|
||||
pub outbound_proxy_policy: codex_http_client::OutboundProxyPolicy,
|
||||
pub system_proxy_fallback: bool,
|
||||
pub configured: ConfigServer,
|
||||
pub resolved: ConfigServer,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct ConfigServerInput {
|
||||
|
||||
@@ -155,6 +155,7 @@ pub use config_requirements::apply_otel_requirements;
|
||||
pub use config_requirements::sandbox_mode_requirement_for_permission_profile;
|
||||
pub use config_server::ConfigServer;
|
||||
pub use config_server::ConfigServerOAuth;
|
||||
pub use config_server::ConfigServerResolution;
|
||||
pub use config_toml::effective_sandbox_mode;
|
||||
pub use constraint::Constrained;
|
||||
pub use constraint::ConstraintError;
|
||||
|
||||
@@ -446,6 +446,7 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
|
||||
.bind_bootstrap_auth(bootstrap_auth_config(&codex_home, &gate_bootstrap)?),
|
||||
gate_bootstrap.config_layer_stack.requirements_toml(),
|
||||
/*enable_codex_api_key_env*/ false,
|
||||
/*resolution*/ None,
|
||||
)
|
||||
.await?;
|
||||
let gate_config = ConfigBuilder::default()
|
||||
@@ -546,6 +547,7 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
|
||||
bootstrap_auth_config,
|
||||
bootstrap_config.config_layer_stack.requirements_toml(),
|
||||
/*enable_codex_api_key_env*/ false,
|
||||
/*resolution*/ None,
|
||||
)
|
||||
.await?;
|
||||
if let Some(worktree) = managed_worktree.as_ref() {
|
||||
|
||||
@@ -1063,6 +1063,7 @@ async fn cloud_config_bundle_for_app_server_target(
|
||||
bootstrap_config: &ConfigTomlLoadResult,
|
||||
codex_home: &Path,
|
||||
embedded_network_policy: &codex_app_server_client::EmbeddedNetworkPolicy,
|
||||
resolution: Option<&codex_config::ConfigServerResolution>,
|
||||
) -> std::io::Result<CloudConfigBundleLoader> {
|
||||
managed_config_bundle_loader_for_storage(
|
||||
embedded_network_policy
|
||||
@@ -1071,6 +1072,7 @@ async fn cloud_config_bundle_for_app_server_target(
|
||||
)),
|
||||
bootstrap_config.config_layer_stack.requirements_toml(),
|
||||
/*enable_codex_api_key_env*/ false,
|
||||
resolution,
|
||||
)
|
||||
.await
|
||||
}
|
||||
@@ -1505,6 +1507,10 @@ async fn run_ratatui_app(
|
||||
embedded_network_policy.bind_bootstrap_auth(initial_config.auth_config()),
|
||||
initial_config.config_layer_stack.requirements_toml(),
|
||||
/*enable_codex_api_key_env*/ false,
|
||||
// The server may have started requiring OAuth during onboarding.
|
||||
cloud_config_bundle
|
||||
.config_server_resolution()
|
||||
.filter(|resolution| resolution.resolved.oauth.is_some()),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -342,6 +342,7 @@ pub(super) async fn start_app_server_for_session_command(
|
||||
&bootstrap_config,
|
||||
codex_home.as_path(),
|
||||
&embedded_network_policy,
|
||||
/*resolution*/ None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -181,6 +181,7 @@ pub(super) async fn run_main_inner(
|
||||
&validation_bootstrap,
|
||||
&codex_home,
|
||||
&embedded_network_policy,
|
||||
/*resolution*/ None,
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
@@ -313,7 +314,7 @@ pub(super) async fn run_main_inner(
|
||||
err
|
||||
}
|
||||
})?;
|
||||
if std::io::stdin().is_terminal() && std::io::stdout().is_terminal() {
|
||||
let resolution = if std::io::stdin().is_terminal() && std::io::stdout().is_terminal() {
|
||||
codex_cloud_config::ensure_config_server_login(
|
||||
embedded_network_policy.bind_bootstrap_auth(bootstrap_auth_config(
|
||||
&codex_home,
|
||||
@@ -325,8 +326,10 @@ pub(super) async fn run_main_inner(
|
||||
.requirements_toml(),
|
||||
codex_cloud_config::ConfigServerLoginMethod::Browser,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
.await?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
// Keep normal terminal signals available until local configuration is ready. Once raw
|
||||
// mode begins, StartupDraft immediately takes ownership of input.
|
||||
let (initialized_terminal, terminal_restore_guard) = tokio::task::spawn_blocking(|| {
|
||||
@@ -402,6 +405,7 @@ pub(super) async fn run_main_inner(
|
||||
&bootstrap_config,
|
||||
&codex_home,
|
||||
&embedded_network_policy,
|
||||
resolution.as_ref(),
|
||||
))
|
||||
.await??;
|
||||
let bootstrap_config_toml = &bootstrap_config.config_toml;
|
||||
@@ -537,6 +541,7 @@ pub(super) async fn run_main_inner(
|
||||
),
|
||||
config.config_layer_stack.requirements_toml(),
|
||||
/*enable_codex_api_key_env*/ false,
|
||||
cloud_config_bundle.config_server_resolution(),
|
||||
))
|
||||
.await??
|
||||
};
|
||||
|
||||
@@ -129,7 +129,7 @@ pub(super) async fn prepare(
|
||||
strict_config: bool,
|
||||
target: &AppServerTarget,
|
||||
arg0_paths: &Arg0DispatchPaths,
|
||||
source_bundle: CloudConfigBundleLoader,
|
||||
mut source_bundle: CloudConfigBundleLoader,
|
||||
embedded_network_policy: &codex_app_server_client::EmbeddedNetworkPolicy,
|
||||
) -> color_eyre::Result<(Config, CloudConfigBundleLoader, ManagedTuiWorktree)> {
|
||||
if let Some(id_or_name) = cli.fork_session_id.as_deref() {
|
||||
@@ -202,11 +202,12 @@ pub(super) async fn prepare(
|
||||
CloudConfigBundleLoader::default(),
|
||||
)
|
||||
.await;
|
||||
let source_bundle = cloud_config_bundle_for_app_server_target(
|
||||
source_bundle = cloud_config_bundle_for_app_server_target(
|
||||
target,
|
||||
&bootstrap,
|
||||
&source.codex_home,
|
||||
embedded_network_policy,
|
||||
source_bundle.config_server_resolution(),
|
||||
)
|
||||
.await?;
|
||||
overrides.cwd = Some(cwd.into_path_buf());
|
||||
@@ -214,7 +215,7 @@ pub(super) async fn prepare(
|
||||
cli_overrides.clone(),
|
||||
overrides.clone(),
|
||||
loader_overrides.clone(),
|
||||
source_bundle,
|
||||
source_bundle.clone(),
|
||||
strict_config,
|
||||
)
|
||||
.await;
|
||||
@@ -279,6 +280,7 @@ pub(super) async fn prepare(
|
||||
&bootstrap,
|
||||
&source.codex_home,
|
||||
embedded_network_policy,
|
||||
source_bundle.config_server_resolution(),
|
||||
)
|
||||
.await?;
|
||||
managed
|
||||
|
||||
Reference in New Issue
Block a user