Skip to content

The agent that grows with you

fix(terminal): cache cleanup keeps the max_age_hours kwarg the housekeeping loop calls

teknium110e7de79a9ba
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 00000000000..b49a1caee54
--- /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 e9e839fe204..80312c08f17 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 5c9f4202bfe..7008bab7809 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: