Skip to content

Your lightweight open-source personal agent.

fix(memory): migrate legacy HISTORY.md even when history.jsonl is empty

Xubin Ren04419326adc3
diff --git a/nanobot/agent/memory.py b/nanobot/agent/memory.py
index c00afaadb..3fbc651c9 100644
--- a/nanobot/agent/memory.py
+++ b/nanobot/agent/memory.py
@@ -72,7 +72,9 @@ class MemoryStore:
The migration is best-effort and prioritizes preserving as much content
as possible over perfect parsing.
"""
- if self.history_file.exists() or not self.legacy_history_file.exists():
+ if not self.legacy_history_file.exists():
+ return
+ if self.history_file.exists() and self.history_file.stat().st_size > 0:
return
try:
diff --git a/tests/agent/test_memory_store.py b/tests/agent/test_memory_store.py
index e7a829140..efe7d198e 100644
--- a/tests/agent/test_memory_store.py
+++ b/tests/agent/test_memory_store.py
@@ -232,6 +232,24 @@ class TestLegacyHistoryMigration:
assert legacy_file.exists()
assert not (memory_dir / "HISTORY.md.bak").exists()
+ def test_empty_history_jsonl_still_allows_legacy_migration(self, tmp_path):
+ memory_dir = tmp_path / "memory"
+ memory_dir.mkdir()
+ history_file = memory_dir / "history.jsonl"
+ history_file.write_text("", encoding="utf-8")
+ legacy_file = memory_dir / "HISTORY.md"
+ legacy_file.write_text("[2026-04-01 10:00] legacy\n\n", encoding="utf-8")
+
+ store = MemoryStore(tmp_path)
+
+ entries = store.read_unprocessed_history(since_cursor=0)
+ assert len(entries) == 1
+ assert entries[0]["cursor"] == 1
+ assert entries[0]["timestamp"] == "2026-04-01 10:00"
+ assert entries[0]["content"] == "legacy"
+ assert not legacy_file.exists()
+ assert (memory_dir / "HISTORY.md.bak").exists()
+
def test_migrates_legacy_history_with_invalid_utf8_bytes(self, tmp_path):
memory_dir = tmp_path / "memory"
memory_dir.mkdir()