diff --git a/codex-rs/core/src/models_manager/cache.rs b/codex-rs/core/src/models_manager/cache.rs index 7399438579..64619a19e4 100644 --- a/codex-rs/core/src/models_manager/cache.rs +++ b/codex-rs/core/src/models_manager/cache.rs @@ -56,6 +56,17 @@ impl ModelsCacheManager { } } + /// Renew the cache TTL by updating the fetched_at timestamp to the current time. + /// This rewrites the cache with a newer fetched_at value, effectively resetting the TTL. + pub(crate) async fn renew_cache_ttl(&self) -> io::Result<()> { + let mut cache = match self.load().await? { + Some(cache) => cache, + None => return Err(io::Error::new(ErrorKind::NotFound, "cache not found")), + }; + cache.fetched_at = Utc::now(); + self.save_internal(&cache).await + } + async fn load(&self) -> io::Result> { match fs::read(&self.cache_path).await { Ok(contents) => { diff --git a/codex-rs/core/src/models_manager/manager.rs b/codex-rs/core/src/models_manager/manager.rs index ab47e4aa8b..acdb93058a 100644 --- a/codex-rs/core/src/models_manager/manager.rs +++ b/codex-rs/core/src/models_manager/manager.rs @@ -163,9 +163,13 @@ impl ModelsManager { /// Refresh models if the provided ETag differs from the cached ETag. /// /// Uses `Online` strategy to fetch latest models when ETags differ. + /// If ETags match, renews the cache TTL to extend its validity. pub(crate) async fn refresh_if_new_etag(&self, etag: String, config: &Config) { let current_etag = self.get_etag().await; if current_etag.clone().is_some() && current_etag.as_deref() == Some(etag.as_str()) { + if let Err(err) = self.cache_manager.renew_cache_ttl().await { + error!("failed to renew cache TTL: {err}"); + } return; } if let Err(err) = self