Skip to content

The agent that grows with you

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.py
index 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 os
import threading
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
@@ -78,8 +79,14 @@ def test_discovery_refuses_unsupported_owner_without_releasing_lease(tmp_path, m
assert details.startswith("Details: ")
assert active_session_registry_snapshot(tmp_path)[0]["lease_id"] == lease.lease_id
registry = 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.py
index 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_path
assert 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 logging
records = []
@@ -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 cadence
guarded("live", session, now)
- assert len(attempts) == 4
warnings = [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.py
index 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 + 1
logger.debug("Bot live-owner delivery poll failed (repeat)", exc_info=True)
- return False
+ return
session["_bot_poll_warned_at"], session["_bot_poll_warn_suppressed"] = now, 0
logger.warning("Bot live-owner delivery poll failed (%d repeat(s) suppressed since the last report)",
suppressed, exc_info=True)
- return False
+ return
session["_bot_poll_warn_suppressed"] = 0
- return started
def _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, sess
last_kanban_poll = last_loop_poll = last_bot_poll = 0.0
while 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: