Files
codex/codex-rs/ext/extension-api/src/catalog_refresh.rs
T
Anthony Tafoya 3fd08b5405 Back off failed cloud skill and plugin catalog refreshes (#55968)
## Why

Failed cloud discovery previously retried before each model step. Apply a cooldown across steps and turns to avoid repeated discovery requests while a provider remains unavailable.

## What changed

- Share per-thread retry backoff logic between cloud skill and plugin catalogs, starting at 30 seconds and doubling to a maximum of 5 minutes.
- Scope cooldowns to authentication and MCP resource generations so account changes and reconnects permit immediate recovery.
- Clear backoff after successful discovery or configuration resets, while allowing cancelled refreshes to retry immediately.

## Testing

Update lifecycle and concurrency tests to cover shared cooldowns, reconnect recovery, and cancellation. Use paused time to verify exponential delays, the 5-minute cap, and backoff across turns.

GitOrigin-RevId: 30dab5ceba51e8ad64c0794c1729719e99f577ce
2026-10-21 19:22:57 +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 success 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(30), |previous| {
(previous.delay * 2).min(Duration::from_secs(300))
});
Self {
auth,
resources,
delay,
retry_at: Instant::now() + delay,
}
}
}