Allow disabling plugin discovery prefetch at app-server startup (#57249)

## Why

Hosts that only need installed plugin inventory should be able to skip startup requests for plugin discovery.

## What changed

Add the stable, default-enabled `features.plugin_discovery_prefetch` flag. Setting it to `false` skips startup prefetching of the plugin directory, featured plugins, and recommendations while preserving installed plugin cache refreshes and bundle downloads.

## Testing

Update app-server integration coverage to verify that installed plugin bundles download with discovery prefetch disabled and that no directory, featured, or suggested plugin requests are made during startup. Also cover listing remote marketplaces with the flag disabled.

GitOrigin-RevId: 7cc3072f6045131b9f1acb851f6240db75ac173e
This commit is contained in:
Alex Zamoshchin
2026-10-26 20:54:08 +00:00
committed by copyberry
parent 8f71a8657e
commit 3ad642e520
7 changed files with 47 additions and 10 deletions
@@ -83,6 +83,7 @@ use codex_core::config::Config;
use codex_core::config::ThreadStoreConfig;
use codex_exec_server::EnvironmentManager;
use codex_extension_api::TurnStartAdmission;
use codex_features::Feature;
use codex_feedback::CodexFeedback;
use codex_goal_extension::GoalService;
use codex_home::CodexHomeUserInstructionsProvider;
@@ -568,6 +569,7 @@ impl MessageProcessor {
.plugins_manager()
.maybe_start_plugin_startup_tasks_for_config(
&config.plugins_config_input(),
config.features.enabled(Feature::PluginDiscoveryPrefetch),
reload_config,
Some(on_effective_plugins_changed),
startup_warnings_tx,
@@ -308,6 +308,7 @@ impl AccountRequestProcessor {
.maybe_start_remote_plugin_caches_refresh(
&plugins_config,
auth,
/*prefetch_recommendations*/ true,
Some(on_effective_plugins_changed),
);
}
@@ -1961,7 +1961,8 @@ enabled = true
}
#[tokio::test]
async fn app_server_startup_sync_downloads_remote_installed_plugin_bundles() -> Result<()> {
async fn app_server_startup_downloads_installed_plugin_bundles_without_discovery_prefetch()
-> Result<()> {
let codex_home = TempDir::new()?;
let server = MockServer::start().await;
write_remote_plugin_catalog_config(
@@ -2001,11 +2002,24 @@ async fn app_server_startup_sync_downloads_remote_installed_plugin_bundles() ->
.await;
mount_empty_user_installed_plugins(&server).await;
for endpoint in [
"/backend-api/ps/plugins/list",
"/backend-api/plugins/featured",
"/backend-api/ps/plugins/suggested/codex",
] {
Mock::given(path(endpoint))
.respond_with(ResponseTemplate::new(404))
.expect(0)
.mount(&server)
.await;
}
let installed_path = codex_home
.path()
.join("plugins/cache/openai-curated-remote/linear/1.2.3");
let _mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
.with_args(&["-c", "features.plugin_discovery_prefetch=false"])
.with_plugin_startup_tasks()
.with_env_overrides(&[(TEST_ALLOW_HTTP_REMOTE_PLUGIN_BUNDLE_DOWNLOADS, Some("1"))])
.build_initialized_with_timeout(DEFAULT_TIMEOUT)
@@ -2137,7 +2151,7 @@ enum ProjectPluginConfiguration {
Invalid,
}
#[test_case(ProjectPluginConfiguration::None, None, "", true, true; "without project override")]
#[test_case(ProjectPluginConfiguration::None, None, "plugin_discovery_prefetch = false", true, true; "without discovery prefetch")]
#[test_case(ProjectPluginConfiguration::Disabled, None, "", true, true; "project disables local plugins")]
#[test_case(ProjectPluginConfiguration::Invalid, None, "", true, true; "invalid project preserves remote plugins")]
#[test_case(ProjectPluginConfiguration::None, Some("tpp"), "", true, true; "configured product sku")]
+12 -8
View File
@@ -1588,6 +1588,7 @@ impl PluginsManager {
self: &Arc<Self>,
config: &PluginsConfigInput,
auth: Option<CodexAuth>,
prefetch_recommendations: bool,
on_effective_plugins_changed: Option<EffectivePluginsChangedCallback>,
) {
self.maybe_start_remote_installed_plugins_cache_refresh_with_notify(
@@ -1598,6 +1599,9 @@ impl PluginsManager {
EffectivePluginsChange::default(),
);
if !prefetch_recommendations {
return;
}
let manager = Arc::clone(self);
let config = config.clone();
tokio::spawn(async move {
@@ -1873,6 +1877,7 @@ impl PluginsManager {
self.maybe_start_remote_plugin_caches_refresh(
&context.global_config,
auth.clone(),
/*prefetch_recommendations*/ true,
on_effective_plugins_changed.clone(),
);
self.maybe_start_remote_installed_plugin_bundle_sync(
@@ -2874,6 +2879,7 @@ impl PluginsManager {
pub fn maybe_start_plugin_startup_tasks_for_config(
self: &Arc<Self>,
config: &PluginsConfigInput,
prefetch_discovery: bool,
reload_config: ConfigLayerReload,
on_effective_plugins_changed: Option<EffectivePluginsChangedCallback>,
upgrade_warnings: mpsc::UnboundedSender<String>,
@@ -2966,6 +2972,7 @@ impl PluginsManager {
manager.maybe_start_remote_plugin_caches_refresh(
&config_for_remote_sync,
auth.clone(),
prefetch_discovery,
on_effective_plugins_changed.clone(),
);
manager.maybe_start_remote_installed_plugin_bundle_sync(
@@ -2973,6 +2980,9 @@ impl PluginsManager {
auth.clone(),
on_effective_plugins_changed,
);
if !prefetch_discovery {
return;
}
let mut scopes = crate::remote::cached_remote_plugin_catalog_scopes(
manager.codex_home.as_path(),
&remote_plugin_service_config(&config_for_remote_sync),
@@ -2985,18 +2995,12 @@ impl PluginsManager {
}
manager.maybe_start_remote_catalog_cache_refresh(
&config_for_remote_sync,
auth,
auth.clone(),
scopes,
RemoteCatalogCacheRefreshMode::Force,
);
});
let config_for_featured_plugins = config.clone();
let manager = Arc::clone(self);
tokio::spawn(async move {
let auth = manager.auth_manager.auth().await;
if let Err(err) = manager
.featured_plugin_ids_for_config(&config_for_featured_plugins, auth.as_ref())
.featured_plugin_ids_for_config(&config_for_remote_sync, auth.as_ref())
.await
{
warn!(
@@ -6147,6 +6147,7 @@ plugins = true
manager.maybe_start_remote_plugin_caches_refresh(
&config,
Some(auth.clone()),
/*prefetch_recommendations*/ true,
/*on_effective_plugins_changed*/ None,
);
+6
View File
@@ -1197,6 +1197,9 @@
"personality": {
"type": "boolean"
},
"plugin_discovery_prefetch": {
"type": "boolean"
},
"plugin_hooks": {
"type": "boolean"
},
@@ -7818,6 +7821,9 @@
"personality": {
"type": "boolean"
},
"plugin_discovery_prefetch": {
"type": "boolean"
},
"plugin_hooks": {
"type": "boolean"
},
+9
View File
@@ -351,6 +351,9 @@ pub enum Feature {
ComputerUse,
/// Enable the PS-backed remote plugin catalog.
RemotePlugin,
/// Prefetch the plugin directory, featured plugins, and recommendations at app-server startup.
/// Inventory-only hosts can disable this. Legacy suggestions read the cached directory.
PluginDiscoveryPrefetch,
/// Enable remote plugin sharing flows.
PluginSharing,
/// Removed compatibility flag retained as a no-op.
@@ -1816,6 +1819,12 @@ pub const FEATURES: &[FeatureSpec] = &[
stage: Stage::Stable,
default_enabled: true,
},
FeatureSpec {
id: Feature::PluginDiscoveryPrefetch,
key: "plugin_discovery_prefetch",
stage: Stage::Stable,
default_enabled: true,
},
FeatureSpec {
id: Feature::PluginSharing,
key: "plugin_sharing",