fix(terminal): log disk warning check failures at debug level (salvage #2372) (#2394)

* fix(terminal): log disk warning check failures at debug level

* fix(terminal): guard _check_disk_usage_warning by moving scratch_dir into try

---------

Co-authored-by: aydnOktay <xaydinoktay@gmail.com>
This commit is contained in:
Teknium
2026-03-21 17:10:17 -07:00
committed by GitHub
parent 1d28b4699b
commit 0ea7d0ec80
2 changed files with 13 additions and 3 deletions

View File

@@ -11,7 +11,7 @@ import pytest
import sys
import tools.terminal_tool # noqa: F401 -- ensure module is loaded
_tt_mod = sys.modules["tools.terminal_tool"]
from tools.terminal_tool import get_active_environments_info
from tools.terminal_tool import get_active_environments_info, _check_disk_usage_warning
# 1 MiB of data so the rounded MB value is clearly distinguishable
_1MB = b"x" * (1024 * 1024)
@@ -62,3 +62,12 @@ class TestDiskUsageGlob:
# Should be ~2.0 MB total (1 MB per task).
# With the bug, each task globs everything -> ~4.0 MB.
assert info["total_disk_usage_mb"] == pytest.approx(2.0, abs=0.1)
class TestDiskUsageWarningHardening:
def test_check_disk_usage_warning_logs_debug_on_unexpected_error(self):
with patch.object(_tt_mod, "_get_scratch_dir", side_effect=RuntimeError("boom")), patch.object(_tt_mod.logger, "debug") as debug_mock:
result = _check_disk_usage_warning()
assert result is False
debug_mock.assert_called()

View File

@@ -75,9 +75,9 @@ DISK_USAGE_WARNING_THRESHOLD_GB = float(os.getenv("TERMINAL_DISK_WARNING_GB", "5
def _check_disk_usage_warning():
"""Check if total disk usage exceeds warning threshold."""
scratch_dir = _get_scratch_dir()
try:
scratch_dir = _get_scratch_dir()
# Get total size of hermes directories
total_bytes = 0
import glob
@@ -98,6 +98,7 @@ def _check_disk_usage_warning():
return False
except Exception as e:
logger.debug("Disk usage warning check failed: %s", e, exc_info=True)
return False