The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-desktop): a killed sleep or check no longer ends the screen's self-stop
kshitijk4poordacca6272f8d
diff --git a/tests/tools/test_bot_desktop_idle_self_stop.py b/tests/tools/test_bot_desktop_idle_self_stop.pyindex fafcf017e76..8867ae9d401 100644--- a/tests/tools/test_bot_desktop_idle_self_stop.py+++ b/tests/tools/test_bot_desktop_idle_self_stop.py@@ -150,6 +150,23 @@ def test_a_self_stop_does_not_sit_out_the_kill_grace(abandoned_screen):assert time.monotonic() - began < 3, "the self-stop waited for stop()'s SIGKILL grace"+def test_a_killed_sleep_does_not_end_the_self_stop(abandoned_screen):+ """The watch loop ran under the launcher's ``set -e``: a sleep killed from outside made ``wait`` fail and+ ended the loop silently, so that screen never stopped itself."""+ import psutil+ _, launcher = abandoned_screen(idle_stop_minutes=0.15) # the first check is due 9 s after start++ def first_sleep():+ for proc in psutil.process_iter(["cmdline"]):+ with contextlib.suppress(psutil.Error):+ if proc.info["cmdline"] == ["sleep", "9"] and os.getpgid(proc.pid) == launcher:+ return proc+ return None++ wait_until(first_sleep, timeout=10, what="the watch loop's first sleep").kill()+ wait_until(lambda: not _alive(launcher), timeout=60, what="the screen to stop itself after its sleep was killed")++def test_a_screen_in_use_is_kept_and_a_returning_gateway_reattaches(abandoned_screen, monkeypatch):from hermes_constants import reset_hermes_home_override, set_hermes_home_overridefrom tools.bot_desktop import runtimediff --git a/tools/bot_desktop/launcher.sh b/tools/bot_desktop/launcher.shindex c23b05c403a..ef963da6d20 100755--- a/tools/bot_desktop/launcher.sh+++ b/tools/bot_desktop/launcher.sh@@ -294,6 +294,9 @@ if [[ -n "${HERMES_BD_IDLE_CMD:-}" ]]; then# Sleep first: a screen just started cannot be idle, so the first check is due a window from now# (runtime.py passes that delay), not while Xfce is still coming up.(+ # Not under the launcher's `set -e`: a sleep or check killed from outside (a stray pkill, the OOM killer)+ # makes `wait` fail, and that must cost at most one slow retry, not the self-stop for the rest of the screen's life.+ set +esleeper=trap 'kill $sleeper 2>/dev/null; exit 0' TERMout="$(dirname "$HERMES_BD_ENV_FILE")/idle-watch.out"@@ -301,7 +304,8 @@ if [[ -n "${HERMES_BD_IDLE_CMD:-}" ]]; thenwhile :; do[[ "$delay" =~ ^[0-9]+$ ]] || delay=300sleep "$delay" & sleeper=$!- wait "$sleeper"+ # Killed (status > 128): check now. A sleep that cannot sleep at all would spin the check: give up.+ wait "$sleeper" || (( $? > 128 )) || { echo "idle self-stop: sleep failed; off for this screen" >&2; exit 0; }sleeper=kill -0 "$$" 2>/dev/null || exit 0eval "set -- $HERMES_BD_IDLE_CMD"