fix(tests): stop log queue listener to prevent FATAL on 3.11 shutdown

The TestRunConversationSurrogateSanitization test creates a full
AIAgent, which starts a QueueListener daemon thread (_monitor) via
setup_logging(). On Python 3.11 the daemon can still be mid-loop when
the interpreter begins shutdown, and accessing partially-torn-down
logging objects produces "FATAL: exception not rethread" at process
exit — a non-zero exit code in CI even though every test passed.

Add an autouse fixture that calls _reset_queued_handlers() after each
test to stop the listener and join its worker thread cleanly.
This commit is contained in:
ethernet 2026-07-13 16:48:00 -04:00
parent c44de99854
commit 67d0ab47ef

View file

@ -16,6 +16,24 @@ from run_agent import (
)
@pytest.fixture(autouse=True)
def _stop_log_queue_listener():
"""Stop the async logging QueueListener after each test.
AIAgent.__init__ setup_logging() starts a QueueListener daemon
thread (_monitor). On Python 3.11 the daemon can still be mid-loop
when the interpreter begins shutdown, and accessing partially-torn-down
logging objects produces "FATAL: exception not rethread" at process
exit a non-zero exit code in CI even though every test passed.
"""
yield
try:
from hermes_logging import _reset_queued_handlers
_reset_queued_handlers()
except Exception:
pass
class TestSanitizeSurrogates:
"""Test the _sanitize_surrogates() helper."""