The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(computer-use): display identity helpers for cached-backend rebind
teknium186cf1d760f73
diff --git a/tests/tools/test_computer_use_backend_rebind.py b/tests/tools/test_computer_use_backend_rebind.pynew file mode 100644index 00000000000..c2ca5b99071--- /dev/null+++ b/tests/tools/test_computer_use_backend_rebind.py@@ -0,0 +1,13 @@+"""A cached computer_use backend is bound to the display it spawned on; the identity helpers notice a change."""++from __future__ import annotations++from tools.computer_use import cua_backend+++def test_backend_display_identity_tracks_the_display_a_spawn_would_get():+ before = cua_backend.desktop_identity({"HOME": "/x"}) # no screen yet+ after = cua_backend.desktop_identity({"HOME": "/x", "DISPLAY": ":37"}) # Bot Desktop came up+ assert before == "" and after == ":37"+ assert cua_backend.backend_display_stale(before, after)+ assert not cua_backend.backend_display_stale(after, cua_backend.desktop_identity({"DISPLAY": ":37"}))diff --git a/tools/computer_use/cua_backend.py b/tools/computer_use/cua_backend.pyindex 812d7556092..d6075d2e7aa 100644--- a/tools/computer_use/cua_backend.py+++ b/tools/computer_use/cua_backend.py@@ -100,6 +100,18 @@ def _computer_use_max_image_dimension() -> Optional[int]:dim = 1456return dim if dim > 0 else None+def desktop_identity(env: Optional[Dict[str, str]] = None) -> str:+ """The screen a backend spawned from ``env`` acts on: its DISPLAY (``''`` when none). Recorded next to the+ cached backend so a Bot Desktop that starts (or restarts on another number) AFTER the backend was cached is+ noticed — the cached cua-driver still points at the old seat or at no display at all."""+ return str((cua_driver_child_env(env) if env is None else env).get("DISPLAY") or "")+++def backend_display_stale(recorded: str, current: str) -> bool:+ """True when a cached backend's recorded display identity no longer matches the one a fresh spawn would get."""+ return (recorded or "") != (current or "")++def cua_driver_child_env(base_env: Optional[Dict[str, str]] = None) -> Dict[str, str]:"""Env for spawning cua-driver: ``base_env`` (default ``os.environ``) plus ``CUA_DRIVER_RS_TELEMETRY_ENABLED=0``unless the user opted in, plus the native-Wayland bridge (``computer_use.native_wayland`` config opt-in, only when