Chirag0123 commited on
Commit
87b51e4
Β·
1 Parent(s): 1dd1900

fix: Handle permission errors for memory persistence on read-only environments

Browse files
Files changed (1) hide show
  1. server/memory_bank.py +14 -2
server/memory_bank.py CHANGED
@@ -286,8 +286,20 @@ class EpisodicMemoryBank:
286
  # ── Persistence ───────────────────────────────────────────────────────────
287
 
288
  def _save(self):
289
- with open(self.persist_path, "w") as f:
290
- json.dump([e.to_dict() for e in self._entries], f, indent=2)
 
 
 
 
 
 
 
 
 
 
 
 
291
 
292
  def _load(self):
293
  try:
 
286
  # ── Persistence ───────────────────────────────────────────────────────────
287
 
288
  def _save(self):
289
+ tpath = getattr(self, "persist_path", None)
290
+ if not tpath:
291
+ return
292
+ try:
293
+ with open(tpath, "w") as f:
294
+ json.dump([e.to_dict() for e in self._entries], f, indent=2)
295
+ except PermissionError:
296
+ import tempfile
297
+ fallback = os.path.join(tempfile.gettempdir(), "agent_memory.json")
298
+ if self.persist_path != fallback:
299
+ self.persist_path = fallback
300
+ self._save()
301
+ except Exception as e:
302
+ print(f"[MemoryBank] Warning: Failed to save to {self.persist_path}: {e}")
303
 
304
  def _load(self):
305
  try: