From 67d0ab47ef6305b97cfac9f0366efe41355139e5 Mon Sep 17 00:00:00 2001 From: ethernet Date: Mon, 13 Jul 2026 16:48:00 -0400 Subject: [PATCH] fix(tests): stop log queue listener to prevent FATAL on 3.11 shutdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tests/cli/test_surrogate_sanitization.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/cli/test_surrogate_sanitization.py b/tests/cli/test_surrogate_sanitization.py index 2a04a5c246f..50eb271c3f4 100644 --- a/tests/cli/test_surrogate_sanitization.py +++ b/tests/cli/test_surrogate_sanitization.py @@ -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."""