From 9fa90b1034555afb7c754034674c35148689be30 Mon Sep 17 00:00:00 2001 From: Jiajun Xie Date: Tue, 5 May 2026 09:24:02 +0000 Subject: [PATCH] fix: only advance dream_cursor on completed batches to prevent silent loss --- nanobot/agent/memory.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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"]