mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-04-30 23:05:51 +00:00
fix(memory): handle missing cursor key in history entries
- Use .get('cursor') instead of direct dict access to prevent KeyError
- Skip entries without cursor and log a warning
- Fix _next_cursor fallback to safely check for cursor existence
Fixes #3190
This commit is contained in:
parent
2b8e90d8fd
commit
f4a7ad16aa
@ -239,13 +239,21 @@ class MemoryStore:
|
|||||||
pass
|
pass
|
||||||
# Fallback: read last line's cursor from the JSONL file.
|
# Fallback: read last line's cursor from the JSONL file.
|
||||||
last = self._read_last_entry()
|
last = self._read_last_entry()
|
||||||
if last:
|
if last and last.get("cursor") is not None:
|
||||||
return last["cursor"] + 1
|
return last["cursor"] + 1
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def read_unprocessed_history(self, since_cursor: int) -> list[dict[str, Any]]:
|
def read_unprocessed_history(self, since_cursor: int) -> list[dict[str, Any]]:
|
||||||
"""Return history entries with cursor > *since_cursor*."""
|
"""Return history entries with cursor > *since_cursor*."""
|
||||||
return [e for e in self._read_entries() if e["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
|
||||||
|
|
||||||
def compact_history(self) -> None:
|
def compact_history(self) -> None:
|
||||||
"""Drop oldest entries if the file exceeds *max_history_entries*."""
|
"""Drop oldest entries if the file exceeds *max_history_entries*."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user