Skip to content

The agent that grows with you

fix(memory): point empty-batch refusal at single remove() calls (#103419)

Halldrix7602b33d79d9
diff --git a/tests/tools/test_memory_tool.py b/tests/tools/test_memory_tool.py
index 6b7346ccf23..f1823f05231 100644
--- a/tests/tools/test_memory_tool.py
+++ b/tests/tools/test_memory_tool.py
@@ -733,6 +733,7 @@ class TestBatchRefusesToEmptyNonEmptyStore:
assert result["success"] is False
assert "current_entries" in result # actionable, counts toward degrade budget
+ assert "single remove()" in result["error"] # points at the deliberate-wipe path
assert seed in path.read_text(encoding="utf-8") # nothing written
assert path.read_text(encoding="utf-8") == before
assert seed in store._entries_for(target)
diff --git a/tools/memory_tool_store.py b/tools/memory_tool_store.py
index 4dcc3b57018..50d8ae141ee 100644
--- a/tools/memory_tool_store.py
+++ b/tools/memory_tool_store.py
@@ -322,14 +322,16 @@ class MemoryStore:
# store (#103419): a background consolidation that removes the
# last entry would otherwise commit an empty USER.md/MEMORY.md
# as a normal successful write. Refuse all-or-nothing so the
- # model keeps at least one entry; a deliberate wipe is a manual
- # file edit, not a consolidation side effect.
+ # model keeps at least one entry; deleting the final entry on
+ # purpose is what single remove() calls are for, not a
+ # consolidation side effect.
label = "USER.md" if target == "user" else "MEMORY.md"
return self._failure_with_entries(target, (
f"Refusing to empty {label}: this batch would remove every entry from a "
f"previously non-empty profile. Nothing was applied (batch is all-or-nothing). "
f"Keep at least one entry — merge overlapping entries into a shorter one instead "
- f"of removing the last one (see current_entries below)."))
+ f"of removing the last one (see current_entries below). To delete the final entry "
+ f"deliberately, use single remove() calls."))
new_total = len(ENTRY_DELIMITER.join(working)) # budget check against the FINAL state only
if new_total > limit:
return self._failure_with_entries(target, (