Skip to content

The agent that grows with you

test(e2e): platform contract waits for the gateway turn boundary between inbounds (#121393); INFO log in failure context

teknium1c5b8469ea279
diff --git a/tests/e2e/core/platforms/_contract.py b/tests/e2e/core/platforms/_contract.py
index b75b232f122..b345f660879 100644
--- a/tests/e2e/core/platforms/_contract.py
+++ b/tests/e2e/core/platforms/_contract.py
@@ -72,6 +72,9 @@ def wait_reply(rig: Rig, chat_id: str, aid: str, what: str = "", timeout: float
def barrier(rig: Rig, token: str, *, group: bool = False) -> None:
"""One more inbound in the same chat, answered: everything queued before it has been handled."""
aid = f"B-{token}"
+ # A reply can be visible while its turn is still closing; wait for the turn boundary first so
+ # the barrier is a new turn (an inbound in that closing window is tracked as #121393).
+ rig.gw.wait_idle()
rig.director.script(token, answer(aid, "barrier"))
inbound = rig.drv.group(f"barrier [in:{token}]", mention=True) if group else rig.drv.dm(f"barrier [in:{token}]")
wait_reply(rig, inbound.chat_id, aid, f"barrier {token} answered")
diff --git a/tests/e2e/core/platforms/_helpers.py b/tests/e2e/core/platforms/_helpers.py
index a3a3d0c8759..c26b1037665 100644
--- a/tests/e2e/core/platforms/_helpers.py
+++ b/tests/e2e/core/platforms/_helpers.py
@@ -9,6 +9,7 @@ token. Nothing on our side of the platform boundary is mocked.
from __future__ import annotations
+import json
import os
import re
import signal
@@ -166,10 +167,27 @@ class GatewayUnderTest:
return self.proc is not None and self.proc.poll() is None
def tail(self, n: int = 6000) -> str:
+ out = []
+ # the child's stdout/stderr, then its INFO-level log (where turn/delivery progress lands)
+ for label, path in (("gateway stdout", self.log_path),
+ ("gateway.log (INFO)", self.hermes_home / "logs" / "gateway.log")):
+ try:
+ out.append(f"--- {label} tail\n" + path.read_text(errors="replace")[-n:])
+ except OSError:
+ out.append(f"--- (no {label})")
+ return "\n".join(out)
+
+ def active_agents(self) -> Optional[int]:
+ """In-flight turns as the gateway persists them to ``gateway_state.json`` at every turn boundary."""
try:
- return "--- gateway log tail\n" + self.log_path.read_text(errors="replace")[-n:]
- except OSError:
- return "--- (no gateway log)"
+ return int(json.loads((self.hermes_home / "gateway_state.json").read_text()).get("active_agents"))
+ except (OSError, ValueError, TypeError):
+ return None
+
+ def wait_idle(self, timeout: float = 90.0) -> None:
+ """Every turn finished (not merely its reply visible): the next inbound starts a fresh turn."""
+ wait_until(lambda: self.active_agents() == 0 or not self.alive(), "gateway idle (active_agents == 0)",
+ timeout=timeout, on_timeout=self.tail)
def grep(self, pattern: str, limit: int = 30) -> str:
"""Gateway log lines matching ``pattern`` (case-insensitive), for assertion context."""
diff --git a/tests/e2e/core/platforms/_suite.py b/tests/e2e/core/platforms/_suite.py
index df2c956ff38..de023aecf86 100644
--- a/tests/e2e/core/platforms/_suite.py
+++ b/tests/e2e/core/platforms/_suite.py
@@ -57,6 +57,7 @@ def run_scenario(name: str, request: pytest.FixtureRequest, tmp_path: Path) -> N
fixture, runner = SCENARIOS[name]
rig = request.getfixturevalue(fixture)
assert rig.gw.alive(), f"gateway died before {name}\n{rig.gw.tail()}"
+ rig.gw.wait_idle() # the previous scenario's last turn fully closed (see barrier())
runner(rig, name.replace("_", ""), tmp_path)