The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tools): spill pointers in structured content and Windows paths count as references (#126351)
Teknium309fddabacd4
diff --git a/hermes_state_media.py b/hermes_state_media.pyindex acc8260bc8a..097e7e29412 100644--- a/hermes_state_media.py+++ b/hermes_state_media.py@@ -22,11 +22,11 @@ def retire_spillover(conn, session_ids):"""Record the spillover archives the doomed sessions' messages point at, inside the deletetransaction (the pointers vanish with the rows), as durable candidates (#126351)."""from hermes_state_common import _id_chunks, _placeholders- from tools.tool_result_storage import spillover_names_in_text+ from tools.tool_result_storage import SPILLOVER_SQL_FILTER, spillover_names_in_textfor chunk in _id_chunks(list(session_ids)):for content, api_content in conn.execute(f"SELECT content, api_content FROM messages WHERE session_id IN ({_placeholders(chunk)})"- " AND (content LIKE '%spillover/%' OR api_content LIKE '%spillover/%')", chunk).fetchall():+ f" AND {SPILLOVER_SQL_FILTER}", chunk).fetchall():conn.executemany('INSERT OR IGNORE INTO state_meta(key,value) VALUES(?,?)',[(SPILLOVER_PREFIX + n, json.dumps(n)) for n in spillover_names_in_text(content, api_content)])diff --git a/tests/test_session_spillover_cleanup.py b/tests/test_session_spillover_cleanup.pyindex 35f410e535c..352099af7cd 100644--- a/tests/test_session_spillover_cleanup.py+++ b/tests/test_session_spillover_cleanup.py@@ -80,6 +80,26 @@ def test_retained_sessions_spill_survives_the_age_sweep(_home):db.close()+def test_structured_and_backslashed_pointers_are_owned(_home):+ """A pointer inside multimodal content (stored behind the NUL sentinel, invisible to LIKE)+ and a backslashed Windows host path both count as references, and both leave with their+ session."""+ db = SessionDB(db_path=_home / "state.db")+ try:+ db.create_session("s", "cli")+ db.append_message("s", "tool", [{"type": "text", "text": _pointer(_home, "parts.txt")},+ {"type": "image_url", "image_url": {"url": "data:image/png;base64,AA"}}])+ db.append_message("s", "tool", "Full output saved to: C:\\h\\cache\\spillover\\win.txt")+ files = [_spill(_home, "parts.txt", age_hours=200 * 24), _spill(_home, "win.txt", age_hours=200 * 24)]++ assert cleanup_spillover_cache(max_age_hours=24) == 0+ assert all(f.exists() for f in files)+ db.delete_session("s")+ assert not any(f.exists() for f in files)+ finally:+ db.close()++def test_prune_sessions_unlinks_the_spill_with_its_session(_home):db = SessionDB(db_path=_home / "state.db")try:diff --git a/tools/tool_result_storage.py b/tools/tool_result_storage.pyindex a2cbafd8806..8ccf4dd73c1 100644--- a/tools/tool_result_storage.py+++ b/tools/tool_result_storage.py@@ -68,7 +68,10 @@ def _spillover_retention_hours() -> int:# the ``~``-relative translation, the in-container mounted path — carries the ``spillover/<name>``# segment. Sandbox-fallback pointers (``…/hermes-results/<name>``) do not, so their host-side# original stays unreferenced and is reclaimed by the orphan sweep, never by ownership.-_SPILLOVER_NAME_RE = re.compile(r"spillover/([A-Za-z0-9_.-]+)")+# Either separator: Windows host paths are backslashed (JSON-escaped as ``\\`` inside structured content).+_SPILLOVER_NAME_RE = re.compile(r"spillover(?:/|\\+)([A-Za-z0-9_.-]+)")+# instr(), not LIKE: structured content is stored behind a NUL sentinel and LIKE stops at NUL.+SPILLOVER_SQL_FILTER = "(instr(content, 'spillover') > 0 OR instr(api_content, 'spillover') > 0)"_ARCHIVE_PATH_RE = re.compile(r"(?:^|[/\\])(?:spillover|hermes-results)[/\\][^/\\]+$")@@ -90,7 +93,7 @@ def spillover_names_in_text(*texts) -> set:"""Spillover archive basenames referenced by transcript message text (empty set on none)."""names: set = set()for text in texts:- if isinstance(text, str) and "spillover/" in text:+ if isinstance(text, str) and "spillover" in text:names.update(_SPILLOVER_NAME_RE.findall(text))return names@@ -109,9 +112,7 @@ def referenced_spillover_names(spill_dir) -> set | None:conn = sqlite3.connect(f"{db_path.as_uri()}?mode=ro", uri=True, timeout=5.0)try:rows = conn.execute(- "SELECT content, api_content FROM messages "- "WHERE content LIKE '%spillover/%' OR api_content LIKE '%spillover/%' "- "LIMIT 20001"+ f"SELECT content, api_content FROM messages WHERE {SPILLOVER_SQL_FILTER} LIMIT 20001").fetchall()finally:conn.close()