Honor explicit plugin mentions during MCP startup (#42406)

## Why

Selected plugin MCP servers may be skipped after the optional startup grace
period. When a user explicitly mentions a plugin or MCP server, the turn should
continue waiting so the requested tools are available to the model.

## What changed

- Track explicitly mentioned plugin IDs and MCP servers across later samples,
  steered input, and same-turn restarts.
- Require matching selected-plugin MCP servers to finish startup before
  capturing the tool catalog, while leaving unmentioned servers optional.
- Match `plugin://` identities independently of display names and ignore
  targeting query parameters such as `app` and `browserFamily`.

## Testing

Added coverage for linked and structured plugin mentions, direct and batched
capability discovery, delayed environment attachment, steering, and same-turn
restarts.

GitOrigin-RevId: c509ef8df45df1a7edb0da6afdb2682dc53a4de8
This commit is contained in:
Matthew Zeng
2026-09-03 01:33:32 +00:00
committed by copyberry
parent b7f710273e
commit 460b63e5f4
14 changed files with 617 additions and 106 deletions
+14 -11
View File
@@ -68,6 +68,19 @@ pub(crate) fn collect_explicit_plugin_mentions(
return Vec::new();
}
// `config_name` stores the full plugin ID, not its display or mention name.
let mentioned_plugin_ids = collect_explicit_plugin_ids(input);
plugins
.iter()
.filter(|plugin| mentioned_plugin_ids.contains(plugin.config_name.as_str()))
.cloned()
.collect()
}
/// Collect exact IDs from explicit `plugin://` references, independently of display names.
///
/// Host plugins use `<plugin>@<marketplace>` IDs; selected roots may supply opaque IDs.
pub(crate) fn collect_explicit_plugin_ids(input: &[UserInput]) -> HashSet<String> {
let messages = input
.iter()
.filter_map(|item| match item {
@@ -76,7 +89,7 @@ pub(crate) fn collect_explicit_plugin_mentions(
})
.collect::<Vec<String>>();
let mentioned_config_names: HashSet<String> = input
input
.iter()
.filter_map(|item| match item {
UserInput::Mention { path, .. } => Some(path.clone()),
@@ -89,16 +102,6 @@ pub(crate) fn collect_explicit_plugin_mentions(
)
.filter(|path| tool_kind_for_path(path.as_str()) == ToolMentionKind::Plugin)
.filter_map(|path| plugin_config_name_from_path(path.as_str()).map(str::to_string))
.collect();
if mentioned_config_names.is_empty() {
return Vec::new();
}
plugins
.iter()
.filter(|plugin| mentioned_config_names.contains(plugin.config_name.as_str()))
.cloned()
.collect()
}
+29 -8
View File
@@ -4,6 +4,7 @@ use codex_protocol::user_input::UserInput;
use pretty_assertions::assert_eq;
use super::collect_explicit_app_ids;
use super::collect_explicit_plugin_ids;
use super::collect_explicit_plugin_mentions;
use crate::plugins::PluginCapabilitySummary;
@@ -77,35 +78,39 @@ fn collect_explicit_app_ids_ignores_non_app_paths() {
#[test]
fn collect_explicit_plugin_mentions_from_structured_paths() {
let expected = plugin("sample@test", "Sample");
let plugins = vec![
plugin("sample@test", "sample"),
plugin("other@test", "other"),
expected.clone(),
plugin("sample@other-marketplace", "Sample"),
plugin("other@test", "alias"),
];
let mentioned = collect_explicit_plugin_mentions(
&[UserInput::Mention {
name: "sample".to_string(),
name: "alias".to_string(),
path: "plugin://sample@test".to_string(),
}],
&plugins,
);
assert_eq!(mentioned, vec![plugin("sample@test", "sample")]);
assert_eq!(mentioned, vec![expected]);
}
#[test]
fn collect_explicit_plugin_mentions_from_linked_text_mentions() {
let expected = plugin("sample@test", "Sample");
let plugins = vec![
plugin("sample@test", "sample"),
plugin("other@test", "other"),
expected.clone(),
plugin("sample@other-marketplace", "Sample"),
plugin("other@test", "alias"),
];
let mentioned = collect_explicit_plugin_mentions(
&[text_input("use [@sample](plugin://sample@test)")],
&[text_input("use [@alias](plugin://sample@test)")],
&plugins,
);
assert_eq!(mentioned, vec![plugin("sample@test", "sample")]);
assert_eq!(mentioned, vec![expected]);
}
#[test]
@@ -154,3 +159,19 @@ fn collect_explicit_plugin_mentions_ignores_dollar_linked_plugin_mentions() {
assert_eq!(mentioned, Vec::<PluginCapabilitySummary>::new());
}
#[test]
fn collect_explicit_plugin_ids_preserves_opaque_ids() {
let input = [
text_input("use [@same](plugin://selected-one)"),
UserInput::Mention {
name: "same".to_string(),
path: "plugin://selected-two".to_string(),
},
];
assert_eq!(
collect_explicit_plugin_ids(&input),
HashSet::from(["selected-one".to_string(), "selected-two".to_string()]),
);
}
+1
View File
@@ -23,6 +23,7 @@ pub(crate) use render::render_explicit_plugin_instructions;
pub(crate) use mentions::build_connector_slug_counts;
pub(crate) use mentions::collect_explicit_app_ids;
pub(crate) use mentions::collect_explicit_plugin_ids;
pub(crate) use mentions::collect_explicit_plugin_mentions;
pub(crate) use mentions::collect_tool_mentions_from_messages;