The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: canonical /compress waits past the fixed 30 s RPC budget
Tekniumc1e5801f3664
diff --git a/hermes_cli/gateway_client.py b/hermes_cli/gateway_client.pyindex da9623c1aa5..ab5cc1bfbb2 100644--- a/hermes_cli/gateway_client.py+++ b/hermes_cli/gateway_client.py@@ -12,6 +12,14 @@ import timefrom gateway.session_contract import CANONICAL_GATEWAY_PROTOCOL as GATEWAY_WS_PROTOCOLGATEWAY_WS_TICKET_PREFIX = "hermes-gateway-ticket."+# Per-request answer budget. Owner verbs are admissions/reads that answer promptly; the one that+# legitimately runs long passes its own budget (``rpc(..., _timeout=...)``).+DEFAULT_RPC_TIMEOUT = 30+# Canonical ``/compress`` answers only after the summary call(s) and the commit: a long session's+# summary routinely takes more than 30 s (``auxiliary.compression.timeout`` defaults to 120 s per+# request, ``compression.context_total_ceiling_seconds`` to 600 s). Same budget as Desktop's+# ``SESSION_COMPRESS_TIMEOUT_MS`` so every surface gives up at the same point.+COMPRESS_RPC_TIMEOUT = 660def gateway_ws_target(endpoint, ticket):@@ -125,14 +133,16 @@ class GatewayClient:self.events.get_nowait()self.events.put_nowait(error)- async def rpc(self, method, **params):+ async def rpc(self, method, *, _timeout=None, **params):+ """Send one request and await its answer; ``_timeout`` (seconds, never sent on the wire)+ overrides ``DEFAULT_RPC_TIMEOUT`` for a verb that legitimately takes longer."""self.sequence += 1rid = self.sequencefuture = asyncio.get_running_loop().create_future()self.pending[rid] = futuretry:await self.websocket.send(json.dumps({"jsonrpc": "2.0", "id": rid, "method": method, "params": params}))- return await asyncio.wait_for(future, 30)+ return await asyncio.wait_for(future, DEFAULT_RPC_TIMEOUT if _timeout is None else _timeout)finally:self.pending.pop(rid, None)diff --git a/hermes_cli/gateway_mutations.py b/hermes_cli/gateway_mutations.pyindex 4fb4bfb80cf..ff1bf4e2bf1 100644--- a/hermes_cli/gateway_mutations.py+++ b/hermes_cli/gateway_mutations.py@@ -1,7 +1,7 @@"""Prepared native controls retain their identity across ambiguous RPC replies."""import jsonimport uuid-from hermes_cli.gateway_client import GatewayClientError+from hermes_cli.gateway_client import COMPRESS_RPC_TIMEOUT, GatewayClientErrorclass PreparedMutations:@@ -19,7 +19,10 @@ class PreparedMutations:entry = self.pending[key]if 'result' not in entry:try:- entry['result'] = await client.rpc('session.mutate', **entry['params'])+ # A compression answers after its summary + commit; the default budget would report+ # a timeout while the owner (which shields the mutation) still commits it.+ budget = {'_timeout': COMPRESS_RPC_TIMEOUT} if operation == 'compress' else {}+ entry['result'] = await client.rpc('session.mutate', **budget, **entry['params'])except GatewayClientError as exc:# A disconnect is not a definitive authority refusal. Preserve# the tuple; never refresh its preconditions behind the user.diff --git a/tests/hermes_cli/test_gateway_client_rpc.py b/tests/hermes_cli/test_gateway_client_rpc.pyindex 25f522b661a..bbe6c5b781d 100644--- a/tests/hermes_cli/test_gateway_client_rpc.py+++ b/tests/hermes_cli/test_gateway_client_rpc.py@@ -45,3 +45,31 @@ async def test_rpc_error_keeps_numeric_code_and_bounded_data():await client.rpc('nope')# Free-text messages stay bounded: the owner's reason code, not the raw sentence.assert str(unknown.value) == 'unknown_method' and unknown.value.code == -32601+++async def test_compress_waits_past_the_default_rpc_budget(monkeypatch):+ """A canonical ``/compress`` answers only after its summary + commit (minutes on a long+ session). The viewer must not report failure at the 30 s default while the owner, which+ shields the mutation, still commits it. Time is scaled 1000x: 30 s -> 30 ms."""+ from hermes_cli.gateway_mutations import PreparedMutations+ real_wait_for = asyncio.wait_for+ monkeypatch.setattr(asyncio, 'wait_for', lambda fut, timeout: real_wait_for(fut, timeout / 1000))+ sent = []++ def reply(req):+ sent.append(req)+ if req['method'] == 'session.resume':+ return {'id': req['id'], 'result': {'revision': 1, 'execution_generation': 1}}++ async def commit(): # a 120 s summary (scaled) then the receipt+ await asyncio.sleep(0.12)+ await owner.inbox.put(json.dumps({'id': req['id'], 'result': {'status': 'applied'}}))+ asyncio.ensure_future(commit())++ owner = _Socket(reply)+ async with GatewayClient(owner) as client:+ result = await PreparedMutations().apply(client, 's', 'compress', {})+ assert result == {'status': 'applied'}+ # The budget is a client-side knob, never a wire parameter the closed contract would refuse.+ assert all('_timeout' not in req['params'] for req in sent)