Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

perf(desktop): shorten computer-use driver window watch and cursor glide (#2897)

Max2c4996c8540b
diff --git a/desktop/src-tauri/src/computer_use.rs b/desktop/src-tauri/src/computer_use.rs
index 604d4249d..6fae98021 100644
--- a/desktop/src-tauri/src/computer_use.rs
+++ b/desktop/src-tauri/src/computer_use.rs
@@ -56,6 +56,13 @@ const DARWIN_SOCKET_PATH_MAX_BYTES: usize = 103;
const SOCKET_DIRECTORY_MODE: u32 = 0o700;
const SOCKET_FLAVOR_HEX_BYTES: usize = 12;
const DAEMON_STDERR_TAIL_BYTES: usize = 8 * 1024;
+/// Upper bound, in milliseconds, of the driver's post-action window-change
+/// watch and the focus-steal lease it holds. The driver default is 1000 ms;
+/// see the Latency section of `docs/plans/desktop-computer-use.md`.
+const DAEMON_WINDOW_CHANGE_TIMEOUT_MS: &str = "500";
+/// Fixed virtual-cursor glide duration, in milliseconds. The driver default
+/// is speed-based and takes 0.45 to 1.5 s per position change.
+const DAEMON_CURSOR_GLIDE_MS: &str = "200";
fn driver_command(driver: &Path) -> Command {
let mut command = Command::new(driver);
@@ -1050,7 +1057,7 @@ async fn stop_daemon_process(mut daemon: Daemon, socket: &Path, diagnostics: &Bo
let _ = std::fs::remove_file(socket);
}
-fn spawn_daemon(driver: &Path, socket: &Path, host_bundle_id: &str, policy: &Path) -> io::Result<Daemon> {
+fn daemon_command(driver: &Path, socket: &Path, host_bundle_id: &str, policy: &Path) -> Command {
let mut command = driver_command(driver);
command
.args([
@@ -1062,8 +1069,16 @@ fn spawn_daemon(driver: &Path, socket: &Path, host_bundle_id: &str, policy: &Pat
])
.arg(socket)
.args(["--host-bundle-id", host_bundle_id, "--permission-mode", "standard"])
+ .args(["--glide-ms", DAEMON_CURSOR_GLIDE_MS])
.env("CUA_DRIVER_EMBEDDED_HOST_PID", std::process::id().to_string())
.env("CUA_DRIVER_MANAGED_POLICY_FILE", policy)
+ .env("CUA_DRIVER_WINDOW_CHANGE_TIMEOUT_MS", DAEMON_WINDOW_CHANGE_TIMEOUT_MS);
+ command
+}
+
+fn spawn_daemon(driver: &Path, socket: &Path, host_bundle_id: &str, policy: &Path) -> io::Result<Daemon> {
+ let mut command = daemon_command(driver, socket, host_bundle_id, policy);
+ command
.stdin(Stdio::piped())
.stdout(Stdio::null())
.stderr(Stdio::piped())
@@ -2194,6 +2209,12 @@ mod tests {
daemon_environment.get("CUA_DRIVER_MANAGED_POLICY_FILE"),
Some(&policy.display().to_string())
);
+ assert_eq!(
+ daemon_environment
+ .get("CUA_DRIVER_WINDOW_CHANGE_TIMEOUT_MS")
+ .map(String::as_str),
+ Some("500")
+ );
assert!(!daemon_environment.contains_key("HOME"));
let permission_root = state_dir.join("permission-probe");
@@ -2355,6 +2376,63 @@ esac
(json!({"ok": true, "result": {"shutdown": true}}), true)
}
+ #[test]
+ fn daemon_command_pins_latency_tuning_and_the_whole_launch_contract() {
+ // Literal values on purpose: changing the 500 ms window-change watch or
+ // the 200 ms glide must be a visible test edit, not a silent drift.
+ // `--glide-ms` is a pinned-driver `serve` flag (cua-driver-rs v0.31.0,
+ // `CursorConfig::parse`), not listed in its `--help`.
+ let command = daemon_command(
+ Path::new("/opt/cua-driver"),
+ Path::new("/tmp/driver.sock"),
+ "bot.avibe.desktop.test",
+ Path::new("/tmp/policy.yaml"),
+ );
+ let command = command.as_std();
+ let arguments: Vec<&str> = command
+ .get_args()
+ .map(|argument| argument.to_str().expect("utf-8 argument"))
+ .collect();
+ assert_eq!(
+ arguments,
+ [
+ "serve",
+ "--embedded",
+ "--parent-liveness-stdio",
+ "--no-permissions-gate",
+ "--socket",
+ "/tmp/driver.sock",
+ "--host-bundle-id",
+ "bot.avibe.desktop.test",
+ "--permission-mode",
+ "standard",
+ "--glide-ms",
+ "200",
+ ]
+ );
+ let environment: BTreeMap<&str, Option<&str>> = command
+ .get_envs()
+ .map(|(name, value)| {
+ (
+ name.to_str().expect("utf-8 name"),
+ value.map(|value| value.to_str().expect("utf-8 value")),
+ )
+ })
+ .collect();
+ let host_pid = std::process::id().to_string();
+ let expected: BTreeMap<&str, Option<&str>> = [
+ ("CUA_DRIVER_EMBEDDED", Some("1")),
+ ("CUA_DRIVER_EMBEDDED_HOST_PID", Some(host_pid.as_str())),
+ ("CUA_DRIVER_MANAGED_POLICY_FILE", Some("/tmp/policy.yaml")),
+ ("CUA_DRIVER_RS_TELEMETRY_ENABLED", Some("0")),
+ ("CUA_DRIVER_RS_UPDATE_CHECK", Some("0")),
+ ("CUA_DRIVER_WINDOW_CHANGE_TIMEOUT_MS", Some("500")),
+ ]
+ .into_iter()
+ .collect();
+ assert_eq!(environment, expected);
+ }
+
#[test]
fn intentional_stop_pinned_shutdown_contract_rejects_legacy_pid_field() {
let (response, should_shutdown) = pinned_shutdown_response(
diff --git a/docs/plans/desktop-computer-use.md b/docs/plans/desktop-computer-use.md
index 409f653fa..544bb9478 100644
--- a/docs/plans/desktop-computer-use.md
+++ b/docs/plans/desktop-computer-use.md
@@ -528,14 +528,15 @@ running. The tray keeps the shell alive after the window closes.
`Contents/Helpers/cua-driver` executable.
- Arguments: `serve --embedded --parent-liveness-stdio
--no-permissions-gate --socket <S> --host-bundle-id <bundle id>
- --permission-mode standard`.
+ --permission-mode standard --glide-ms 200`. `--glide-ms` fixes the
+ virtual cursor's glide at 200 ms (see Latency).
- Environment: start from an empty environment, then set
`CUA_DRIVER_EMBEDDED=1`, `CUA_DRIVER_EMBEDDED_HOST_PID=<shell pid>`,
`CUA_DRIVER_MANAGED_POLICY_FILE=<bundled tool policy>`,
- `CUA_DRIVER_RS_TELEMETRY_ENABLED=0`, and `CUA_DRIVER_RS_UPDATE_CHECK=0`.
- `CUA_DRIVER_WINDOW_CHANGE_TIMEOUT_MS` stays unset, so the driver keeps
- its 1000 ms post-action watch and the focus-steal lease that comes with
- it (see Latency).
+ `CUA_DRIVER_RS_TELEMETRY_ENABLED=0`, `CUA_DRIVER_RS_UPDATE_CHECK=0`, and
+ `CUA_DRIVER_WINDOW_CHANGE_TIMEOUT_MS=500`, which bounds the post-action
+ watch and the focus-steal lease that comes with it at 500 ms (see
+ Latency).
- Avibe does not depend on that crate. It is unpublished and pulls in the
whole platform stack, while the protocol needs only these few lines.
- **Liveness.** The shell keeps the child's stdin pipe open for the daemon's
@@ -626,7 +627,7 @@ running. The tray keeps the shell alive after the window closes.
- No tool exists whose purpose is activation.
- Foreground delivery is rejected, and input must address one window
(below).
- - The driver keeps its 1000 ms focus-steal lease, which reverts an
+ - The driver keeps a 500 ms focus-steal lease, which reverts an
activation seen during the post-action watch.
- As defense in depth, the server rejects the focus-intent shortcuts
that guide names: `⌘L`, `⌘⇧G`, and the browser tab shortcuts `⌘1`
@@ -1017,14 +1018,31 @@ Direct-mode runs used `cua-driver mcp --direct` from a scratch directory with
the proxy takes 1 to 2 ms, so the remaining 1.3 s floor sits inside
Calculator's AXPress (the slow `-25204` path, trycua/cua#3836). The watch also
holds the driver's focus-steal lease, which reverts another app's activation
- while it runs. Upstream warns that shortening it weakens that protection. So
- v1 keeps the 1000 ms default and gives up the measured 0.7 s per action. Focus
- protection outweighs latency for unattended use, and latency tuning waits for
- a measured need. Even at 1000 ms, an app that activates itself later than the
- watch can stay frontmost. The idle-desktop validation measures this, and the
- user docs state it. Upstream measured 78 ms at `0`, so the floor depends on
- how fast the target app answers. Click results report `effect: unverifiable`
- either way, so agents observe after acting.
+ while it runs. Upstream warns that shortening it weakens that protection.
+ Upstream measured 78 ms at `0`, so the floor depends on how fast the target
+ app answers. Click results report `effect: unverifiable` either way, so
+ agents observe after acting.
+ - **v1 (until 2026-10-21): 1000 ms.** v1 kept the driver default and gave up
+ the measured 0.7 s per action, because focus protection outweighed latency
+ for unattended use and latency tuning waited for a measured need.
+ - **Since 2026-10-21: 500 ms, chosen by the owner.** The need arrived.
+ Profiling on the owner's Mac (rc13, driver at `5272e49`) showed that when
+ an action changes no window, the driver waits out the whole watch. That is
+ about 85 % of a click. Halving the watch saves up to 0.5 s per action. The
+ owner chose 500 ms rather than 300 ms to keep half a second of focus
+ protection after each action.
+ - **Trade-off.** A pop-up or focus steal that appears between 500 ms and
+ 1000 ms after the action was caught before and now is not: the lease does
+ not revert it, and the action result does not report it. At either bound,
+ an app that activates itself after the watch can stay frontmost. The
+ idle-desktop validation measures this, and the user docs state it.
+ - **Cursor glide: 200 ms.** The virtual cursor's default glide is
+ speed-based and adds 0.45 to 1.5 s whenever the click position changes.
+ The daemon starts with `--glide-ms 200`, the pinned driver's `serve` flag
+ for a fixed glide duration. It takes 200 ms at any distance, and the cursor
+ still visibly moves to each target. `--cursor-reduced-motion on` is not
+ the knob: at the pinned driver it only stills the idle animation and
+ leaves the glide unchanged.
- **Element tokens are session-scoped** (`s00000001:5`). Observe and act on one
persistent MCP connection. A one-shot CLI call cannot reuse a token.
- **A locked screen blocks all input; window capture still works.** With the