Files
codex/codex-rs/ext/extension-api/src/catalog_refresh.rs
T
Anthony Tafoya 0b297ec5ee Retry incomplete cloud catalogs with exponential backoff (#61400)
## What changed

- Keep partial cloud skill and plugin catalogs, and catalogs with warnings, usable while retrying discovery with exponential backoff. Start retries after 5 seconds and cap the delay at 5 minutes; clear backoff after a complete, warning-free result.
- Replace previous catalog entries with each accepted result, including partial results, and clear cached cloud skill resources when publishing a replacement.
- Check catalog freshness across turns and steps using auth and resource identity. Auth or resource changes bypass retry cooldowns, including within the same turn.

## Testing

Add and update tests for retry delays and recovery, concurrent refreshes, auth and resource invalidation, partial catalog replacement, and cloud skill read-cache replacement.

GitOrigin-RevId: 0ce5a9d5596e8a73d7084abbbaeb4fb8cda84aa0
2026-11-13 23:14:47 +00:00

56 lines
1.7 KiB
Rust

//! Thread-owned cloud catalog retry cooldowns scoped to auth and resource generations.
use codex_mcp::McpResourceClientAuthKey;
use codex_mcp::McpResourceServerCacheKey;
use std::time::Duration;
use tokio::time::Instant;
/// Store per catalog and thread; clear on a complete, warning-free result or configuration reset.
#[derive(Clone)]
pub struct CatalogRefreshBackoff {
auth: Option<McpResourceClientAuthKey>,
resources: Option<McpResourceServerCacheKey>,
delay: Duration,
retry_at: Instant,
}
impl std::fmt::Debug for CatalogRefreshBackoff {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("CatalogRefreshBackoff")
.field("delay", &self.delay)
.field("retry_at", &self.retry_at)
.finish_non_exhaustive()
}
}
impl CatalogRefreshBackoff {
pub fn is_pending(
&self,
auth: Option<&McpResourceClientAuthKey>,
resources: Option<&McpResourceServerCacheKey>,
) -> bool {
self.auth.as_ref() == auth
&& self.resources.as_ref() == resources
&& Instant::now() < self.retry_at
}
pub fn after_failure(
auth: Option<McpResourceClientAuthKey>,
resources: Option<McpResourceServerCacheKey>,
previous: Option<&Self>,
) -> Self {
let delay = previous
.filter(|previous| previous.auth == auth && previous.resources == resources)
.map_or(Duration::from_secs(5), |previous| {
(previous.delay * 2).min(Duration::from_secs(300))
});
Self {
auth,
resources,
delay,
retry_at: Instant::now() + delay,
}
}
}