Lightweight coding agent that runs in your terminal
Rust
tools: remove is_mutating dispatch gating (#22382)
pakrym-oai862b2122ee97
diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lockindex 30d4bf3640..afb3cbbed9 100644--- a/codex-rs/Cargo.lock+++ b/codex-rs/Cargo.lock@@ -2516,7 +2516,6 @@ dependencies = ["codex-utils-path","codex-utils-plugins","codex-utils-pty",- "codex-utils-readiness","codex-utils-stream-parser","codex-utils-string","codex-utils-template",diff --git a/codex-rs/Cargo.toml b/codex-rs/Cargo.tomlindex 5a21e98995..3b9a0f0d7d 100644--- a/codex-rs/Cargo.toml+++ b/codex-rs/Cargo.toml@@ -228,7 +228,6 @@ codex-utils-output-truncation = { path = "utils/output-truncation" }codex-utils-path = { path = "utils/path-utils" }codex-utils-plugins = { path = "utils/plugins" }codex-utils-pty = { path = "utils/pty" }-codex-utils-readiness = { path = "utils/readiness" }codex-utils-rustls-provider = { path = "utils/rustls-provider" }codex-utils-sandbox-summary = { path = "utils/sandbox-summary" }codex-utils-sleep-inhibitor = { path = "utils/sleep-inhibitor" }diff --git a/codex-rs/core/Cargo.toml b/codex-rs/core/Cargo.tomlindex 86e7c07ad9..ec82a53d08 100644--- a/codex-rs/core/Cargo.toml+++ b/codex-rs/core/Cargo.toml@@ -70,7 +70,6 @@ codex-utils-output-truncation = { workspace = true }codex-utils-path = { workspace = true }codex-utils-plugins = { workspace = true }codex-utils-pty = { workspace = true }-codex-utils-readiness = { workspace = true }codex-utils-string = { workspace = true }codex-utils-stream-parser = { workspace = true }codex-utils-template = { workspace = true }diff --git a/codex-rs/core/src/session/mod.rs b/codex-rs/core/src/session/mod.rsindex ea0196a23a..8739eb0634 100644--- a/codex-rs/core/src/session/mod.rs+++ b/codex-rs/core/src/session/mod.rs@@ -358,7 +358,6 @@ use codex_tools::ToolEnvironmentMode;use codex_tools::ToolsConfig;use codex_tools::ToolsConfigParams;use codex_utils_absolute_path::AbsolutePathBuf;-use codex_utils_readiness::ReadinessFlag;#[cfg(test)]use codex_utils_stream_parser::ProposedPlanSegment;diff --git a/codex-rs/core/src/session/review.rs b/codex-rs/core/src/session/review.rsindex 7d4b1b736a..b0113cbdb7 100644--- a/codex-rs/core/src/session/review.rs+++ b/codex-rs/core/src/session/review.rs@@ -146,7 +146,6 @@ pub(super) async fn spawn_review_thread(final_output_json_schema: None,codex_self_exe: parent_turn_context.codex_self_exe.clone(),codex_linux_sandbox_exe: parent_turn_context.codex_linux_sandbox_exe.clone(),- tool_call_gate: Arc::new(ReadinessFlag::new()),dynamic_tools: parent_turn_context.dynamic_tools.clone(),truncation_policy: model_info.truncation_policy.into(),turn_metadata_state,diff --git a/codex-rs/core/src/session/tests.rs b/codex-rs/core/src/session/tests.rsindex 705139cfd8..4b847295ba 100644--- a/codex-rs/core/src/session/tests.rs+++ b/codex-rs/core/src/session/tests.rs@@ -2837,10 +2837,6 @@ async fn turn_context_with_model_updates_model_fields() {updated.truncation_policy,expected_model_info.truncation_policy.into());- assert!(!Arc::ptr_eq(- &updated.tool_call_gate,- &turn_context.tool_call_gate- ));}#[test]diff --git a/codex-rs/core/src/session/turn_context.rs b/codex-rs/core/src/session/turn_context.rsindex 5a8885e0f3..79d07ede01 100644--- a/codex-rs/core/src/session/turn_context.rs+++ b/codex-rs/core/src/session/turn_context.rs@@ -89,7 +89,6 @@ pub struct TurnContext {pub(crate) final_output_json_schema: Option<Value>,pub(crate) codex_self_exe: Option<PathBuf>,pub(crate) codex_linux_sandbox_exe: Option<PathBuf>,- pub(crate) tool_call_gate: Arc<ReadinessFlag>,pub(crate) truncation_policy: TruncationPolicy,pub(crate) dynamic_tools: Vec<DynamicToolSpec>,pub(crate) turn_metadata_state: Arc<TurnMetadataState>,@@ -272,7 +271,6 @@ impl TurnContext {final_output_json_schema: self.final_output_json_schema.clone(),codex_self_exe: self.codex_self_exe.clone(),codex_linux_sandbox_exe: self.codex_linux_sandbox_exe.clone(),- tool_call_gate: Arc::new(ReadinessFlag::new()),truncation_policy,dynamic_tools: self.dynamic_tools.clone(),turn_metadata_state: self.turn_metadata_state.clone(),@@ -571,7 +569,6 @@ impl Session {final_output_json_schema: None,codex_self_exe: per_turn_config.codex_self_exe.clone(),codex_linux_sandbox_exe: per_turn_config.codex_linux_sandbox_exe.clone(),- tool_call_gate: Arc::new(ReadinessFlag::new()),truncation_policy: model_info.truncation_policy.into(),dynamic_tools: session_configuration.dynamic_tools.clone(),turn_metadata_state,diff --git a/codex-rs/core/src/tools/handlers/apply_patch.rs b/codex-rs/core/src/tools/handlers/apply_patch.rsindex 85b2c979bb..da70b39856 100644--- a/codex-rs/core/src/tools/handlers/apply_patch.rs+++ b/codex-rs/core/src/tools/handlers/apply_patch.rs@@ -311,10 +311,6 @@ impl ToolHandler for ApplyPatchHandler {matches!(payload, ToolPayload::Custom { .. })}- async fn is_mutating(&self, _invocation: &ToolInvocation) -> bool {- true- }-fn create_diff_consumer(&self) -> Option<Box<dyn ToolArgumentDiffConsumer>> {Some(Box::<ApplyPatchArgumentDiffConsumer>::default())}diff --git a/codex-rs/core/src/tools/handlers/dynamic.rs b/codex-rs/core/src/tools/handlers/dynamic.rsindex 59450a837d..7cc9e61e30 100644--- a/codex-rs/core/src/tools/handlers/dynamic.rs+++ b/codex-rs/core/src/tools/handlers/dynamic.rs@@ -35,10 +35,6 @@ impl ToolHandler for DynamicToolHandler {self.tool_name.clone()}- async fn is_mutating(&self, _invocation: &ToolInvocation) -> bool {- true- }-async fn handle(&self, invocation: ToolInvocation) -> Result<Self::Output, 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.rsindex f76708478d..da0a935152 100644--- a/codex-rs/core/src/tools/handlers/extension_tools.rs+++ b/codex-rs/core/src/tools/handlers/extension_tools.rs@@ -83,10 +83,6 @@ impl ToolHandler for BundledToolHandler {self.arguments_from_payload(payload).is_some()}- async fn is_mutating(&self, _invocation: &ToolInvocation) -> bool {- true- }-fn pre_tool_use_payload(&self, invocation: &ToolInvocation) -> Option<PreToolUsePayload> {let arguments = self.arguments_from_payload(&invocation.payload)?;Some(PreToolUsePayload {@@ -189,7 +185,7 @@ mod tests {}#[tokio::test]- async fn exposes_generic_hook_payloads_and_is_conservatively_mutating() {+ async fn exposes_generic_hook_payloads() {let bundle = codex_tool_api::ToolBundle::new(codex_tool_api::FunctionToolSpec {name: "extension_echo".to_string(),@@ -225,7 +221,6 @@ mod tests {value: json!({ "ok": true }),};- assert!(ToolHandler::is_mutating(&handler, &invocation).await);assert_eq!(ToolHandler::pre_tool_use_payload(&handler, &invocation),Some(PreToolUsePayload {diff --git a/codex-rs/core/src/tools/handlers/shell/container_exec.rs b/codex-rs/core/src/tools/handlers/shell/container_exec.rsindex cb09a51501..515b8ca7d8 100644--- a/codex-rs/core/src/tools/handlers/shell/container_exec.rs+++ b/codex-rs/core/src/tools/handlers/shell/container_exec.rs@@ -1,5 +1,4 @@use codex_protocol::models::ShellToolCallParams;-use codex_shell_command::is_safe_command::is_known_safe_command;use codex_tools::ToolName;use crate::function_tool::FunctionCallError;@@ -33,16 +32,6 @@ impl ToolHandler for ContainerExecHandler {matches!(payload, ToolPayload::Function { .. })}- async fn is_mutating(&self, invocation: &ToolInvocation) -> bool {- let ToolPayload::Function { arguments } = &invocation.payload else {- return true;- };-- serde_json::from_str::<ShellToolCallParams>(arguments)- .map(|params| !is_known_safe_command(¶ms.command))- .unwrap_or(true)- }-fn pre_tool_use_payload(&self, invocation: &ToolInvocation) -> Option<PreToolUsePayload> {shell_function_pre_tool_use_payload(invocation)}diff --git a/codex-rs/core/src/tools/handlers/shell/local_shell.rs b/codex-rs/core/src/tools/handlers/shell/local_shell.rsindex 6265be4285..9312b69138 100644--- a/codex-rs/core/src/tools/handlers/shell/local_shell.rs+++ b/codex-rs/core/src/tools/handlers/shell/local_shell.rs@@ -1,4 +1,3 @@-use codex_shell_command::is_safe_command::is_known_safe_command;use codex_tools::ToolName;use crate::function_tool::FunctionCallError;@@ -42,20 +41,12 @@ impl ToolHandler for LocalShellHandler {self.include_spec.then(create_local_shell_tool)}- fn supports_parallel_tool_calls(&self) -> bool {- self.include_spec- }-fn matches_kind(&self, payload: &ToolPayload) -> bool {matches!(payload, ToolPayload::LocalShell { .. })}- async fn is_mutating(&self, invocation: &ToolInvocation) -> bool {- let ToolPayload::LocalShell { params } = &invocation.payload else {- return true;- };-- !is_known_safe_command(¶ms.command)+ fn supports_parallel_tool_calls(&self) -> bool {+ self.include_spec}fn pre_tool_use_payload(&self, invocation: &ToolInvocation) -> Option<PreToolUsePayload> {diff --git a/codex-rs/core/src/tools/handlers/shell/shell_command.rs b/codex-rs/core/src/tools/handlers/shell/shell_command.rsindex f5ecd80664..aa88da95dc 100644--- a/codex-rs/core/src/tools/handlers/shell/shell_command.rs+++ b/codex-rs/core/src/tools/handlers/shell/shell_command.rs@@ -1,6 +1,5 @@use codex_protocol::ThreadId;use codex_protocol::models::ShellCommandToolCallParams;-use codex_shell_command::is_safe_command::is_known_safe_command;use codex_tools::ShellCommandBackendConfig;use codex_tools::ToolName;@@ -141,33 +140,12 @@ impl ToolHandler for ShellCommandHandler {})}- fn supports_parallel_tool_calls(&self) -> bool {- self.options.is_some()- }-fn matches_kind(&self, payload: &ToolPayload) -> bool {matches!(payload, ToolPayload::Function { .. })}- async fn is_mutating(&self, invocation: &ToolInvocation) -> bool {- let ToolPayload::Function { arguments } = &invocation.payload else {- return true;- };-- serde_json::from_str::<ShellCommandToolCallParams>(arguments)- .map(|params| {- let use_login_shell = match Self::resolve_use_login_shell(- params.login,- invocation.turn.tools_config.allow_login_shell,- ) {- Ok(use_login_shell) => use_login_shell,- Err(_) => return true,- };- let shell = invocation.session.user_shell();- let command = Self::base_command(shell.as_ref(), ¶ms.command, use_login_shell);- !is_known_safe_command(&command)- })- .unwrap_or(true)+ fn supports_parallel_tool_calls(&self) -> bool {+ self.options.is_some()}fn pre_tool_use_payload(&self, invocation: &ToolInvocation) -> Option<PreToolUsePayload> {diff --git a/codex-rs/core/src/tools/handlers/shell/shell_handler.rs b/codex-rs/core/src/tools/handlers/shell/shell_handler.rsindex 39422734f5..fdcb86230a 100644--- a/codex-rs/core/src/tools/handlers/shell/shell_handler.rs+++ b/codex-rs/core/src/tools/handlers/shell/shell_handler.rs@@ -1,6 +1,5 @@use codex_protocol::ThreadId;use codex_protocol::models::ShellToolCallParams;-use codex_shell_command::is_safe_command::is_known_safe_command;use codex_tools::ToolName;use crate::exec::ExecCapturePolicy;@@ -74,22 +73,12 @@ impl ToolHandler for ShellHandler {self.options.map(create_shell_tool)}- fn supports_parallel_tool_calls(&self) -> bool {- self.options.is_some()- }-fn matches_kind(&self, payload: &ToolPayload) -> bool {matches!(payload, ToolPayload::Function { .. })}- async fn is_mutating(&self, invocation: &ToolInvocation) -> bool {- let ToolPayload::Function { arguments } = &invocation.payload else {- return true;- };-- serde_json::from_str::<ShellToolCallParams>(arguments)- .map(|params| !is_known_safe_command(¶ms.command))- .unwrap_or(true)+ fn supports_parallel_tool_calls(&self) -> bool {+ self.options.is_some()}fn pre_tool_use_payload(&self, invocation: &ToolInvocation) -> Option<PreToolUsePayload> {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.rsindex 1311813262..3a69b3c63b 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@@ -26,7 +26,6 @@ use crate::unified_exec::generate_chunk_id;use codex_features::Feature;use codex_otel::SessionTelemetry;use codex_otel::TOOL_CALL_UNIFIED_EXEC_METRIC;-use codex_shell_command::is_safe_command::is_known_safe_command;use codex_tools::ToolName;use codex_tools::ToolSpec;use codex_utils_output_truncation::approx_token_count;@@ -85,36 +84,12 @@ impl ToolHandler for ExecCommandHandler {))}- fn supports_parallel_tool_calls(&self) -> bool {- true- }-fn matches_kind(&self, payload: &ToolPayload) -> bool {matches!(payload, ToolPayload::Function { .. })}- async fn is_mutating(&self, invocation: &ToolInvocation) -> bool {- let ToolPayload::Function { arguments } = &invocation.payload else {- tracing::error!(- "This should never happen, invocation payload is wrong: {:?}",- invocation.payload- );- return true;- };-- let Ok(params) = parse_arguments::<ExecCommandArgs>(arguments) else {- return true;- };- let command = match get_command(- ¶ms,- invocation.session.user_shell(),- &invocation.turn.tools_config.unified_exec_shell_mode,- invocation.turn.tools_config.allow_login_shell,- ) {- Ok(command) => command,- Err(_) => return true,- };- !is_known_safe_command(&command)+ fn supports_parallel_tool_calls(&self) -> bool {+ true}fn pre_tool_use_payload(&self, invocation: &ToolInvocation) -> Option<PreToolUsePayload> {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.rsindex 3250a9d0a2..455d7b6417 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@@ -45,10 +45,6 @@ impl ToolHandler for WriteStdinHandler {matches!(payload, ToolPayload::Function { .. })}- async fn is_mutating(&self, _invocation: &ToolInvocation) -> bool {- true- }-fn post_tool_use_payload(&self,invocation: &ToolInvocation,diff --git a/codex-rs/core/src/tools/registry.rs b/codex-rs/core/src/tools/registry.rsindex 235cb6fef3..01b3caa34c 100644--- a/codex-rs/core/src/tools/registry.rs+++ b/codex-rs/core/src/tools/registry.rs@@ -27,7 +27,6 @@ use codex_protocol::protocol::EventMsg;use codex_tool_api::ToolBundle as ExtensionToolBundle;use codex_tools::ToolName;use codex_tools::ToolSpec;-use codex_utils_readiness::Readiness;use futures::future::BoxFuture;use serde_json::Value;use tracing::warn;@@ -62,17 +61,6 @@ pub trait ToolHandler: Send + Sync {async { Vec::new() }}- /// Returns `true` if the [ToolInvocation] *might* mutate the environment of the- /// user (through file system, OS operations, ...).- /// This function must remains defensive and return `true` if a doubt exist on the- /// exact effect of a ToolInvocation.- fn is_mutating(- &self,- _invocation: &ToolInvocation,- ) -> impl std::future::Future<Output = bool> + Send {- async { false }- }-fn post_tool_use_payload(&self,_invocation: &ToolInvocation,@@ -185,8 +173,6 @@ trait AnyToolHandler: Send + Sync {fn matches_kind(&self, payload: &ToolPayload) -> bool;- fn is_mutating<'a>(&'a self, invocation: &'a ToolInvocation) -> BoxFuture<'a, bool>;-fn pre_tool_use_payload(&self, invocation: &ToolInvocation) -> Option<PreToolUsePayload>;fn with_updated_hook_input(@@ -219,10 +205,6 @@ whereToolHandler::matches_kind(self, payload)}- fn is_mutating<'a>(&'a self, invocation: &'a ToolInvocation) -> BoxFuture<'a, bool> {- Box::pin(ToolHandler::is_mutating(self, invocation))- }-fn pre_tool_use_payload(&self, invocation: &ToolInvocation) -> Option<PreToolUsePayload> {ToolHandler::pre_tool_use_payload(self, invocation)}@@ -305,7 +287,8 @@ impl ToolRegistry {}pub(crate) fn supports_parallel_tool_calls(&self, name: &ToolName) -> Option<bool> {- Some(self.handler(name)?.supports_parallel_tool_calls())+ let handler = self.handler(name)?;+ Some(handler.supports_parallel_tool_calls())}#[expect(@@ -424,7 +407,6 @@ impl ToolRegistry {}}- let is_mutating = handler.is_mutating(&invocation).await;let response_cell = tokio::sync::Mutex::new(None);let invocation_for_tool = invocation.clone();let log_payload = invocation.payload.log_payload();@@ -440,11 +422,6 @@ impl ToolRegistry {let handler = handler.clone();let response_cell = &response_cell;async move {- if is_mutating {- tracing::trace!("waiting for tool gate");- invocation_for_tool.turn.tool_call_gate.wait_ready().await;- tracing::trace!("tool gate released");- }match handler.handle_any(invocation_for_tool).await {Ok(result) => {let preview = result.result.log_preview();diff --git a/codex-rs/core/src/tools/router_tests.rs b/codex-rs/core/src/tools/router_tests.rsindex b3fe087fcc..e78bd9402f 100644--- a/codex-rs/core/src/tools/router_tests.rs+++ b/codex-rs/core/src/tools/router_tests.rs@@ -361,7 +361,6 @@ async fn extension_tool_bundles_are_model_visible_and_dispatchable() -> anyhow::call_id: "call-extension".to_string(),})?.expect("function_call should produce a tool call");-let result = router.dispatch_tool_call_with_code_mode_result(Arc::new(session),