Skip to content

The agent that grows with you

fix(update): bound optional cua-driver refresh

blunkjamie-dev105cea64f721
diff --git a/hermes_cli/tools_config.py b/hermes_cli/tools_config.py
index 9a92fe77f43..0df022443a4 100644
--- a/hermes_cli/tools_config.py
+++ b/hermes_cli/tools_config.py
@@ -1013,6 +1013,11 @@ def install_cua_driver(
``hermes update`` already prints a contextual line before its update
check, so it disables this to avoid printing the refresh twice.
+ The confirmed-update path is also bounded by
+ ``_CUA_BACKGROUND_UPDATE_TIMEOUT``. It runs as an optional, quiet part of
+ ``hermes update`` and must not inherit the explicit install command's
+ 11-minute ceiling when an upstream prompt or UAC dialog is unattended.
+
Returns True iff cua-driver is installed (or successfully refreshed)
when the function returns. Supported on macOS, Windows, and Linux
(Linux is alpha). Silently returns False on unsupported platforms.
@@ -1255,6 +1260,11 @@ def install_cua_driver(
verbose=False,
pin_version=confirmed_version,
show_progress=show_installer_progress,
+ installer_timeout=(
+ _CUA_BACKGROUND_UPDATE_TIMEOUT
+ if require_confirmed_update
+ else None
+ ),
)
if ok and repair_existing:
repaired = _cua_driver_contract_status()
@@ -1300,6 +1310,13 @@ _CUA_INSTALLER_TIMEOUT = 660
# normal case; it only caps how long a failed one can stall the update.
_CUA_INSTALLER_DRAIN_GRACE = 15
+# Optional refreshes launched by ``hermes update`` are quiet and unattended.
+# Keep their interruption bounded even when upstream waits on Read-Host or a
+# consent prompt. Explicit ``computer-use install --upgrade`` runs retain the
+# full installer ceiling above. (The lock/network preflights below make a
+# legitimate long wait impossible on this path, so a short ceiling is safe.)
+_CUA_BACKGROUND_UPDATE_TIMEOUT = 120
+
# Upstream installer's stale-lock threshold (LOCK_STALE_AFTER_SECONDS in
# _install-rust.sh). Used by the pre-clear below to avoid yanking a lock
# that a live-but-slow install still holds.
@@ -1552,6 +1569,7 @@ def _run_cua_driver_installer(
verbose: bool = True,
pin_version: Optional[str] = None,
show_progress: bool = True,
+ installer_timeout: Optional[float] = None,
) -> bool:
"""Run the upstream cua-driver installer for this platform.
@@ -1568,6 +1586,9 @@ def _run_cua_driver_installer(
is bumped by Release Please *before* the release assets are published,
so an unpinned run inside that window fails with a 404; pinning to the
version ``check-update`` confirmed sidesteps the race entirely.
+
+ ``installer_timeout`` lets quiet callers use a shorter ceiling without
+ weakening the explicit install path's stale-lock recovery window.
"""
import platform as _plat
import shutil
@@ -1639,6 +1660,11 @@ def _run_cua_driver_installer(
else:
_print_info(f"→ {label} cua-driver (Computer Use)...")
driver_cmd = _cua_driver_cmd()
+ timeout = (
+ _CUA_INSTALLER_TIMEOUT
+ if installer_timeout is None
+ else installer_timeout
+ )
installer_env = _cua_driver_env()
if pin_version:
@@ -1761,7 +1787,7 @@ def _run_cua_driver_installer(
**popen_kwargs
)
try:
- proc.communicate(timeout=_CUA_INSTALLER_TIMEOUT)
+ proc.communicate(timeout=timeout)
except subprocess.TimeoutExpired:
_reap_after_timeout(proc)
raise
@@ -1778,7 +1804,7 @@ def _run_cua_driver_installer(
**popen_kwargs
)
try:
- out, _ = proc.communicate(timeout=_CUA_INSTALLER_TIMEOUT)
+ out, _ = proc.communicate(timeout=timeout)
except subprocess.TimeoutExpired:
_reap_after_timeout(proc)
raise
@@ -1831,7 +1857,7 @@ def _run_cua_driver_installer(
except subprocess.TimeoutExpired:
_print_warning(
f" cua-driver {label.lower()} timed out after "
- f"{_CUA_INSTALLER_TIMEOUT}s."
+ f"{timeout}s."
)
if not is_windows:
_print_info(
diff --git a/tests/hermes_cli/test_install_cua_driver.py b/tests/hermes_cli/test_install_cua_driver.py
index 65b90dcd9ea..1a3228c7e6d 100644
--- a/tests/hermes_cli/test_install_cua_driver.py
+++ b/tests/hermes_cli/test_install_cua_driver.py
@@ -239,6 +239,46 @@ class TestInstallCuaDriverUpgrade:
info.assert_not_called()
+ def test_quiet_refresh_closes_stdin_and_honors_custom_timeout(self):
+ """A background refresh must neither wait on a hidden prompt nor
+ inherit the explicit install command's 11-minute ceiling."""
+ import subprocess
+ from unittest.mock import MagicMock
+
+ from hermes_cli import tools_config
+
+ fake_proc = MagicMock()
+ fake_proc.pid = 1
+ fake_proc.returncode = 0
+ fake_proc.communicate.return_value = ("", None)
+
+ with patch(
+ "subprocess.run",
+ return_value=MagicMock(returncode=0, stderr=""),
+ ), \
+ patch("subprocess.Popen", return_value=fake_proc) as popen, \
+ patch.object(
+ tools_config.shutil,
+ "which",
+ return_value="/usr/local/bin/cua-driver",
+ ), \
+ patch.object(tools_config, "_clear_stale_cua_install_lock"), \
+ patch.object(
+ tools_config,
+ "_repair_cua_driver_autostart_windows",
+ return_value=True,
+ ), \
+ patch.object(tools_config, "_print_info"), \
+ patch.object(tools_config, "_print_success"):
+ assert tools_config._run_cua_driver_installer(
+ label="Refreshing",
+ verbose=False,
+ installer_timeout=120,
+ ) is True
+
+ assert popen.call_args.kwargs["stdin"] is subprocess.DEVNULL
+ fake_proc.communicate.assert_called_once_with(timeout=120)
+
def test_upgrade_can_suppress_installer_progress(self):
from hermes_cli import tools_config
@@ -517,6 +557,7 @@ class TestRequireConfirmedUpdate:
ok, runner, _ = self._install(state, require_confirmed=True)
assert ok is True
runner.assert_called_once()
+ assert runner.call_args.kwargs["installer_timeout"] == 120
@pytest.mark.windows_only
def test_windows_confirmed_update_defers_interactive_installer(self):
@@ -1049,6 +1090,10 @@ class TestInstallerTimeoutKillsProcessGroup:
parent.kill.assert_called_once_with()
fake_proc.kill.assert_not_called()
assert fake_proc.communicate.call_count == 2
+ assert (
+ fake_proc.communicate.call_args_list[1].kwargs["timeout"]
+ == tools_config._CUA_INSTALLER_REAP_TIMEOUT
+ )
@pytest.mark.windows_only
def test_windows_tree_enumeration_failure_falls_back_to_direct_kill(self):