[codex-cli] serialize startup ChatGPT token refresh [ci changed_files]

This commit is contained in:
Cooper Gamble
2026-05-21 23:00:30 +00:00
parent d5eb810671
commit 4e0397eea7
5 changed files with 188 additions and 55 deletions
+53 -3
View File
@@ -45,6 +45,7 @@ use tokio::time::sleep;
use tokio::time::timeout;
const CLOUD_REQUIREMENTS_TIMEOUT: Duration = Duration::from_secs(15);
const CHATGPT_ACCESS_TOKEN_STARTUP_REFRESH_TIMEOUT: Duration = Duration::from_secs(15);
const CLOUD_REQUIREMENTS_MAX_ATTEMPTS: usize = 5;
const CLOUD_REQUIREMENTS_CACHE_FILENAME: &str = "cloud-requirements-cache.json";
const CLOUD_REQUIREMENTS_CACHE_REFRESH_INTERVAL: Duration = Duration::from_secs(5 * 60);
@@ -728,22 +729,71 @@ pub fn cloud_requirements_loader(
})
}
async fn cloud_requirements_auth_manager_for_storage(
codex_home: &Path,
enable_codex_api_key_env: bool,
credentials_store_mode: AuthCredentialsStoreMode,
chatgpt_base_url: &str,
) -> Arc<AuthManager> {
AuthManager::shared(
codex_home.to_path_buf(),
enable_codex_api_key_env,
credentials_store_mode,
Some(chatgpt_base_url.to_string()),
)
.await
}
pub async fn cloud_requirements_loader_for_storage(
codex_home: PathBuf,
enable_codex_api_key_env: bool,
credentials_store_mode: AuthCredentialsStoreMode,
chatgpt_base_url: String,
) -> CloudRequirementsLoader {
let auth_manager = AuthManager::shared(
codex_home.clone(),
let auth_manager = cloud_requirements_auth_manager_for_storage(
&codex_home,
enable_codex_api_key_env,
credentials_store_mode,
Some(chatgpt_base_url.clone()),
&chatgpt_base_url,
)
.await;
cloud_requirements_loader(auth_manager, chatgpt_base_url, codex_home)
}
pub async fn cloud_requirements_loader_for_storage_with_startup_refresh(
codex_home: PathBuf,
enable_codex_api_key_env: bool,
credentials_store_mode: AuthCredentialsStoreMode,
chatgpt_base_url: String,
) -> CloudRequirementsLoader {
let auth_manager = cloud_requirements_auth_manager_for_storage(
&codex_home,
enable_codex_api_key_env,
credentials_store_mode,
&chatgpt_base_url,
)
.await;
match timeout(
CHATGPT_ACCESS_TOKEN_STARTUP_REFRESH_TIMEOUT,
auth_manager.refresh_managed_chatgpt_token_if_near_expiry(),
)
.await
{
Ok(Ok(())) => {}
Ok(Err(err)) => {
tracing::warn!(
"failed to proactively refresh ChatGPT access token during CLI startup: {err}"
);
}
Err(_) => {
tracing::warn!(
"timed out proactively refreshing ChatGPT access token during CLI startup"
);
}
}
cloud_requirements_loader(auth_manager, chatgpt_base_url, codex_home)
}
fn parse_cloud_requirements(
contents: &str,
requirements_base_dir: &Path,