The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: prove local completion recovery after owner kill
Teknium9afff7e9d5b7
diff --git a/tests/gateway/fixtures/local_automation_daemon.py b/tests/gateway/fixtures/local_automation_daemon.pynew file mode 100644index 00000000000..88ada2c908c--- /dev/null+++ b/tests/gateway/fixtures/local_automation_daemon.py@@ -0,0 +1,20 @@+"""Crash barrier after real automation commit, before producer ACK/first claim."""+import os+import runpy+import signal++from gateway.session_authority import SessionAuthority+from hermes_state_runtime import list_session_admissions++original = SessionAuthority._schedule+++def schedule(self, ref):+ original(self, ref)+ rows = list_session_admissions(self.db, session_id=ref.session_id)+ if any(r['principal_id'].startswith('automation:') for r in rows):+ os.kill(os.getpid(), signal.SIGSTOP)+++SessionAuthority._schedule = schedule+runpy.run_module('gateway.run', run_name='__main__')diff --git a/tests/gateway/fixtures/local_automation_peer.py b/tests/gateway/fixtures/local_automation_peer.pyindex 4d177fed939..c07ff5e1f96 100644--- a/tests/gateway/fixtures/local_automation_peer.py+++ b/tests/gateway/fixtures/local_automation_peer.py@@ -13,6 +13,8 @@ from local_recovery_probe import daemon, websocket, rpcdef probe(base, source):+ restart = source == 'restart'+ source = 'gui' if restart else sourceroot = Path(__file__).resolve().parents[3]home, user = base / 'state', base / 'user'home.mkdir(); user.mkdir()@@ -53,6 +55,11 @@ def probe(base, source):await submit('spawn', 'SPAWN_AUTOMATION')await wait(lambda: rows()[0]['status'] == 'terminal')assert 'REAL_TERMINAL_COMPLETION' in json.dumps(model.requests)+ if restart:+ model.gate.touch()+ await wait(lambda: any(r['principal_id'].startswith('automation:') for r in rows()))+ assert rows()[-1]['status'] == 'queued', rows()+ return {'session_id': sid, 'committed': rows()}await submit('held', 'HOLD_AUTOMATION')assert await asyncio.to_thread(model.blocked.wait, 20)await submit('follower', 'HUMAN_FIFO_FOLLOWER')@@ -79,14 +86,38 @@ def probe(base, source):'observer_closed_before_completion': True}try:- with daemon(root, home, env, barrier=False) as (proc, desc):+ with daemon(root, home, env, barrier=restart, fixture='local_automation_daemon.py') as (proc, desc):try:receipt = asyncio.run(run(desc))receipt['daemon_pid'] = proc.pid- print(json.dumps(receipt))+ if not restart:+ print(json.dumps(receipt))except BaseException:- print((home / 'restart.log').read_text()[-15000:], file=sys.stderr)+ print((home / ('first.log' if restart else 'restart.log')).read_text()[-15000:], file=sys.stderr)raise+ if restart:+ pids = [receipt['daemon_pid']]+ epochs = [desc['authority_epoch']]+ async def recovered(desc):+ await wait(lambda: all(r['status'] == 'terminal' for r in rows()))+ # Retry the unacknowledged producer on its real recovered watcher cadence.+ await asyncio.sleep(8)+ assert len(rows()) == len(receipt['committed']), rows()+ assert rows()[-1]['outcome'] == 'completed', rows()+ async with websocket(home, desc) as ws:+ result = await rpc(ws, 'session.resume', session_id=receipt['session_id'])+ assert 'result' in result, result+ for _ in range(2):+ with daemon(root, home, env, barrier=False) as (proc, desc):+ pids.append(proc.pid); epochs.append(desc['authority_epoch'])+ asyncio.run(recovered(desc))+ texts = [next((m.get('content', '') for m in reversed(r['messages']) if m['role'] == 'user'), '')+ for r in model.requests if r.get('messages')]+ completion_inputs = [t for t in texts if 'REAL_TERMINAL_COMPLETION' in str(t)]+ assert len(completion_inputs) == 1, texts+ assert len(set(pids)) == 3 and epochs == sorted(set(epochs))+ print(json.dumps({'pids': pids, 'epochs': epochs, 'ledger': rows(),+ 'model_inputs': texts, 'lost_producer_ack': True}))finally:model.gate.touch(); model.release.set()model.shutdown(); model.server_close()diff --git a/tests/gateway/test_local_automation.py b/tests/gateway/test_local_automation.pyindex 4552eb52bb9..cb7c2403f63 100644--- a/tests/gateway/test_local_automation.py+++ b/tests/gateway/test_local_automation.py@@ -7,8 +7,7 @@ import sysimport pytest[email protected]('source', ['cli', 'tui', 'gui'])-def test_local_completion_joins_fifo_without_an_observer(tmp_path, source):+def _probe(tmp_path, source):root = Path(__file__).resolve().parents[2]env = {k: os.environ[k] for k in ('PATH', 'LANG', 'TZ') if k in os.environ}env['PYTHONPATH'] = str(root)@@ -17,3 +16,12 @@ def test_local_completion_joins_fifo_without_an_observer(tmp_path, source):capture_output=True, text=True, timeout=150)assert result.returncode == 0, result.stdout + result.stderrprint(result.stdout)++[email protected]('source', ['cli', 'tui', 'gui'])+def test_local_completion_joins_fifo_without_an_observer(tmp_path, source):+ _probe(tmp_path, source)+++def test_local_completion_survives_owner_kill_without_duplicate(tmp_path):+ _probe(tmp_path, 'restart')