mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
[codex] Reuse parsed plugin skills during session startup (#28844)
## Summary - Preserve raw plugin skill-root snapshots in the matching loaded-plugin cache entry, keyed by the effective plugin root identity including namespace. - Pass those snapshots through `SkillsLoadInput` as an optional preload, so session startup reuses plugin parsing while ordinary skill loads pass `None`. - Keep plugin skill loading cohesive: the existing loaders accept the optional snapshots directly, and uncached or marketplace-detail paths do not create a cache. ## Why Plugin discovery already parses plugin skills to determine available capabilities. Cold session startup then scanned and parsed the same roots again while building the skills snapshot. This solves the same duplicate-work problem as #28623 while keeping ownership narrow: `PluginsManager` creates and owns `PluginSkillSnapshots` only for its loaded-plugin cache entry; `SkillsService` consumes an optional clone. Entry replacement or clearing naturally drops the snapshots, with no separate generation, capacity policy, or watcher coupling. ## Validation - `cargo clippy -p codex-core-skills --all-targets -- -D warnings` - `just test -p codex-core-plugins skills_service_reuses_skills_parsed_during_plugin_load` - `just test -p codex-core-skills namespaces_plugin_skills_using_provided_namespace` - `just fmt`
This commit is contained in:
1 parent
346d2c163f
commit
e83b7841b0
17 files changed
+527
-211
No files matched your search
@@ -61,6 +61,7 @@ use codex_config::set_user_plugin_enabled;
|
||||
use codex_config::types::PluginConfig;
|
||||
use codex_config::types::ToolSuggestDisabledTool;
|
||||
use codex_config::types::ToolSuggestDiscoverableType;
|
||||
use codex_core_skills::PluginSkillSnapshots;
|
||||
use codex_core_skills::SkillMetadata;
|
||||
use codex_core_skills::config_rules::SkillConfigRules;
|
||||
use codex_core_skills::config_rules::skill_config_rules_from_stack;
|
||||
@@ -370,6 +371,7 @@ pub struct PluginsManager {
|
||||
struct LoadedPluginsCacheEntry {
|
||||
key: PluginLoadCacheKey,
|
||||
plugins: Vec<LoadedPlugin>,
|
||||
plugin_skill_snapshots: PluginSkillSnapshots,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -385,6 +387,16 @@ struct PluginLoadCacheKey {
|
||||
remote_plugin_enabled: bool,
|
||||
}
|
||||
|
||||
impl PluginLoadCacheKey {
|
||||
fn from_config(config: &PluginsConfigInput) -> Self {
|
||||
Self {
|
||||
configured_plugins: configured_plugins_from_stack(&config.config_layer_stack),
|
||||
skill_config_rules: skill_config_rules_from_stack(&config.config_layer_stack),
|
||||
remote_plugin_enabled: config.remote_plugin_enabled,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PluginsManager {
|
||||
pub fn new(codex_home: PathBuf) -> Self {
|
||||
Self::new_with_options(codex_home, Some(Product::Codex), /*auth_mode*/ None)
|
||||
@@ -470,6 +482,24 @@ impl PluginsManager {
|
||||
.await
|
||||
}
|
||||
|
||||
/// Returns skill snapshots parsed while loading the matching plugin cache entry.
|
||||
pub fn plugin_skill_snapshots_for_config(
|
||||
&self,
|
||||
config: &PluginsConfigInput,
|
||||
) -> Option<PluginSkillSnapshots> {
|
||||
if !config.plugins_enabled {
|
||||
return None;
|
||||
}
|
||||
let key = PluginLoadCacheKey::from_config(config);
|
||||
self.loaded_plugins_cache
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.entry
|
||||
.as_ref()
|
||||
.filter(|cached| cached.key == key)
|
||||
.map(|cached| cached.plugin_skill_snapshots.clone())
|
||||
}
|
||||
|
||||
#[instrument(
|
||||
name = "plugins_for_config",
|
||||
level = "info",
|
||||
@@ -489,11 +519,7 @@ impl PluginsManager {
|
||||
return PluginLoadOutcome::default();
|
||||
}
|
||||
|
||||
let cache_key = PluginLoadCacheKey {
|
||||
configured_plugins: configured_plugins_from_stack(&config.config_layer_stack),
|
||||
skill_config_rules: skill_config_rules_from_stack(&config.config_layer_stack),
|
||||
remote_plugin_enabled: config.remote_plugin_enabled,
|
||||
};
|
||||
let cache_key = PluginLoadCacheKey::from_config(config);
|
||||
if !force_reload && let Some(plugins) = self.cached_loaded_plugins(&cache_key) {
|
||||
return self.resolve_loaded_plugins_for_auth(plugins);
|
||||
}
|
||||
@@ -506,16 +532,23 @@ impl PluginsManager {
|
||||
return self.resolve_loaded_plugins_for_auth(plugins);
|
||||
}
|
||||
let cache_generation = self.loaded_plugins_cache_generation();
|
||||
let plugin_skill_snapshots = PluginSkillSnapshots::for_plugin_load();
|
||||
let plugins = load_plugins_from_layer_stack(
|
||||
&config.config_layer_stack,
|
||||
self.remote_installed_plugin_configs(),
|
||||
&self.store,
|
||||
Some(&plugin_skill_snapshots),
|
||||
self.restriction_product,
|
||||
config.remote_plugin_enabled,
|
||||
)
|
||||
.await;
|
||||
log_plugin_load_errors(&plugins);
|
||||
self.cache_loaded_plugins_if_current(cache_generation, cache_key, plugins.clone());
|
||||
self.cache_loaded_plugins_if_current(
|
||||
cache_generation,
|
||||
cache_key,
|
||||
plugins.clone(),
|
||||
plugin_skill_snapshots,
|
||||
);
|
||||
self.resolve_loaded_plugins_for_auth(plugins)
|
||||
}
|
||||
|
||||
@@ -589,6 +622,7 @@ impl PluginsManager {
|
||||
config_layer_stack,
|
||||
self.remote_installed_plugin_configs(),
|
||||
&self.store,
|
||||
/*plugin_skill_snapshots*/ None,
|
||||
self.restriction_product,
|
||||
config.remote_plugin_enabled,
|
||||
)
|
||||
@@ -626,19 +660,13 @@ impl PluginsManager {
|
||||
}
|
||||
|
||||
fn cached_loaded_plugins(&self, key: &PluginLoadCacheKey) -> Option<Vec<LoadedPlugin>> {
|
||||
match self.loaded_plugins_cache.read() {
|
||||
Ok(cache) => cache
|
||||
.entry
|
||||
.as_ref()
|
||||
.filter(|cached| cached.key == *key)
|
||||
.map(|cached| cached.plugins.clone()),
|
||||
Err(err) => err
|
||||
.into_inner()
|
||||
.entry
|
||||
.as_ref()
|
||||
.filter(|cached| cached.key == *key)
|
||||
.map(|cached| cached.plugins.clone()),
|
||||
}
|
||||
self.loaded_plugins_cache
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.entry
|
||||
.as_ref()
|
||||
.filter(|cached| cached.key == *key)
|
||||
.map(|cached| cached.plugins.clone())
|
||||
}
|
||||
|
||||
fn loaded_plugins_cache_generation(&self) -> u64 {
|
||||
@@ -653,13 +681,18 @@ impl PluginsManager {
|
||||
generation: u64,
|
||||
key: PluginLoadCacheKey,
|
||||
plugins: Vec<LoadedPlugin>,
|
||||
plugin_skill_snapshots: PluginSkillSnapshots,
|
||||
) {
|
||||
let mut cache = match self.loaded_plugins_cache.write() {
|
||||
Ok(cache) => cache,
|
||||
Err(err) => err.into_inner(),
|
||||
};
|
||||
if cache.generation == generation {
|
||||
cache.entry = Some(LoadedPluginsCacheEntry { key, plugins });
|
||||
cache.entry = Some(LoadedPluginsCacheEntry {
|
||||
key,
|
||||
plugins,
|
||||
plugin_skill_snapshots,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1659,6 +1692,7 @@ impl PluginsManager {
|
||||
&codex_core_skills::config_rules::skill_config_rules_from_stack(
|
||||
&config.config_layer_stack,
|
||||
),
|
||||
/*plugin_skill_snapshots*/ None,
|
||||
)
|
||||
.await;
|
||||
let plugin_data_root = self.store.plugin_data_root(&plugin_id);
|
||||
|
||||
Reference in new issue
Block a user