Skip to content

The agent that grows with you

fix(tests): idle-proof live test waits for the startup cron tick to drain

teknium141456ea82eb4
diff --git a/tests/hermes_cli/test_web_server_idle_proof.py b/tests/hermes_cli/test_web_server_idle_proof.py
index 30c6aa1e21f..f6b9384512b 100644
--- a/tests/hermes_cli/test_web_server_idle_proof.py
+++ b/tests/hermes_cli/test_web_server_idle_proof.py
@@ -12,6 +12,7 @@ import socket
import subprocess
import sys
import threading
+import time
import urllib.error
import urllib.request
import json
@@ -168,6 +169,18 @@ def _probe(port: int, token: str | None = TOKEN) -> tuple[int, dict]:
return exc.code, {}
+def _await_verdict(port: int, accept, timeout: float = 60.0) -> tuple[tuple[int, dict], list]:
+ """Probe until ``accept(verdict)`` or the deadline; returns the last verdict and every one seen."""
+ deadline = time.monotonic() + timeout
+ seen: list[tuple[int, dict]] = []
+ while True:
+ verdict = _probe(port)
+ seen.append(verdict)
+ if accept(verdict) or time.monotonic() >= deadline:
+ return verdict, seen
+ time.sleep(0.2)
+
+
@pytestmark_live
def test_live_pooled_children_prove_idle_or_busy_over_the_desktop_probe(tmp_path):
"""Three real children at the Desktop's pool cap; exactly one is busy. The Desktop's probe
@@ -186,11 +199,19 @@ def test_live_pooled_children_prove_idle_or_busy_over_the_desktop_probe(tmp_path
ready_line = next(l for l in lines if "HERMES_BACKEND_READY" in l)
ports[name] = int(ready_line.strip().rsplit("port=", 1)[1])
- verdicts = {name: _probe(port) for name, port in ports.items()}
- assert verdicts["resident-a"] == (200, {"ok": True, "idle": True, "reason": None}), verdicts
- assert verdicts["resident-b"] == (200, {"ok": True, "idle": True, "reason": None}), verdicts
- assert verdicts["cron-busy"] == (200, {
- "ok": True, "idle": False, "reason": "turn_in_flight", "detail": "cron:live-idle-proof-job"}), verdicts
+ # READY precedes quiescence: the desktop child's cron ticker runs its first tick right at
+ # start and holds retirement admission through the whole scan (``retirement_admission``),
+ # which on a loaded runner outlasts the first probe. A resident is "provably idle" once that
+ # startup work drains, so wait for the idle verdict instead of sampling once.
+ idle = (200, {"ok": True, "idle": True, "reason": None})
+ for name in ("resident-a", "resident-b"):
+ verdict, seen = _await_verdict(ports[name], lambda v: v == idle)
+ assert verdict == idle, f"{name} never proved idle; observed: {seen}"
+ busy = (200, {"ok": True, "idle": False, "reason": "turn_in_flight", "detail": "cron:live-idle-proof-job"})
+ verdict, seen = _await_verdict(ports["cron-busy"], lambda v: v == busy)
+ assert verdict == busy, f"cron-busy never named its ledger; observed: {seen}"
+ # Whatever startup work shadowed the cron ledger, the busy child never once claimed idle.
+ assert all(body.get("idle") is False for _status, body in seen), seen
status, body = _probe(ports["resident-a"], token=None)
assert status == 401 and "idle" not in body