Borrow user input in extension turn contexts (#62540)

Pass the host's existing `&[UserInput]` into `TurnInputContext` to avoid
cloning the input when building extension turn items. Use the borrowed
slice directly for skill mention detection and shadow selection.

GitOrigin-RevId: f4983b584830e481d914f0c9aa1e39e78b965a19
This commit is contained in:
jif
2026-11-19 15:46:27 +00:00
committed by copyberry
parent 0b248182be
commit f6a1b61912
8 changed files with 19 additions and 19 deletions
+1 -1
View File
@@ -1566,7 +1566,7 @@ async fn build_extension_turn_input_items(
let input = TurnInputContext {
step_store: &step_context.extension_data,
turn_id: turn_context.sub_id.to_string(),
user_input: user_input.to_vec(),
user_input,
environments,
};
let extension_metrics =
@@ -23,8 +23,8 @@ pub struct TurnInputContext<'a> {
pub step_store: &'a crate::ExtensionData,
/// Stable host-owned turn identifier.
pub turn_id: String,
/// User input submitted for this turn.
pub user_input: Vec<UserInput>,
/// User input submitted for this turn, borrowed from the host for the contribution.
pub user_input: &'a [UserInput],
/// Resolved turn environments, in host priority order.
pub environments: Vec<TurnInputEnvironment<'a>>,
}
+2 -2
View File
@@ -375,14 +375,14 @@ where
self.emit_warning(thread_store.level_id(), Some(&input.turn_id), warning);
}
let selected_entries = collect_explicit_skill_mentions(&input.user_input, &catalog);
let selected_entries = collect_explicit_skill_mentions(input.user_input, &catalog);
let shadow_selection_turn = if config.shadow_selection_enabled {
let mut shadow_catalog = catalog.clone();
if let Some(host_skills) = host_skills {
shadow_catalog.extend(host_skills.clone());
}
let shadow_selected_entries =
collect_explicit_skill_mentions(&input.user_input, &shadow_catalog);
collect_explicit_skill_mentions(input.user_input, &shadow_catalog);
Some(self.shadow_selection.start(
&input,
shadow_catalog,
@@ -141,7 +141,7 @@ async fn turn_input_and_history_advance_while_ranking_is_blocked()
TurnInputContext {
step_store: &turn_store,
turn_id: turn_id.to_string(),
user_input: vec![UserInput::Skill {
user_input: &[UserInput::Skill {
name: "selected".to_string(),
path: "selected/SKILL.md".into(),
}],
@@ -85,8 +85,8 @@ impl ShadowSelectionExperiment {
recent_skill_invocations: Arc<RecentSkillInvocations>,
task_context: Arc<ShadowTaskContext>,
) -> ShadowSelectionTurnState {
let query = build_shadow_query(&input.user_input);
let task_snapshot = task_context.begin_turn(&input.turn_id, &query, &input.user_input);
let query = build_shadow_query(input.user_input);
let task_snapshot = task_context.begin_turn(&input.turn_id, &query, input.user_input);
let recent_skill_resources = recent_skill_invocations.snapshot();
let explicitly_selected_skill_resources = explicitly_selected
.iter()
@@ -387,7 +387,7 @@ async fn installed_extension_uses_host_service_snapshot() -> TestResult {
TurnInputContext {
step_store: &ExtensionData::new("step"),
turn_id: "turn-1".to_string(),
user_input: vec![UserInput::Text {
user_input: &[UserInput::Text {
text: "$demo".to_string(),
text_elements: Vec::new(),
}],
@@ -1064,7 +1064,7 @@ async fn shadow_selection_uses_host_catalog_when_instructions_are_disabled() ->
TurnInputContext {
step_store: &step_store,
turn_id: "turn-1".to_string(),
user_input: vec![UserInput::Text {
user_input: &[UserInput::Text {
text: "Fix lint errors.".to_string(),
text_elements: Vec::new(),
}],
@@ -1170,7 +1170,7 @@ async fn shadow_lru_selector_recovers_a_skill_invoked_on_an_earlier_turn() -> Te
TurnInputContext {
step_store: &ExtensionData::new("step"),
turn_id: turn_id.to_string(),
user_input: vec![UserInput::Text {
user_input: &[UserInput::Text {
text: text.to_string(),
text_elements: Vec::new(),
}],
@@ -1372,7 +1372,7 @@ async fn selected_executor_catalog_caches_root_selections_per_turn_and_reuses_di
TurnInputContext {
step_store: &step_store,
turn_id: "turn-1".to_string(),
user_input: vec![UserInput::Text {
user_input: &[UserInput::Text {
text: "$lint-fix please".to_string(),
text_elements: Vec::new(),
}],
@@ -3009,7 +3009,7 @@ async fn root_qualified_locator_selects_only_the_matching_executor_skill() -> Te
TurnInputContext {
step_store: &step_store,
turn_id: "turn-1".to_string(),
user_input: vec![UserInput::Mention {
user_input: &[UserInput::Mention {
name: "lint-fix".to_string(),
path: root_b_locator.to_string(),
}],
@@ -3277,7 +3277,7 @@ async fn executor_catalog_emits_at_most_four_warnings() -> TestResult {
TurnInputContext {
step_store: &step_store,
turn_id: "turn-1".to_string(),
user_input: Vec::new(),
user_input: &[],
environments: Vec::new(),
},
/*extension_metrics*/ None,
@@ -3384,7 +3384,7 @@ async fn host_catalog_compacts_shared_paths_under_budget_pressure() -> TestResul
TurnInputContext {
step_store: &ExtensionData::new("step"),
turn_id: "turn-1".to_string(),
user_input: vec![UserInput::Text {
user_input: &[UserInput::Text {
text: "hello".to_string(),
text_elements: Vec::new(),
}],
@@ -3470,7 +3470,7 @@ async fn prompt_hidden_skill_can_still_be_invoked() -> TestResult {
TurnInputContext {
step_store: &ExtensionData::new("step"),
turn_id: "turn-1".to_string(),
user_input: vec![UserInput::Text {
user_input: &[UserInput::Text {
text: "$hidden-skill".to_string(),
text_elements: Vec::new(),
}],
@@ -1252,7 +1252,7 @@ async fn v2_implicit_and_explicit_invocations_retain_their_step_catalog() -> Tes
TurnInputContext {
step_store,
turn_id: "turn-1".to_string(),
user_input: vec![UserInput::Mention {
user_input: &[UserInput::Mention {
name: installed.name.clone(),
path: installed.main_prompt.as_str().to_string(),
}],
@@ -1398,7 +1398,7 @@ async fn v2_shadow_observation_tracks_merged_skills_independently_of_read_route(
TurnInputContext {
step_store: &harness.step_store,
turn_id: turn_id.to_string(),
user_input: vec![UserInput::Text {
user_input: &[UserInput::Text {
text: "continue".to_string(),
text_elements: Vec::new(),
}],
@@ -170,7 +170,7 @@ async fn task_context_recovers_prior_requests_and_explicit_intent_without_changi
TurnInputContext {
step_store: &ExtensionData::new("step"),
turn_id: turn_id.to_string(),
user_input,
user_input: &user_input,
environments: vec![codex_extension_api::TurnInputEnvironment {
environment_id: "test".to_string(),
cwd: PathUri::from_host_native_path(