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:
jif
2026-11-26 14:27:37 +00:00
committed by copyberry
parent ad7176f787
commit 7ca4eada90
88 changed files with 173 additions and 401 deletions
@@ -106,10 +106,7 @@ impl ToolExecutor<ToolInvocation> for TestHandler {
})
}
fn handle<'a>(&'a self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async {
Ok(Box::new(FunctionToolOutput::from_text(
"audit-probe-ok".to_string(),
@@ -179,10 +179,7 @@ impl ToolExecutor<ToolInvocation> for CodeModeExecuteHandler {
self.spec.clone()
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -59,10 +59,7 @@ impl ToolExecutor<ToolInvocation> for CodeModeWaitHandler {
self.spec.clone()
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
+4
View File
@@ -130,6 +130,10 @@ pub struct ToolInvocation {
pub(crate) environments: ToolEnvironments,
}
impl codex_tools::ToolInput for ToolInvocation {
type Call<'a> = Self;
}
/// Identity of the model call that started a tool invocation, retained across code-mode waits.
#[derive(Clone)]
pub(crate) struct ToolCallOrigin {
@@ -293,10 +293,7 @@ impl ToolExecutor<ToolInvocation> for ApplyPatchHandler {
create_apply_patch_freeform_tool(self.multi_environment)
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -87,10 +87,7 @@ impl ToolExecutor<ToolInvocation> for CurrentTimeHandler {
})
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
if !matches!(invocation.payload, ToolPayload::Function { .. }) {
return Err(FunctionCallError::RespondToModel(format!(
+1 -4
View File
@@ -120,10 +120,7 @@ impl ToolExecutor<ToolInvocation> for DynamicToolHandler {
)
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -27,14 +27,10 @@ use crate::tools::registry::CoreToolRuntime;
use crate::tools::registry::ToolExecutor;
use crate::turn_metadata::ExecutionMetadata;
pub(crate) struct ExtensionToolAdapter(
Arc<dyn for<'call> codex_tools::ToolExecutor<ExtensionToolCall<'call>>>,
);
pub(crate) struct ExtensionToolAdapter(Arc<dyn ToolExecutor>);
impl ExtensionToolAdapter {
pub(crate) fn new(
executor: Arc<dyn for<'call> codex_tools::ToolExecutor<ExtensionToolCall<'call>>>,
) -> Self {
pub(crate) fn new(executor: Arc<dyn ToolExecutor>) -> Self {
Self(executor)
}
}
@@ -60,10 +56,7 @@ impl ToolExecutor<ToolInvocation> for ExtensionToolAdapter {
self.0.search_info()
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
let step = &invocation.step_context;
let selected: Vec<_> = match &invocation.environments {
@@ -296,9 +289,7 @@ mod tests {
struct StubExtensionExecutor;
impl<'call> codex_extension_api::ToolExecutor<codex_tools::ToolCall<'call>>
for StubExtensionExecutor
{
impl codex_extension_api::ToolExecutor for StubExtensionExecutor {
fn tool_name(&self) -> codex_tools::ToolName {
codex_tools::ToolName::plain("extension_echo")
}
@@ -324,11 +315,8 @@ mod tests {
fn handle<'a>(
&'a self,
_call: codex_tools::ToolCall<'call>,
) -> codex_tools::ToolExecutorFuture<'a>
where
'call: 'a,
{
_call: codex_tools::ToolCall<'a>,
) -> codex_tools::ToolExecutorFuture<'a> {
Box::pin(async {
Ok(
Box::new(codex_tools::JsonToolOutput::new(json!({ "ok": true })))
@@ -343,9 +331,7 @@ mod tests {
captured_sandbox_cwds: Arc<Mutex<Vec<PathUri>>>,
}
impl<'call> codex_extension_api::ToolExecutor<codex_tools::ToolCall<'call>>
for CapturingExtensionExecutor
{
impl codex_extension_api::ToolExecutor for CapturingExtensionExecutor {
fn tool_name(&self) -> codex_tools::ToolName {
codex_tools::ToolName::plain("extension_echo")
}
@@ -363,11 +349,8 @@ mod tests {
fn handle<'a>(
&'a self,
call: codex_tools::ToolCall<'call>,
) -> codex_tools::ToolExecutorFuture<'a>
where
'call: 'a,
{
call: codex_tools::ToolCall<'a>,
) -> codex_tools::ToolExecutorFuture<'a> {
Box::pin(self.handle_call(call))
}
}
@@ -82,10 +82,7 @@ impl ToolExecutor<ToolInvocation> for GetContextRemainingHandler {
self.spec.clone()
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
if !matches!(invocation.payload, ToolPayload::Function { .. }) {
return Err(FunctionCallError::RespondToModel(
@@ -67,10 +67,7 @@ impl ToolExecutor<ToolInvocation> for ListAvailablePluginsToInstallHandler {
true
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
+1 -4
View File
@@ -235,10 +235,7 @@ impl ToolExecutor<ToolInvocation> for McpHandler {
)
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -34,10 +34,7 @@ impl ToolExecutor<ToolInvocation> for ListMcpResourceTemplatesHandler {
true
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -34,10 +34,7 @@ impl ToolExecutor<ToolInvocation> for ListMcpResourcesHandler {
true
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -36,10 +36,7 @@ impl ToolExecutor<ToolInvocation> for ReadMcpResourceHandler {
true
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -21,10 +21,7 @@ impl ToolExecutor<ToolInvocation> for Handler {
)
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move { handle_close_agent(invocation).await.map(boxed_tool_output) })
}
}
@@ -22,10 +22,7 @@ impl ToolExecutor<ToolInvocation> for Handler {
)
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move { handle_resume_agent(invocation).await.map(boxed_tool_output) })
}
}
@@ -25,10 +25,7 @@ impl ToolExecutor<ToolInvocation> for Handler {
)
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -45,10 +45,7 @@ impl ToolExecutor<ToolInvocation> for Handler {
)
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move { handle_spawn_agent(invocation).await.map(boxed_tool_output) })
}
}
@@ -44,10 +44,7 @@ impl ToolExecutor<ToolInvocation> for Handler {
)
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -17,10 +17,7 @@ impl ToolExecutor<ToolInvocation> for Handler {
create_followup_task_tool()
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
let mut analytics = ToolCallAnalytics::new(&invocation, CollabAgentTool::FollowupTask);
let result = self.handle_call(invocation, &mut analytics).await;
@@ -17,10 +17,7 @@ impl ToolExecutor<ToolInvocation> for Handler {
create_interrupt_agent_tool_v2()
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
let mut analytics =
ToolCallAnalytics::new(&invocation, CollabAgentTool::InterruptAgent);
@@ -18,10 +18,7 @@ impl ToolExecutor<ToolInvocation> for Handler {
create_list_agents_tool()
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
let analytics = ToolCallAnalytics::new(&invocation, CollabAgentTool::ListAgents);
let result = self.handle_call(invocation).await;
@@ -17,10 +17,7 @@ impl ToolExecutor<ToolInvocation> for Handler {
create_send_message_tool()
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
let mut analytics = ToolCallAnalytics::new(&invocation, CollabAgentTool::SendMessage);
let result = self.handle_call(invocation, &mut analytics).await;
@@ -41,10 +41,7 @@ impl ToolExecutor<ToolInvocation> for Handler {
create_spawn_agent_tool_v2(self.options.clone(), self.description_override.as_deref())
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
let analytics = invocation.session.services.analytics_events_client.clone();
let sender_thread_id = invocation.session.thread_id;
@@ -29,10 +29,7 @@ impl ToolExecutor<ToolInvocation> for Handler {
create_wait_agent_tool_v2(self.options)
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -35,10 +35,7 @@ impl ToolExecutor<ToolInvocation> for NewContextWindowHandler {
self.spec.clone()
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
if !matches!(invocation.payload, ToolPayload::Function { .. }) {
return Err(FunctionCallError::RespondToModel(
+1 -4
View File
@@ -55,10 +55,7 @@ impl ToolExecutor<ToolInvocation> for PlanHandler {
create_update_plan_tool()
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -94,10 +94,7 @@ impl ToolExecutor<ToolInvocation> for RequestPermissionsHandler {
create_request_permissions_tool(request_permissions_tool_description())
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -81,10 +81,7 @@ impl ToolExecutor<ToolInvocation> for RequestPluginInstallHandler {
false
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -31,10 +31,7 @@ impl ToolExecutor<ToolInvocation> for RequestUserInputHandler {
create_request_user_input_tool(request_user_input_tool_description(&self.available_modes))
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -86,10 +86,7 @@ impl ToolExecutor<ToolInvocation> for RequestUserInputAsyncHandler {
})
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
let ToolInvocation {
session,
@@ -56,10 +56,7 @@ impl ToolExecutor<ToolInvocation> for SendMessageToUserAsyncHandler {
})
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
let ToolInvocation {
session,
+1 -4
View File
@@ -75,10 +75,7 @@ impl ToolExecutor<ToolInvocation> for SleepHandler {
ToolExposure::DirectModelOnly
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
let ToolInvocation {
session,
@@ -73,10 +73,7 @@ impl ToolExecutor<ToolInvocation> for TestSyncHandler {
true
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -212,10 +212,7 @@ impl ToolExecutor<ToolInvocation> for ToolSearchHandler {
true
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -120,10 +120,7 @@ impl ToolExecutor<ToolInvocation> for ExecCommandHandler {
true
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -57,10 +57,7 @@ impl ToolExecutor<ToolInvocation> for WriteStdinHandler {
true
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -88,10 +88,7 @@ impl ToolExecutor<ToolInvocation> for ViewImageHandler {
true
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call(invocation))
}
}
@@ -105,10 +105,7 @@ impl ToolExecutor<ToolInvocation> for WaitForEnvironmentHandler {
})
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async move {
let ToolInvocation {
payload,
+1 -4
View File
@@ -125,10 +125,7 @@ impl ToolExecutor<ToolInvocation> for MultiAgentV2ToolOverrides {
self.handler.search_info()
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
self.handler.handle(invocation)
}
}
+1 -4
View File
@@ -1010,10 +1010,7 @@ mod tests {
})
}
fn handle<'a>(&'a self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
self.calls.fetch_add(1, Ordering::Relaxed);
Box::pin(async {
Ok(
+3 -12
View File
@@ -22,10 +22,7 @@ impl ToolExecutor<ToolInvocation> for TestHandler {
test_spec(&self.tool_name)
}
fn handle<'a>(&'a self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async {
Ok(
Box::new(crate::tools::context::FunctionToolOutput::from_text(
@@ -53,10 +50,7 @@ impl ToolExecutor<ToolInvocation> for ReadinessTestHandler {
self.handler.spec()
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
self.handler.handle(invocation)
}
}
@@ -89,10 +83,7 @@ impl ToolExecutor<ToolInvocation> for LifecycleTestHandler {
test_spec(&self.tool_name)
}
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
assert_eq!(
invocation.tool_name,
self.tool_name.clone().with_default_namespace()
+4 -9
View File
@@ -116,14 +116,14 @@ impl codex_extension_api::ToolContributor for ExtensionEchoContributor {
&self,
_session_store: &ExtensionData,
_thread_store: &ExtensionData,
) -> Vec<Arc<dyn for<'call> ToolExecutor<ExtensionToolCall<'call>>>> {
) -> Vec<Arc<dyn ToolExecutor>> {
vec![Arc::new(ExtensionEchoExecutor)]
}
}
struct ExtensionEchoExecutor;
impl<'call> ToolExecutor<ExtensionToolCall<'call>> for ExtensionEchoExecutor {
impl ToolExecutor for ExtensionEchoExecutor {
fn tool_name(&self) -> ToolName {
ToolName::namespaced("extension/", "echo")
}
@@ -151,10 +151,7 @@ impl<'call> ToolExecutor<ExtensionToolCall<'call>> for ExtensionEchoExecutor {
})
}
fn handle<'a>(&'a self, call: ExtensionToolCall<'call>) -> codex_tools::ToolExecutorFuture<'a>
where
'call: 'a,
{
fn handle<'a>(&'a self, call: ExtensionToolCall<'a>) -> codex_tools::ToolExecutorFuture<'a> {
Box::pin(self.handle_call(call))
}
}
@@ -184,9 +181,7 @@ fn extension_tool_test_registry() -> Arc<ExtensionRegistry<Config>> {
fn test_tool_router(
step_context: &StepContext,
mcp_tools: Vec<RegisteredTool>,
extension_tool_executors: impl IntoIterator<
Item = Arc<dyn for<'call> ToolExecutor<ExtensionToolCall<'call>>>,
>,
extension_tool_executors: impl IntoIterator<Item = Arc<dyn ToolExecutor>>,
dynamic_tools: &[DynamicToolSpec],
) -> ToolRouter {
let mut registry = build_core_tool_registry(
+3 -6
View File
@@ -84,7 +84,6 @@ use codex_protocol::protocol::MultiAgentVersion;
use codex_tools::IndirectNamespacePrefixes;
use codex_tools::ResponsesApiNamespaceTool;
use codex_tools::TOOL_SEARCH_TOOL_NAME;
use codex_tools::ToolCall as ExtensionToolCall;
use codex_tools::ToolEnvironmentMode;
use codex_tools::ToolExecutor;
use codex_tools::ToolExposures;
@@ -326,9 +325,7 @@ pub(crate) fn append_source_tools(
model_info: &ModelInfo,
registry: &mut ToolRegistry,
mcp_tools: Vec<RegisteredTool>,
extension_tool_executors: impl IntoIterator<
Item = Arc<dyn for<'call> ToolExecutor<ExtensionToolCall<'call>>>,
>,
extension_tool_executors: impl IntoIterator<Item = Arc<dyn ToolExecutor>>,
dynamic_tools: &[DynamicToolSpec],
) -> Vec<ToolSpec> {
for tool in mcp_tools {
@@ -352,7 +349,7 @@ pub(crate) fn append_source_tools(
pub(crate) fn extension_tool_executors<'a>(
session: &'a Session,
step_store: &'a ExtensionData,
) -> impl Iterator<Item = Arc<dyn for<'call> ToolExecutor<ExtensionToolCall<'call>>>> + 'a {
) -> impl Iterator<Item = Arc<dyn ToolExecutor>> + 'a {
session
.services
.extensions
@@ -1629,7 +1626,7 @@ fn append_tool_search_executor(
fn append_extension_tool_executors(
turn_context: &TurnContext,
model_info: &ModelInfo,
executors: impl IntoIterator<Item = Arc<dyn for<'call> ToolExecutor<ExtensionToolCall<'call>>>>,
executors: impl IntoIterator<Item = Arc<dyn ToolExecutor>>,
registry: &mut ToolRegistry,
) -> Option<ToolName> {
let standalone_web_search_enabled = standalone_web_search_enabled(turn_context, model_info);
@@ -205,7 +205,7 @@ async fn strict_finalization_cannot_resurrect_hidden_or_policy_denied_tools() {
),
mcp_runtime("denied", "mcp__denied", "lookup", ToolExposure::Direct),
],
std::iter::empty::<Arc<dyn for<'call> ToolExecutor<ExtensionToolCall<'call>>>>(),
std::iter::empty::<Arc<dyn ToolExecutor>>(),
&[
dynamic_tool(
/*namespace*/ None,
+6 -15
View File
@@ -69,7 +69,7 @@ const MULTI_AGENT_V2_NAMESPACE: &str = "collaboration";
struct ToolPlanInputs {
tool_runtimes: Vec<RegisteredTool>,
tool_suggest_candidates: Option<ToolSuggestCandidates>,
extension_tool_executors: Vec<Arc<dyn for<'call> ToolExecutor<ExtensionToolCall<'call>>>>,
extension_tool_executors: Vec<Arc<dyn ToolExecutor>>,
wait_for_environment_tool_config: Option<Arc<WaitForEnvironmentToolConfig>>,
dynamic_tools: Vec<DynamicToolSpec>,
}
@@ -317,7 +317,7 @@ struct TestNamespaceExtensionTool {
tool_name: &'static str,
}
impl<'call> ToolExecutor<ExtensionToolCall<'call>> for TestNamespaceExtensionTool {
impl ToolExecutor for TestNamespaceExtensionTool {
fn tool_name(&self) -> ToolName {
ToolName::namespaced(self.namespace, self.tool_name)
}
@@ -337,10 +337,7 @@ impl<'call> ToolExecutor<ExtensionToolCall<'call>> for TestNamespaceExtensionToo
})
}
fn handle<'a>(&'a self, _call: ExtensionToolCall<'call>) -> codex_tools::ToolExecutorFuture<'a>
where
'call: 'a,
{
fn handle<'a>(&'a self, _call: ExtensionToolCall<'a>) -> codex_tools::ToolExecutorFuture<'a> {
Box::pin(async {
Ok(Box::new(codex_tools::JsonToolOutput::new(json!({}))) as Box<dyn ToolOutput>)
})
@@ -349,7 +346,7 @@ impl<'call> ToolExecutor<ExtensionToolCall<'call>> for TestNamespaceExtensionToo
struct DeferredExtensionTool;
impl<'call> ToolExecutor<ExtensionToolCall<'call>> for DeferredExtensionTool {
impl ToolExecutor for DeferredExtensionTool {
fn tool_name(&self) -> ToolName {
ToolName::plain("extension_echo")
}
@@ -376,10 +373,7 @@ impl<'call> ToolExecutor<ExtensionToolCall<'call>> for DeferredExtensionTool {
ToolExposure::Deferred
}
fn handle<'a>(&'a self, _call: ExtensionToolCall<'call>) -> codex_tools::ToolExecutorFuture<'a>
where
'call: 'a,
{
fn handle<'a>(&'a self, _call: ExtensionToolCall<'a>) -> codex_tools::ToolExecutorFuture<'a> {
Box::pin(async { panic!("spec planning should not execute extension tools") })
}
}
@@ -536,10 +530,7 @@ async fn allowed_tools_filter_sources_before_code_mode_and_discovery() {
mcp_runtime("kept", "kept", "lookup", ToolExposure::Deferred),
mcp_runtime("excluded", "excluded", "lookup", ToolExposure::Deferred),
],
[Arc::new(DeferredExtensionTool)
as Arc<
dyn for<'call> ToolExecutor<ExtensionToolCall<'call>>,
>],
[Arc::new(DeferredExtensionTool) as Arc<dyn ToolExecutor>],
&[dynamic_tool(
/*namespace*/ None,
"dynamic_echo",
@@ -48,10 +48,7 @@ impl ToolExecutor<ToolInvocation> for TestHandler {
})
}
fn handle<'a>(&'a self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
where
ToolInvocation: 'a,
{
fn handle(&self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async {
Ok(
Box::new(FunctionToolOutput::from_text("ok".to_string(), Some(true)))