qin-chenghan 9eebc6a9e5
fix(config): sync _memory_config with AppConfig auto-reload (#4208)
* fix(config): sync _memory_config with AppConfig auto-reload

get_memory_config() now calls get_app_config() before returning the
cached _memory_config singleton. get_app_config() auto-reloads when
the config file signature changes, and its _apply_singleton_configs()
calls load_memory_config_from_dict() to populate _memory_config.
Without this side effect, changing memory.mode in config.yaml (e.g.
from "middleware" to "tool") would never take effect at runtime
because _memory_config retained the stale value.

Only call get_app_config() when _app_config has already been loaded
to avoid picking up a config file as a side effect of the first
access to get_memory_config(), which would break callers that expect
module-level defaults (e.g. unit tests). Catch FileNotFoundError for
environments without a config file.

Closes #4204.

* fix(memory): broaden config-reload guard and add isolated-path tests

Addresses two review findings from willem-bd:

1. Broken-config crash risk: broaden the except from FileNotFoundError
   to Exception so transiently broken config.yaml (YAMLError,
   ValidationError, ValueError) falls back to the last-good singleton
   instead of crashing per-turn hot paths (memory_middleware,
   summarization_hook, lead_agent/prompt.py).

2. Missing regression test: add test_get_memory_config_self_syncs_...
   (calls get_memory_config() after file mutation with no intervening
   get_app_config() call) and test_get_memory_config_falls_back_on_...
   (verifies broken config does not crash, returns cached value).
2026-07-21 10:14:29 +08:00
..