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)(macos): guard SkyLight auth-message selector for macOS 14 Sonoma (#1503) (#1782)
Francesco Bonacci6c31427c763f
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/input/skylight.rs b/libs/cua-driver/rust/crates/platform-macos/src/input/skylight.rsindex cedda2bd73..d3910daa92 100644--- a/libs/cua-driver/rust/crates/platform-macos/src/input/skylight.rs+++ b/libs/cua-driver/rust/crates/platform-macos/src/input/skylight.rs@@ -206,6 +206,28 @@ fn sel_register(name: &CStr) -> *mut c_void {}}+/// Whether `cls` actually implements `sel`, via `class_respondsToSelector`.+///+/// macOS 14 (Sonoma) compatibility guard: `SLSEventAuthenticationMessage`+/// exists on macOS 14, but `messageWithEventRecord:pid:version:` was only+/// added in macOS 15 (Sequoia). `sel_registerName` always succeeds (it just+/// interns the string), so a `!sel.is_null()` check is not enough — we must+/// confirm the class responds before calling `objc_msgSend`, or the runtime+/// raises `NSInvalidArgumentException: unrecognized selector`. See #1503.+fn class_responds_to_selector(cls: *mut c_void, sel: *mut c_void) -> bool {+ if cls.is_null() || sel.is_null() {+ return false;+ }+ type RespondsToFn = unsafe extern "C" fn(*mut c_void, *mut c_void) -> bool;+ static SYM: OnceLock<Option<RespondsToFn>> = OnceLock::new();+ let f = *SYM+ .get_or_init(|| find_sym(b"class_respondsToSelector\0").map(|p| unsafe { as_fn(p) }));+ match f {+ Some(f) => unsafe { f(cls, sel) },+ None => false,+ }+}+// ── SLSEventRecord extraction ──────────────────────────────────────────────/// Extract the embedded `SLSEventRecord *` from a `CGEvent`.@@ -244,11 +266,19 @@ pub fn post_to_pid(pid: pid_t, event_ptr: *mut c_void, attach_auth_message: boolif attach_auth_message {// Build and attach SLSEventAuthenticationMessage.+ //+ // macOS 14 (Sonoma) compatibility: the class exists on macOS 14 but+ // `messageWithEventRecord:pid:version:` was added in macOS 15. Guard+ // with `class_respondsToSelector` (a `!sel.is_null()` check is not+ // enough — `sel_registerName` interns any name); when the selector is+ // absent we skip the auth envelope and fall through to the plain+ // `SLEventPostToPid` below. Chromium-class targets may not receive the+ // event on macOS 14, but the daemon no longer crashes. See #1503.let cls = objc_class(c"SLSEventAuthenticationMessage");let sel = sel_register(c"messageWithEventRecord:pid:version:");let factory = factory_msg_send_fn();- if !cls.is_null() && !sel.is_null() {+ if class_responds_to_selector(cls, sel) {if let Some(factory_fn) = factory {let record = unsafe { extract_event_record(event_ptr) };if !record.is_null() {diff --git a/libs/cua-driver/swift/Sources/CuaDriverCore/Input/SkyLightEventPost.swift b/libs/cua-driver/swift/Sources/CuaDriverCore/Input/SkyLightEventPost.swiftindex 7d753de960..d11b9c76fa 100644--- a/libs/cua-driver/swift/Sources/CuaDriverCore/Input/SkyLightEventPost.swift+++ b/libs/cua-driver/swift/Sources/CuaDriverCore/Input/SkyLightEventPost.swift@@ -104,13 +104,22 @@ public enum SkyLightEventPost {"SLSEventAuthenticationMessage")else { return nil }+ // macOS 14 (Sonoma) compatibility: the class exists on macOS 14 but+ // `messageWithEventRecord:pid:version:` was added in macOS 15.+ // `NSSelectorFromString` always succeeds (it interns the string), so+ // verify the class responds before storing it — otherwise `objc_msgSend`+ // raises NSInvalidArgumentException at runtime and crashes the daemon.+ // When absent, return nil so callers skip the auth envelope. See #1503.+ let factorySelector = NSSelectorFromString(+ "messageWithEventRecord:pid:version:")+ guard messageClass.responds(to: factorySelector) else { return nil }+return Resolved(postToPid: postToPid,setAuthMessage: setAuth,msgSendFactory: msgSend,messageClass: messageClass,- factorySelector: NSSelectorFromString(- "messageWithEventRecord:pid:version:")+ factorySelector: factorySelector)}()