Honor per-repository plugin configuration in catalog requests (#41208)

## What changed

- Load the effective plugin configuration for every requested `cwd` in
  `plugin/list` and `plugin/installed`.
- Combine local marketplaces in request order, keeping the first source for
  duplicates while merging installed and enabled state across repositories.
- Report invalid project configurations through `marketplaceLoadErrors` without
  dropping valid local catalogs or globally enabled remote catalogs.
- Use the combined marketplace context for forced and background cache refreshes,
  while keeping remote plugin feature gating request-wide.

## Testing

- Cover distinct and duplicate marketplaces, cross-repository enabled state,
  invalid project configuration, local cache refresh, and global versus
  project-local feature flags.

GitOrigin-RevId: 53c8e0e9c760dc2b969ab10d0e63fb439673c230
This commit is contained in:
willwang-openai authored and copyberry committed 2026-08-27 21:10:10 +00:00
1 parent 19321435b1
commit c4c51c56e4
8 files changed
+802 -208

No files matched your search

+76 -108
View File
@@ -1,3 +1,8 @@
#[path = "marketplace_context.rs"]
mod marketplace_context;
pub use marketplace_context::PluginMarketplaceContext;
pub use marketplace_context::PluginMarketplaceScope;
use super::LoadedPlugin;
use super::PluginLoadOutcome;
use crate::PluginGitMode;
@@ -321,6 +326,7 @@ struct RemoteCatalogCacheRefreshState {
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct PluginListBackgroundTaskOptions {
pub local_marketplaces: Vec<ConfiguredMarketplace>,
pub remote_catalog_cache_refresh_scopes: BTreeSet<RemotePluginScope>,
}
@@ -475,6 +481,12 @@ pub struct ConfiguredMarketplaceListOutcome {
pub errors: Vec<MarketplaceListError>,
}
#[derive(Default)]
struct ConfiguredPluginStates {
installed: HashSet<String>,
enabled: HashSet<String>,
}
impl From<PluginDetail> for PluginCapabilitySummary {
fn from(value: PluginDetail) -> Self {
let has_skills = value.skills.iter().any(|skill| {
@@ -1588,28 +1600,27 @@ impl PluginsManager {
});
}
pub fn maybe_start_plugin_list_background_tasks_for_config(
pub fn maybe_start_plugin_list_background_tasks(
self: &Arc<Self>,
config: &PluginsConfigInput,
context: &PluginMarketplaceContext,
auth: Option<CodexAuth>,
roots: &[AbsolutePathBuf],
options: PluginListBackgroundTaskOptions,
on_effective_plugins_changed: Option<EffectivePluginsChangedCallback>,
) {
self.maybe_start_non_curated_plugin_cache_refresh(config, roots);
self.maybe_start_non_curated_plugin_cache_refresh(context, &options.local_marketplaces);
self.maybe_start_remote_catalog_cache_refresh(
config,
&context.global_config,
auth.clone(),
options.remote_catalog_cache_refresh_scopes,
RemoteCatalogCacheRefreshMode::OnlyIfStale,
);
self.maybe_start_remote_plugin_caches_refresh(
config,
&context.global_config,
auth.clone(),
on_effective_plugins_changed.clone(),
);
self.maybe_start_remote_installed_plugin_bundle_sync(
config,
&context.global_config,
auth,
on_effective_plugins_changed,
);
@@ -2161,6 +2172,14 @@ impl PluginsManager {
Ok(())
}
pub fn list_marketplaces_for_context(
&self,
context: &PluginMarketplaceContext,
include_openai_curated: bool,
) -> Result<ConfiguredMarketplaceListOutcome, MarketplaceError> {
context.list_marketplaces(self, include_openai_curated)
}
pub fn list_marketplaces_for_config(
&self,
config: &PluginsConfigInput,
@@ -2171,7 +2190,22 @@ impl PluginsManager {
return Ok(ConfiguredMarketplaceListOutcome::default());
}
let (installed_plugins, enabled_plugins) = self.configured_plugin_states(config);
let plugin_states = self.configured_plugin_states(config);
self.list_marketplaces_for_config_with_states(
config,
additional_roots,
include_openai_curated,
&plugin_states,
)
}
fn list_marketplaces_for_config_with_states(
&self,
config: &PluginsConfigInput,
additional_roots: &[AbsolutePathBuf],
include_openai_curated: bool,
plugin_states: &ConfiguredPluginStates,
) -> Result<ConfiguredMarketplaceListOutcome, MarketplaceError> {
let marketplace_roots =
self.marketplace_roots(config, additional_roots, include_openai_curated);
let marketplace_outcome = self.list_marketplaces_with_policy(config, &marketplace_roots)?;
@@ -2194,13 +2228,13 @@ impl PluginsManager {
}
let plugin_id =
PluginId::new(plugin.name.clone(), marketplace_name.clone()).ok();
let installed = installed_plugins.contains(&plugin_key);
let installed = plugin_states.installed.contains(&plugin_key);
let installed_version = installed.then_some(()).and_then(|_| {
plugin_id
.as_ref()
.and_then(|plugin_id| self.store.active_plugin_version(plugin_id))
});
let enabled = enabled_plugins.contains(&plugin_key);
let enabled = plugin_states.enabled.contains(&plugin_key);
let mut interface = plugin.interface;
let mut local_version = plugin.local_version;
let manifest_fallback = plugin.manifest_fallback.clone();
@@ -2323,8 +2357,8 @@ impl PluginsManager {
.manifest_fallback
.contents_if_has_metadata()
.map(|_| plugin.manifest_fallback.clone());
let (installed_plugins, enabled_plugins) = self.configured_plugin_states(config);
let installed = installed_plugins.contains(&plugin_key);
let plugin_states = self.configured_plugin_states(config);
let installed = plugin_states.installed.contains(&plugin_key);
let installed_version = if installed {
self.store.active_plugin_version(&plugin.plugin_id)
} else {
@@ -2352,7 +2386,7 @@ impl PluginsManager {
.unwrap_or_default(),
manifest_fallback,
installed,
enabled: enabled_plugins.contains(&plugin_key),
enabled: plugin_states.enabled.contains(&plugin_key),
},
)
.await?;
@@ -2755,34 +2789,45 @@ impl PluginsManager {
pub fn maybe_start_non_curated_plugin_cache_refresh(
self: &Arc<Self>,
config: &PluginsConfigInput,
roots: &[AbsolutePathBuf],
context: &PluginMarketplaceContext,
marketplaces: &[ConfiguredMarketplace],
) {
self.schedule_non_curated_plugin_cache_refresh(
config,
roots,
if let Some(request) = context.non_curated_cache_refresh_request(
self,
marketplaces,
NonCuratedCacheRefreshMode::IfVersionChanged,
PluginGitMode::Automatic,
);
) {
self.schedule_non_curated_plugin_cache_refresh(request);
}
}
/// Runs an explicitly requested refresh using the caller's normal Git configuration.
pub async fn refresh_non_curated_plugin_cache_for_config(
pub async fn refresh_non_curated_plugin_cache_for_context(
self: &Arc<Self>,
config: &PluginsConfigInput,
roots: &[AbsolutePathBuf],
context: &PluginMarketplaceContext,
) -> bool {
let Ok(_refresh_permit) = self.non_curated_cache_refresh_lock.acquire().await else {
return false;
};
let mut completion = self.non_curated_cache_refresh_completion.subscribe();
let changed_sequence = completion.borrow_and_update().changed_sequence;
self.schedule_non_curated_plugin_cache_refresh(
config,
roots,
let marketplaces =
match self.list_marketplaces_for_context(context, /*include_openai_curated*/ false) {
Ok(outcome) => outcome.marketplaces,
Err(err) => {
warn!("failed to prepare non-curated plugin cache refresh: {err}");
Vec::new()
}
};
if let Some(request) = context.non_curated_cache_refresh_request(
self,
&marketplaces,
NonCuratedCacheRefreshMode::IfVersionChanged,
PluginGitMode::Manual,
);
) {
self.schedule_non_curated_plugin_cache_refresh(request);
}
loop {
let in_flight = match self.non_curated_cache_refresh_state.read() {
@@ -2925,82 +2970,8 @@ impl PluginsManager {
fn schedule_non_curated_plugin_cache_refresh(
self: &Arc<Self>,
config: &PluginsConfigInput,
roots: &[AbsolutePathBuf],
mode: NonCuratedCacheRefreshMode,
git_mode: PluginGitMode,
mut request: NonCuratedCacheRefreshRequest,
) {
let marketplace_roots =
self.marketplace_roots(config, roots, /*include_openai_curated*/ false);
let outcome = match self.list_marketplaces_with_policy(config, &marketplace_roots) {
Ok(outcome) => outcome,
Err(err) => {
warn!("failed to prepare non-curated plugin cache refresh: {err}");
return;
}
};
let policy = MarketplacePolicy::from_requirements(config.config_layer_stack.requirements());
let mut configured_plugin_keys =
configured_plugins_from_stack(&config.config_layer_stack, self.codex_home.as_path())
.into_keys()
.collect::<Vec<_>>();
configured_plugin_keys.sort_unstable();
let mut configured_plugin_sources = Vec::new();
let mut roots = outcome
.marketplaces
.into_iter()
.filter(|marketplace| !is_openai_curated_marketplace_name(&marketplace.name))
.filter_map(|marketplace| {
match policy.validate_install(
&config.config_layer_stack,
self.codex_home.as_path(),
&marketplace.path,
&marketplace.name,
) {
Ok(()) => {
for plugin in marketplace.plugins {
let plugin_key = format!("{}@{}", plugin.name, marketplace.name);
if configured_plugin_keys.binary_search(&plugin_key).is_ok() {
configured_plugin_sources.push(NonCuratedPluginSource {
marketplace_path: marketplace.path.clone(),
plugin_key,
source: plugin.source,
local_version: plugin.local_version,
});
}
}
Some(marketplace.path)
}
Err(err) => {
warn!(
marketplace = marketplace.name,
path = %marketplace.path.display(),
error = %err,
"skipping marketplace source during plugin cache refresh"
);
None
}
}
})
.collect::<Vec<_>>();
roots.sort_unstable();
roots.dedup();
if roots.is_empty() || configured_plugin_keys.is_empty() {
return;
}
configured_plugin_sources.sort_by(|left, right| {
left.marketplace_path
.cmp(&right.marketplace_path)
.then_with(|| left.plugin_key.cmp(&right.plugin_key))
});
let mut request = NonCuratedCacheRefreshRequest {
roots,
configured_plugin_keys,
configured_plugin_sources,
mode,
git_mode,
};
let should_spawn = {
let mut state = match self.non_curated_cache_refresh_state.write() {
Ok(state) => state,
@@ -3361,13 +3332,10 @@ impl PluginsManager {
}
}
fn configured_plugin_states(
&self,
config: &PluginsConfigInput,
) -> (HashSet<String>, HashSet<String>) {
fn configured_plugin_states(&self, config: &PluginsConfigInput) -> ConfiguredPluginStates {
let configured_plugins =
configured_plugins_from_stack(&config.config_layer_stack, self.codex_home.as_path());
let installed_plugins = configured_plugins
let installed = configured_plugins
.keys()
.filter(|plugin_key| {
PluginId::parse(plugin_key)
@@ -3376,11 +3344,11 @@ impl PluginsManager {
})
.cloned()
.collect::<HashSet<_>>();
let enabled_plugins = configured_plugins
let enabled = configured_plugins
.into_iter()
.filter_map(|(plugin_key, plugin)| plugin.enabled.then_some(plugin_key))
.collect::<HashSet<_>>();
(installed_plugins, enabled_plugins)
ConfiguredPluginStates { installed, enabled }
}
fn marketplace_roots(