Add explicit cloud catalog refresh before turn admission (#61449)

## Why

Hosts need to refresh cloud plugin and skill catalogs without starting a turn or waiting for step preparation.

## What changed

- Add `CodexThread::refresh_cloud_plugins()` and a turn-independent extension callback that bypass cached catalog reuse and failure cooldowns.
- Run catalog contributors concurrently while serializing publication with step snapshot capture. Invalidate MCP resource caches before explicit discovery and schedule MCP reconciliation afterward.
- Accept complete and partial catalogs, report discovery errors, and keep failed or cancelled refreshes retryable.
- Allow hosts to gate cloud plugin discovery through effective configuration.

## Testing

Add coverage for discovery before turn admission, catalog replacement and reuse, immediate retry after failure, concurrent contributors, and cancellation-safe publication and invalidation.

GitOrigin-RevId: 83e847fcab6562581af2c9e831b1d2a310f2b270
This commit is contained in:
Anthony Tafoya
2026-11-14 02:45:51 +00:00
committed by copyberry
parent 32cec881b7
commit d26406987e
32 changed files with 953 additions and 247 deletions
@@ -63,6 +63,7 @@ pub use tool_lifecycle::ToolTimingInput;
pub use turn_input::TurnInputContext;
pub use turn_input::TurnInputEnvironment;
pub use turn_lifecycle::CatalogRefreshInput;
pub use turn_lifecycle::CloudCatalogRefreshInput;
pub use turn_lifecycle::TurnAbortInput;
pub use turn_lifecycle::TurnErrorInput;
pub use turn_lifecycle::TurnStartInput;
@@ -215,6 +216,12 @@ pub trait ThreadLifecycleContributor<C: Sync>: Send + Sync {
/// Implementations should use these callbacks to seed, observe, or clear
/// extension-private turn state. The host exposes stable identifiers and
/// extension stores instead of core runtime objects.
///
/// Core serializes explicit catalog refresh and step preparation per thread.
/// Within a refresh, contributors run concurrently and must not depend on each
/// other's publication order.
/// Cloud discovery runs through those refresh callbacks; hosts requesting discovery
/// should use Core's refresh API rather than invoke hooks directly.
pub trait TurnLifecycleContributor: Send + Sync {
/// Selects the start phase using the current thread policy. Disabled callbacks
/// may retain the default phase and return without doing any work.
@@ -233,6 +240,7 @@ pub trait TurnLifecycleContributor: Send + Sync {
}
/// Refreshes catalogs before a step; returns true when MCP needs rebuilding.
/// Called under the same per-thread catalog lock as explicit refresh and step preparation.
fn refresh_catalog_for_step<'a>(
&'a self,
_input: CatalogRefreshInput<'a>,
@@ -240,6 +248,19 @@ pub trait TurnLifecycleContributor: Send + Sync {
Box::pin(async { false })
}
/// Publishes cloud catalogs after explicit invalidation, without requiring a turn.
/// Core marks MCP dirty after publication. Accepted complete or partial catalogs
/// replace the previous result; failed or superseded discovery returns an error.
/// Core invalidates resource keys before calling. MCP-backed catalogs record
/// the new key only on acceptance, keeping failed or cancelled refreshes stale.
/// Called under the same per-thread catalog lock as step preparation.
fn refresh_cloud_catalog<'a>(
&'a self,
_input: CloudCatalogRefreshInput<'a>,
) -> ExtensionFuture<'a, Result<(), String>> {
Box::pin(async { Ok(()) })
}
/// Observes a completed item without changing it or delaying streamed deltas.
fn on_item_completed<'a>(
&'a self,
@@ -42,6 +42,22 @@ pub struct CatalogRefreshInput<'a> {
pub turn_store: &'a ExtensionData,
}
/// Inputs for explicit cloud discovery, including before a thread has any turns.
#[derive(Clone, Copy)]
pub struct CloudCatalogRefreshInput<'a> {
pub session_store: &'a ExtensionData,
pub thread_store: &'a ExtensionData,
}
impl<'a> From<CatalogRefreshInput<'a>> for CloudCatalogRefreshInput<'a> {
fn from(input: CatalogRefreshInput<'a>) -> Self {
Self {
session_store: input.session_store,
thread_store: input.thread_store,
}
}
}
/// Input supplied when the host completes a turn.
pub struct TurnStopInput<'a> {
/// Store scoped to the host session runtime.
+1
View File
@@ -58,6 +58,7 @@ pub use contributors::ApprovalDecision;
pub use contributors::ApprovalDecisionInput;
pub use contributors::ApprovalReviewContributor;
pub use contributors::CatalogRefreshInput;
pub use contributors::CloudCatalogRefreshInput;
pub use contributors::CodeModeCellTiming;
pub use contributors::CommandStartInput;
pub use contributors::ConfigContributor;