Skip to content

The agent that grows with you

fix(tools): read_file on a pruned spill archive says "expired" (#126351)

Teknium1f1bb5cdb5ee
diff --git a/tests/tools/test_tool_result_storage.py b/tests/tools/test_tool_result_storage.py
index 36e53414175..b16a110a28e 100644
--- a/tests/tools/test_tool_result_storage.py
+++ b/tests/tools/test_tool_result_storage.py
@@ -23,6 +23,7 @@ from tools.tool_result_storage import (
_write_to_sandbox,
cleanup_spillover_cache,
enforce_turn_budget,
+ extract_persisted_path,
generate_preview,
get_spillover_dir,
maybe_persist_tool_result,
@@ -606,6 +607,25 @@ class TestSpillover:
assert not old.exists()
assert (spill_dir / "tc_prune_1.txt").exists()
+ def test_read_file_on_pruned_archive_says_expired(self, tmp_path, monkeypatch):
+ """A pruned archive's pointer read via read_file says "expired", not a generic miss;
+ an ordinary missing file keeps the plain not-found result."""
+ monkeypatch.setenv("TERMINAL_CWD", str(tmp_path))
+ monkeypatch.chdir(tmp_path)
+ from tools.file_tools import read_file_tool
+ out = maybe_persist_tool_result(content="z" * 50_000, tool_name="terminal",
+ tool_use_id="tc_expired_1", env=None, threshold=30_000)
+ path = extract_persisted_path(out)
+ assert path
+ os.remove(path)
+
+ expired = json.loads(read_file_tool(path, task_id="t_expired_archive"))
+ plain = json.loads(read_file_tool(str(tmp_path / "nope.txt"), task_id="t_expired_archive"))
+
+ assert expired["error"].startswith("File not found:")
+ assert expired.get("expired") is True and "expired" in expired["hint"]
+ assert "expired" not in plain and "expired" not in (plain.get("hint") or "")
+
# ── recovery hint in the persisted preview ────────────────────────────
# ── MCP envelope unwrapping (#90426) ──────────────────────────────────
diff --git a/tools/file_tools.py b/tools/file_tools.py
index 237d97d87e6..75dd2131943 100644
--- a/tools/file_tools.py
+++ b/tools/file_tools.py
@@ -689,6 +689,11 @@ 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
_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 aa2c7f4ce4b..2d469406766 100644
--- a/tools/tool_result_storage.py
+++ b/tools/tool_result_storage.py
@@ -71,6 +71,20 @@ def _spillover_retention_hours() -> int:
_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)."""
+ 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 "
+ "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.")
+
+
def spillover_names_in_text(*texts) -> set:
"""Spillover archive basenames referenced by transcript message text (empty set on none)."""
names: set = set()