The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): drop the no-op drain reset; model a foreign owner in the denied-inspection attach test
kshitijk4poor0caf219aafdf
diff --git a/tests/hermes_cli/test_shared_session_attach.py b/tests/hermes_cli/test_shared_session_attach.pyindex b1a01a0715f..8161b618bdb 100644--- a/tests/hermes_cli/test_shared_session_attach.py+++ b/tests/hermes_cli/test_shared_session_attach.py@@ -1,6 +1,7 @@"""Local owner discovery must fence profile and lease identity."""import json+import osimport threadingfrom http.server import BaseHTTPRequestHandler, ThreadingHTTPServer@@ -78,8 +79,14 @@ def test_discovery_refuses_unsupported_owner_without_releasing_lease(tmp_path, massert details.startswith("Details: ")assert active_session_registry_snapshot(tmp_path)[0]["lease_id"] == lease.lease_idregistry = tmp_path / "runtime" / "active_sessions.json"- before = registry.read_bytes()with monkeypatch.context() as patch:+ # Our own pid is never probed (#108005), so model a FOREIGN owner whose inspection is denied.+ from hermes_cli.active_sessions import _read_entries, _write_entries+ entries = _read_entries(registry)+ entries[0]["pid"] = os.getpid() + 2**22+ _write_entries(registry, entries)+ before = registry.read_bytes()+def denied(pid):raise PermissionError("process inspection denied")patch.setattr("gateway.status._pid_exists", denied)diff --git a/tests/tui_gateway/test_bot_live_owner_delivery.py b/tests/tui_gateway/test_bot_live_owner_delivery.pyindex a0ec4b1fd6f..2e6263ad16e 100644--- a/tests/tui_gateway/test_bot_live_owner_delivery.py+++ b/tests/tui_gateway/test_bot_live_owner_delivery.py@@ -119,8 +119,8 @@ def test_mailbox_poll_skips_owner_lookup_without_a_mailbox(monkeypatch, tmp_pathassert lookups == [tmp_path]-def test_failing_mailbox_poll_backs_off_and_warns_once_per_window():- """A failing poll is retried only after the backoff and logged at WARNING once per window."""+def test_failing_mailbox_poll_warns_once_per_window():+ """A failing poll is logged at WARNING once per window; repeats within it are counted, not logged."""import loggingrecords = []@@ -143,7 +143,6 @@ def test_failing_mailbox_poll_backs_off_and_warns_once_per_window():session = {}for now in (0.0, 6.0, 12.0, 61.0): # the poller calls at _BOT_DELIVERY_POLL_SECONDS cadenceguarded("live", session, now)- assert len(attempts) == 4warnings = [r for r in records if r.levelno == logging.WARNING]assert [r.getMessage() for r in warnings] == ["Bot live-owner delivery poll failed (0 repeat(s) suppressed since the last report)",diff --git a/tui_gateway/session_notifications.py b/tui_gateway/session_notifications.pyindex aadd39e0e33..b771e8c8205 100644--- a/tui_gateway/session_notifications.py+++ b/tui_gateway/session_notifications.py@@ -655,26 +655,24 @@ def _poll_bot_live_delivery_once(sid: str, session: dict) -> bool:_BOT_POLL_WARN_INTERVAL_S = 60.0-def _poll_bot_live_delivery_guarded(sid: str, session: dict, now: float) -> bool:- """One poller-loop pass of the mailbox poll. Returns True when a delivery turn was started, so the- caller can poll again at tick cadence while the mailbox is draining. A failure is logged at WARNING- once per ``_BOT_POLL_WARN_INTERVAL_S`` (with the count of suppressed repeats) and at DEBUG otherwise.- An unthrottled poll logged ``Bot live-owner delivery poll failed`` ~2×/minute per session for days,+def _poll_bot_live_delivery_guarded(sid: str, session: dict, now: float) -> None:+ """One poller-loop pass of the mailbox poll. A failure is logged at WARNING once per+ ``_BOT_POLL_WARN_INTERVAL_S`` (with the count of suppressed repeats) and at DEBUG otherwise. An+ unthrottled poll logged ``Bot live-owner delivery poll failed`` ~2×/minute per session for days,91% of an install's WARNING output (#111719)."""try:- started = _poll_bot_live_delivery_once(sid, session)+ _poll_bot_live_delivery_once(sid, session)except Exception:suppressed = int(session.get("_bot_poll_warn_suppressed", 0))if now - session.get("_bot_poll_warned_at", -_BOT_POLL_WARN_INTERVAL_S) < _BOT_POLL_WARN_INTERVAL_S:session["_bot_poll_warn_suppressed"] = suppressed + 1logger.debug("Bot live-owner delivery poll failed (repeat)", exc_info=True)- return False+ returnsession["_bot_poll_warned_at"], session["_bot_poll_warn_suppressed"] = now, 0logger.warning("Bot live-owner delivery poll failed (%d repeat(s) suppressed since the last report)",suppressed, exc_info=True)- return False+ returnsession["_bot_poll_warn_suppressed"] = 0- return starteddef _notification_poller_loop(stop_event: threading.Event, sid: str, session: dict) -> None:@@ -700,9 +698,9 @@ def _notification_poller_scoped_loop(stop_event: threading.Event, sid: str, sesslast_kanban_poll = last_loop_poll = last_bot_poll = 0.0while not stop_event.is_set() and not session.get("_finalized"):now = time.monotonic()- if now - last_bot_poll >= _BOT_DELIVERY_POLL_SECONDS:- # A mailbox that just handed out a turn drains at tick cadence; an idle one waits the full window.- last_bot_poll = 0.0 if _poll_bot_live_delivery_guarded(sid, session, now) else now+ if now - last_bot_poll >= _BOT_DELIVERY_POLL_SECONDS: # bot DM → live-owner delivery latency ≤ 5 s+ last_bot_poll = now+ _poll_bot_live_delivery_guarded(sid, session, now)# /loop and /heartbeat wakeup drivers: fire a due tick for THIS session while idle (same claim-under-lock# as kanban dispatch). An active non-parked /goal owns the idle boundary and defers the loop tick.if now - last_loop_poll >= _LOOP_POLL_SECONDS: