Skip to content

The agent that grows with you

fix(bot-desktop): an infinite idle window is off and never fails start()

kshitijk4poor8f40eac43852
diff --git a/tests/tools/test_bot_desktop_idle.py b/tests/tools/test_bot_desktop_idle.py
index f6c587b36ff..61366e15f1f 100644
--- a/tests/tools/test_bot_desktop_idle.py
+++ b/tests/tools/test_bot_desktop_idle.py
@@ -88,6 +88,17 @@ def test_idle_stop_disabled_by_zero(tmp_path, monkeypatch):
assert runtime.stop_if_idle() is False and stops == []
+def test_an_infinite_idle_window_is_off_and_never_overflows_the_next_check(monkeypatch):
+ """``idle_stop_minutes: .inf`` meant "never stop" before the self-stop; the launcher's first-check delay
+ is computed from it in start(), where an infinite window raised OverflowError."""
+ from hermes_cli import config
+ from tools.bot_desktop.idle_watch import next_check_in
+ for minutes in (float("inf"), 1e308): # 1e308 is finite, but not in seconds
+ monkeypatch.setattr(config, "load_config_readonly", lambda m=minutes: {"bot_desktop": {"idle_stop_minutes": m}})
+ assert runtime.idle_stop_seconds() == 0.0, minutes
+ assert next_check_in(runtime.idle_stop_seconds(), 0.0) == 1800 # off: the setting is re-read in 30 min
+
+
def test_the_launchers_idle_check_sleeps_until_the_screen_could_be_due():
from tools.bot_desktop.idle_watch import next_check_in
assert next_check_in(1800, 600) == 1200 # wakes when the window runs out at the current age
diff --git a/tools/bot_desktop/runtime.py b/tools/bot_desktop/runtime.py
index 8308fb60b1d..08279bed733 100644
--- a/tools/bot_desktop/runtime.py
+++ b/tools/bot_desktop/runtime.py
@@ -16,6 +16,7 @@ from __future__ import annotations
import contextlib
import logging
+import math
import os
import shlex
import shutil
@@ -461,7 +462,10 @@ def idle_stop_seconds() -> float:
minutes = float(cfg.get("idle_stop_minutes", DEFAULT_IDLE_STOP_MINUTES))
except (TypeError, ValueError):
minutes = DEFAULT_IDLE_STOP_MINUTES
- return max(0.0, minutes) * 60
+ # .inf ("never") is off, like 0, and so are .nan and a window too large to convert to seconds (1e308): none
+ # can ever be due, and the launcher's next-check arithmetic would raise on them and fail start().
+ seconds = minutes * 60
+ return seconds if math.isfinite(seconds) and seconds > 0 else 0.0
def _idle_due(launcher: Optional[tuple[int, float]]) -> Optional[float]: