Skip to content

The agent that grows with you

fix(kanban): wait for kanban.run's admission answer past the RPC default

Teknium07506d8de4fc
diff --git a/hermes_cli/kanban_worker_client.py b/hermes_cli/kanban_worker_client.py
index 42e7fca60d8..cfed689b9e2 100644
--- a/hermes_cli/kanban_worker_client.py
+++ b/hermes_cli/kanban_worker_client.py
@@ -8,6 +8,7 @@ except ModuleNotFoundError as exc:
raise
import asyncio
+import math
import os
from pathlib import Path
import sys
@@ -39,7 +40,13 @@ async def run(params, board_db):
async def _submit_claim(client, params, board_db):
from hermes_cli.gateway_client import GatewayClientError
db = str(await asyncio.to_thread(Path(board_db).resolve))
- accepted = await client.rpc('kanban.run', **dict(params, db=db))
+ # No deadline on the admission answer: the owner checks the claim and writes its
+ # ``owner_admitted`` marker in one board write transaction first, and the board (the
+ # cross-profile dispatch bus) has a 120 s busy timeout. Giving up at the 30 s default left
+ # the owner admitting an attempt whose submitter had exited, so the later-bound worker's
+ # submitter-liveness watcher ended it and the admission was left ``unknown``. A hang-up still
+ # fails the wait; the dispatcher's runtime cap and reclaim bound a stuck submitter.
+ accepted = await client.rpc('kanban.run', _timeout=math.inf, **dict(params, db=db))
sid, receipt = accepted['session_id'], accepted['receipt']
print(f'Session: {sid}', file=sys.stderr)
while receipt['status'] not in {'terminal', 'unknown'}:
diff --git a/tests/hermes_cli/test_kanban_worker_admission_wait.py b/tests/hermes_cli/test_kanban_worker_admission_wait.py
new file mode 100644
index 00000000000..d259f101c8c
--- /dev/null
+++ b/tests/hermes_cli/test_kanban_worker_admission_wait.py
@@ -0,0 +1,56 @@
+"""KB-7: the Kanban submitter waits for ``kanban.run``'s admission answer past the default RPC budget.
+
+Before it answers, the owner's ``kanban.run`` checks the claim and writes its ``owner_admitted``
+marker in one ``BEGIN IMMEDIATE`` on the board, the cross-profile dispatch bus, whose busy
+timeout is 120 s. Behind another board writer, the answer can come after the client's 30 s
+default. The submitter then exited "Gateway connection failed" while the owner went on to admit
+the attempt. The later-bound worker's submitter-liveness watcher ended it, and the admission was
+left ``unknown``. Time is scaled 1000x: 30 s -> 30 ms.
+"""
+import asyncio
+import json
+
+import pytest
+
+from hermes_cli import kanban_worker_client
+from hermes_cli.gateway_client import GatewayClient
+
+
+class _Owner:
+ """Answers ``kanban.run`` after a 120 s (scaled) board wait, then a terminal receipt."""
+
+ def __init__(self):
+ self.inbox, self.sent = asyncio.Queue(), []
+
+ async def send(self, raw):
+ req = json.loads(raw)
+ self.sent.append(req)
+ if req['method'] == 'kanban.run':
+ async def admit():
+ await asyncio.sleep(0.12) # health: allow HX013 -- must land after the scaled 30 ms default budget
+ await self.inbox.put(json.dumps({'id': req['id'], 'result': {
+ 'session_id': 's1', 'receipt': {'status': 'terminal', 'admission_id': 'a1'}}}))
+ asyncio.ensure_future(admit())
+
+ def __aiter__(self):
+ return self
+
+ async def __anext__(self):
+ return await self.inbox.get()
+
+
+async def test_a_slow_admission_answer_is_awaited_not_failed(monkeypatch, tmp_path):
+ real_wait_for = asyncio.wait_for
+ monkeypatch.setattr(asyncio, 'wait_for', lambda fut, timeout: real_wait_for(
+ fut, None if timeout is None else timeout / 1000))
+ from gateway import session_kanban
+ monkeypatch.setattr(session_kanban, 'worker_result', lambda db, params: {'exit_code': 0, 'last_output': 'done'})
+ owner = _Owner()
+ params = {'board': 'b', 'task_id': 't1', 'run_id': 1, 'claim_lock': 'lock'}
+ async with GatewayClient(owner) as client:
+ code = await kanban_worker_client._submit_claim(client, params, str(tmp_path / 'kanban.db'))
+ assert code == 0
+ # One submission: the wait never resends the claim, and the budget never goes on the wire.
+ assert [r['method'] for r in owner.sent] == ['kanban.run']
+ assert all('_timeout' not in r['params'] for r in owner.sent)