[codex] Remove async_trait from ToolExecutor (#27304)

## Why

We're now [discouraging use of
`async_trait`](https://github.com/openai/codex/pull/20242).

Removing use of `async_trait` from `ToolExecutor` yields a `codex_core`
debug test build speedup of ~78% (from 227.5s to 50.3s) on my machine.

Stacked on #27299, this PR applies the trait change after the handler
bodies have been outlined.

## What

Changed `ToolExecutor::handle` to return an explicit boxed
`ToolExecutorFuture` instead of using `async_trait`.

Updated ToolExecutor implementors to return `Box::pin(...)`, reexported
the future alias through `codex-tools` and `codex-extension-api`, and
removed `codex-tools` direct `async-trait` dependency.
This commit is contained in:
Adam Perry @ OpenAI authored and GitHub committed 2026-06-10 10:26:53 -07:00
1 parent d3abd8774e
commit 2704ecea9a
56 files changed
+161 -357

No files matched your search

+13 -15
View File
@@ -5,7 +5,6 @@ struct TestHandler {
tool_name: codex_tools::ToolName,
}
#[async_trait::async_trait]
impl ToolExecutor<ToolInvocation> for TestHandler {
fn tool_name(&self) -> codex_tools::ToolName {
self.tool_name.clone()
@@ -15,13 +14,15 @@ impl ToolExecutor<ToolInvocation> for TestHandler {
test_spec(&self.tool_name)
}
async fn handle(
&self,
_invocation: ToolInvocation,
) -> Result<Box<dyn crate::tools::context::ToolOutput>, FunctionCallError> {
Ok(Box::new(
crate::tools::context::FunctionToolOutput::from_text("ok".to_string(), Some(true)),
))
fn handle(&self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(async {
Ok(
Box::new(crate::tools::context::FunctionToolOutput::from_text(
"ok".to_string(),
Some(true),
)) as Box<dyn crate::tools::context::ToolOutput>,
)
})
}
}
@@ -38,7 +39,6 @@ struct LifecycleTestHandler {
result: LifecycleTestResult,
}
#[async_trait::async_trait]
impl ToolExecutor<ToolInvocation> for LifecycleTestHandler {
fn tool_name(&self) -> codex_tools::ToolName {
self.tool_name.clone()
@@ -48,11 +48,8 @@ impl ToolExecutor<ToolInvocation> for LifecycleTestHandler {
test_spec(&self.tool_name)
}
async fn handle(
&self,
_invocation: ToolInvocation,
) -> Result<Box<dyn crate::tools::context::ToolOutput>, FunctionCallError> {
self.handle_call().await
fn handle(&self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> {
Box::pin(self.handle_call())
}
}
@@ -66,7 +63,8 @@ impl LifecycleTestHandler {
"ok".to_string(),
Some(success),
),
)),
)
as Box<dyn crate::tools::context::ToolOutput>),
LifecycleTestResult::Err => Err(FunctionCallError::RespondToModel(
"handler failed".to_string(),
)),