Prefer remote Sites over the bundled plugin (#42100)

## Why

When the remote Sites plugin is installed and its local bundle is available, exposing the bundled copy as well creates duplicate catalog entries and can load the wrong skills.

## What changed

- Persist an account- and backend-scoped exclusion for `sites@openai-bundled` once the remote replacement is installed and loadable.
- Apply the exclusion to plugin catalogs, search, direct reads and installs, runtime loading, hooks, and skill caches while preserving the remote plugin's server-owned enabled state.
- Restore the bundled fallback when the remote plugin is absent or its local files are unavailable, and throttle repeated availability checks for 60 seconds.

## Testing

- Added manager tests for persistence across restarts, account/backend isolation, fallback restoration, concurrent checks, and refresh throttling.
- Added app-server and agent-turn tests confirming that catalog, search, and skill loading prefer remote Sites.

GitOrigin-RevId: bc1154f79d3107910fee9fa27389a0ddb48ce6cf
This commit is contained in:
Jiwon Kim
2026-09-01 16:58:54 +00:00
committed by copyberry
parent a17ee5705c
commit b6ab99ed87
16 changed files with 864 additions and 27 deletions
+49 -7
View File
@@ -1,3 +1,5 @@
#[path = "bundled_plugin_exclusions.rs"]
mod bundled_plugin_exclusions;
#[path = "marketplace_context.rs"]
mod marketplace_context;
pub use marketplace_context::PluginMarketplaceContext;
@@ -528,6 +530,8 @@ pub struct PluginsManager {
skill_root_loader: Arc<dyn SkillRootLoader<PluginSkillRoot>>,
tool_suggest_metadata_cache: ToolSuggestMetadataCache,
remote_installed_plugins_cache: RwLock<RemoteInstalledPluginsCache>,
// TODO(sites-migration): Remove this throttle together with the bundled Sites migration.
sites_migration_checked_at: Mutex<Option<(PathBuf, Instant)>>,
remote_installed_plugin_bundle_sync_gate: Arc<Semaphore>,
remote_installed_plugins_cache_refresh_state: RwLock<RemoteInstalledPluginsCacheRefreshState>,
remote_catalog_cache_refresh_state: RwLock<RemoteCatalogCacheRefreshState>,
@@ -566,6 +570,8 @@ struct PluginLoadCacheKey {
skill_config_rules: SkillConfigRules,
remote_global_catalog_active: bool,
auth_identity: Option<RemoteInstalledPluginsAuthIdentity>,
// TODO(sites-migration): Remove once bundled Sites no longer needs scoped exclusions.
excluded_plugin_ids: BTreeSet<String>,
}
impl PluginLoadCacheKey {
@@ -574,6 +580,7 @@ impl PluginLoadCacheKey {
codex_home: &Path,
remote_global_catalog_active: bool,
auth_identity: RemoteInstalledPluginsAuthIdentity,
excluded_plugin_ids: BTreeSet<String>,
) -> Self {
Self {
configured_plugins: configured_plugins_from_stack(
@@ -584,6 +591,7 @@ impl PluginLoadCacheKey {
remote_global_catalog_active,
// Local curated loads are auth-independent; only remote snapshots vary by account.
auth_identity: remote_global_catalog_active.then_some(auth_identity),
excluded_plugin_ids,
}
}
}
@@ -645,6 +653,7 @@ impl PluginsManager {
skill_root_loader,
tool_suggest_metadata_cache: ToolSuggestMetadataCache::new(),
remote_installed_plugins_cache: RwLock::new(RemoteInstalledPluginsCache::default()),
sites_migration_checked_at: Mutex::new(None),
remote_installed_plugin_bundle_sync_gate,
remote_installed_plugins_cache_refresh_state: RwLock::new(
RemoteInstalledPluginsCacheRefreshState::default(),
@@ -723,6 +732,7 @@ impl PluginsManager {
self.codex_home.as_path(),
self.remote_global_catalog_active(config),
RemoteInstalledPluginsAuthIdentity::from_auth(auth.as_ref()),
self.excluded_bundled_plugin_ids(config),
);
self.loaded_plugins_cache
.lock()
@@ -758,11 +768,12 @@ impl PluginsManager {
let auth = self.auth_manager.auth_cached();
let auth_mode = auth.as_ref().map(CodexAuth::api_auth_mode);
let auth_identity = RemoteInstalledPluginsAuthIdentity::from_auth(auth.as_ref());
let cache_key = PluginLoadCacheKey::from_config(
let mut cache_key = PluginLoadCacheKey::from_config(
config,
self.codex_home.as_path(),
remote_global_catalog_active,
auth_identity.clone(),
self.excluded_bundled_plugin_ids(config),
);
if let Some(plugins) = self.cached_loaded_plugins(&cache_key) {
let outcome = self.resolve_loaded_plugins_for_auth(plugins, auth_mode);
@@ -795,6 +806,8 @@ impl PluginsManager {
}
continue;
}
// Migration may have changed the effective exclusion while this load was queued.
cache_key.excluded_plugin_ids = self.excluded_bundled_plugin_ids(config);
if let Some(plugins) = self.cached_loaded_plugins(&cache_key) {
let outcome = self.resolve_loaded_plugins_for_auth(plugins, auth_mode);
if *auth_change_receiver.borrow() == auth_revision {
@@ -818,6 +831,7 @@ impl PluginsManager {
self.restriction_product,
remote_global_catalog_active,
self.skill_root_loader.as_ref(),
&cache_key.excluded_plugin_ids,
)
.await;
loaded_cache_metrics::record_duration(
@@ -934,6 +948,7 @@ impl PluginsManager {
load_plugin_hooks_from_layer_stack(
config_layer_stack,
self.remote_installed_plugin_configs(),
&self.excluded_bundled_plugin_ids(config),
&self.store,
target_curated_marketplace,
self.remote_global_catalog_active(config),
@@ -1212,6 +1227,7 @@ impl PluginsManager {
generation,
plugins,
auth,
&config.chatgpt_base_url,
RemoteInstalledPluginsCachePublication::Refresh,
) else {
let auth_identity = RemoteInstalledPluginsAuthIdentity::from_auth(auth);
@@ -1315,6 +1331,7 @@ impl PluginsManager {
generation: u64,
plugins: Vec<RemoteInstalledPlugin>,
auth: Option<&CodexAuth>,
service_base_url: &str,
publication: RemoteInstalledPluginsCachePublication,
) -> Option<bool> {
let auth_identity = RemoteInstalledPluginsAuthIdentity::from_auth(auth);
@@ -1347,8 +1364,11 @@ impl PluginsManager {
cache.reconciliation_generation = None;
cache.generation = cache.generation.wrapping_add(1);
}
let needs_effective_plugins_refresh =
is_reconcile && std::mem::take(&mut cache.needs_effective_plugins_refresh);
// TODO(sites-migration): Remove exclusion publication once bundled Sites is retired.
let exclusion_changed = self.update_sites_exclusion(service_base_url, auth, &plugins);
let needs_effective_plugins_refresh = (is_reconcile
&& std::mem::take(&mut cache.needs_effective_plugins_refresh))
|| exclusion_changed;
if cache.plugins.as_ref() == Some(&plugins) {
drop(cache);
if needs_effective_plugins_refresh {
@@ -1372,6 +1392,7 @@ impl PluginsManager {
generation,
plugins,
auth.as_ref(),
"",
RemoteInstalledPluginsCachePublication::Refresh,
)
.expect("test cache generation should remain current")
@@ -1656,6 +1677,7 @@ impl PluginsManager {
generation,
result.installed_plugins,
auth,
&config.chatgpt_base_url,
RemoteInstalledPluginsCachePublication::Reconcile,
) else {
return Err(RemoteInstalledPluginBundleSyncError::Superseded);
@@ -1956,10 +1978,10 @@ impl PluginsManager {
pub async fn install_plugin(
&self,
config_layer_stack: &ConfigLayerStack,
config: &PluginsConfigInput,
request: PluginInstallRequest,
) -> Result<PluginInstallOutcome, PluginInstallError> {
let resolved = self.resolve_installable_plugin(config_layer_stack, &request)?;
let resolved = self.resolve_installable_plugin(config, &request)?;
let plugin_id = resolved.plugin_id.clone();
match self.install_resolved_plugin(resolved).await {
Ok(outcome) => Ok(outcome),
@@ -1977,7 +1999,7 @@ impl PluginsManager {
fn resolve_installable_plugin(
&self,
config_layer_stack: &ConfigLayerStack,
config: &PluginsConfigInput,
request: &PluginInstallRequest,
) -> Result<ResolvedMarketplacePlugin, PluginInstallError> {
let resolved = match find_installable_marketplace_plugin(
@@ -1991,6 +2013,15 @@ impl PluginsManager {
return Err(err.into());
}
};
if self.bundled_sites_is_hidden(config, &resolved.plugin_id.as_key()) {
let err = MarketplaceError::PluginNotFound {
plugin_name: resolved.plugin_id.plugin_name,
marketplace_name: resolved.plugin_id.marketplace_name,
};
self.track_plugin_install_resolution_failed(&err);
return Err(err.into());
}
let config_layer_stack = &config.config_layer_stack;
if let Err(message) =
MarketplacePolicy::from_requirements(config_layer_stack.requirements())
.validate_install(
@@ -2016,7 +2047,7 @@ impl PluginsManager {
auth: Option<&CodexAuth>,
request: PluginInstallRequest,
) -> Result<PluginInstallOutcome, PluginInstallError> {
let resolved = self.resolve_installable_plugin(&config.config_layer_stack, &request)?;
let resolved = self.resolve_installable_plugin(config, &request)?;
let plugin_id = resolved.plugin_id.as_key();
// This only forwards the backend mutation before the local install flow.
if let Err(err) = crate::remote_legacy::enable_remote_plugin(
@@ -2303,6 +2334,7 @@ impl PluginsManager {
include_openai_curated: bool,
plugin_states: &ConfiguredPluginStates,
) -> Result<ConfiguredMarketplaceListOutcome, MarketplaceError> {
let excluded_plugin_ids = self.excluded_bundled_plugin_ids(config);
let marketplace_roots =
self.marketplace_roots(config, additional_roots, include_openai_curated);
let marketplace_outcome = self.list_marketplaces_with_policy(config, &marketplace_roots)?;
@@ -2317,6 +2349,9 @@ impl PluginsManager {
.into_iter()
.filter_map(|plugin| {
let plugin_key = format!("{}@{marketplace_name}", plugin.name);
if excluded_plugin_ids.contains(&plugin_key) {
return None;
}
if !seen_plugin_keys.insert(plugin_key.clone()) {
return None;
}
@@ -2430,6 +2465,12 @@ impl PluginsManager {
}
let plugin = find_marketplace_plugin(&request.marketplace_path, &request.plugin_name)?;
if self.bundled_sites_is_hidden(config, &plugin.plugin_id.as_key()) {
return Err(MarketplaceError::PluginNotFound {
plugin_name: plugin.plugin_id.plugin_name,
marketplace_name: plugin.plugin_id.marketplace_name,
});
}
MarketplacePolicy::from_requirements(config.config_layer_stack.requirements())
.validate_install(
&config.config_layer_stack,
@@ -3239,6 +3280,7 @@ impl PluginsManager {
request.generation,
plugins,
request.auth.as_ref(),
&request.service_config.chatgpt_base_url,
RemoteInstalledPluginsCachePublication::Refresh,
) else {
continue;