mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Honor layered configuration when loading plugins (#40954)
## What changed - Resolve plugin activation, MCP server policy, and marketplace definitions from the effective configuration stack, including system settings and trusted project overrides. - Load plugin skills independently for each working directory passed to `skills/list`. - Exclude project configuration from catalog requests whose `cwds` are omitted or empty. - Cache up to eight loaded plugin configurations with least-recently-used eviction so requests for different working directories can reuse their results. ## Testing - Cover layered plugin and MCP policy across trusted and untrusted projects. - Cover per-directory skill and plugin catalog results, cache reuse and eviction, and system-defined marketplaces. GitOrigin-RevId: cb68b2b1bdab1da48e05ca7562bc05014431fc71
This commit is contained in:
1 parent
7276d67081
commit
6ac012a0d4
18 files changed
+490
-132
No files matched your search
@@ -109,6 +109,7 @@ use std::collections::VecDeque;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::RwLock;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::Ordering;
|
||||
@@ -125,6 +126,7 @@ static CURATED_REPO_SYNC_STARTED: AtomicBool = AtomicBool::new(false);
|
||||
const FEATURED_PLUGIN_IDS_CACHE_TTL: std::time::Duration =
|
||||
std::time::Duration::from_secs(60 * 60 * 3);
|
||||
const REMOTE_INSTALLED_PLUGIN_SYNC_WAIT_TIMEOUT: Duration = Duration::from_secs(120);
|
||||
const LOADED_PLUGINS_CACHE_CAPACITY: usize = 8;
|
||||
|
||||
type EffectivePluginsChangedCallback = Arc<dyn Fn(EffectivePluginsChange) + Send + Sync + 'static>;
|
||||
|
||||
@@ -503,8 +505,8 @@ pub struct PluginsManager {
|
||||
non_curated_cache_refresh_lock: Semaphore,
|
||||
non_curated_cache_refresh_state: RwLock<NonCuratedCacheRefreshState>,
|
||||
non_curated_cache_refresh_completion: watch::Sender<NonCuratedCacheRefreshCompletion>,
|
||||
// Remote installed plugins vary by account, so loaded capabilities are cached per auth.
|
||||
loaded_plugins_cache: RwLock<LoadedPluginsCache>,
|
||||
// Loaded capabilities vary by effective configuration and, for remote plugins, account.
|
||||
loaded_plugins_cache: Mutex<LoadedPluginsCache>,
|
||||
loaded_plugins_load_semaphore: Semaphore,
|
||||
skill_root_loader: Arc<dyn SkillRootLoader<PluginSkillRoot>>,
|
||||
tool_suggest_metadata_cache: ToolSuggestMetadataCache,
|
||||
@@ -528,7 +530,17 @@ struct LoadedPluginsCacheEntry {
|
||||
#[derive(Default)]
|
||||
struct LoadedPluginsCache {
|
||||
generation: u64,
|
||||
entry: Option<LoadedPluginsCacheEntry>,
|
||||
// Most recently used first.
|
||||
entries: VecDeque<LoadedPluginsCacheEntry>,
|
||||
}
|
||||
|
||||
impl LoadedPluginsCache {
|
||||
fn get(&mut self, key: &PluginLoadCacheKey) -> Option<&LoadedPluginsCacheEntry> {
|
||||
let index = self.entries.iter().position(|entry| &entry.key == key)?;
|
||||
let entry = self.entries.remove(index)?;
|
||||
self.entries.push_front(entry);
|
||||
self.entries.front()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
@@ -611,7 +623,7 @@ impl PluginsManager {
|
||||
NonCuratedCacheRefreshCompletion::default(),
|
||||
)
|
||||
.0,
|
||||
loaded_plugins_cache: RwLock::new(LoadedPluginsCache::default()),
|
||||
loaded_plugins_cache: Mutex::new(LoadedPluginsCache::default()),
|
||||
loaded_plugins_load_semaphore: Semaphore::new(/*permits*/ 1),
|
||||
skill_root_loader,
|
||||
tool_suggest_metadata_cache: ToolSuggestMetadataCache::new(),
|
||||
@@ -696,11 +708,9 @@ impl PluginsManager {
|
||||
RemoteInstalledPluginsAuthIdentity::from_auth(auth.as_ref()),
|
||||
);
|
||||
self.loaded_plugins_cache
|
||||
.read()
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.entry
|
||||
.as_ref()
|
||||
.filter(|cached| cached.key == key)
|
||||
.get(&key)
|
||||
.map(|cached| cached.plugin_skill_snapshots.clone())
|
||||
}
|
||||
|
||||
@@ -855,12 +865,12 @@ impl PluginsManager {
|
||||
|
||||
fn clear_loaded_plugins_cache(&self) {
|
||||
self.tool_suggest_metadata_cache.clear();
|
||||
let mut cache = match self.loaded_plugins_cache.write() {
|
||||
let mut cache = match self.loaded_plugins_cache.lock() {
|
||||
Ok(cache) => cache,
|
||||
Err(err) => err.into_inner(),
|
||||
};
|
||||
cache.generation = cache.generation.wrapping_add(1);
|
||||
cache.entry = None;
|
||||
cache.entries.clear();
|
||||
}
|
||||
|
||||
fn clear_caches_after_marketplace_source_refresh(
|
||||
@@ -900,16 +910,14 @@ impl PluginsManager {
|
||||
|
||||
fn cached_loaded_plugins(&self, key: &PluginLoadCacheKey) -> Option<Vec<LoadedPlugin>> {
|
||||
self.loaded_plugins_cache
|
||||
.read()
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.entry
|
||||
.as_ref()
|
||||
.filter(|cached| cached.key == *key)
|
||||
.get(key)
|
||||
.map(|cached| cached.plugins.clone())
|
||||
}
|
||||
|
||||
fn loaded_plugins_cache_generation(&self) -> u64 {
|
||||
match self.loaded_plugins_cache.read() {
|
||||
match self.loaded_plugins_cache.lock() {
|
||||
Ok(cache) => cache.generation,
|
||||
Err(err) => err.into_inner().generation,
|
||||
}
|
||||
@@ -922,16 +930,18 @@ impl PluginsManager {
|
||||
plugins: Vec<LoadedPlugin>,
|
||||
plugin_skill_snapshots: SkillRootSnapshots<PluginSkillRoot>,
|
||||
) {
|
||||
let mut cache = match self.loaded_plugins_cache.write() {
|
||||
let mut cache = match self.loaded_plugins_cache.lock() {
|
||||
Ok(cache) => cache,
|
||||
Err(err) => err.into_inner(),
|
||||
};
|
||||
if cache.generation == generation {
|
||||
cache.entry = Some(LoadedPluginsCacheEntry {
|
||||
cache.entries.retain(|entry| entry.key != key);
|
||||
cache.entries.push_front(LoadedPluginsCacheEntry {
|
||||
key,
|
||||
plugins,
|
||||
plugin_skill_snapshots,
|
||||
});
|
||||
cache.entries.truncate(LOADED_PLUGINS_CACHE_CAPACITY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user