The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(gateway): crash-probe peers publish their ready files by rename
Teknium91cb66c5130b
diff --git a/tests/gateway/fixtures/native_ingress_media_peer.py b/tests/gateway/fixtures/native_ingress_media_peer.pyindex 009a9432184..8288520780a 100644--- a/tests/gateway/fixtures/native_ingress_media_peer.py+++ b/tests/gateway/fixtures/native_ingress_media_peer.py@@ -110,7 +110,9 @@ async def probe(mode, peer):assert claim_session_input(authority.db, epoch=authority.epoch, session_id=unknown.ref.session_id)evidence = dict(sid=receipt.ref.session_id, saved=saved, unknown_sid=unknown.ref.session_id,retained=str(retained), unknown=rows(unknown.ref.session_id))- (state / 'accepted.json').write_text(json.dumps(evidence))+ # Published by rename: the parent SIGKILLs this process the moment the file exists.+ (state / 'accepted.tmp').write_text(json.dumps(evidence))+ os.replace(state / 'accepted.tmp', state / 'accepted.json')threading.Event().wait(60)raise AssertionError('parent failed to kill owner')diff --git a/tests/gateway/fixtures/rotation_persistence_worker.py b/tests/gateway/fixtures/rotation_persistence_worker.pyindex fbb196bfb1d..2af2086a14f 100644--- a/tests/gateway/fixtures/rotation_persistence_worker.py+++ b/tests/gateway/fixtures/rotation_persistence_worker.py@@ -10,6 +10,13 @@ from agent.runtime_session_store import RuntimeSessionStore, WorkerRPCfrom tests.gateway.fixtures.agent_persistence_worker import writable_fds+def _publish(path, text):+ """Create the receipt by rename: the parent polls for EXISTENCE, then reads it at once."""+ tmp = Path(str(path) + '.tmp')+ tmp.write_text(text)+ os.replace(tmp, path)++def main():command = json.loads(sys.stdin.readline())home = Path(command['home'])@@ -49,14 +56,14 @@ def main():assert agent.tools == frozen_toolsrestart_proof = {}if command.get('restart'):- Path(command['ready']).write_text(json.dumps(dict(session_id=agent.session_id, epoch=store.scope['epoch'])))+ _publish(command['ready'], json.dumps(dict(session_id=agent.session_id, epoch=store.scope['epoch'])))assert sys.stdin.readline().strip() == 'outage'try:store.touch_session_activity(agent.session_id, description='surviving rotated worker')raise AssertionError('owner outage accepted a mutation')except Exception:assert len(store.journal['pending']) == 1- Path(command['outage']).write_text('pending')+ _publish(command['outage'], 'pending')assert sys.stdin.readline().strip() == 'adopt'try:store.retry_pending()@@ -73,7 +80,7 @@ def main():assert not result.get('failed'), resulthistory = store.get_messages_as_conversation(agent.session_id, include_row_ids=True)store.finish()- Path(command['receipt']).write_text(json.dumps(dict(before=before, after=agent.session_id,+ _publish(command['receipt'], json.dumps(dict(before=before, after=agent.session_id,history=history, compressed_count=len(compressed), input_count=len(messages), opens=opens,fds=writable_fds(), negatives={}, result=result['final_response'], restart=restart_proof)))finally:diff --git a/tests/gateway/fixtures/shared_authority_recovery.py b/tests/gateway/fixtures/shared_authority_recovery.pyindex e6dcfd780e1..1fec4318b05 100644--- a/tests/gateway/fixtures/shared_authority_recovery.py+++ b/tests/gateway/fixtures/shared_authority_recovery.py@@ -70,7 +70,11 @@ async def prepare_crash(runner, adapter, source, peer):'blocked': rows(authority, sid), 'safe': rows(authority, accepted.ref.session_id)}assert evidence['safe'][-1]['status'] == 'queued'assert any(r['status'] == 'started' for r in evidence['blocked'])- Path(os.environ['HERMES_HOME'], 'crash-ready.json').write_text(json.dumps(evidence))+ # Published by rename: the parent SIGKILLs this process the moment the file EXISTS, so a plain+ # write_text (create+truncate, then write) could be killed between the two and leave an empty file.+ ready = Path(os.environ['HERMES_HOME'], 'crash-ready.json')+ ready.with_suffix('.tmp').write_text(json.dumps(evidence))+ os.replace(ready.with_suffix('.tmp'), ready)threading.Event().wait(60)raise AssertionError('parent did not kill the actual owner')