feat(ledger): quiet idle outbox polling

This commit is contained in:
Hermes Agent
2026-09-20 21:57:30 +09:00
parent 62e4f57c2b
commit a2be76b199
14 changed files with 437 additions and 15 deletions
@@ -0,0 +1,47 @@
"""Ledger writer loop failures remain visible without leaking exception text."""
from __future__ import annotations
import logging
import threading
from typing import Any
from trex_core.runtime.daemon import Daemon
_SENTINEL = "SECRET-LEDGER-DSN-PAYLOAD-DO-NOT-LOG"
def test_ledger_loop_logs_sanitized_error_and_continues(caplog):
call_count = 0
stop_event = threading.Event()
class _Writer:
def run_once(self):
nonlocal call_count
call_count += 1
if call_count == 1:
raise RuntimeError(f"dsn=postgresql://user:{_SENTINEL}@host/db")
stop_event.set()
class _Config:
ledger_interval_sec = 0.001
instance_key = "instance-a"
daemon: Any = object.__new__(Daemon)
daemon.stop = stop_event
daemon.config = _Config()
daemon.ledger_writer = _Writer()
with caplog.at_level(logging.ERROR, logger="trex_core.runtime.daemon"):
thread = threading.Thread(target=daemon._ledger_loop, daemon=True)
thread.start()
thread.join(timeout=2.0)
assert not thread.is_alive()
assert call_count >= 2
assert len(caplog.records) == 1
record = caplog.records[0]
assert "reason=ledger_writer_run_once_failed" in record.getMessage()
assert "instance_key=instance-a" in record.getMessage()
assert "exc_type=RuntimeError" in record.getMessage()
assert _SENTINEL not in caplog.text
assert record.exc_info is None