d73ff9b0fb
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
Docker / shell lint / Lint Dockerfile (hadolint) (push) Has been cancelled
Docker / shell lint / Lint docker/ shell scripts (shellcheck) (push) Has been cancelled
Docker Build and Publish / build-amd64 (push) Has been cancelled
Docker Build and Publish / build-arm64 (push) Has been cancelled
Lint (ruff + ty) / ruff + ty diff (push) Has been cancelled
Lint (ruff + ty) / ruff enforcement (blocking) (push) Has been cancelled
Lint (ruff + ty) / Windows footguns (blocking) (push) Has been cancelled
Nix Lockfile Fix / auto-fix-main (push) Has been cancelled
Nix Lockfile Fix / fix (push) Has been cancelled
Nix / nix (macos-latest) (push) Has been cancelled
Nix / nix (ubuntu-latest) (push) Has been cancelled
OSV-Scanner / Scan lockfiles (push) Has been cancelled
Build Skills Index / build-index (push) Has been cancelled
Tests / test (1) (push) Has been cancelled
Tests / test (2) (push) Has been cancelled
Tests / test (3) (push) Has been cancelled
Tests / test (4) (push) Has been cancelled
Tests / test (5) (push) Has been cancelled
Tests / test (6) (push) Has been cancelled
Tests / e2e (push) Has been cancelled
uv.lock check / uv lock --check (push) Has been cancelled
Docker Build and Publish / merge (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
Tests / save-durations (push) Has been cancelled
61 lines
2.2 KiB
Python
61 lines
2.2 KiB
Python
"""Tests for the activity-heartbeat behavior of the blocking gateway approval wait.
|
|
|
|
Regression test for false gateway inactivity timeouts firing while the agent
|
|
is legitimately blocked waiting for a user to respond to a dangerous-command
|
|
approval prompt. Before the fix, ``entry.event.wait(timeout=...)`` blocked
|
|
silently — no ``_touch_activity()`` calls — and the gateway's inactivity
|
|
watchdog (``agent.gateway_timeout``, default 1800s) would kill the agent
|
|
while the user was still choosing whether to approve.
|
|
|
|
The fix polls the event in short slices and fires ``touch_activity_if_due``
|
|
between slices, mirroring ``_wait_for_process`` in ``tools/environments/base.py``.
|
|
"""
|
|
|
|
import os
|
|
|
|
|
|
def _clear_approval_state():
|
|
"""Reset all module-level approval state between tests."""
|
|
from tools import approval as mod
|
|
mod._gateway_queues.clear()
|
|
mod._gateway_notify_cbs.clear()
|
|
mod._session_approved.clear()
|
|
mod._permanent_approved.clear()
|
|
mod._pending.clear()
|
|
|
|
|
|
class TestApprovalHeartbeat:
|
|
"""The blocking gateway approval wait must fire activity heartbeats.
|
|
|
|
Without heartbeats, the gateway's inactivity watchdog kills the agent
|
|
thread while it's legitimately waiting for a slow user to respond to
|
|
an approval prompt (observed in real user logs: MRB, April 2026).
|
|
"""
|
|
|
|
SESSION_KEY = "heartbeat-test-session"
|
|
|
|
def setup_method(self):
|
|
_clear_approval_state()
|
|
self._saved_env = {
|
|
k: os.environ.get(k)
|
|
for k in ("HERMES_GATEWAY_SESSION", "HERMES_YOLO_MODE",
|
|
"HERMES_SESSION_KEY")
|
|
}
|
|
os.environ.pop("HERMES_YOLO_MODE", None)
|
|
os.environ["HERMES_GATEWAY_SESSION"] = "1"
|
|
# The blocking wait path reads the session key via contextvar OR
|
|
# os.environ fallback. Contextvars don't propagate across threads
|
|
# by default, so env var is the portable way to drive this in tests.
|
|
os.environ["HERMES_SESSION_KEY"] = self.SESSION_KEY
|
|
|
|
def teardown_method(self):
|
|
for k, v in self._saved_env.items():
|
|
if v is None:
|
|
os.environ.pop(k, None)
|
|
else:
|
|
os.environ[k] = v
|
|
_clear_approval_state()
|
|
|
|
|
|
|