Lightweight coding agent that runs in your terminal
Rust
Add logs to model cache (#11551)
Ahmed Ibrahim21ceefc0d183
diff --git a/codex-rs/core/src/models_manager/cache.rs b/codex-rs/core/src/models_manager/cache.rsindex e95b634b51..812716d29c 100644--- a/codex-rs/core/src/models_manager/cache.rs+++ b/codex-rs/core/src/models_manager/cache.rs@@ -9,6 +9,7 @@ use std::path::PathBuf;use std::time::Duration;use tokio::fs;use tracing::error;+use tracing::info;/// Manages loading and saving of models cache to disk.#[derive(Debug)]@@ -28,6 +29,11 @@ impl ModelsCacheManager {/// Attempt to load a fresh cache entry. Returns `None` if the cache doesn't exist or is stale.pub(crate) async fn load_fresh(&self, expected_version: &str) -> Option<ModelsCache> {+ info!(+ cache_path = %self.cache_path.display(),+ expected_version,+ "models cache: attempting load_fresh"+ );let cache = match self.load().await {Ok(cache) => cache?,Err(err) => {@@ -35,12 +41,35 @@ impl ModelsCacheManager {return None;}};+ info!(+ cache_path = %self.cache_path.display(),+ cached_version = ?cache.client_version,+ fetched_at = %cache.fetched_at,+ "models cache: loaded cache file"+ );if cache.client_version.as_deref() != Some(expected_version) {+ info!(+ cache_path = %self.cache_path.display(),+ expected_version,+ cached_version = ?cache.client_version,+ "models cache: cache version mismatch"+ );return None;}if !cache.is_fresh(self.cache_ttl) {+ info!(+ cache_path = %self.cache_path.display(),+ cache_ttl_secs = self.cache_ttl.as_secs(),+ fetched_at = %cache.fetched_at,+ "models cache: cache is stale"+ );return None;}+ info!(+ cache_path = %self.cache_path.display(),+ cache_ttl_secs = self.cache_ttl.as_secs(),+ "models cache: cache hit"+ );Some(cache)}diff --git a/codex-rs/core/src/models_manager/manager.rs b/codex-rs/core/src/models_manager/manager.rsindex 5c6a5db7fc..8fbb3c22e1 100644--- a/codex-rs/core/src/models_manager/manager.rs+++ b/codex-rs/core/src/models_manager/manager.rs@@ -26,6 +26,7 @@ use tokio::sync::RwLock;use tokio::sync::TryLockError;use tokio::time::timeout;use tracing::error;+use tracing::info;const MODEL_CACHE_FILE: &str = "models_cache.json";const DEFAULT_MODEL_CACHE_TTL: Duration = Duration::from_secs(300);@@ -216,8 +217,10 @@ impl ModelsManager {RefreshStrategy::OnlineIfUncached => {// Try cache first, fall back to online if unavailableif self.try_load_cache().await {+ info!("models cache: using cached models for OnlineIfUncached");return Ok(());}+ info!("models cache: cache miss, fetching remote models");self.fetch_and_update_models().await}RefreshStrategy::Online => {@@ -285,13 +288,22 @@ impl ModelsManager {let _timer =codex_otel::start_global_timer("codex.remote_models.load_cache.duration_ms", &[]);let client_version = crate::models_manager::client_version_to_whole();+ info!(client_version, "models cache: evaluating cache eligibility");let cache = match self.cache_manager.load_fresh(&client_version).await {Some(cache) => cache,- None => return false,+ None => {+ info!("models cache: no usable cache entry");+ return false;+ }};let models = cache.models.clone();*self.etag.write().await = cache.etag.clone();self.apply_remote_models(models.clone()).await;+ info!(+ models_count = models.len(),+ etag = ?cache.etag,+ "models cache: cache entry applied"+ );true}