The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(display): display.lease.release without a viewer_id no longer yanks another viewer's lease
teknium196431d8239c3
diff --git a/tests/tui_gateway/test_display_methods.py b/tests/tui_gateway/test_display_methods.pyindex 8a863821894..e6aa3287e86 100644--- a/tests/tui_gateway/test_display_methods.py+++ b/tests/tui_gateway/test_display_methods.py@@ -60,3 +60,16 @@ def test_thumbnail_is_suppressed_while_a_human_holds_the_lease(monkeypatch, _fre_fresh_lease.release("viewer-1")assert _call(server, "display.thumbnail", {})["result"]["data_url"].endswith("SECRET")++def test_release_without_viewer_id_cannot_yank_another_viewers_lease(_fresh_lease):+ """lease.release(None) skips the holder check, so a client that lost its viewer id (or a bare RPC)+ must be refused unless it forces; a matching viewer id and force keep working."""+ import tui_gateway.server as server++ _fresh_lease.acquire("viewer-1")+ refused = _call(server, "display.lease.release", {})+ assert refused["error"]["data"]["code"] == "viewer_mismatch"+ assert _fresh_lease.get().holder == _fresh_lease.HUMAN+ assert _call(server, "display.lease.release", {"viewer_id": "viewer-1"})["result"]["lease"]["holder"] == _fresh_lease.AGENT+ _fresh_lease.acquire("viewer-2")+ assert _call(server, "display.lease.release", {"force": True})["result"]["lease"]["holder"] == _fresh_lease.AGENTdiff --git a/tui_gateway/methods_display.py b/tui_gateway/methods_display.pyindex aae515fe43f..37d0248dd37 100644--- a/tui_gateway/methods_display.py+++ b/tui_gateway/methods_display.py@@ -174,6 +174,11 @@ def _(rid, params: dict) -> dict:def _(rid, params: dict) -> dict:from tools.bot_desktop import lease as _bd_leaseviewer_id = str(params.get("viewer_id") or "").strip() or None+ # lease.release(None) skips the holder check; a client that lost its viewer id must not be able to+ # yank control from whoever holds it unless it says so explicitly (force).+ if viewer_id is None and not params.get("force") and _bd_lease.human_holds():+ 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()})