Skip to content

Your lightweight open-source personal agent.

fix(memory): also fsync directory for rename durability

yorkhellen53ca2836e7bf
diff --git a/nanobot/agent/memory.py b/nanobot/agent/memory.py
index 3b34f68d7..4cf687d4a 100644
--- a/nanobot/agent/memory.py
+++ b/nanobot/agent/memory.py
@@ -369,6 +369,19 @@ class MemoryStore:
f.flush()
os.fsync(f.fileno())
os.replace(tmp_path, self.history_file)
+
+ # fsync the directory so the rename is durable.
+ # On Windows, opening a directory with O_RDONLY raises
+ # PermissionError — skip the dir sync there (NTFS
+ # journals metadata synchronously).
+ try:
+ fd = os.open(str(self.history_file.parent), os.O_RDONLY)
+ try:
+ os.fsync(fd)
+ finally:
+ os.close(fd)
+ except PermissionError:
+ pass # Windows — directory fsync not supported
except BaseException:
tmp_path.unlink(missing_ok=True)
raise