The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(memory): keep a runaway-recall ceiling when prefetch spilling is off
teknium18bff64d6ed34
diff --git a/agent/memory_manager.py b/agent/memory_manager.pyindex 63c75957db0..d8f772f7f91 100644--- a/agent/memory_manager.py+++ b/agent/memory_manager.py@@ -455,10 +455,9 @@ class MemoryManager:# Snapshot both gates at registration, never re-read them mid-conversation.memory = load_config().get("memory", {})spill_config = get_spill_config()- spill_config["enabled"] = (- spill_config["enabled"] and isinstance(memory, dict)- and memory.get("prefetch_spill_enabled", False) is True- )+ if not (isinstance(memory, dict) and memory.get("prefetch_spill_enabled", False) is True):+ # Off by default, but keep a ceiling so a runaway provider can't overflow the context.+ spill_config["max_chars"] = max(spill_config["max_chars"] * 10, 100_000)self._external_prefetch_spill_config = spill_configself._has_external = Truediff --git a/tests/agent/test_memory_provider.py b/tests/agent/test_memory_provider.pyindex 68d41482eb2..6da68343870 100644--- a/tests/agent/test_memory_provider.py+++ b/tests/agent/test_memory_provider.py@@ -225,7 +225,7 @@ class TestMemoryManager:"memory": memory,"hooks": {"output_spill": {} if hooks_enabled else {"enabled": False}},})- text = "start\n" + "ranked middle\n" * DEFAULT_MAX_CHARS + "end\n"+ text = "start\n" + "ranked middle\n" * (DEFAULT_MAX_CHARS // 2) + "end\n" # over max_chars, under the ceilingprovider = FakeMemoryProvider("external")provider._prefetch_result = textmgr = MemoryManager()@@ -255,6 +255,22 @@ class TestMemoryManager:assert mgr.prefetch_all("recall again", session_id="memory") == textassert not (tmp_path / "hook_outputs" / "memory").exists()+ def test_runaway_recall_still_spills_without_opt_in(self, tmp_path, monkeypatch):+ """Opt-out keeps normal recall whole but still caps a runaway provider at the ceiling."""+ from hermes_cli.config import atomic_config_write++ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ atomic_config_write(tmp_path / "config.yaml", {"memory": {}})+ provider = FakeMemoryProvider("external")+ provider._prefetch_result = "x" * 100_001+ mgr = MemoryManager()+ mgr.add_provider(provider)++ result = mgr.prefetch_all("recall", session_id="runaway")+ assert len(result) < 100_000+ (saved,) = (tmp_path / "hook_outputs" / "runaway").glob("*.txt")+ assert saved.read_text(encoding="utf-8").rstrip("\n") == provider._prefetch_result+def test_prefetch_spill_profile_snapshot_preserves_opt_in(self, tmp_path, monkeypatch):"""A→B→A config reads are isolated; existing managers keep their registration policy."""from agent.secret_scope import (diff --git a/website/docs/developer-guide/memory-provider-plugin.md b/website/docs/developer-guide/memory-provider-plugin.mdindex bcd83c8fbe2..d7f2e1f37ec 100644--- a/website/docs/developer-guide/memory-provider-plugin.md+++ b/website/docs/developer-guide/memory-provider-plugin.md@@ -189,7 +189,9 @@ identity should skip destructive mirroring when it is absent.### Oversized prefetch resultsExternal `prefetch()` results are returned in full by default, preserving the-provider's relevance-ranked recall. To opt into spilling oversized results for+provider's relevance-ranked recall, up to a safety ceiling of 10×+`hooks.output_spill.max_chars` (at least 100,000 characters) above which they+still spill. Keep your own recall budget well under that. To opt into spilling oversized results forthe active profile, set:```yamldiff --git a/website/docs/user-guide/features/memory.md b/website/docs/user-guide/features/memory.mdindex 1926e491cce..1d37fc71c68 100644--- a/website/docs/user-guide/features/memory.md+++ b/website/docs/user-guide/features/memory.md@@ -292,7 +292,10 @@ The inverse configuration advertises only `memory` and rejects `USER.md` writes.### External recall size-External memory providers return their full prefetched context by default.+External memory providers return their full prefetched context by default,+up to a safety ceiling of 10× `hooks.output_spill.max_chars` (at least 100,000+characters); recall above that still spills so a runaway provider can't overflow+the context window.`memory.prefetch_spill_enabled: true` opts the active profile into replacingoversized recall with a head/tail preview and a file path. This can reducereplayed context, but the relevance-ranked middle is no longer immediately