Prefer remote Sites over the bundled plugin (#42100)

## Why

When the remote Sites plugin is installed and its local bundle is available, exposing the bundled copy as well creates duplicate catalog entries and can load the wrong skills.

## What changed

- Persist an account- and backend-scoped exclusion for `sites@openai-bundled` once the remote replacement is installed and loadable.
- Apply the exclusion to plugin catalogs, search, direct reads and installs, runtime loading, hooks, and skill caches while preserving the remote plugin's server-owned enabled state.
- Restore the bundled fallback when the remote plugin is absent or its local files are unavailable, and throttle repeated availability checks for 60 seconds.

## Testing

- Added manager tests for persistence across restarts, account/backend isolation, fallback restoration, concurrent checks, and refresh throttling.
- Added app-server and agent-turn tests confirming that catalog, search, and skill loading prefer remote Sites.

GitOrigin-RevId: bc1154f79d3107910fee9fa27389a0ddb48ce6cf
This commit is contained in:
Jiwon Kim authored and copyberry committed 2026-09-01 16:58:54 +00:00
1 parent a17ee5705c
commit b6ab99ed87
16 files changed
+864 -27

No files matched your search

+283 -8
View File
@@ -72,6 +72,7 @@ use wiremock::matchers::header;
use wiremock::matchers::method;
use wiremock::matchers::path;
use wiremock::matchers::query_param;
use wiremock::matchers::query_param_is_missing;
const MAX_CAPABILITY_SUMMARY_DESCRIPTION_LEN: usize = 1024;
@@ -82,6 +83,17 @@ fn unrestricted_config_layer_stack() -> ConfigLayerStack {
ConfigLayerStack::default()
}
fn unrestricted_plugins_config_input() -> PluginsConfigInput {
PluginsConfigInput::new(
unrestricted_config_layer_stack(),
String::new(),
/*plugins_enabled*/ true,
/*remote_plugin_enabled*/ false,
String::new(),
test_http_client_factory(),
)
}
fn config_layer_stack_with_requirements(
codex_home: &Path,
user_config: &str,
@@ -3105,6 +3117,7 @@ fn loaded_plugins_cache_evicts_least_recently_used_configuration() {
skill_config_rules: SkillConfigRules::default(),
remote_global_catalog_active: false,
auth_identity: None,
excluded_plugin_ids: BTreeSet::new(),
})
.collect::<Vec<_>>();
let generation = manager.loaded_plugins_cache_generation();
@@ -3149,6 +3162,7 @@ fn loaded_plugins_cache_invalidation_rejects_stale_load_completion() {
skill_config_rules: SkillConfigRules::default(),
remote_global_catalog_active: false,
auth_identity: None,
excluded_plugin_ids: BTreeSet::new(),
};
let stale_generation = manager.loaded_plugins_cache_generation();
@@ -3287,7 +3301,7 @@ async fn install_plugin_updates_config_with_relative_path_and_plugin_key() {
let result = test_plugins_manager(tmp.path().to_path_buf())
.install_plugin(
&unrestricted_config_layer_stack(),
&unrestricted_plugins_config_input(),
PluginInstallRequest {
plugin_name: "sample-plugin".to_string(),
marketplace_path: AbsolutePathBuf::try_from(
@@ -3345,7 +3359,7 @@ source = "local"
path = {marketplace_root:?}
"#
);
let config = config_layer_stack_with_requirements(codex_home.path(), "", &requirements);
let config = plugins_config_input_with_requirements(codex_home.path(), "", &requirements);
let marketplace_path =
AbsolutePathBuf::try_from(marketplace_root.join(".agents/plugins/marketplace.json"))
.expect("absolute marketplace path");
@@ -3377,7 +3391,7 @@ source = {marketplace_root:?}
);
write_file(&codex_home.path().join(CONFIG_TOML_FILE), &user_config);
let config =
config_layer_stack_with_requirements(codex_home.path(), &user_config, &requirements);
plugins_config_input_with_requirements(codex_home.path(), &user_config, &requirements);
let outcome = manager
.install_plugin(
&config,
@@ -3403,7 +3417,7 @@ async fn install_openai_curated_plugin_uses_short_sha_cache_version() {
let result = test_plugins_manager(tmp.path().to_path_buf())
.install_plugin(
&unrestricted_config_layer_stack(),
&unrestricted_plugins_config_input(),
PluginInstallRequest {
plugin_name: "slack".to_string(),
marketplace_path: AbsolutePathBuf::try_from(
@@ -3464,7 +3478,7 @@ async fn install_plugin_uses_manifest_version_for_non_curated_plugins() {
let result = test_plugins_manager(tmp.path().to_path_buf())
.install_plugin(
&unrestricted_config_layer_stack(),
&unrestricted_plugins_config_input(),
PluginInstallRequest {
plugin_name: "sample-plugin".to_string(),
marketplace_path: AbsolutePathBuf::try_from(
@@ -3532,7 +3546,7 @@ async fn install_plugin_writes_marketplace_manifest_fallback_when_missing_plugin
let result = test_plugins_manager(tmp.path().to_path_buf())
.install_plugin(
&unrestricted_config_layer_stack(),
&unrestricted_plugins_config_input(),
PluginInstallRequest {
plugin_name: "quality-review".to_string(),
marketplace_path: AbsolutePathBuf::try_from(
@@ -3632,7 +3646,7 @@ async fn install_plugin_supports_git_subdir_marketplace_sources() {
let result = test_plugins_manager(tmp.path().to_path_buf())
.install_plugin(
&unrestricted_config_layer_stack(),
&unrestricted_plugins_config_input(),
PluginInstallRequest {
plugin_name: "toolkit".to_string(),
marketplace_path: AbsolutePathBuf::try_from(
@@ -3686,7 +3700,7 @@ async fn install_plugin_supports_relative_git_subdir_marketplace_sources() {
let result = test_plugins_manager(tmp.path().to_path_buf())
.install_plugin(
&unrestricted_config_layer_stack(),
&unrestricted_plugins_config_input(),
PluginInstallRequest {
plugin_name: "toolkit".to_string(),
marketplace_path: AbsolutePathBuf::try_from(
@@ -5095,6 +5109,13 @@ plugins = true
marketplaces
.iter()
.map(|marketplace| marketplace.name.as_str())
// Personal marketplaces do not affect which curated catalog auth selects.
.filter(|name| {
matches!(
*name,
OPENAI_CURATED_MARKETPLACE_NAME | OPENAI_API_CURATED_MARKETPLACE_NAME
)
})
.collect::<Vec<_>>(),
vec![expected_marketplace],
"unexpected curated catalog for provider `{resolved_provider}` with auth {auth_mode:?}"
@@ -6923,6 +6944,7 @@ async fn load_plugins_uses_project_config_files() {
Some(Product::Codex),
/*remote_global_catalog_active*/ false,
test_skill_root_loader().as_ref(),
&BTreeSet::new(),
)
.await;
@@ -7210,6 +7232,255 @@ remote_plugin = true
server.verify().await;
}
#[tokio::test]
async fn sites_migration_throttles_absence_without_blocking_normal_sync() {
let home = TempDir::new().unwrap();
write_file(
&home.path().join(CONFIG_TOML_FILE),
"[features]\nplugins = true\nremote_plugin = true\n",
);
let server = MockServer::start().await;
let mut config = load_config(home.path(), home.path()).await;
config.chatgpt_base_url = format!("{}/backend-api", server.uri());
let manager = test_plugins_manager_with_options(
home.path().to_path_buf(),
Some(Product::Codex),
Some(AuthMode::Chatgpt),
);
let auth = manager.auth_manager.auth_cached().unwrap();
let installed_path = "/backend-api/ps/plugins/installed";
let failed_check = Mock::given(method("GET"))
.and(path(installed_path))
.respond_with(ResponseTemplate::new(503))
.mount_as_scoped(&server)
.await;
assert!(
manager
.ensure_sites_migration_ready(&config, Some(&auth))
.await
.is_err()
);
drop(failed_check);
Mock::given(method("GET"))
.and(path(installed_path))
.and(query_param_is_missing("includeDownloadUrls"))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
"plugins": [], "pagination": {"next_page_token": null}
})))
.expect(1)
.mount(&server)
.await;
// An unrelated startup download must not block a successful Sites-absence check.
let unrelated_sync = manager
.acquire_remote_installed_plugin_sync_guard()
.await
.unwrap();
for _ in 0..2 {
assert!(
tokio::time::timeout(
Duration::from_secs(1),
manager.ensure_sites_migration_ready(&config, Some(&auth)),
)
.await
.expect("Sites absence must not wait for unrelated bundle downloads")
.unwrap()
.is_none()
);
}
drop(unrelated_sync);
Mock::given(method("GET"))
.and(path(installed_path))
.and(query_param("includeDownloadUrls", "true"))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
"plugins": [], "pagination": {"next_page_token": null}
})))
.expect(1)
.mount(&server)
.await;
manager
.reconcile_remote_installed_plugins(&config, Some(&auth))
.await
.unwrap();
}
#[tokio::test]
async fn sites_migration_persists_only_exclusion_without_repeating_rollout() {
let home = TempDir::new().unwrap();
let marketplace_root = home.path().join(".tmp/bundled-marketplaces/openai-bundled");
write_file(
&home.path().join(CONFIG_TOML_FILE),
&format!(
"[features]\nplugins = true\nremote_plugin = true\n[plugins.\"sites@openai-bundled\"]\nenabled = true\n[marketplaces.openai-bundled]\nsource_type = \"local\"\nsource = {marketplace_root:?}\n"
),
);
write_cached_plugin(home.path(), "openai-bundled", "sites");
write_plugin(&marketplace_root, "sites", "sites");
write_file(
&marketplace_root.join(".agents/plugins/marketplace.json"),
r#"{"name":"openai-bundled","plugins":[{"name":"sites","source":{"source":"local","path":"./sites"}}]}"#,
);
let server = MockServer::start().await;
let mut config = load_config(home.path(), home.path()).await;
config.chatgpt_base_url = format!("{}/backend-api", server.uri());
let auth_manager = test_auth_manager(Some(AuthMode::Chatgpt));
let auth = auth_manager.auth_cached().unwrap();
Mock::given(method("GET"))
.and(path("/backend-api/ps/plugins/installed"))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
"plugins": [{
"id": "plugins~plugin_connector_1p_689987207de08191979cf68eca2941c6",
"name": "sites", "scope": "GLOBAL", "enabled": false,
"installation_policy": "AVAILABLE", "authentication_policy": "ON_USE",
"release": {"version": "local", "display_name": "Sites", "description": "Sites", "interface": {}}
}],
"pagination": {"next_page_token": null}
})))
.mount(&server).await;
let manager = test_plugins_manager_with_auth_manager(
home.path().to_path_buf(),
Some(Product::Codex),
auth_manager.clone(),
);
let has_bundled_sites = |manager: &PluginsManager| {
manager
.list_marketplaces_for_config(&config, &[], /*include_openai_curated*/ false)
.unwrap()
.marketplaces
.into_iter()
.flat_map(|marketplace| marketplace.plugins)
.any(|plugin| plugin.id == "sites@openai-bundled")
};
// An installed remote entry without local files must preserve the bundled runtime fallback.
manager
.reconcile_remote_installed_plugins(&config, Some(&auth))
.await
.unwrap();
assert!(has_bundled_sites(&manager));
assert_eq!(
loaded_plugin_names(&manager, &config).await,
vec!["sites@openai-bundled"]
);
write_cached_plugin(home.path(), REMOTE_GLOBAL_MARKETPLACE_NAME, "sites");
let read_request = PluginReadRequest {
plugin_name: "sites".to_string(),
marketplace_path: AbsolutePathBuf::try_from(
marketplace_root.join(".agents/plugins/marketplace.json"),
)
.unwrap(),
};
let install_request = PluginInstallRequest {
plugin_name: read_request.plugin_name.clone(),
marketplace_path: read_request.marketplace_path.clone(),
};
let (first, concurrent) = tokio::join!(
manager.ensure_sites_migration_ready(&config, Some(&auth)),
manager.ensure_sites_migration_ready(&config, Some(&auth)),
);
assert!(first.unwrap().is_some() ^ concurrent.unwrap().is_some());
assert!(!manager.remote_installed_plugin_configs()["sites@openai-curated-remote"].enabled);
assert!(
server
.received_requests()
.await
.unwrap()
.iter()
.all(|request| request.method == "GET")
);
let config_before_rejected_install = fs::read(home.path().join(CONFIG_TOML_FILE)).unwrap();
assert!(matches!(
manager.read_plugin_for_config(&config, &read_request).await,
Err(MarketplaceError::PluginNotFound { plugin_name, marketplace_name })
if plugin_name == "sites" && marketplace_name == "openai-bundled"
));
assert!(matches!(
manager.install_plugin(&config, install_request.clone()).await,
Err(PluginInstallError::Marketplace(MarketplaceError::PluginNotFound { plugin_name, marketplace_name }))
if plugin_name == "sites" && marketplace_name == "openai-bundled"
));
assert_eq!(
fs::read(home.path().join(CONFIG_TOML_FILE)).unwrap(),
config_before_rejected_install
);
let exclusion_file = std::fs::read_dir(home.path().join("cache/bundled_plugin_exclusions"))
.unwrap()
.next()
.unwrap()
.unwrap()
.path();
assert_eq!(
serde_json::from_slice::<serde_json::Value>(&std::fs::read(exclusion_file).unwrap())
.unwrap(),
serde_json::json!({"disabled-bundled-plugin-ids": ["sites@openai-bundled"]})
);
let requests = server.received_requests().await.unwrap().len();
let restarted = test_plugins_manager_with_auth_manager(
home.path().to_path_buf(),
Some(Product::Codex),
auth_manager.clone(),
);
assert!(
restarted
.ensure_sites_migration_ready(&config, Some(&auth))
.await
.unwrap()
.is_none()
);
assert_eq!(server.received_requests().await.unwrap().len(), requests);
assert!(!has_bundled_sites(&restarted));
assert!(restarted.remote_installed_plugin_configs().is_empty());
assert!(
!loaded_plugin_names(&restarted, &config)
.await
.contains(&"sites@openai-bundled".to_string())
);
// A warm runtime/skill cache must not carry this backend's exclusion into another backend.
let mut other_backend = config.clone();
other_backend.chatgpt_base_url = format!("{}/other-backend", server.uri());
assert!(
restarted
.excluded_bundled_plugin_ids(&other_backend)
.is_empty()
);
assert!(
restarted
.plugin_skill_snapshots_for_config(&config)
.is_some()
);
assert!(
restarted
.plugin_skill_snapshots_for_config(&other_backend)
.is_none()
);
assert_eq!(
loaded_plugin_names(&restarted, &other_backend).await,
vec!["sites@openai-bundled"]
);
assert!(loaded_plugin_names(&restarted, &config).await.is_empty());
server.reset().await;
Mock::given(method("GET"))
.and(path("/backend-api/ps/plugins/installed"))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
"plugins": [], "pagination": {"next_page_token": null}
})))
.mount(&server)
.await;
restarted
.reconcile_remote_installed_plugins(&config, Some(&auth))
.await
.unwrap();
assert!(has_bundled_sites(&restarted));
restarted
.read_plugin_for_config(&config, &read_request)
.await
.unwrap();
restarted
.install_plugin(&config, install_request)
.await
.unwrap();
}
#[tokio::test]
async fn reconcile_remote_installed_plugins_reports_cached_state_changes() {
let codex_home = TempDir::new().unwrap();
@@ -7469,6 +7740,7 @@ fn reconciliation_fences_refresh_publication_and_recovers_after_cancellation() {
stale_refresh_generation,
Vec::new(),
/*auth*/ None,
"",
RemoteInstalledPluginsCachePublication::Refresh,
),
None
@@ -7478,6 +7750,7 @@ fn reconciliation_fences_refresh_publication_and_recovers_after_cancellation() {
reconcile_generation,
vec![remote_installed_linear_plugin()],
/*auth*/ None,
"",
RemoteInstalledPluginsCachePublication::Reconcile,
),
Some(true)
@@ -7501,6 +7774,7 @@ fn reconciliation_fences_refresh_publication_and_recovers_after_cancellation() {
refresh_generation,
vec![remote_installed_plugin("beta")],
/*auth*/ None,
"",
RemoteInstalledPluginsCachePublication::Refresh,
),
Some(true)
@@ -7513,6 +7787,7 @@ fn reconciliation_fences_refresh_publication_and_recovers_after_cancellation() {
retry_generation,
vec![remote_installed_plugin("beta")],
/*auth*/ None,
"",
RemoteInstalledPluginsCachePublication::Reconcile,
),
Some(true)