The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: pause workers on outbox I/O failure and preserve local lease waits
Teknium23b549216de9
diff --git a/agent/runtime_session_store.py b/agent/runtime_session_store.pyindex 12e463d7d31..de431a492a9 100644--- a/agent/runtime_session_store.py+++ b/agent/runtime_session_store.py@@ -144,7 +144,11 @@ class RuntimeSessionStore:candidate = json.loads(json.dumps(self.journal))candidate['pending'].append(json.loads(json.dumps(entry, allow_nan=False)))candidate['next_sequence'] += 1- self._save(candidate)+ try:+ self._save(candidate)+ except Exception as exc:+ self.failure = str(exc)+ raiseself.journal = candidatereturn self.retry_pending()[0]@@ -188,6 +192,17 @@ class RuntimeSessionStore:self._session(session_id)return self._apply('turn.acquire', {'holder': holder, 'ttl_seconds': ttl_seconds})['value']+ def acquire_session_turn_lease(self, session_id, holder, *, ttl_seconds=300.0,+ wait_seconds=1800.0, poll_interval_seconds=1.0, on_wait=None,+ wait_notice_interval_seconds=15.0, should_abort=None, acquire_patience_s=0.5):+ # Reuse only the local polling orchestrator, not the SQLite mixin surface.+ from hermes_state_compression import SessionCompressionMixin+ return SessionCompressionMixin.acquire_session_turn_lease(self, session_id, holder,+ ttl_seconds=ttl_seconds, wait_seconds=wait_seconds,+ poll_interval_seconds=poll_interval_seconds, on_wait=on_wait,+ wait_notice_interval_seconds=wait_notice_interval_seconds,+ should_abort=should_abort, acquire_patience_s=acquire_patience_s)+def refresh_session_turn_lease(self, session_id, holder, *, ttl_seconds=300.0):self._session(session_id)return self._apply('turn.renew', {'holder': holder, 'ttl_seconds': ttl_seconds})['value']diff --git a/tests/agent/test_runtime_session_store.py b/tests/agent/test_runtime_session_store.pyindex 408d0ee28a2..2f76c15c282 100644--- a/tests/agent/test_runtime_session_store.py+++ b/tests/agent/test_runtime_session_store.py@@ -52,3 +52,32 @@ def test_outbox_capacity_failure_does_not_advance_or_discard(tmp_path):finally:with pytest.raises(WorkerPersistenceError, match='outbox_full'):store.close()+++def test_worker_turn_wait_callbacks_remain_local(tmp_path):+ attempts, notices = [], []+ def rpc(method, **params):+ attempts.append(params)+ return {'value': len(attempts) > 1}+ store = RuntimeSessionStore(rpc, {'session_id': 's'}, tmp_path / 'private')+ try:+ assert store.acquire_session_turn_lease('s', 'holder', wait_seconds=3,+ poll_interval_seconds=.01, on_wait=notices.append)+ assert notices and len(attempts) == 2+ assert all(set(row['payload']) == {'holder', 'ttl_seconds'} for row in attempts)+ assert not store.acquire_session_turn_lease('s', 'holder', should_abort=lambda: True)+ finally:+ store.close()+++def test_outbox_filesystem_failure_is_sticky(tmp_path, monkeypatch):+ store = RuntimeSessionStore(lambda *a, **k: {}, {'session_id': 's'}, tmp_path / 'private')+ def fail_replace(*args):+ raise OSError('disk unavailable')+ monkeypatch.setattr('agent.runtime_session_store.os.replace', fail_replace)+ try:+ with pytest.raises(OSError, match='disk unavailable'):+ store.queue_token_counts('s', input_tokens=1)+ assert store.failure == 'disk unavailable'+ finally:+ store._outbox_owner.close()