mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Simplify tool executor lifetimes (#64159)
## Why Extension tools borrow host capabilities for each call. Expressing that borrow in the executor's type argument requires higher-ranked lifetime bounds wherever extension executors are stored or returned. ## What changed Define the per-call input as `ToolInput::Call<'a>` so `ToolExecutor` can use the same lifetime for the input, the executor borrow, and the returned future while remaining usable as a trait object. Default to borrowed `ToolCall<'a>` inputs so extension contributors can return `Arc<dyn ToolExecutor>`. Core handlers continue to take owned `ToolInvocation` inputs. GitOrigin-RevId: efbf56c1e758c59a18b192d210c2ab1b368793e2
This commit is contained in:
@@ -8,7 +8,6 @@ use codex_protocol::dynamic_tools::DynamicToolFunctionSpec;
|
||||
use codex_protocol::dynamic_tools::DynamicToolSpec;
|
||||
use codex_protocol::request_user_input::RequestUserInputAnswer;
|
||||
use codex_protocol::request_user_input::RequestUserInputResponse;
|
||||
use codex_tools::ToolCall;
|
||||
use codex_tools::ToolExecutor;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::HashMap;
|
||||
@@ -42,7 +41,7 @@ impl ToolContributor for StepPreparationObserver {
|
||||
&self,
|
||||
_session_store: &ExtensionData,
|
||||
_thread_store: &ExtensionData,
|
||||
) -> Vec<Arc<dyn for<'call> ToolExecutor<ToolCall<'call>>>> {
|
||||
) -> Vec<Arc<dyn ToolExecutor>> {
|
||||
if let Some(ready) = self.tools_ready.lock().expect("tool gate").take() {
|
||||
ready
|
||||
.send(())
|
||||
|
||||
@@ -8185,7 +8185,7 @@ impl ToolContributor for NamespacedCustomTool {
|
||||
&self,
|
||||
_session_store: &ExtensionData,
|
||||
_thread_store: &ExtensionData,
|
||||
) -> Vec<Arc<dyn for<'call> ToolExecutor<ToolCall<'call>>>> {
|
||||
) -> Vec<Arc<dyn ToolExecutor>> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
@@ -8194,7 +8194,7 @@ impl ToolContributor for NamespacedCustomTool {
|
||||
_session_store: &ExtensionData,
|
||||
_thread_store: &ExtensionData,
|
||||
_step_store: &ExtensionData,
|
||||
) -> Vec<Arc<dyn for<'call> ToolExecutor<ToolCall<'call>>>> {
|
||||
) -> Vec<Arc<dyn ToolExecutor>> {
|
||||
vec![Arc::new(Self {
|
||||
generation: self.generations.fetch_add(1, Ordering::Relaxed) + 1,
|
||||
generations: Arc::clone(&self.generations),
|
||||
@@ -8202,7 +8202,7 @@ impl ToolContributor for NamespacedCustomTool {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'call> ToolExecutor<ToolCall<'call>> for NamespacedCustomTool {
|
||||
impl ToolExecutor for NamespacedCustomTool {
|
||||
fn tool_name(&self) -> ToolName {
|
||||
ToolName::namespaced("editor", "apply_patch")
|
||||
}
|
||||
@@ -8224,10 +8224,7 @@ impl<'call> ToolExecutor<ToolCall<'call>> for NamespacedCustomTool {
|
||||
})
|
||||
}
|
||||
|
||||
fn handle<'a>(&'a self, call: ToolCall<'call>) -> ToolExecutorFuture<'a>
|
||||
where
|
||||
'call: 'a,
|
||||
{
|
||||
fn handle<'a>(&'a self, call: ToolCall<'a>) -> ToolExecutorFuture<'a> {
|
||||
Box::pin(async move {
|
||||
let ToolPayload::Custom { input } = call.payload else {
|
||||
return Err(FunctionCallError::Fatal(
|
||||
|
||||
@@ -63,12 +63,12 @@ impl ToolContributor for GatedTool {
|
||||
&self,
|
||||
_session_store: &ExtensionData,
|
||||
_thread_store: &ExtensionData,
|
||||
) -> Vec<Arc<dyn for<'call> ToolExecutor<ToolCall<'call>>>> {
|
||||
) -> Vec<Arc<dyn ToolExecutor>> {
|
||||
vec![Arc::new(self.clone())]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'call> ToolExecutor<ToolCall<'call>> for GatedTool {
|
||||
impl ToolExecutor for GatedTool {
|
||||
fn tool_name(&self) -> ToolName {
|
||||
ToolName::plain(if matches!(self.admission, Admission::Unsupported) {
|
||||
"followup_task"
|
||||
@@ -92,10 +92,7 @@ impl<'call> ToolExecutor<ToolCall<'call>> for GatedTool {
|
||||
matches!(self.admission, Admission::Parallel)
|
||||
}
|
||||
|
||||
fn handle<'a>(&'a self, call: ToolCall<'call>) -> ToolExecutorFuture<'a>
|
||||
where
|
||||
'call: 'a,
|
||||
{
|
||||
fn handle<'a>(&'a self, call: ToolCall<'a>) -> ToolExecutorFuture<'a> {
|
||||
Box::pin(async move {
|
||||
self.entered
|
||||
.send((call.call_id.to_string(), Instant::now()))
|
||||
|
||||
@@ -953,12 +953,12 @@ impl ToolContributor for DeferredCustomTool {
|
||||
&self,
|
||||
_session_store: &ExtensionData,
|
||||
_thread_store: &ExtensionData,
|
||||
) -> Vec<Arc<dyn for<'call> ToolExecutor<ToolCall<'call>>>> {
|
||||
) -> Vec<Arc<dyn ToolExecutor>> {
|
||||
vec![Arc::new(Self)]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'call> ToolExecutor<ToolCall<'call>> for DeferredCustomTool {
|
||||
impl ToolExecutor for DeferredCustomTool {
|
||||
fn tool_name(&self) -> ToolName {
|
||||
ToolName::plain("custom_echo")
|
||||
}
|
||||
@@ -980,10 +980,7 @@ impl<'call> ToolExecutor<ToolCall<'call>> for DeferredCustomTool {
|
||||
ToolExposure::Deferred
|
||||
}
|
||||
|
||||
fn handle<'a>(&'a self, call: ToolCall<'call>) -> ToolExecutorFuture<'a>
|
||||
where
|
||||
'call: 'a,
|
||||
{
|
||||
fn handle<'a>(&'a self, call: ToolCall<'a>) -> ToolExecutorFuture<'a> {
|
||||
Box::pin(async move {
|
||||
let ToolPayload::Custom { input } = call.payload else {
|
||||
return Err(FunctionCallError::Fatal(
|
||||
|
||||
@@ -187,7 +187,6 @@ async fn step_preparation_finishes_before_tools_and_world_state() -> Result<()>
|
||||
use codex_extension_api::ExtensionFuture;
|
||||
use codex_extension_api::SelectedPluginSnapshot;
|
||||
use codex_extension_api::StepPreparationInput;
|
||||
use codex_extension_api::ToolCall;
|
||||
use codex_extension_api::ToolContributor;
|
||||
use codex_extension_api::ToolExecutor;
|
||||
use codex_extension_api::WorldStateContributionInput;
|
||||
@@ -221,7 +220,7 @@ async fn step_preparation_finishes_before_tools_and_world_state() -> Result<()>
|
||||
_session_store: &ExtensionData,
|
||||
_thread_store: &ExtensionData,
|
||||
step_store: &ExtensionData,
|
||||
) -> Vec<Arc<dyn for<'call> ToolExecutor<ToolCall<'call>>>> {
|
||||
) -> Vec<Arc<dyn ToolExecutor>> {
|
||||
assert!(step_store.get::<SelectedPluginSnapshot>().is_some());
|
||||
assert_eq!(
|
||||
*step_store
|
||||
|
||||
@@ -2998,12 +2998,12 @@ impl ToolContributor for SettingsEcho {
|
||||
&self,
|
||||
_session_store: &ExtensionData,
|
||||
_thread_store: &ExtensionData,
|
||||
) -> Vec<Arc<dyn for<'call> ToolExecutor<ToolCall<'call>>>> {
|
||||
) -> Vec<Arc<dyn ToolExecutor>> {
|
||||
vec![Arc::new(self.clone())]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'call> ToolExecutor<ToolCall<'call>> for SettingsEcho {
|
||||
impl ToolExecutor for SettingsEcho {
|
||||
fn tool_name(&self) -> ToolName {
|
||||
ToolName::plain("extension_settings")
|
||||
}
|
||||
@@ -3019,10 +3019,7 @@ impl<'call> ToolExecutor<ToolCall<'call>> for SettingsEcho {
|
||||
})
|
||||
}
|
||||
|
||||
fn handle<'a>(&'a self, call: ToolCall<'call>) -> ToolExecutorFuture<'a>
|
||||
where
|
||||
'call: 'a,
|
||||
{
|
||||
fn handle<'a>(&'a self, call: ToolCall<'a>) -> ToolExecutorFuture<'a> {
|
||||
Box::pin(async move {
|
||||
*self.history.lock().expect("history lock") = Some(call.conversation_history);
|
||||
let metadata: Value = serde_json::from_str(
|
||||
|
||||
Reference in New Issue
Block a user