Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(cua-driver): report unknown tools accurately
injaneity7d1e178522cf
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/server.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/server.rsindex 7c85f09756..09007a5540 100644--- a/libs/cua-driver/rust/crates/cua-driver-core/src/server.rs+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/server.rs@@ -18,6 +18,10 @@ use crate::tool::ToolRegistry;#[async_trait::async_trait]pub trait ToolProvider: Send + Sync {fn tools_list(&self) -> serde_json::Value;+ fn is_known_tool(&self, _name: &str) -> bool {+ true+ }+async fn invoke_tool(&self,name: &str,@@ -31,6 +35,10 @@ impl ToolProvider for ToolRegistry {ToolRegistry::tools_list(self)}+ fn is_known_tool(&self, name: &str) -> bool {+ ToolRegistry::is_known_tool(self, name)+ }+async fn invoke_tool(&self,name: &str,@@ -937,6 +945,16 @@ async fn dispatch_request();}+ if !provider.is_known_tool(&call.name) {+ return Response::ok(+ id,+ tool_error_result(+ format!("Unknown tool: {}", call.name),+ serde_json::json!({"code": "unknown_tool"}),+ ),+ );+ }+let public_session = call.args.get("session")@@ -997,6 +1015,10 @@ mod dispatch_contract_tests {#[async_trait::async_trait]impl ToolProvider for NeverInvokeProvider {+ fn is_known_tool(&self, name: &str) -> bool {+ name == "get_config"+ }+fn tools_list(&self) -> serde_json::Value {serde_json::json!({"tools": [{"name": "get_config"}]})}@@ -1060,6 +1082,10 @@ mod dispatch_contract_tests {#[async_trait::async_trait]impl ToolProvider for StubProvider {+ fn is_known_tool(&self, _name: &str) -> bool {+ true+ }+fn tools_list(&self) -> serde_json::Value {serde_json::json!({"tools": []})}@@ -1153,6 +1179,10 @@ mod observation_tests {serde_json::json!({"tools": []})}+ fn is_known_tool(&self, _name: &str) -> bool {+ true+ }+async fn invoke_tool(&self,_name: &str,diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rsindex 5493c6c386..afef86dc4e 100644--- a/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs@@ -1300,6 +1300,10 @@ impl ToolRegistry {self.tools.insert(name, tool);}+ pub fn is_known_tool(&self, name: &str) -> bool {+ name == "type_text_chars" || self.tools.contains_key(renamed_tool(name).unwrap_or(name))+ }+pub fn retain_session_end_hook(&mut self,registration: crate::session::SessionEndHookRegistration,diff --git a/libs/cua-driver/rust/crates/cua-driver-core/tests/recording_transport_identity.rs b/libs/cua-driver/rust/crates/cua-driver-core/tests/recording_transport_identity.rsindex 52e0c2d3cb..8b5b7a6c03 100644--- a/libs/cua-driver/rust/crates/cua-driver-core/tests/recording_transport_identity.rs+++ b/libs/cua-driver/rust/crates/cua-driver-core/tests/recording_transport_identity.rs@@ -17,6 +17,10 @@ struct CaptureProvider {#[async_trait]impl ToolProvider for CaptureProvider {+ fn is_known_tool(&self, _name: &str) -> bool {+ true+ }+fn tools_list(&self) -> Value {json!({"tools": []})}diff --git a/libs/cua-driver/rust/crates/cua-driver-sdk/src/abi.rs b/libs/cua-driver/rust/crates/cua-driver-sdk/src/abi.rsindex d5a96b78ed..92bd2d3f76 100644--- a/libs/cua-driver/rust/crates/cua-driver-sdk/src/abi.rs+++ b/libs/cua-driver/rust/crates/cua-driver-sdk/src/abi.rs@@ -1313,6 +1313,15 @@ impl NativeAbiDriver {}}+ pub(crate) fn is_known_tool(&self, name: &str) -> bool {+ unsafe {+ self.raw_handle()+ .cast::<CuaDriverHandle>()+ .as_ref()+ .is_some_and(|handle| handle.runtime.is_known_tool(name))+ }+ }+pub(crate) fn is_available(&self) -> bool {let mut available = false;let mut error = CuaDriverBuffer::empty();diff --git a/libs/cua-driver/rust/crates/cua-driver-sdk/src/lib.rs b/libs/cua-driver/rust/crates/cua-driver-sdk/src/lib.rsindex 5e5a831016..121e841ab9 100644--- a/libs/cua-driver/rust/crates/cua-driver-sdk/src/lib.rs+++ b/libs/cua-driver/rust/crates/cua-driver-sdk/src/lib.rs@@ -313,6 +313,18 @@ enum DriverBackend {}impl CuaDriver {+ /// Trusted Rust-host lookup against the embedded registry. Unlike+ /// `list_tools_json`, policy filtering does not hide registered tools.+ #[doc(hidden)]+ pub fn local_is_known_tool(&self, name: &str) -> Option<bool> {+ match &self.backend {+ DriverBackend::Embedded(runtime) => Some(runtime.is_known_tool(name)),+ DriverBackend::Daemon(_)+ | DriverBackend::PrivateWorker(_)+ | DriverBackend::Remote(_) => None,+ }+ }+/// Trusted Rust-host access to the daemon-owned local history controller./// This is intentionally absent from UniFFI and public agent protocols.#[doc(hidden)]diff --git a/libs/cua-driver/rust/crates/cua-driver-sdk/src/runtime.rs b/libs/cua-driver/rust/crates/cua-driver-sdk/src/runtime.rsindex 044d66bc25..95ca7b2e1e 100644--- a/libs/cua-driver/rust/crates/cua-driver-sdk/src/runtime.rs+++ b/libs/cua-driver/rust/crates/cua-driver-sdk/src/runtime.rs@@ -256,6 +256,10 @@ impl DriverRuntime {self.is_running().then(|| self.registry.tools_list())}+ pub(crate) fn is_known_tool(&self, name: &str) -> bool {+ self.is_running() && self.registry.is_known_tool(name)+ }+pub(crate) fn history(&self) -> Option<Arc<cua_driver_core::history::HistoryManager>> {self.is_running().then(|| self.registry.history()).flatten()}diff --git a/libs/cua-driver/rust/crates/cua-driver/src/sdk_adapter.rs b/libs/cua-driver/rust/crates/cua-driver/src/sdk_adapter.rsindex b06386078b..81c43bfe87 100644--- a/libs/cua-driver/rust/crates/cua-driver/src/sdk_adapter.rs+++ b/libs/cua-driver/rust/crates/cua-driver/src/sdk_adapter.rs@@ -152,17 +152,8 @@ impl SdkAdapter {}pub fn is_known_tool(&self, name: &str) -> bool {- name == "type_text_chars"- || cua_driver_core::tool::renamed_tool(name).is_some()- || self- .tools_list- .get("tools")- .and_then(Value::as_array)- .is_some_and(|tools| {- tools- .iter()- .any(|tool| tool.get("name").and_then(Value::as_str) == Some(name))- })+ cua_driver_core::tool::renamed_tool(name).is_some()+ || self.driver.local_is_known_tool(name).unwrap_or(false)}pub fn describe(&self, name: &str) -> Option<Value> {@@ -469,6 +460,10 @@ impl ToolProvider for SdkAdapter {self.tools_list()}+ fn is_known_tool(&self, name: &str) -> bool {+ SdkAdapter::is_known_tool(self, name)+ }+async fn invoke_tool(&self, name: &str, arguments: Value) -> Result<Value, String> {self.invoke_raw(name, arguments).await}diff --git a/libs/cua-driver/rust/crates/cua-driver/src/serve.rs b/libs/cua-driver/rust/crates/cua-driver/src/serve.rsindex d97ca38eac..fce88c4fd7 100644--- a/libs/cua-driver/rust/crates/cua-driver/src/serve.rs+++ b/libs/cua-driver/rust/crates/cua-driver/src/serve.rs@@ -496,20 +496,16 @@ async fn invoke_daemon_tool(}}- // Policy enforcement — defense-in-depth for direct daemon socket connections.- // Evaluate before registry lookup so a deny-by-default policy does not leak- // whether an unapproved name happens to be registered. This also preserves- // the MCP policy contract now that every call passes through the daemon.- if let Err(error) = cua_driver_core::authorization::authorize_tool_call(&tool_name, &args) {- observe_daemon_error(observation, 1);- return DaemonResponse::err(error.to_string(), 1);- }-if !known_tool {observe_daemon_error(observation, 64);return DaemonResponse::err(format!("Unknown tool: {tool_name}"), 64);}+ if let Err(error) = cua_driver_core::authorization::authorize_tool_call(&tool_name, &args) {+ observe_daemon_error(observation, 1);+ return DaemonResponse::err(error.to_string(), 1);+ }+inject_browser_approvals(&tool_name, &mut args, req.session_id.as_deref());let session_context = observation_transport.and_then(|transport| {@@ -2706,6 +2702,26 @@ mod gate_tests {let sid = "gate-test-session-A1B2C3";+ let unknown_socket = socket.clone();+ let unknown = DaemonRequest {+ method: "call".into(),+ name: Some("get_active_window".into()),+ args: Some(serde_json::json!({})),+ session_id: Some(sid.to_owned()),+ observation_origin: None,+ client_kind: None,+ };+ let response = tokio::task::spawn_blocking(move || send_request(&unknown_socket, &unknown))+ .await+ .unwrap()+ .expect("unknown call response");+ assert!(!response.ok);+ assert_eq!(response.exit_code, Some(64));+ assert_eq!(+ response.error.as_deref(),+ Some("Unknown tool: get_active_window")+ );+// 1. LIVE session call → tool runs.let socket1 = socket.clone();let s1 = sid.to_owned();diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_handshake_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_handshake_test.rsindex cd108c25ab..59bcded272 100644--- a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_handshake_test.rs+++ b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_handshake_test.rs@@ -91,6 +91,10 @@ fn tools_call_unknown_tool() {// Error should be in the content with isError=true, not a protocol error.let is_error = resp["result"]["isError"].as_bool().unwrap_or(false);assert!(is_error, "Expected isError=true for unknown tool");+ assert_eq!(+ resp["result"]["content"][0]["text"],+ "Unknown tool: nonexistent_tool"+ );}#[test]