From 11976ca1199e735e11d0f967902cd1cd4dc07665 Mon Sep 17 00:00:00 2001 From: ian-at-strix Date: Wed, 7 Oct 2026 14:32:42 -0400 Subject: [PATCH] fix(logging): suppress Agents SDK PTY warning that interferes with TUI (#1392) --- strix/telemetry/logging.py | 12 ++++++++++ tests/test_pty_warning_filter.py | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/test_pty_warning_filter.py diff --git a/strix/telemetry/logging.py b/strix/telemetry/logging.py index 670b2236..40391cc1 100644 --- a/strix/telemetry/logging.py +++ b/strix/telemetry/logging.py @@ -3,6 +3,7 @@ from __future__ import annotations import contextlib +import functools import logging import os import sys @@ -78,6 +79,16 @@ class _StdoutQuietFilter(logging.Filter): ) +class _PtyThresholdFilter(logging.Filter): + def filter(self, record: logging.LogRecord) -> bool: + return "PTY process count reached warning threshold" not in record.getMessage() + + +@functools.cache # install once; tests reset via ``cache_clear()`` +def _silence_pty_threshold_warning() -> None: + logging.getLogger("agents.sandbox.sandboxes.docker").addFilter(_PtyThresholdFilter()) + + def configure_dependency_logging() -> None: """Quiet dependency logging/warnings that obscure Strix scan logs.""" litellm = sys.modules.get("litellm") @@ -89,6 +100,7 @@ def configure_dependency_logging() -> None: logging.getLogger("asyncio").propagate = False warnings.filterwarnings("ignore", category=RuntimeWarning, module="asyncio") _route_unraisable_to_log() + _silence_pty_threshold_warning() def _route_unraisable_to_log() -> None: diff --git a/tests/test_pty_warning_filter.py b/tests/test_pty_warning_filter.py new file mode 100644 index 00000000..7cd14fca --- /dev/null +++ b/tests/test_pty_warning_filter.py @@ -0,0 +1,41 @@ +import logging +from collections.abc import Iterator + +import pytest + +from strix.telemetry import logging as tlog + + +_SDK_LOGGER = "agents.sandbox.sandboxes.docker" + + +@pytest.fixture +def sdk_logger() -> Iterator[logging.Logger]: + logger = logging.getLogger(_SDK_LOGGER) + original = list(logger.filters) + logger.filters.clear() + tlog._silence_pty_threshold_warning.cache_clear() + yield logger + logger.filters[:] = original + tlog._silence_pty_threshold_warning.cache_clear() + + +def _record(msg: str, *args: object) -> logging.LogRecord: + return logging.LogRecord(_SDK_LOGGER, logging.WARNING, __file__, 0, msg, args, None) + + +def test_installed_filter_drops_pty_threshold_warning(sdk_logger: logging.Logger) -> None: + tlog._silence_pty_threshold_warning() + record = _record("PTY process count reached warning threshold: %s active sessions", 62) + assert not sdk_logger.filter(record) + + +def test_installed_filter_keeps_other_warnings(sdk_logger: logging.Logger) -> None: + tlog._silence_pty_threshold_warning() + assert sdk_logger.filter(_record("something else went wrong")) + + +def test_install_is_idempotent(sdk_logger: logging.Logger) -> None: + tlog._silence_pty_threshold_warning() + tlog._silence_pty_threshold_warning() + assert len(sdk_logger.filters) == 1