The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): a managed worker's clarify wait honours the profile's clarify timeout
Tekniumd28ed5220c96
diff --git a/agent/managed_worker.py b/agent/managed_worker.pyindex f1e1b8af8d3..584d81124d9 100644--- a/agent/managed_worker.py+++ b/agent/managed_worker.py@@ -228,6 +228,8 @@ class WorkerControls:def _ask(self, question, choices, multi_select):import uuid+ from tools.clarify_gateway import get_clarify_timeout+ timeout = get_clarify_timeout() # the frozen worker config; <= 0 is unlimited, as on every surfaceprompt_id = uuid.uuid4().hexstate = {'event': threading.Event(), 'answer': None}with self.lock:@@ -237,7 +239,7 @@ class WorkerControls:try:self.channel.send('clarify', prompt_id=prompt_id, question=question,choices=list(choices or []), multi_select=bool(multi_select))- state['event'].wait(3600)+ state['event'].wait(timeout if timeout > 0 else None)return state['answer']finally:with self.lock:diff --git a/tests/gateway/test_managed_worker_clarify_timeout.py b/tests/gateway/test_managed_worker_clarify_timeout.pynew file mode 100644index 00000000000..90e8fd6f721--- /dev/null+++ b/tests/gateway/test_managed_worker_clarify_timeout.py@@ -0,0 +1,54 @@+"""A managed worker's clarify wait honours the profile's clarify timeout (<= 0 = unlimited)."""+import threading+import time++import pytest+++class _Channel:+ def __init__(self):+ self.sent = []++ def send(self, kind, **payload):+ self.sent.append(kind)+++def _controls():+ from agent import managed_worker as worker+ controls = worker.WorkerControls.__new__(worker.WorkerControls) # no stdin reader thread+ controls.channel, controls.route, controls.agent = _Channel(), 'route', None+ controls.stopped, controls.lock, controls.clarifications = threading.Event(), threading.Lock(), {}+ return controls+++def _config(tmp_path, monkeypatch, body):+ (tmp_path / 'config.yaml').write_text(body, encoding='utf-8')+ monkeypatch.setenv('HERMES_HOME', str(tmp_path))+++def test_unanswered_clarify_times_out_at_the_configured_value(tmp_path, monkeypatch):+ _config(tmp_path, monkeypatch, 'agent:\n clarify_timeout: 1\n')+ controls, result = _controls(), []+ asker = threading.Thread(target=lambda: result.append(controls._ask('q?', [], False)), daemon=True)+ started = time.monotonic()+ asker.start()+ asker.join(10)+ assert not asker.is_alive(), 'the worker held the clarify past the configured 1 s timeout'+ assert result == [None] and time.monotonic() - started < 10+ assert controls.channel.sent == ['clarify', 'prompt_settled']++[email protected]('body', ['agent:\n clarify_timeout: 0\n', 'clarify:\n timeout: -1\n'])+def test_nonpositive_clarify_timeout_waits_unbounded(tmp_path, monkeypatch, body):+ from agent import managed_worker as worker+ _config(tmp_path, monkeypatch, body)+ waits = []++ class _Event(threading.Event):+ def wait(self, timeout=None):+ waits.append(timeout)+ return True++ monkeypatch.setattr(worker.threading, 'Event', _Event)+ assert _controls()._ask('q?', [], False) is None+ assert waits == [None]