fix(plugins): close host capability gating gaps

This commit is contained in:
Casey Chow
2026-07-09 23:05:24 +00:00
parent ba60aff590
commit 44d2376f06
9 changed files with 320 additions and 10 deletions
+3 -2
View File
@@ -98,7 +98,8 @@ Clients declare host features available to runtime plugins with
compatibility signals, not authorization grants; omitted or `null`
capabilities are treated as an empty set. The capability set is fixed for the
lifetime of a loaded thread, so clients must use the same set when resuming or
starting turns on that thread.
performing model-visible runtime operations on that thread. Capability-independent
settings updates remain available; the next `turn/start` enforces compatibility.
Plugin manifests declare all-of host requirements with
`{"requires":{"hostCapabilities":["codex.inline_visualization"]}}`. A plugin
@@ -1835,7 +1836,7 @@ Use `app/list` to fetch available apps (connectors). Each entry includes metadat
} }
```
When `threadId` is provided, app feature gating (`Feature::Apps`) is evaluated using that thread's config snapshot. When omitted, the latest global config is used.
When `threadId` is provided, app feature gating (`Feature::Apps`) is evaluated using that thread's config snapshot, and the requesting connection must have the same host capability set as the loaded thread. When omitted, the latest global config is used.
`app/list` returns after both accessible apps and directory apps are loaded. Set `forceRefetch: true` to bypass app caches and fetch fresh data from sources. Cache entries are only replaced when those refetches succeed.
+7 -2
View File
@@ -1136,7 +1136,12 @@ impl MessageProcessor {
}
ClientRequest::ThreadRollback { params, .. } => {
self.thread_processor
.thread_rollback(&request_id, params, app_server_client_info.name.as_deref())
.thread_rollback(
&request_id,
params,
app_server_client_info.name.as_deref(),
host_capabilities.clone(),
)
.await
}
ClientRequest::ThreadList { params, .. } => {
@@ -1280,7 +1285,7 @@ impl MessageProcessor {
}
ClientRequest::TurnInterrupt { params, .. } => {
self.turn_processor
.turn_interrupt(&request_id, params)
.turn_interrupt(&request_id, params, host_capabilities.clone())
.await
}
ClientRequest::ThreadRealtimeStart { params, .. } => {
@@ -52,7 +52,14 @@ impl AppsRequestProcessor {
let installed_start = Instant::now();
let reload = params.force_refetch;
let thread = if let Some(thread_id) = params.thread_id.as_deref() {
let (_, loaded_thread) = self.load_thread(thread_id).await?;
let (thread_id, loaded_thread) = self.load_thread(thread_id).await?;
ensure_thread_host_capabilities(
thread_id,
loaded_thread.as_ref(),
&host_capabilities,
"list apps",
)
.await?;
Some(loaded_thread)
} else {
None
@@ -669,12 +669,13 @@ impl ThreadRequestProcessor {
request_id: &ConnectionRequestId,
params: ThreadRollbackParams,
app_server_client_name: Option<&str>,
host_capabilities: HostCapabilities,
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
if app_server_client_name != Some(CODEX_TUI_CLIENT_NAME) {
self.send_thread_rollback_deprecation_notice(request_id.connection_id)
.await;
}
self.thread_rollback_inner(request_id, params)
self.thread_rollback_inner(request_id, params, host_capabilities)
.await
.map(|()| None)
}
@@ -1750,14 +1751,17 @@ impl ThreadRequestProcessor {
&self,
request_id: &ConnectionRequestId,
params: ThreadRollbackParams,
host_capabilities: HostCapabilities,
) -> Result<(), JSONRPCErrorError> {
self.thread_rollback_start(request_id, params).await
self.thread_rollback_start(request_id, params, host_capabilities)
.await
}
async fn thread_rollback_start(
&self,
request_id: &ConnectionRequestId,
params: ThreadRollbackParams,
host_capabilities: HostCapabilities,
) -> Result<(), JSONRPCErrorError> {
let ThreadRollbackParams {
thread_id,
@@ -1769,6 +1773,13 @@ impl ThreadRequestProcessor {
}
let (thread_id, thread) = self.load_thread(&thread_id).await?;
ensure_thread_host_capabilities(
thread_id,
thread.as_ref(),
&host_capabilities,
"roll back",
)
.await?;
let request = request_id.clone();
@@ -208,8 +208,9 @@ impl TurnRequestProcessor {
&self,
request_id: &ConnectionRequestId,
params: TurnInterruptParams,
host_capabilities: HostCapabilities,
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
self.turn_interrupt_inner(request_id, params)
self.turn_interrupt_inner(request_id, params, host_capabilities)
.await
.map(|response| response.map(Into::into))
}
@@ -1389,11 +1390,19 @@ impl TurnRequestProcessor {
&self,
request_id: &ConnectionRequestId,
params: TurnInterruptParams,
host_capabilities: HostCapabilities,
) -> Result<Option<TurnInterruptResponse>, JSONRPCErrorError> {
let TurnInterruptParams { thread_id, turn_id } = params;
let is_startup_interrupt = turn_id.is_empty();
let (thread_uuid, thread) = self.load_thread(&thread_id).await?;
ensure_thread_host_capabilities(
thread_uuid,
thread.as_ref(),
&host_capabilities,
"interrupt a turn",
)
.await?;
// Record turn interrupts so we can reply when TurnAborted arrives. Startup
// interrupts do not have a turn and are acknowledged after submission.
@@ -356,6 +356,68 @@ async fn host_capabilities_are_normalized_and_sticky_for_loaded_threads() -> Res
inject_error.error.message
);
send_request(
&mut mismatched_client,
"app/list",
/*id*/ 11,
Some(json!({
"threadId": thread_id,
})),
)
.await?;
let apps_error = read_error_for_id(&mut mismatched_client, /*id*/ 11)
.await
.context("mismatched-client app/list error")?;
assert!(apps_error.error.message.contains("cannot list apps"));
send_request(
&mut mismatched_client,
"thread/rollback",
/*id*/ 12,
Some(json!({
"threadId": thread_id,
"numTurns": 1,
})),
)
.await?;
let rollback_error = read_error_for_id(&mut mismatched_client, /*id*/ 12)
.await
.context("mismatched-client thread/rollback error")?;
assert!(rollback_error.error.message.contains("cannot roll back"));
send_request(
&mut mismatched_client,
"turn/interrupt",
/*id*/ 13,
Some(json!({
"threadId": thread_id,
"turnId": "turn-under-test",
})),
)
.await?;
let interrupt_error = read_error_for_id(&mut mismatched_client, /*id*/ 13)
.await
.context("mismatched-client turn/interrupt error")?;
assert!(
interrupt_error
.error
.message
.contains("cannot interrupt a turn")
);
send_request(
&mut mismatched_client,
"thread/settings/update",
/*id*/ 14,
Some(json!({
"threadId": thread_id,
})),
)
.await?;
read_response_for_id(&mut mismatched_client, /*id*/ 14)
.await
.context("mismatched-client thread/settings/update response")?;
process
.kill()
.await
@@ -951,7 +1013,13 @@ pub(super) async fn send_initialize_request(
id: i64,
client_name: &str,
) -> Result<()> {
send_initialize_request_with_host_capabilities(stream, id, client_name, None).await
send_initialize_request_with_host_capabilities(
stream,
id,
client_name,
/*host_capabilities*/ None,
)
.await
}
async fn send_initialize_request_with_host_capabilities(
@@ -350,6 +350,101 @@ async fn reprojects_cached_configured_and_fallback_plugins_for_host_capabilities
);
}
#[tokio::test]
async fn filters_unmaterialized_remote_plugins_by_fallback_host_capabilities() {
let codex_home = tempdir().expect("tempdir should succeed");
let marketplace_name = "remote-marketplace";
let plugin_name = "remote-plugin";
let plugin_id = format!("{plugin_name}@{marketplace_name}");
let malformed_plugin_name = "malformed-remote-plugin";
let malformed_plugin_id = format!("{malformed_plugin_name}@{marketplace_name}");
let marketplace_root = codex_home
.path()
.join(format!(".tmp/marketplaces/{marketplace_name}"));
write_file(
&marketplace_root.join(".agents/plugins/marketplace.json"),
&format!(
r#"{{
"name": "{marketplace_name}",
"plugins": [
{{
"name": "{plugin_name}",
"source": {{
"source": "git-subdir",
"url": "openai/remote-plugin",
"path": "plugins/remote-plugin"
}},
"requires": {{
"hostCapabilities": ["{HOST_CAPABILITY_INLINE_VISUALIZATION}"]
}}
}},
{{
"name": "{malformed_plugin_name}",
"source": {{
"source": "git-subdir",
"url": "openai/malformed-remote-plugin",
"path": "plugins/malformed-remote-plugin"
}},
"requires": {{
"hostCapabilities": "{HOST_CAPABILITY_INLINE_VISUALIZATION}"
}}
}}
]
}}
"#
),
);
write_file(
&codex_home.path().join(CONFIG_TOML_FILE),
&format!(
r#"[features]
plugins = true
[marketplaces.{marketplace_name}]
source_type = "git"
source = "/tmp/{marketplace_name}"
"#
),
);
let mut plugins = load_plugins_config(codex_home.path(), codex_home.path()).await;
let plugins_manager = PluginsManager::new(codex_home.path().to_path_buf());
let unsupported = list_discoverable_plugins(
&plugins_manager,
discovery_input(
plugins.clone(),
&[plugin_id.as_str(), malformed_plugin_id.as_str()],
&[],
&[],
),
/*auth*/ None,
)
.await;
assert_eq!(unsupported, Vec::new());
plugins
.host_capabilities
.insert(HOST_CAPABILITY_INLINE_VISUALIZATION.to_string());
let supported = list_discoverable_plugins(
&plugins_manager,
discovery_input(
plugins,
&[plugin_id.as_str(), malformed_plugin_id.as_str()],
&[],
&[],
),
/*auth*/ None,
)
.await;
assert_eq!(
supported
.into_iter()
.map(|plugin| plugin.id)
.collect::<Vec<_>>(),
vec![plugin_id]
);
}
#[tokio::test]
async fn reprojects_cached_skill_availability_for_current_config() {
let codex_home = tempdir().expect("tempdir should succeed");
@@ -206,13 +206,23 @@ async fn load_plugin_metadata(
)?;
let MarketplacePluginSource::Local { path: plugin_root } = &plugin.source else {
let required_host_capabilities = match plugin.manifest_fallback.as_ref() {
Some(fallback) => {
fallback
.parse_for_listing()
.ok_or_else(|| "invalid marketplace plugin manifest fallback".to_string())?
.requires
.host_capabilities
}
None => Vec::new(),
};
return Ok(Arc::new(ToolSuggestMetadataFragment {
config_name: plugin.id.clone(),
display_name: plugin.name.clone(),
description: prompt_safe_plugin_description(Some(
&remote_plugin_install_required_description(&plugin.source),
)),
required_host_capabilities: Vec::new(),
required_host_capabilities,
mcp_server_names: Vec::new(),
app_declarations: Vec::new(),
skill_inventory: None,
+104
View File
@@ -29,6 +29,7 @@ use core_test_support::test_codex::TestCodex;
use core_test_support::test_codex::test_codex;
use core_test_support::wait_for_event;
use core_test_support::wait_for_mcp_server;
use pretty_assertions::assert_eq;
use tempfile::TempDir;
use wiremock::MockServer;
@@ -274,6 +275,109 @@ async fn capability_sections_render_in_developer_message_in_order() -> Result<()
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn host_capabilities_gate_plugin_guidance_and_tools_all_of() -> Result<()> {
skip_if_no_network!(Ok(()));
let rmcp_test_server_bin = match stdio_server_bin() {
Ok(bin) => bin,
Err(err) => {
eprintln!("test_stdio_server binary not available, skipping test: {err}");
return Ok(());
}
};
for (host_capabilities, expected_supported) in [
(Vec::new(), false),
(vec!["capability-a"], false),
(vec!["capability-b"], false),
(vec!["capability-a", "capability-b"], true),
(
vec!["capability-a", "capability-b", "capability-extra"],
true,
),
] {
let server = start_mock_server().await;
let mock = mount_plugin_tool_search_turn(&server).await;
let codex_home = Arc::new(TempDir::new()?);
write_plugin_skill_plugin(codex_home.as_ref());
write_plugin_mcp_plugin(codex_home.as_ref(), &rmcp_test_server_bin);
std::fs::write(
sample_plugin_root(codex_home.as_ref()).join(".codex-plugin/plugin.json"),
format!(
r#"{{
"name": "{SAMPLE_PLUGIN_DISPLAY_NAME}",
"description": "{SAMPLE_PLUGIN_DESCRIPTION}",
"requires": {{
"hostCapabilities": ["capability-a", "capability-b"]
}}
}}"#
),
)?;
let mut builder = test_codex()
.with_home(codex_home)
.with_auth(CodexAuth::from_api_key("Test API Key"))
.with_config(move |config| {
config.host_capabilities = host_capabilities
.iter()
.map(std::string::ToString::to_string)
.collect();
});
let test_codex = builder
.build(&server)
.await
.expect("create new conversation");
let codex = Arc::clone(&test_codex.codex);
let startup = loop {
let event = codex
.next_event()
.await
.expect("stream ended unexpectedly while waiting for MCP startup");
if let EventMsg::McpStartupComplete(startup) = event.msg {
break startup;
}
};
let sample_ready = startup.ready.iter().any(|server| server == "sample");
let sample_reported = sample_ready
|| startup
.failed
.iter()
.any(|failure| failure.server == "sample")
|| startup.cancelled.iter().any(|server| server == "sample");
assert_eq!(sample_reported, expected_supported);
assert_eq!(sample_ready, expected_supported);
codex
.submit(Op::UserInput {
items: vec![codex_protocol::user_input::UserInput::Text {
text: "hello".into(),
text_elements: Vec::new(),
}],
final_output_json_schema: None,
responsesapi_client_metadata: None,
additional_context: Default::default(),
thread_settings: Default::default(),
})
.await?;
wait_for_event(&codex, |ev| matches!(ev, EventMsg::TurnComplete(_))).await;
let requests = mock.requests();
let developer_text = requests[0].message_input_texts("developer").join("\n\n");
assert_eq!(
developer_text.contains("sample:sample-search: inspect sample data"),
expected_supported
);
assert_eq!(
developer_text.contains(SAMPLE_PLUGIN_DESCRIPTION),
expected_supported
);
let (_, echo_tool) = searched_plugin_tools(&requests[1]);
assert_eq!(echo_tool.is_some(), expected_supported);
}
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn explicit_plugin_mentions_use_apps_for_chatgpt_dual_surface_plugins() -> Result<()> {
skip_if_no_network!(Ok(()));