The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): read a turn's receipt and stats even past Ctrl-C's settle bound
Tekniumb951c1e071a1
diff --git a/hermes_cli/gateway_agent.py b/hermes_cli/gateway_agent.pyindex 7aceaa828d4..28f4740efdd 100644--- a/hermes_cli/gateway_agent.py+++ b/hermes_cli/gateway_agent.py@@ -660,6 +660,11 @@ class GatewayAgent:"""The ``abandon`` of a turn's blocking reads: it lost the terminal, or Ctrl-C's settle bound passed."""return lambda: not self._owns(turn) or self._expired()+ def _lost(self, turn):+ """The ``abandon`` of a turn's end-of-turn reads (its receipt, the cumulative stats): only losing the+ terminal stops them. Past Ctrl-C's settle bound they still run, bounded by their own timeouts."""+ return lambda: not self._owns(turn)+def _pump(self, stream_callback, starts, turn):"""Dispatch frames until this admission's ``message.complete``; returns its payload, or thetransport error (disconnect)."""@@ -1004,7 +1009,7 @@ class GatewayAgent:complete = {"outcome": receipt.get("outcome")}elif turn.admission:try:- receipt = self.connection.call("prompt.receipt", session_id=turn.session_id, abandon=self._stop(turn),+ receipt = self.connection.call("prompt.receipt", session_id=turn.session_id, abandon=self._lost(turn),admission_id=turn.admission, include_result=True) or {}except GatewayClientError as exc:logger.debug("prompt.receipt failed: %s", exc)@@ -1092,7 +1097,7 @@ class GatewayAgent:"""``session.stats`` → the same attributes ``session.usage`` sets; False when unavailable."""try:stats = self.connection.call("session.stats", session_id=self.session_id, timeout=10,- abandon=turn and self._stop(turn))+ abandon=turn and self._lost(turn))except GatewayClientError as exc:logger.debug("session.stats unavailable: %s", exc)return Falsediff --git a/tests/hermes_cli/test_gateway_agent_replay_gap.py b/tests/hermes_cli/test_gateway_agent_replay_gap.pyindex 15e8cfbbfd8..6d423ae4074 100644--- a/tests/hermes_cli/test_gateway_agent_replay_gap.py+++ b/tests/hermes_cli/test_gateway_agent_replay_gap.py@@ -99,6 +99,25 @@ def test_idle_gap_reattach_cannot_submit_abandoned_input(agents, monkeypatch, chassert not [params for method, params in client.calls if method == "prompt.submit"]+def test_a_turn_past_its_interrupt_settle_bound_still_reads_its_receipt_and_stats(agents, monkeypatch):+ """Ctrl-C's settle bound ends the turn's wait for frames; the end-of-turn ``prompt.receipt`` and+ cumulative ``session.stats`` reads still run (main made both), since the turn still owns the terminal."""+ agent, client = agents([frame("message.delta", {"text": "partial"}), "wait", "wait", "wait", "wait"])+ monkeypatch.setattr("hermes_cli.gateway_agent.INTERRUPT_SETTLE_SECONDS", 0)+ worker = threading.Thread(target=lambda: agent.run_conversation("q"), daemon=True)+ worker.start()+ try:+ deadline = threading.Event()+ while not any(method == "prompt.submit" for method, _ in client.calls) and not deadline.wait(0.01):+ pass+ agent.interrupt()+ finally:+ worker.join(5)+ assert not worker.is_alive()+ methods = [method for method, _ in client.calls]+ assert "prompt.receipt" in methods and "session.stats" in methods, methods++def test_tool_start_closes_a_prefix_whose_separator_fell_in_the_hole(agents, monkeypatch):output, final = [], "The answer is 42."agent, client = agents([frame("message.delta", {"text": "The answer"}), GAP],