fix(memory): reject negative history cursors
This commit is contained in:
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user