From 10e7de79a9ba602c5c4c42f81560511e5de8d2b1 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Mon, 21 Sep 2026 18:39:16 -0700 Subject: [PATCH] fix(terminal): cache cleanup keeps the max_age_hours kwarg the housekeeping loop calls 7fe77f29a77 renamed cleanup_terminal_temp_cache's kwarg to max_idle_hours; gateway/run.py::_run_media_cache_cleanup calls every registered cleanup as fn(max_age_hours=24), so the terminal sweep raised TypeError inside housekeeping on every tick. The kwarg is the shared cleanup_*_cache signature (bot_relay notes the same parity); the idle semantics stay. A test binds the loop's call shape against every registered cleanup. --- .../test_media_cache_cleanup_signature.py | 24 +++++++++++++++++++ tests/tools/test_local_temp_dir.py | 2 +- tools/environments/local.py | 9 +++---- 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 tests/gateway/test_media_cache_cleanup_signature.py diff --git a/tests/gateway/test_media_cache_cleanup_signature.py b/tests/gateway/test_media_cache_cleanup_signature.py new file mode 100644 index 0000000000..b49a1caee5 --- /dev/null +++ b/tests/gateway/test_media_cache_cleanup_signature.py @@ -0,0 +1,24 @@ +"""Every cache cleanup the gateway housekeeping loop iterates accepts the loop's call shape. + +The loop calls each entry as ``fn(max_age_hours=24)``; a cleanup renamed to another kwarg +raised ``TypeError`` inside housekeeping on every tick (the terminal temp sweep did, once). +""" +import inspect + + +def test_every_housekeeping_cache_cleanup_accepts_max_age_hours(tmp_path, monkeypatch): + monkeypatch.setenv("HERMES_HOME", str(tmp_path)) + from tools.environments.local import cleanup_terminal_temp_cache + from tools.bot_mode_dm import cleanup_bot_dm_cache + from tools.bot_relay import cleanup_bot_relay_artifacts + from tools.tool_result_storage import cleanup_spillover_cache + from gateway.platforms.base import ( + cleanup_audio_cache, cleanup_document_cache, cleanup_image_cache, + cleanup_screenshot_cache, cleanup_video_cache, + ) + cleanups = (cleanup_image_cache, cleanup_document_cache, cleanup_audio_cache, cleanup_video_cache, + cleanup_screenshot_cache, cleanup_spillover_cache, cleanup_terminal_temp_cache, + cleanup_bot_dm_cache, cleanup_bot_relay_artifacts) + for fn in cleanups: + inspect.signature(fn).bind(max_age_hours=24) + assert isinstance(fn(max_age_hours=24), int), fn.__name__ diff --git a/tests/tools/test_local_temp_dir.py b/tests/tools/test_local_temp_dir.py index e9e839fe20..80312c08f1 100644 --- a/tests/tools/test_local_temp_dir.py +++ b/tests/tools/test_local_temp_dir.py @@ -114,7 +114,7 @@ def test_cleanup_terminal_temp_cache(tmp_path, monkeypatch): f.write_text("x") os.utime(f, (old, old)) - removed = local_mod.cleanup_terminal_temp_cache(max_idle_hours=24) + removed = local_mod.cleanup_terminal_temp_cache(max_age_hours=24) assert removed == 4 # stale snap + 3 dead-group files assert keep.exists() assert live_pid.exists() and live_log.exists() diff --git a/tools/environments/local.py b/tools/environments/local.py index 5c9f4202bf..7008bab780 100644 --- a/tools/environments/local.py +++ b/tools/environments/local.py @@ -58,16 +58,17 @@ def _default_terminal_temp_dir() -> "Path | None": return None -def cleanup_terminal_temp_cache(max_idle_hours: float = TERMINAL_TEMP_MAX_IDLE_HOURS) -> int: - """Delete session temp artifacts idle for *max_idle_hours* (no write anywhere in a - directory's subtree); return count. +def cleanup_terminal_temp_cache(max_age_hours: float = TERMINAL_TEMP_MAX_IDLE_HOURS) -> int: + """Delete session temp artifacts idle for *max_age_hours* (no write anywhere in a + directory's subtree; the kwarg name is the ``cleanup_*_cache`` signature the gateway + housekeeping loop calls every entry with); return count. Only the managed default dir is pruned — never a user-pointed ``terminal.temp_dir``.""" from hermes_constants_scratch import subtree_touched_since root = _default_terminal_temp_dir() if root is None: return 0 - cutoff = time.time() - (max_idle_hours * 3600) + cutoff = time.time() - (max_age_hours * 3600) try: entries = list(root.iterdir()) except OSError: