The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(logging): name an unavailable log file once instead of silently dropping records
teknium1b847c1ea5e72
diff --git a/hermes_logging.py b/hermes_logging.pyindex b1f2ffa8a37..5461256c1f3 100644--- a/hermes_logging.py+++ b/hermes_logging.py@@ -267,6 +267,7 @@ class _ManagedRotatingFileHandler(RotatingFileHandler):def __init__(self, *args, **kwargs):from hermes_cli.config import is_managedself._managed = is_managed()+ self._unavailable_reported = Falsesuper().__init__(*args, **kwargs)self._record_stream_stat()@@ -336,9 +337,14 @@ class _ManagedRotatingFileHandler(RotatingFileHandler):if _is_windows_concurrent_log_lock_timeout(exc):returnif _is_unavailable_log_stream(exc):- # The QueueListener must not turn a transient filesystem failure- # into a traceback for every queued record. Drop the stale stream;- # the next emit will reopen it if the destination has recovered.+ # The QueueListener must not turn a failing log destination into a traceback for+ # every queued record. Name the path once, drop the stale stream; the next emit+ # reopens it if the destination has recovered.+ if not self._unavailable_reported:+ self._unavailable_reported = True+ _quietly(lambda: print(+ f"hermes_logging: {self.baseFilename} unavailable ({exc}); "+ "file logging paused until it recovers", file=_safe_stderr()))if self.stream is not None:_quietly(self.stream.close)self.stream = None # type: ignore[assignment]@@ -348,6 +354,7 @@ class _ManagedRotatingFileHandler(RotatingFileHandler):def _open(self):stream = super()._open()self._chmod_if_managed()+ self._unavailable_reported = False # recovered: report again if it breaks anewreturn streamdef doRollover(self):diff --git a/tests/test_hermes_logging.py b/tests/test_hermes_logging.pyindex 6a2073ea8ba..0b2f6cdc6ff 100644--- a/tests/test_hermes_logging.py+++ b/tests/test_hermes_logging.py@@ -613,7 +613,7 @@ def test_eio_from_file_handler_names_the_path_once_then_recovers(tmp_path, capsydef writable(self):return True- def write(self, _s):+ def write(self, *_a):raise OSError(5, "Input/output error")seek = tell = flush = write