mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Add configurable default plugin activation policy (#52220)
## What changed Support `plugins._default.enabled` with explicit per-plugin `enabled` overrides. Omission preserves existing source and account enablement; configuration cannot activate a plugin disabled at its source. Plugin settings such as remembered tool approvals inherit the default unless `enabled` is explicitly set. Apply the policy to plugin skills, MCP servers, Apps, and hooks, including selected executor roots and runtime configuration refreshes. Preserve the latest plugin policy when adding MCP dependencies and rebuild hooks when concurrent configuration updates replace their inputs. Report effective enablement in `plugin/list`, `plugin/installed`, `plugin/read`, and `plugin/share/list`. Remote installation still installs disabled packages, but skips MCP and Apps authentication setup without writing an enablement override. ## Testing Add regression coverage for default inheritance and explicit overrides, source-disabled plugins, policy refreshes during active turns, disabled or malformed selected plugin roots, and remote installation authentication behavior. GitOrigin-RevId: 83b70c5b47fc95474fec292f248683f1f887221e
This commit is contained in:
@@ -237,7 +237,7 @@ async fn account_change_clears_hosted_plugins_before_waiting_for_executor() -> a
|
||||
&config, &init, &thread, "test", &roots, /*executor_capability_discovery*/ None,
|
||||
)
|
||||
.with_auth_changed(/*auth_changed*/ true);
|
||||
let mut loading = std::pin::pin!(contributor.selected_plugins(context));
|
||||
let mut loading = std::pin::pin!(contributor.selected_plugins(context, &config.plugins));
|
||||
assert!(futures::poll!(&mut loading).is_pending());
|
||||
assert_eq!(state.cloud_catalog(), None);
|
||||
Ok(())
|
||||
|
||||
+139
-24
@@ -1,8 +1,11 @@
|
||||
use codex_config::types::PluginMcpServerConfig;
|
||||
use codex_config::types::PluginsConfigToml;
|
||||
use codex_connectors_extension::PluginAppProvider;
|
||||
use codex_core::config::Config;
|
||||
use codex_core_plugins::ExecutorPluginProviderError;
|
||||
use codex_core_plugins::PluginRootOwnership;
|
||||
use codex_core_plugins::loader::apply_configured_plugin_mcp_server_policies;
|
||||
use codex_core_plugins::loader::configured_plugin_mcp_server_policies;
|
||||
use codex_exec_server::CapabilityRootDiscovery;
|
||||
use codex_exec_server::FileSystemSandboxContext;
|
||||
use codex_extension_api::ExtensionFuture;
|
||||
use codex_extension_api::McpServerContribution;
|
||||
use codex_extension_api::McpServerContributionContext;
|
||||
@@ -13,19 +16,75 @@ use codex_features::Feature;
|
||||
use codex_protocol::capabilities::CapabilityRootLocation;
|
||||
use codex_protocol::capabilities::SelectedCapabilityRoot;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use self::provider::PluginMcpProvider;
|
||||
use crate::PluginsThreadState;
|
||||
use crate::cloud_plugin::hosted_plugin_connectors;
|
||||
use crate::plugin_contributor::PluginContributor;
|
||||
use crate::plugin_contributor_state::CachedPluginMetadata;
|
||||
use crate::plugin_contributor_state::CachedSelectedRoot;
|
||||
|
||||
mod discovery;
|
||||
mod provider;
|
||||
|
||||
impl PluginContributor {
|
||||
async fn ownership_for_root(
|
||||
&self,
|
||||
state: &PluginsThreadState,
|
||||
selected_root: &SelectedCapabilityRoot,
|
||||
discovery: Option<&CapabilityRootDiscovery>,
|
||||
sandbox: Option<&FileSystemSandboxContext>,
|
||||
) -> Result<PluginRootOwnership, ExecutorPluginProviderError> {
|
||||
if let Some(ownership) = state
|
||||
.contributor_state()
|
||||
.executor_cache
|
||||
.iter()
|
||||
.find(|cached| {
|
||||
cached.root == *selected_root && cached.ownership_sandbox.as_deref() == sandbox
|
||||
})
|
||||
.and_then(|cached| cached.ownership)
|
||||
{
|
||||
return Ok(ownership);
|
||||
}
|
||||
let ownership = self
|
||||
.providers
|
||||
.executor
|
||||
.root_ownership(selected_root, discovery, sandbox)
|
||||
.await
|
||||
.inspect_err(|error| {
|
||||
let CapabilityRootLocation::Environment { environment_id, .. } =
|
||||
&selected_root.location;
|
||||
tracing::warn!(
|
||||
selected_root = selected_root.id,
|
||||
environment_id,
|
||||
error = %error,
|
||||
"failed to resolve selected root plugin ownership"
|
||||
);
|
||||
})?;
|
||||
let mut state = state.contributor_state();
|
||||
if let Some(cached) = state
|
||||
.executor_cache
|
||||
.iter_mut()
|
||||
.find(|cached| cached.root == *selected_root)
|
||||
{
|
||||
if cached.ownership_sandbox.as_deref() == sandbox
|
||||
&& let Some(ownership) = cached.ownership
|
||||
{
|
||||
return Ok(ownership);
|
||||
}
|
||||
cached.ownership = Some(ownership);
|
||||
cached.ownership_sandbox = sandbox.cloned().map(Box::new);
|
||||
} else {
|
||||
state.executor_cache.push(CachedSelectedRoot {
|
||||
root: selected_root.clone(),
|
||||
ownership: Some(ownership),
|
||||
ownership_sandbox: sandbox.cloned().map(Box::new),
|
||||
metadata: CachedPluginMetadata::Unloaded,
|
||||
});
|
||||
}
|
||||
Ok(ownership)
|
||||
}
|
||||
|
||||
/// Returns metadata for one stable selected root.
|
||||
///
|
||||
/// Successful resolution, including a root that is not a plugin or declares no capabilities,
|
||||
@@ -37,13 +96,16 @@ impl PluginContributor {
|
||||
state: &PluginsThreadState,
|
||||
selected_root: &SelectedCapabilityRoot,
|
||||
) -> Option<SelectedPluginContribution> {
|
||||
if let Some(cached) = state
|
||||
if let Some(CachedSelectedRoot {
|
||||
metadata: CachedPluginMetadata::Loaded(metadata),
|
||||
..
|
||||
}) = state
|
||||
.contributor_state()
|
||||
.executor_cache
|
||||
.iter()
|
||||
.find(|cached| cached.root == *selected_root)
|
||||
{
|
||||
return cached.metadata.clone();
|
||||
return metadata.clone();
|
||||
}
|
||||
|
||||
let plugin = match self.providers.executor.resolve_bound(selected_root).await {
|
||||
@@ -99,13 +161,22 @@ impl PluginContributor {
|
||||
};
|
||||
let mut state = state.contributor_state();
|
||||
let cache = &mut state.executor_cache;
|
||||
if let Some(cached) = cache.iter().find(|cached| cached.root == *selected_root) {
|
||||
return cached.metadata.clone();
|
||||
if let Some(cached) = cache
|
||||
.iter_mut()
|
||||
.find(|cached| cached.root == *selected_root)
|
||||
{
|
||||
if let CachedPluginMetadata::Loaded(metadata) = &cached.metadata {
|
||||
return metadata.clone();
|
||||
}
|
||||
cached.metadata = CachedPluginMetadata::Loaded(metadata.clone());
|
||||
} else {
|
||||
cache.push(CachedSelectedRoot {
|
||||
root: selected_root.clone(),
|
||||
ownership: None,
|
||||
ownership_sandbox: None,
|
||||
metadata: CachedPluginMetadata::Loaded(metadata.clone()),
|
||||
});
|
||||
}
|
||||
cache.push(CachedSelectedRoot {
|
||||
root: selected_root.clone(),
|
||||
metadata: metadata.clone(),
|
||||
});
|
||||
metadata
|
||||
}
|
||||
}
|
||||
@@ -142,6 +213,7 @@ impl McpServerContributor<Config> for PluginContributor {
|
||||
fn selected_plugins<'a>(
|
||||
&'a self,
|
||||
context: McpServerContributionContext<'a, Config>,
|
||||
plugins_config: &'a PluginsConfigToml,
|
||||
) -> ExtensionFuture<'a, Vec<SelectedPlugin<'a>>> {
|
||||
Box::pin(async move {
|
||||
let Some(thread_store) = context.thread_store() else {
|
||||
@@ -155,8 +227,6 @@ impl McpServerContributor<Config> for PluginContributor {
|
||||
let selected_roots = context
|
||||
.ready_selected_capability_roots()
|
||||
.unwrap_or_default();
|
||||
// All plugins in this refresh share the same policy, but step-only readers never need it.
|
||||
let plugin_policies = Arc::new(OnceLock::new());
|
||||
let mut plugins = Vec::new();
|
||||
|
||||
if let Some(snapshot) = context.executor_capability_discovery() {
|
||||
@@ -172,12 +242,31 @@ impl McpServerContributor<Config> for PluginContributor {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let CapabilityRootLocation::Environment { environment_id, .. } =
|
||||
&root.selected_root.location;
|
||||
// Ownership survives capability parse failures; an unresolved root cannot
|
||||
// bypass a denying policy.
|
||||
if !plugins_config.allows_plugin(&root.selected_root.id)
|
||||
&& discovery.error.is_none()
|
||||
&& !matches!(
|
||||
self.ownership_for_root(
|
||||
&state,
|
||||
&root.selected_root,
|
||||
Some(discovery),
|
||||
snapshot.sandbox_contexts().get(environment_id),
|
||||
)
|
||||
.await,
|
||||
Ok(PluginRootOwnership::Standalone)
|
||||
)
|
||||
{
|
||||
plugins.push(denied_plugin(&root.selected_root));
|
||||
continue;
|
||||
}
|
||||
let Some((manifest, plugin_files)) =
|
||||
discovery::manifest_from_discovery(&root.selected_root, discovery)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let plugin_policies = Arc::clone(&plugin_policies);
|
||||
plugins.push(SelectedPlugin {
|
||||
selected_root_id: root.selected_root.id.clone(),
|
||||
plugin_id: root.selected_root.id.clone(),
|
||||
@@ -190,8 +279,8 @@ impl McpServerContributor<Config> for PluginContributor {
|
||||
);
|
||||
project_metadata(
|
||||
context.config(),
|
||||
plugins_config,
|
||||
&root.selected_root.id,
|
||||
&plugin_policies,
|
||||
metadata,
|
||||
)
|
||||
}),
|
||||
@@ -199,18 +288,32 @@ impl McpServerContributor<Config> for PluginContributor {
|
||||
}
|
||||
} else {
|
||||
for selected_root in selected_roots {
|
||||
if !plugins_config.allows_plugin(&selected_root.id) {
|
||||
if !matches!(
|
||||
self.ownership_for_root(
|
||||
&state,
|
||||
selected_root,
|
||||
/*discovery*/ None,
|
||||
/*sandbox*/ None
|
||||
)
|
||||
.await,
|
||||
Ok(PluginRootOwnership::Standalone)
|
||||
) {
|
||||
plugins.push(denied_plugin(selected_root));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let Some(metadata) = self.metadata_for_root(&state, selected_root).await else {
|
||||
continue;
|
||||
};
|
||||
let plugin_policies = Arc::clone(&plugin_policies);
|
||||
plugins.push(SelectedPlugin {
|
||||
selected_root_id: selected_root.id.clone(),
|
||||
plugin_id: selected_root.id.clone(),
|
||||
mcp: Box::pin(async move {
|
||||
project_metadata(
|
||||
context.config(),
|
||||
plugins_config,
|
||||
&selected_root.id,
|
||||
&plugin_policies,
|
||||
metadata,
|
||||
)
|
||||
}),
|
||||
@@ -222,10 +325,25 @@ impl McpServerContributor<Config> for PluginContributor {
|
||||
}
|
||||
}
|
||||
|
||||
fn denied_plugin(selected_root: &SelectedCapabilityRoot) -> SelectedPlugin<'static> {
|
||||
let CapabilityRootLocation::Environment { environment_id, .. } = &selected_root.location;
|
||||
let metadata = SelectedPluginContribution {
|
||||
plugin_display_name: selected_root.id.clone(),
|
||||
source_environment_id: environment_id.clone(),
|
||||
servers: Vec::new(),
|
||||
connector_ids: Vec::new(),
|
||||
};
|
||||
SelectedPlugin {
|
||||
selected_root_id: selected_root.id.clone(),
|
||||
plugin_id: selected_root.id.clone(),
|
||||
mcp: Box::pin(async move { metadata }),
|
||||
}
|
||||
}
|
||||
|
||||
fn project_metadata(
|
||||
config: &Config,
|
||||
plugins_config: &PluginsConfigToml,
|
||||
plugin_id: &str,
|
||||
plugin_policies: &OnceLock<HashMap<String, HashMap<String, PluginMcpServerConfig>>>,
|
||||
plugin: SelectedPluginContribution,
|
||||
) -> SelectedPluginContribution {
|
||||
let mut servers = if config.features.enabled(Feature::Plugins) {
|
||||
@@ -234,11 +352,8 @@ fn project_metadata(
|
||||
HashMap::new()
|
||||
};
|
||||
if !servers.is_empty() {
|
||||
if let Some(plugin_policy) = plugin_policies
|
||||
.get_or_init(|| configured_plugin_mcp_server_policies(&config.config_layer_stack))
|
||||
.get(plugin_id)
|
||||
{
|
||||
apply_configured_plugin_mcp_server_policies(plugin_policy, &mut servers);
|
||||
if let Some(plugin_policy) = plugins_config.plugins.get(plugin_id) {
|
||||
apply_configured_plugin_mcp_server_policies(&plugin_policy.mcp_servers, &mut servers);
|
||||
}
|
||||
config.apply_plugin_mcp_server_requirements(plugin_id, &mut servers);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
//! Thread-owned cloud catalog and legacy selected-root cache, guarded by a short-lived mutex.
|
||||
//! Thread-owned cloud catalog and stable selected-root metadata, guarded by a short-lived mutex.
|
||||
|
||||
use codex_core_plugins::PluginCatalog;
|
||||
use codex_core_plugins::PluginRootOwnership;
|
||||
use codex_exec_server::FileSystemSandboxContext;
|
||||
use codex_extension_api::SelectedPluginContribution;
|
||||
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
|
||||
use codex_mcp::McpResourceClient;
|
||||
@@ -110,5 +112,13 @@ impl PluginContributorState {
|
||||
|
||||
pub(crate) struct CachedSelectedRoot {
|
||||
pub(crate) root: SelectedCapabilityRoot,
|
||||
pub(crate) metadata: Option<SelectedPluginContribution>,
|
||||
pub(crate) ownership: Option<PluginRootOwnership>,
|
||||
pub(crate) ownership_sandbox: Option<Box<FileSystemSandboxContext>>,
|
||||
pub(crate) metadata: CachedPluginMetadata,
|
||||
}
|
||||
|
||||
/// Denied roots retain ownership without loading their capabilities.
|
||||
pub(crate) enum CachedPluginMetadata {
|
||||
Unloaded,
|
||||
Loaded(Option<SelectedPluginContribution>),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user