From 524c097f76bbcb883c30dde7a11cdeee2cfb8b6d Mon Sep 17 00:00:00 2001 From: chengyongru Date: Thu, 16 Apr 2026 10:33:29 +0800 Subject: [PATCH] refactor(memory): simplify read_unprocessed_history cursor guard Replace verbose loop with one-liner list comprehension using e.get("cursor", 0) to handle missing cursor keys. --- nanobot/agent/memory.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/nanobot/agent/memory.py b/nanobot/agent/memory.py index bed1b6d3..66da912f 100644 --- a/nanobot/agent/memory.py +++ b/nanobot/agent/memory.py @@ -245,15 +245,7 @@ class MemoryStore: def read_unprocessed_history(self, since_cursor: int) -> list[dict[str, Any]]: """Return history entries with cursor > *since_cursor*.""" - entries = [] - for e in self._read_entries(): - cursor = e.get("cursor") - if cursor is None: - logger.warning("Skipping history entry without cursor: {}", e.get("timestamp", "unknown")) - continue - if cursor > since_cursor: - entries.append(e) - return entries + return [e for e in self._read_entries() if e.get("cursor", 0) > since_cursor] def compact_history(self) -> None: """Drop oldest entries if the file exceeds *max_history_entries*."""