fix(memory): reject negative history cursors

This commit is contained in:
Xubin Ren
2026-06-21 13:05:57 +08:00
parent be058c0922
commit a81c5e704a
2 changed files with 20 additions and 7 deletions
+4 -4
View File
@@ -61,7 +61,7 @@ class MemoryStore:
self.user_file = workspace / "USER.md"
self._cursor_file = self.memory_dir / ".cursor"
self._dream_cursor_file = self.memory_dir / ".dream_cursor"
self._corruption_logged = False # rate-limit non-int cursor warning
self._corruption_logged = False # rate-limit invalid cursor warning
self._malformed_entry_logged = False # rate-limit bad history shape warning
self._oversize_logged = False # rate-limit oversized-entry warning
self._append_lock = threading.Lock() # serialize cursor allocation + append
@@ -291,8 +291,8 @@ class MemoryStore:
@staticmethod
def _valid_cursor(value: Any) -> int | None:
"""Int cursors only reject bool (``isinstance(True, int)`` is True)."""
if isinstance(value, bool) or not isinstance(value, int):
"""Non-negative int cursors only; reject bool (``isinstance(True, int)`` is True)."""
if isinstance(value, bool) or not isinstance(value, int) or value < 0:
return None
return value
@@ -315,7 +315,7 @@ class MemoryStore:
if poisoned is not None and not self._corruption_logged:
self._corruption_logged = True
logger.warning(
"history.jsonl contains a non-int cursor ({!r}); dropping it. "
"history.jsonl contains an invalid cursor ({!r}); dropping it. "
"Usually caused by an external writer; further occurrences suppressed.",
poisoned,
)