Skip to content

The agent that grows with you

chore: satisfy the code-health gate on the spillover retention branch

Tekniumbf10f6f85cb5
diff --git a/gateway/run_housekeeping_disk.py b/gateway/run_housekeeping_disk.py
index a93765154a0..4b6a3162f75 100644
--- a/gateway/run_housekeeping_disk.py
+++ b/gateway/run_housekeeping_disk.py
@@ -18,9 +18,7 @@ logger = logging.getLogger(__name__)
def housekeeping_media_caches() -> None:
- """Every platform media cache prunes on the same hourly cadence (24h max age).
- Spillover is the exception: its files are archives the transcript points at, so
- cleanup_spillover_cache() keeps them for the session retention window (#126351)."""
+ """Hourly media-cache prune (24h max age); spillover (None) keeps the session retention window."""
from gateway.platforms.base import (
cleanup_audio_cache, cleanup_document_cache, cleanup_image_cache, cleanup_screenshot_cache,
cleanup_video_cache)
@@ -34,21 +32,15 @@ def housekeeping_media_caches() -> None:
for cache_name, cleanup_fn in (
("Image", cleanup_image_cache), ("Document", cleanup_document_cache),
("Audio", cleanup_audio_cache), ("Video", cleanup_video_cache),
- ("Screenshot", cleanup_screenshot_cache),
+ ("Screenshot", cleanup_screenshot_cache), ("Spillover", cleanup_spillover_cache),
("Terminal temp", cleanup_terminal_temp_cache), ("Bot DM", cleanup_bot_dm_cache),
("Bot relay", cleanup_bot_relay_artifacts)):
def _one(name=cache_name, fn=cleanup_fn):
- removed = fn(max_age_hours=MEDIA_CACHE_MAX_AGE_HOURS)
+ removed = fn(max_age_hours=None if fn is cleanup_spillover_cache else MEDIA_CACHE_MAX_AGE_HOURS)
if removed:
logger.info("%s cache cleanup: removed %d stale file(s)", name, removed)
_housekeeping_chore(f"{cache_name} cache cleanup", _one)
- def _spillover():
- removed = cleanup_spillover_cache()
- if removed:
- logger.info("Spillover cache cleanup: removed %d stale file(s)", removed)
- _housekeeping_chore("Spillover cache cleanup", _spillover)
-
def maybe_post_auto_prune_prompt(runner, loop) -> None:
"""One housekeeping tick: post the prompt to every served profile that has a home channel, a
diff --git a/hermes_state_maintenance.py b/hermes_state_maintenance.py
index 6cda829d39d..c8404a91b75 100644
--- a/hermes_state_maintenance.py
+++ b/hermes_state_maintenance.py
@@ -357,8 +357,8 @@ class SessionMaintenanceMixin:
(spill_dir / name).unlink(missing_ok=True)
except OSError as exc:
logger.debug("Spillover unlink failed for %s: %s", name, exc)
- except Exception as exc:
- logger.debug("Spillover cleanup after session delete failed: %s", exc)
+ except Exception: # best-effort post-commit cleanup; the orphan sweep retries
+ logger.debug("Spillover cleanup after session delete failed", exc_info=True)
def prune_sessions(self, older_than_days: Optional[float] = 90, source: str | None = None,
sessions_dir: Optional[Path] = None, exclude_active_write_guards: bool = False,
diff --git a/tools/file_tools.py b/tools/file_tools.py
index 75dd2131943..f9eeda023a1 100644
--- a/tools/file_tools.py
+++ b/tools/file_tools.py
@@ -689,11 +689,8 @@ def read_file_tool(path: str, offset: int = 1, limit: int = DEFAULT_READ_LIMIT,
# Failed reads cannot establish whole-file knowledge.
_err = result_dict.get("error") or ""
if isinstance(_err, str) and _err.startswith("File not found:"):
- from tools.tool_result_storage import expired_archive_hint
- _expired = expired_archive_hint(path)
- if _expired:
- result_dict["expired"] = True
- result_dict["hint"] = _expired
+ from tools.tool_result_storage import expired_archive_fields
+ result_dict.update(expired_archive_fields(path))
_record_not_found("read", resolved_str, task_id, json.dumps(result_dict, ensure_ascii=False))
if _err or result_dict.get("is_binary"):
return json.dumps(result_dict, ensure_ascii=False)
diff --git a/tools/tool_result_storage.py b/tools/tool_result_storage.py
index 2d469406766..a2cbafd8806 100644
--- a/tools/tool_result_storage.py
+++ b/tools/tool_result_storage.py
@@ -56,7 +56,7 @@ def _spillover_retention_hours() -> int:
days = float((load_config_readonly().get("sessions") or {}).get("retention_days", 90))
if not math.isfinite(days): # YAML ``.inf`` / ``.nan`` parse as floats; int() would raise
return SPILLOVER_MAX_AGE_HOURS
- except Exception:
+ except Exception: # health: allow BLE001 -- any config read/parse failure means the legacy floor
return SPILLOVER_MAX_AGE_HOURS
# ``retention_days: 0`` is legal (ended sessions pruned at once) but session prune never
# touches OPEN sessions, while a zero-hour spill cutoff deletes the file the first spill
@@ -74,15 +74,16 @@ _SPILLOVER_NAME_RE = re.compile(r"spillover/([A-Za-z0-9_.-]+)")
_ARCHIVE_PATH_RE = re.compile(r"(?:^|[/\\])(?:spillover|hermes-results)[/\\][^/\\]+$")
-def expired_archive_hint(path: str) -> str | None:
- """Hint for a read_file miss on a persisted-tool-result path: the archive was pruned, so the
- model gets "expired" instead of a generic not-found it might mistake for a typo (#126351)."""
+def expired_archive_fields(path: str) -> dict:
+ """Extra read_file not-found fields for a persisted-tool-result path: the archive was pruned,
+ so the model gets "expired" instead of a generic miss it might take for a typo (#126351)."""
if not isinstance(path, str) or not _ARCHIVE_PATH_RE.search(path):
- return None
- return ("This was a persisted tool result archive and it has expired (pruned with its "
+ return {}
+ return {"expired": True, "hint": (
+ "This was a persisted tool result archive and it has expired (pruned with its "
"session or by the cache sweep); the full output is no longer recoverable. Inspect "
"the current state before re-running the original tool — the call that produced it "
- "may already have taken effect.")
+ "may already have taken effect.")}
def spillover_names_in_text(*texts) -> set:
@@ -114,7 +115,7 @@ def referenced_spillover_names(spill_dir) -> set | None:
).fetchall()
finally:
conn.close()
- except Exception:
+ except (sqlite3.Error, OSError):
return None
if len(rows) > 20000: # truncated reference set: treat as unknown, never guess
return None