The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-screen): wire lane call sites: atomic install claim, redacted lease views everywhere, backend rebind on display change, footgun annotations, grace in schema
teknium116289e22f7e5
diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex d379c5763ac..74cf272b8c2 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -2256,7 +2256,7 @@ DEFAULT_CONFIG = {"paste_collapse_char_threshold": 2000,# Bot Desktop: a headless Xfce screen per profile on the gateway host (Linux), streamed to Hermes- # Desktop where a human can watch, take over (logins, 2FA, CAPTCHAs) and hand back. `hermes desktop`.+ # Desktop where a human can watch, take over (logins, 2FA, CAPTCHAs) and hand back. `hermes computer-use screen`."bot_desktop": {"geometry": "1440x900",# Opt-in: start the screen automatically the first time computer_use needs a display on a headlessdiff --git a/hermes_cli/pty_bridge.py b/hermes_cli/pty_bridge.pyindex 90d6a61a6c3..2788eb9ecee 100644--- a/hermes_cli/pty_bridge.py+++ b/hermes_cli/pty_bridge.py@@ -10,13 +10,13 @@ from __future__ import annotationsimport asyncioimport errno-import fcntl+import fcntl # windows-footgun: ok — POSIX-only module by design (see docstring)import osimport selectimport signalimport structimport sys-import termios+import termios # windows-footgun: ok — POSIX-only module by design (see docstring)import timefrom typing import Optional, Sequencediff --git a/scripts/profile-tui.py b/scripts/profile-tui.pyindex 4d86aa057bf..a59b76659d8 100755--- a/scripts/profile-tui.py+++ b/scripts/profile-tui.py@@ -26,7 +26,7 @@ from __future__ import annotationsimport argparseimport jsonimport os-import pty+import pty # windows-footgun: ok — dev profiling script, POSIX pty by designimport selectimport signalimport sqlite3diff --git a/tools/computer_use/schema.py b/tools/computer_use/schema.pyindex e984bfe3f60..880d9bdc582 100644--- a/tools/computer_use/schema.py+++ b/tools/computer_use/schema.py@@ -153,6 +153,7 @@ _PROPERTIES: Dict[str, Any] = {),},"seconds": {"type": "number", "description": "wait: seconds to pause (max 30). wait_for_human: how long to block for the hand-back (default 600, max 1800)."},+ "grace": {"type": "number", "description": "wait_for_human: seconds to wait for someone to take over before returning no_takeover (default 60); once a human holds control the full `seconds` applies."},"raise_window": {"type": "boolean","description": (diff --git a/tools/computer_use/tool.py b/tools/computer_use/tool.pyindex 04b6715795c..32f892db38c 100644--- a/tools/computer_use/tool.py+++ b/tools/computer_use/tool.py@@ -79,6 +79,7 @@ _backend: Optional[ComputerUseBackend] = None # backward-compatible empty-sessi_backends: Dict[str, ComputerUseBackend] = {}_backend_call_locks: Dict[str, threading.RLock] = {}_backend_permission_modes: Dict[str, str] = {}+_backend_displays: Dict[str, str] = {} # DISPLAY the cached backend was spawned against (Bot Desktop rebind)# (home key, provider, model) → bool. The decision reads the active profile's config (auxiliary.vision# override, declared supports_vision), so a multiplexed process must not serve profile A's verdict to B._AUX_VISION_ROUTE_CACHE: Dict[Tuple[str, str, str], bool] = {}@@ -133,7 +134,9 @@ def _install_backend(sid: str, backend: ComputerUseBackend, permission_mode: str"""Record a backend in the session caches (the empty session also mirrors it onto the ``_backend`` hook).Caller holds ``_backend_lock``."""global _backend+ from tools.computer_use.cua_backend import desktop_identity_backends[sid], _backend_permission_modes[sid] = backend, permission_mode+ _backend_displays[sid] = desktop_identity()_backend_call_locks[sid] = threading.RLock()_backend = backend if sid == "" else _backendreturn backend@@ -142,7 +145,7 @@ def _detach_locked(sid: str) -> Tuple[Optional[ComputerUseBackend], Optional[thr"""Remove one session's cache entries, plus the ``_backend`` injection hook when it aliases the empty session(older callers/tests may populate only the hook). Caller holds ``_backend_lock``."""global _backend- _backend_permission_modes.pop(sid, None)+ _backend_permission_modes.pop(sid, None), _backend_displays.pop(sid, None)backend, call_lock = _backends.pop(sid, None), _backend_call_locks.pop(sid, None)if sid == "":backend = _backend if backend is None else backend@@ -170,9 +173,12 @@ def _get_backend(session_id: str = "") -> ComputerUseBackend:backend = _new_backend(permission_mode)backend.start() # under the cache lock: one backend per session; a concurrent toggle releases itreturn _install_backend(sid, backend, permission_mode)- if _backend_permission_modes.get(sid, "standard") == permission_mode:+ from tools.computer_use.cua_backend import backend_display_stale, desktop_identity+ if (_backend_permission_modes.get(sid, "standard") == permission_mode+ and not backend_display_stale(_backend_displays.get(sid, ""), desktop_identity())):return cached- # Cua's mode is immutable after daemon startup: a /yolo toggle replaces only this session's backend.+ # Cua's mode and DISPLAY are fixed at daemon startup: a /yolo toggle, or a Bot Desktop that started+ # (or moved) after this backend was cached, replaces only this session's backend._, stale_lock = _detach_locked(sid) # stopped outside the cache lock; the loop re-reads the mode first_stop_backend(cached, stale_lock, lambda e: None)@@ -207,7 +213,7 @@ def _shutdown_backend_atexit() -> None:if _backend is not None:unique.setdefault(id(_backend), (_backend, _backend_call_locks.get("")))_backend = None- _backends.clear(), _backend_call_locks.clear(), _backend_permission_modes.clear()+ _backends.clear(), _backend_call_locks.clear(), _backend_permission_modes.clear(), _backend_displays.clear()with _approval_lock:_session_auto_approve.clear(), _always_allow.clear(), _escalation_warned.clear()for backend, call_lock in unique.values():diff --git a/tui_gateway/methods_display.py b/tui_gateway/methods_display.pyindex 38e4fba6976..660a8a685ff 100644--- a/tui_gateway/methods_display.py+++ b/tui_gateway/methods_display.py@@ -177,7 +177,7 @@ def _(rid, params: dict) -> dict:def _run() -> None:try:- code = _bd_install.install_packages(ask_password=_ask_password, on_line=_line)+ code = _bd_install.install_packages(ask_password=_ask_password, on_line=_line, claimed=True)except Exception as e:_line(f"install failed: {e}")code = 1@@ -185,7 +185,7 @@ def _(rid, params: dict) -> dict:"status": _display_snapshot()})try:- _bd_install.assert_not_running()+ _bd_install.claim() # atomic: two fast clicks cannot both start a package managerexcept _bd_install.InstallBusy as e:return _err(rid, _DISPLAY_ERR, str(e))threading.Thread(target=ctx.run, args=(_run,), name=f"bot-desktop-install:{profile_key}", daemon=True).start()@@ -200,7 +200,7 @@ def _(rid, params: dict) -> dict:if not viewer_id:return _err(rid, _DISPLAY_ERR, "viewer_id required")lease = _bd_lease.acquire(viewer_id, reason=str(params.get("reason") or ""))- return _ok(rid, {"lease": lease.as_dict()})+ return _ok(rid, {"lease": _lease_view(lease)})@method("display.lease.release")@@ -214,7 +214,7 @@ def _(rid, params: dict) -> dict:return _err(rid, _DISPLAY_ERR, "viewer_id required to release another viewer's lease (or pass force: true)",data={"code": "viewer_mismatch"})lease = _bd_lease.release(viewer_id)- return _ok(rid, {"lease": lease.as_dict()})+ return _ok(rid, {"lease": _lease_view(lease)})def register(server) -> None:diff --git a/tui_gateway/methods_display_watch.py b/tui_gateway/methods_display_watch.pyindex 7c0efb16221..3050d08b767 100644--- a/tui_gateway/methods_display_watch.py+++ b/tui_gateway/methods_display_watch.py@@ -26,8 +26,9 @@ _lease_mtimes: dict[str, int | None] = {}def _lease_event_payload(profile_key: str, lease) -> dict:- # Mirrors methods_display._install_lease_listener's nested payload; keep the two in step.- return {"profile_key": profile_key, "lease": lease.as_dict()}+ # Same shape and the same redaction (viewer_hash, never the raw id) as the in-process broadcast.+ from tui_gateway.methods_display import _lease_view+ return {"profile_key": profile_key, "lease": _lease_view(lease)}def _watched_lease_homes() -> list[Path]: