deerflow2/backend/packages/harness/deerflow/agents/memory
DanielWalnut 898f4e8ac2
fix: Memory update system has cache corruption, data loss, and thread-safety bugs (#2251)
* fix(memory): cache corruption, thread-safety, and caller mutation bugs

Bug 1 (updater.py): deep-copy current_memory before passing to
_apply_updates() so a subsequent save() failure cannot leave a
partially-mutated object in the storage cache.

Bug 3 (storage.py): add _cache_lock (threading.Lock) to
FileMemoryStorage and acquire it around every read/write of
_memory_cache, fixing concurrent-access races between the background
timer thread and HTTP reload calls.

Bug 4 (storage.py): replace in-place mutation
  memory_data["lastUpdated"] = ...
with a shallow copy
  memory_data = {**memory_data, "lastUpdated": ...}
so save() no longer silently modifies the caller's dict.

Regression tests added for all three bugs in test_memory_storage.py
and test_memory_updater.py.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* style: format test_memory_updater.py with ruff

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* style: remove stale bug-number labels from code comments and docstrings

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 12:00:31 +08:00
..
__init__.py feat: add memory management actions and local filters in memory settings (#1467) 2026-03-29 13:14:45 +08:00
message_processing.py feat: flush memory before summarization (#2176) 2026-04-14 15:01:06 +08:00
prompt.py fix: inject longTermBackground into memory prompt (#1734) 2026-04-03 11:21:58 +08:00
queue.py feat: flush memory before summarization (#2176) 2026-04-14 15:01:06 +08:00
storage.py fix: Memory update system has cache corruption, data loss, and thread-safety bugs (#2251) 2026-04-17 12:00:31 +08:00
summarization_hook.py feat: flush memory before summarization (#2176) 2026-04-14 15:01:06 +08:00
updater.py fix: Memory update system has cache corruption, data loss, and thread-safety bugs (#2251) 2026-04-17 12:00:31 +08:00