From db531b4a6c07dd8a4cb624f25b8d6abbd28ccf96 Mon Sep 17 00:00:00 2001 From: "Adam Perry @ OpenAI" Date: Wed, 10 Jun 2026 09:40:41 -0700 Subject: [PATCH] [codex] Outline ToolExecutor handler bodies (#27299) ## 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. For ease of reviewing, this is a prefactor to extract trait method implementations to inherent methods. This will prevent changing indentation from creating a huge diff. ## What Outlined existing `ToolExecutor::handle` bodies into inherent async `handle_call` methods across core and extension tool handlers. The trait methods still use `async_trait` and now delegate to `self.handle_call(...).await`; handler behavior is unchanged. --- .../src/tools/code_mode/execute_handler.rs | 9 +++++++++ .../core/src/tools/code_mode/wait_handler.rs | 9 +++++++++ .../agent_jobs/report_agent_job_result.rs | 9 +++++++++ .../handlers/agent_jobs/spawn_agents_on_csv.rs | 9 +++++++++ .../core/src/tools/handlers/apply_patch.rs | 9 +++++++++ codex-rs/core/src/tools/handlers/dynamic.rs | 9 +++++++++ .../core/src/tools/handlers/extension_tools.rs | 18 ++++++++++++++++++ .../list_available_plugins_to_install.rs | 9 +++++++++ codex-rs/core/src/tools/handlers/mcp.rs | 9 +++++++++ .../list_mcp_resource_templates.rs | 9 +++++++++ .../mcp_resource/list_mcp_resources.rs | 9 +++++++++ .../handlers/mcp_resource/read_mcp_resource.rs | 9 +++++++++ .../tools/handlers/multi_agents/send_input.rs | 9 +++++++++ .../src/tools/handlers/multi_agents/wait.rs | 9 +++++++++ .../handlers/multi_agents_v2/followup_task.rs | 9 +++++++++ .../handlers/multi_agents_v2/list_agents.rs | 9 +++++++++ .../handlers/multi_agents_v2/send_message.rs | 9 +++++++++ .../src/tools/handlers/multi_agents_v2/wait.rs | 9 +++++++++ codex-rs/core/src/tools/handlers/plan.rs | 9 +++++++++ .../src/tools/handlers/request_permissions.rs | 9 +++++++++ .../tools/handlers/request_plugin_install.rs | 9 +++++++++ .../src/tools/handlers/request_user_input.rs | 9 +++++++++ .../src/tools/handlers/shell/shell_command.rs | 9 +++++++++ codex-rs/core/src/tools/handlers/test_sync.rs | 9 +++++++++ .../core/src/tools/handlers/tool_search.rs | 9 +++++++++ .../handlers/unified_exec/exec_command.rs | 9 +++++++++ .../tools/handlers/unified_exec/write_stdin.rs | 9 +++++++++ codex-rs/core/src/tools/handlers/view_image.rs | 9 +++++++++ codex-rs/core/src/tools/parallel.rs | 9 +++++++++ codex-rs/core/src/tools/registry_tests.rs | 8 ++++++++ codex-rs/core/src/tools/router_tests.rs | 9 +++++++++ codex-rs/ext/image-generation/src/tool.rs | 6 ++++++ codex-rs/ext/memories/src/tools/ad_hoc_note.rs | 13 +++++++++++++ codex-rs/ext/memories/src/tools/list.rs | 13 +++++++++++++ codex-rs/ext/memories/src/tools/read.rs | 13 +++++++++++++ codex-rs/ext/memories/src/tools/search.rs | 13 +++++++++++++ codex-rs/ext/web-search/src/tool.rs | 6 ++++++ 37 files changed, 351 insertions(+) diff --git a/codex-rs/core/src/tools/code_mode/execute_handler.rs b/codex-rs/core/src/tools/code_mode/execute_handler.rs index 1d69c8f4c..0bdb8b20a 100644 --- a/codex-rs/core/src/tools/code_mode/execute_handler.rs +++ b/codex-rs/core/src/tools/code_mode/execute_handler.rs @@ -104,6 +104,15 @@ impl ToolExecutor for CodeModeExecuteHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl CodeModeExecuteHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/code_mode/wait_handler.rs b/codex-rs/core/src/tools/code_mode/wait_handler.rs index 74cc314a7..c1928955f 100644 --- a/codex-rs/core/src/tools/code_mode/wait_handler.rs +++ b/codex-rs/core/src/tools/code_mode/wait_handler.rs @@ -57,6 +57,15 @@ impl ToolExecutor for CodeModeWaitHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl CodeModeWaitHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/agent_jobs/report_agent_job_result.rs b/codex-rs/core/src/tools/handlers/agent_jobs/report_agent_job_result.rs index c7adb2761..5f2a61532 100644 --- a/codex-rs/core/src/tools/handlers/agent_jobs/report_agent_job_result.rs +++ b/codex-rs/core/src/tools/handlers/agent_jobs/report_agent_job_result.rs @@ -26,6 +26,15 @@ impl ToolExecutor for ReportAgentJobResultHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl ReportAgentJobResultHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, payload, .. diff --git a/codex-rs/core/src/tools/handlers/agent_jobs/spawn_agents_on_csv.rs b/codex-rs/core/src/tools/handlers/agent_jobs/spawn_agents_on_csv.rs index 26438ca7b..16e1b1f72 100644 --- a/codex-rs/core/src/tools/handlers/agent_jobs/spawn_agents_on_csv.rs +++ b/codex-rs/core/src/tools/handlers/agent_jobs/spawn_agents_on_csv.rs @@ -27,6 +27,15 @@ impl ToolExecutor for SpawnAgentsOnCsvHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl SpawnAgentsOnCsvHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/apply_patch.rs b/codex-rs/core/src/tools/handlers/apply_patch.rs index 66fb1d308..6a322ed6a 100644 --- a/codex-rs/core/src/tools/handlers/apply_patch.rs +++ b/codex-rs/core/src/tools/handlers/apply_patch.rs @@ -318,6 +318,15 @@ impl ToolExecutor for ApplyPatchHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl ApplyPatchHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/dynamic.rs b/codex-rs/core/src/tools/handlers/dynamic.rs index a74f44fd6..e0151cf18 100644 --- a/codex-rs/core/src/tools/handlers/dynamic.rs +++ b/codex-rs/core/src/tools/handlers/dynamic.rs @@ -89,6 +89,15 @@ impl ToolExecutor for DynamicToolHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl DynamicToolHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/extension_tools.rs b/codex-rs/core/src/tools/handlers/extension_tools.rs index 5e177156c..a94c764a9 100644 --- a/codex-rs/core/src/tools/handlers/extension_tools.rs +++ b/codex-rs/core/src/tools/handlers/extension_tools.rs @@ -221,6 +221,15 @@ mod tests { async fn handle( &self, call: codex_tools::ToolCall, + ) -> Result, codex_tools::FunctionCallError> { + self.handle_call(call).await + } + } + + impl CapturingExtensionExecutor { + async fn handle_call( + &self, + call: codex_tools::ToolCall, ) -> Result, codex_tools::FunctionCallError> { let item = ExtensionTurnItem::WebSearch(WebSearchItem { id: call.call_id.clone(), @@ -452,6 +461,15 @@ mod tests { async fn handle( &self, call: codex_tools::ToolCall, + ) -> Result, codex_tools::FunctionCallError> { + self.handle_call(call).await + } + } + + impl ImageGenerationExtensionExecutor { + async fn handle_call( + &self, + call: codex_tools::ToolCall, ) -> Result, codex_tools::FunctionCallError> { call.turn_item_emitter .emit_started(ExtensionTurnItem::ImageGeneration( diff --git a/codex-rs/core/src/tools/handlers/list_available_plugins_to_install.rs b/codex-rs/core/src/tools/handlers/list_available_plugins_to_install.rs index d18a1ca36..2b782e455 100644 --- a/codex-rs/core/src/tools/handlers/list_available_plugins_to_install.rs +++ b/codex-rs/core/src/tools/handlers/list_available_plugins_to_install.rs @@ -71,6 +71,15 @@ impl ToolExecutor for ListAvailablePluginsToInstallHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl ListAvailablePluginsToInstallHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { payload, .. } = invocation; match payload { diff --git a/codex-rs/core/src/tools/handlers/mcp.rs b/codex-rs/core/src/tools/handlers/mcp.rs index 77ff3c14a..d60cdfdd0 100644 --- a/codex-rs/core/src/tools/handlers/mcp.rs +++ b/codex-rs/core/src/tools/handlers/mcp.rs @@ -116,6 +116,15 @@ impl ToolExecutor for McpHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl McpHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resource_templates.rs b/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resource_templates.rs index e96aad755..8974d678f 100644 --- a/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resource_templates.rs +++ b/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resource_templates.rs @@ -43,6 +43,15 @@ impl ToolExecutor for ListMcpResourceTemplatesHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl ListMcpResourceTemplatesHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resources.rs b/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resources.rs index 1b052184e..f3a7b43c2 100644 --- a/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resources.rs +++ b/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resources.rs @@ -43,6 +43,15 @@ impl ToolExecutor for ListMcpResourcesHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl ListMcpResourcesHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/mcp_resource/read_mcp_resource.rs b/codex-rs/core/src/tools/handlers/mcp_resource/read_mcp_resource.rs index f059d12c8..9861e5d22 100644 --- a/codex-rs/core/src/tools/handlers/mcp_resource/read_mcp_resource.rs +++ b/codex-rs/core/src/tools/handlers/mcp_resource/read_mcp_resource.rs @@ -43,6 +43,15 @@ impl ToolExecutor for ReadMcpResourceHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl ReadMcpResourceHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs b/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs index 6e28d0a1d..b811faf91 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs @@ -26,6 +26,15 @@ impl ToolExecutor for Handler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl Handler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/multi_agents/wait.rs b/codex-rs/core/src/tools/handlers/multi_agents/wait.rs index 525ee7f2e..1f6b7db8f 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/wait.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/wait.rs @@ -47,6 +47,15 @@ impl ToolExecutor for Handler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl Handler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs index 2fe09f5f2..66a39cc79 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs @@ -20,6 +20,15 @@ impl ToolExecutor for Handler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl Handler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let arguments = function_arguments(invocation.payload.clone())?; let args: FollowupTaskArgs = parse_arguments(&arguments)?; diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs index 46b29bdf1..18421278f 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs @@ -18,6 +18,15 @@ impl ToolExecutor for Handler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl Handler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/send_message.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/send_message.rs index a8e360584..2fd636a85 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/send_message.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/send_message.rs @@ -20,6 +20,15 @@ impl ToolExecutor for Handler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl Handler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let arguments = function_arguments(invocation.payload.clone())?; let args: SendMessageArgs = parse_arguments(&arguments)?; diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs index 5e37725b7..9d671b198 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs @@ -32,6 +32,15 @@ impl ToolExecutor for Handler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl Handler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/plan.rs b/codex-rs/core/src/tools/handlers/plan.rs index bd1060b3d..ff18a3281 100644 --- a/codex-rs/core/src/tools/handlers/plan.rs +++ b/codex-rs/core/src/tools/handlers/plan.rs @@ -58,6 +58,15 @@ impl ToolExecutor for PlanHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl PlanHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/request_permissions.rs b/codex-rs/core/src/tools/handlers/request_permissions.rs index a20ff2b66..7c24f1569 100644 --- a/codex-rs/core/src/tools/handlers/request_permissions.rs +++ b/codex-rs/core/src/tools/handlers/request_permissions.rs @@ -38,6 +38,15 @@ impl ToolExecutor for RequestPermissionsHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl RequestPermissionsHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/request_plugin_install.rs b/codex-rs/core/src/tools/handlers/request_plugin_install.rs index ce5bb3fb1..64625aaac 100644 --- a/codex-rs/core/src/tools/handlers/request_plugin_install.rs +++ b/codex-rs/core/src/tools/handlers/request_plugin_install.rs @@ -65,6 +65,15 @@ impl ToolExecutor for RequestPluginInstallHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl RequestPluginInstallHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { payload, diff --git a/codex-rs/core/src/tools/handlers/request_user_input.rs b/codex-rs/core/src/tools/handlers/request_user_input.rs index 0aa4b4f6f..3f3adf0ba 100644 --- a/codex-rs/core/src/tools/handlers/request_user_input.rs +++ b/codex-rs/core/src/tools/handlers/request_user_input.rs @@ -33,6 +33,15 @@ impl ToolExecutor for RequestUserInputHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl RequestUserInputHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/shell/shell_command.rs b/codex-rs/core/src/tools/handlers/shell/shell_command.rs index 7c492b364..e9fcf8204 100644 --- a/codex-rs/core/src/tools/handlers/shell/shell_command.rs +++ b/codex-rs/core/src/tools/handlers/shell/shell_command.rs @@ -144,6 +144,15 @@ impl ToolExecutor for ShellCommandHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl ShellCommandHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/test_sync.rs b/codex-rs/core/src/tools/handlers/test_sync.rs index 0e5fe894a..802859c91 100644 --- a/codex-rs/core/src/tools/handlers/test_sync.rs +++ b/codex-rs/core/src/tools/handlers/test_sync.rs @@ -74,6 +74,15 @@ impl ToolExecutor for TestSyncHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl TestSyncHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { payload, .. } = invocation; diff --git a/codex-rs/core/src/tools/handlers/tool_search.rs b/codex-rs/core/src/tools/handlers/tool_search.rs index 2de1e20dd..a4781e75e 100644 --- a/codex-rs/core/src/tools/handlers/tool_search.rs +++ b/codex-rs/core/src/tools/handlers/tool_search.rs @@ -70,6 +70,15 @@ impl ToolExecutor for ToolSearchHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl ToolSearchHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { payload, .. } = invocation; diff --git a/codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs b/codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs index ba69f0d03..9fe3b343b 100644 --- a/codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs +++ b/codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs @@ -95,6 +95,15 @@ impl ToolExecutor for ExecCommandHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl ExecCommandHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/unified_exec/write_stdin.rs b/codex-rs/core/src/tools/handlers/unified_exec/write_stdin.rs index a639ea006..9b319d543 100644 --- a/codex-rs/core/src/tools/handlers/unified_exec/write_stdin.rs +++ b/codex-rs/core/src/tools/handlers/unified_exec/write_stdin.rs @@ -44,6 +44,15 @@ impl ToolExecutor for WriteStdinHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl WriteStdinHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let ToolInvocation { session, diff --git a/codex-rs/core/src/tools/handlers/view_image.rs b/codex-rs/core/src/tools/handlers/view_image.rs index 5a67db1a6..eb761359a 100644 --- a/codex-rs/core/src/tools/handlers/view_image.rs +++ b/codex-rs/core/src/tools/handlers/view_image.rs @@ -81,6 +81,15 @@ impl ToolExecutor for ViewImageHandler { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } +} + +impl ViewImageHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { if !invocation .turn diff --git a/codex-rs/core/src/tools/parallel.rs b/codex-rs/core/src/tools/parallel.rs index 7db1ec964..a6f630a34 100644 --- a/codex-rs/core/src/tools/parallel.rs +++ b/codex-rs/core/src/tools/parallel.rs @@ -314,6 +314,15 @@ mod tests { async fn handle( &self, invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call(invocation).await + } + } + + impl CancellationCleanupHandler { + async fn handle_call( + &self, + invocation: ToolInvocation, ) -> Result, FunctionCallError> { let started = self .started diff --git a/codex-rs/core/src/tools/registry_tests.rs b/codex-rs/core/src/tools/registry_tests.rs index f2566251c..cc7f39e2a 100644 --- a/codex-rs/core/src/tools/registry_tests.rs +++ b/codex-rs/core/src/tools/registry_tests.rs @@ -51,6 +51,14 @@ impl ToolExecutor for LifecycleTestHandler { async fn handle( &self, _invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + self.handle_call().await + } +} + +impl LifecycleTestHandler { + async fn handle_call( + &self, ) -> Result, FunctionCallError> { match self.result.clone() { LifecycleTestResult::Ok { success } => Ok(Box::new( diff --git a/codex-rs/core/src/tools/router_tests.rs b/codex-rs/core/src/tools/router_tests.rs index 7c3e0157b..a9a52ca46 100644 --- a/codex-rs/core/src/tools/router_tests.rs +++ b/codex-rs/core/src/tools/router_tests.rs @@ -76,6 +76,15 @@ impl ToolExecutor for ExtensionEchoExecutor { async fn handle( &self, call: ExtensionToolCall, + ) -> Result, codex_tools::FunctionCallError> { + self.handle_call(call).await + } +} + +impl ExtensionEchoExecutor { + async fn handle_call( + &self, + call: ExtensionToolCall, ) -> Result, codex_tools::FunctionCallError> { let arguments: serde_json::Value = serde_json::from_str(call.function_arguments()?).expect("test arguments should parse"); diff --git a/codex-rs/ext/image-generation/src/tool.rs b/codex-rs/ext/image-generation/src/tool.rs index 69b99bdbc..70880b466 100644 --- a/codex-rs/ext/image-generation/src/tool.rs +++ b/codex-rs/ext/image-generation/src/tool.rs @@ -97,6 +97,12 @@ impl ToolExecutor for ImageGenerationTool { /// Executes the selected image operation and returns the completed image result. async fn handle(&self, call: ToolCall) -> Result, FunctionCallError> { + self.handle_call(call).await + } +} + +impl ImageGenerationTool { + async fn handle_call(&self, call: ToolCall) -> Result, FunctionCallError> { let args = parse_args(&call)?; let request = request_for_args(&args, call.conversation_history.items())?; call.turn_item_emitter diff --git a/codex-rs/ext/memories/src/tools/ad_hoc_note.rs b/codex-rs/ext/memories/src/tools/ad_hoc_note.rs index a6712a402..3495d57d3 100644 --- a/codex-rs/ext/memories/src/tools/ad_hoc_note.rs +++ b/codex-rs/ext/memories/src/tools/ad_hoc_note.rs @@ -61,6 +61,19 @@ where &self, call: ToolCall, ) -> Result, codex_extension_api::FunctionCallError> + { + self.handle_call(call).await + } +} + +impl AddAdHocNoteTool +where + B: MemoriesBackend, +{ + async fn handle_call( + &self, + call: ToolCall, + ) -> Result, codex_extension_api::FunctionCallError> { let backend = self.backend.clone(); let args: AddAdHocNoteArgs = parse_args(&call)?; diff --git a/codex-rs/ext/memories/src/tools/list.rs b/codex-rs/ext/memories/src/tools/list.rs index 301c7cab7..d3b23b1ca 100644 --- a/codex-rs/ext/memories/src/tools/list.rs +++ b/codex-rs/ext/memories/src/tools/list.rs @@ -59,6 +59,19 @@ where &self, call: ToolCall, ) -> Result, codex_extension_api::FunctionCallError> + { + self.handle_call(call).await + } +} + +impl ListTool +where + B: MemoriesBackend, +{ + async fn handle_call( + &self, + call: ToolCall, + ) -> Result, codex_extension_api::FunctionCallError> { let backend = self.backend.clone(); let args: ListArgs = parse_args(&call)?; diff --git a/codex-rs/ext/memories/src/tools/read.rs b/codex-rs/ext/memories/src/tools/read.rs index 33ede3c60..e408a17ca 100644 --- a/codex-rs/ext/memories/src/tools/read.rs +++ b/codex-rs/ext/memories/src/tools/read.rs @@ -58,6 +58,19 @@ where &self, call: ToolCall, ) -> Result, codex_extension_api::FunctionCallError> + { + self.handle_call(call).await + } +} + +impl ReadTool +where + B: MemoriesBackend, +{ + async fn handle_call( + &self, + call: ToolCall, + ) -> Result, codex_extension_api::FunctionCallError> { let backend = self.backend.clone(); let args: ReadArgs = parse_args(&call)?; diff --git a/codex-rs/ext/memories/src/tools/search.rs b/codex-rs/ext/memories/src/tools/search.rs index 1d0507270..cc8ba201a 100644 --- a/codex-rs/ext/memories/src/tools/search.rs +++ b/codex-rs/ext/memories/src/tools/search.rs @@ -67,6 +67,19 @@ where &self, call: ToolCall, ) -> Result, codex_extension_api::FunctionCallError> + { + self.handle_call(call).await + } +} + +impl SearchTool +where + B: MemoriesBackend, +{ + async fn handle_call( + &self, + call: ToolCall, + ) -> Result, codex_extension_api::FunctionCallError> { let backend = self.backend.clone(); let args: SearchArgs = parse_args(&call)?; diff --git a/codex-rs/ext/web-search/src/tool.rs b/codex-rs/ext/web-search/src/tool.rs index 35f126dd6..1de65edf8 100644 --- a/codex-rs/ext/web-search/src/tool.rs +++ b/codex-rs/ext/web-search/src/tool.rs @@ -75,6 +75,12 @@ impl ToolExecutor for WebSearchTool { } async fn handle(&self, call: ToolCall) -> Result, FunctionCallError> { + self.handle_call(call).await + } +} + +impl WebSearchTool { + async fn handle_call(&self, call: ToolCall) -> Result, FunctionCallError> { let commands = parse_commands(&call)?; let command_action = command_action(&commands); let provider = self