Skip to content

Your lightweight open-source personal agent.

fix: only advance dream_cursor on completed batches to prevent silent loss

Jiajun Xie9fa90b103455
diff --git a/nanobot/agent/memory.py b/nanobot/agent/memory.py
index 85cc5ab4a..7794af5c2 100644
--- a/nanobot/agent/memory.py
+++ b/nanobot/agent/memory.py
@@ -974,12 +974,10 @@ class Dream:
if event["status"] == "ok":
changelog.append(f"{event['name']}: {event['detail']}")
- # Advance cursor — always, to avoid re-processing Phase 1
- new_cursor = batch[-1]["cursor"]
- self.store.set_last_dream_cursor(new_cursor)
- self.store.compact_history()
-
+ # Only advance cursor on successful completion to prevent silent loss
if result and result.stop_reason == "completed":
+ new_cursor = batch[-1]["cursor"]
+ self.store.set_last_dream_cursor(new_cursor)
logger.info(
"Dream done: {} change(s), cursor advanced to {}",
len(changelog), new_cursor,
@@ -987,10 +985,12 @@ class Dream:
else:
reason = result.stop_reason if result else "exception"
logger.warning(
- "Dream incomplete ({}): cursor advanced to {}",
- reason, new_cursor,
+ "Dream incomplete ({}): cursor NOT advanced, will retry next cron cycle",
+ reason,
)
+ self.store.compact_history()
+
# Git auto-commit (only when there are actual changes)
if changelog and self.store.git.is_initialized():
ts = batch[-1]["timestamp"]