Files
hermes-webui/api/request_logging.py
danpark 1a7b82d41e fix: preserve access logs during agent stdout capture (#2684)
Own a private stdout descriptor before agent imports and serialize request log writes. Keep logging failures isolated from HTTP responses. Add successful chat/start subprocess delivery regressions and document header-latency semantics and cron ownership.
2026-09-19 07:26:12 -04:00

27 lines
732 B
Python

"""Request output independent of agent/tool stdout capture."""
import os
import threading
# Import before agent code. Own the descriptor so replacing or closing Python's
# sys.stdout cannot capture access/error records intended for the service log.
try:
_STREAM = os.fdopen(
os.dup(1), "w", encoding="utf-8", errors="backslashreplace", buffering=1,
)
except OSError:
_STREAM = None
_LOCK = threading.Lock()
def emit_request_log(message: str) -> None:
"""Flush one complete record without letting a broken sink break HTTP."""
try:
if _STREAM is not None:
with _LOCK:
_STREAM.write(message + "\n")
_STREAM.flush()
except Exception:
pass