The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-desktop): a short idle window never times out a human between two viewer stamps
kshitijk4poorea25df6e570f
diff --git a/tests/tools/test_bot_desktop_idle.py b/tests/tools/test_bot_desktop_idle.pyindex d16b636cff8..6aa1e9b7847 100644--- a/tests/tools/test_bot_desktop_idle.py+++ b/tests/tools/test_bot_desktop_idle.py@@ -65,6 +65,22 @@ def test_a_human_lease_keeps_the_screen_until_nothing_has_used_it_for_four_windoassert runtime.stop_if_idle() is True and stops == [True], "abandoned: no use for four windows"+def test_a_short_window_never_times_out_a_human_between_two_viewer_stamps(tmp_path, monkeypatch):+ """An attached viewer stamps activity at most once a minute (and the panel clock repaints once a+ minute), so stamps can be about two minutes apart. With idle_stop_minutes: 0.1 four windows are+ 24 s: the human's screen must not be stopped in that gap."""+ sd, stops = _running(monkeypatch, tmp_path)+ monkeypatch.setattr(runtime, "idle_stop_seconds", lambda: 6.0)+ monkeypatch.setattr(lease, "get", lambda profile_key=None: lease.Lease(holder=lease.HUMAN, viewer_id="v1"))+ (sd / "activity").touch()++ _age(sd / "activity", 150)+ assert runtime.stop_if_idle() is False and stops == [], "a human between two viewer stamps was timed out"++ _age(sd / "activity", runtime.HUMAN_LEASE_ABANDONED_MIN_S + 60)+ assert runtime.stop_if_idle() is True and stops == [True], "abandoned: no use past the floor"++def test_idle_stop_disabled_by_zero(tmp_path, monkeypatch):sd, stops = _running(monkeypatch, tmp_path)monkeypatch.setattr(runtime, "idle_stop_seconds", lambda: 0.0)diff --git a/tests/tools/test_bot_desktop_idle_self_stop.py b/tests/tools/test_bot_desktop_idle_self_stop.pyindex 98412f2a841..fafcf017e76 100644--- a/tests/tools/test_bot_desktop_idle_self_stop.py+++ b/tests/tools/test_bot_desktop_idle_self_stop.py@@ -154,7 +154,7 @@ def test_a_screen_in_use_is_kept_and_a_returning_gateway_reattaches(abandoned_scfrom hermes_constants import reset_hermes_home_override, set_hermes_home_overridefrom tools.bot_desktop import runtime- sd, launcher = abandoned_screen(idle_stop_minutes=0.1) # 6 s; a human lease lapses after 4 windows (24 s)+ sd, launcher = abandoned_screen(idle_stop_minutes=0.1) # 6 s; a human lease lapses after 10 min (the floor over 4 windows)log = sd / "launcher.log"def checks_kept() -> int:@@ -186,7 +186,7 @@ def test_a_screen_in_use_is_kept_and_a_returning_gateway_reattaches(abandoned_scwait_until(lambda: checks_kept() >= seen + 1, timeout=30, what="an idle check while a human holds the screen")assert _alive(launcher)- # ...but a human lease nothing has used for four windows (the viewer's link dropped and never came back)+ # ...but a human lease nothing has used past its lapse (the viewer's link dropped and never came back)# no longer keeps it.old = time.time() - 3600os.utime(sd / "activity", (old, old))diff --git a/tools/bot_desktop/runtime.py b/tools/bot_desktop/runtime.pyindex f4dcd254b71..8308fb60b1d 100644--- a/tools/bot_desktop/runtime.py+++ b/tools/bot_desktop/runtime.py@@ -426,9 +426,12 @@ def _should_auto_start(env: dict[str, str]) -> bool:DEFAULT_IDLE_STOP_MINUTES = 30# A human holding the screen is never timed out while there is evidence of one: an attached viewer stamps# ``activity`` (every RFB update it receives, at most once a minute; the panel clock repaints every minute).-# A human lease with no stamp for this many windows is a link that dropped and never came back, or a-# corrupt lease file (which reads as human): the screen is stopped like any idle one.+# A human lease with no stamp for this many windows, and never less than HUMAN_LEASE_ABANDONED_MIN_S, is+# a link that dropped and never came back, or a corrupt lease file (which reads as human): the screen is+# stopped like any idle one. The floor keeps a short window (idle_stop_minutes: 0.1) from timing out a+# human between two viewer stamps, which can be up to about two minutes apart.HUMAN_LEASE_ABANDONED_WINDOWS = 4+HUMAN_LEASE_ABANDONED_MIN_S = 600.0def touch_activity() -> None:@@ -475,14 +478,16 @@ def _idle_due(launcher: Optional[tuple[int, float]]) -> Optional[float]:if idle is None or idle < limit:return Nonefrom tools.bot_desktop import lease as _bd_lease- if _bd_lease.get().holder == _bd_lease.HUMAN and idle < limit * HUMAN_LEASE_ABANDONED_WINDOWS:+ abandoned_after = max(limit * HUMAN_LEASE_ABANDONED_WINDOWS, HUMAN_LEASE_ABANDONED_MIN_S)+ if _bd_lease.get().holder == _bd_lease.HUMAN and idle < abandoned_after:return Nonereturn idledef stop_if_idle(launcher: Optional[tuple[int, float]] = None) -> bool:"""Stop this profile's screen when it has been idle past the limit and no human holds it (a human lease- with no use for ``HUMAN_LEASE_ABANDONED_WINDOWS`` windows counts as abandoned). True when+ with no use for ``HUMAN_LEASE_ABANDONED_WINDOWS`` windows, and at least ``HUMAN_LEASE_ABANDONED_MIN_S``,+ counts as abandoned). True whenit was stopped. ``launcher`` names the screen the caller judges (the launcher's own check passes it).The decision is taken again under ``start.lock`` before anything is killed: a check that waited on thediff --git a/website/docs/user-guide/features/bot-screen.md b/website/docs/user-guide/features/bot-screen.mdindex 6b815fc4abf..8a0a9747b42 100644--- a/website/docs/user-guide/features/bot-screen.md+++ b/website/docs/user-guide/features/bot-screen.md@@ -93,7 +93,8 @@ reverse proxy's access log may record an already-spent ticket.applies that window itself too, so it also stops when the gateway thatstarted it is gone and never restarts. A screen a human has taken over iskept while their viewer keeps it in use; once nothing has used it for four- windows (a viewer whose link dropped and never came back) it stops as well.+ windows, and at least 10 minutes (a viewer whose link dropped and never came+ back), it stops as well.Practical guidancefor small instances: 4 GB runs the desktop, 8 GB is where a takeover with abrowser is comfortable.