The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-desktop): lease reader fails closed on well-formed JSON of the wrong shape
teknium1a9d7e392cc6d
diff --git a/tests/tools/test_bot_desktop_lease.py b/tests/tools/test_bot_desktop_lease.pyindex f1ada766cef..50f948f46ad 100644--- a/tests/tools/test_bot_desktop_lease.py+++ b/tests/tools/test_bot_desktop_lease.py@@ -118,6 +118,13 @@ def test_unreadable_lease_file_fails_closed_and_takeover_keeps_the_agents_reasonlease.release(profile_key=home) # a successful write repairs itassert lease.get(profile_key=home).holder == lease.AGENT+ # Valid JSON of the wrong shape is just as untrustworthy as torn JSON: never read it as "agent holds".+ for wrong_shape in ("[]", "null", "5", "{}", '{"holder": "root"}'):+ path.write_text(wrong_shape, encoding="utf-8")+ assert lease.get(profile_key=home).holder == lease.HUMAN, wrong_shape+ lease.release(profile_key=home)+ assert lease.get(profile_key=home).holder == lease.AGENT+lease.request_handoff("log in to the bank, 2FA on your phone", profile_key=home)held = lease.acquire("desk-1", profile_key=home)assert held.pending_handoff is None and held.reason == "log in to the bank, 2FA on your phone"diff --git a/tools/bot_desktop/lease.py b/tools/bot_desktop/lease.pyindex f890677dc38..9aea7a63d89 100644--- a/tools/bot_desktop/lease.py+++ b/tools/bot_desktop/lease.py@@ -74,8 +74,13 @@ def _read(path: Path) -> Lease:return Lease(holder=HUMAN, viewer_id="unreadable-lease", reason="lease file unreadable")try:data = json.loads(raw)+ except ValueError:+ data = None+ if not isinstance(data, dict) or data.get("holder") not in (AGENT, HUMAN):+ return Lease(holder=HUMAN, viewer_id="unreadable-lease", reason="lease file corrupt")+ try:return Lease(**{k: v for k, v in data.items() if k in Lease.__dataclass_fields__})- except (ValueError, TypeError):+ except TypeError:return Lease(holder=HUMAN, viewer_id="unreadable-lease", reason="lease file corrupt")