fix: /config/reset now resets live globals to defaults

reset_to_defaults() previously only cleared the runtime_config dict and
saved config_runtime.yaml, but never touched the actual globals that
control runtime behavior. After a reset, LANGUAGE_MODE, AUTONOMOUS_DEBUG,
VOICE_DEBUG_MODE, USE_CHESHIRE_CAT, PREFER_AMD_GPU, and DM_MOOD all kept
their current in-memory values until the next restart.

Now reset_to_defaults() also resets the corresponding globals to their
default values from CONFIG (the static config loaded from config.yaml).
Both full reset and single-key reset are supported. The default values
come from the Pydantic AppConfig schema, ensuring consistency.

Tested: set non-default values, full reset -> all back to defaults,
single-key reset -> only that key back to default, runtime_state property
reflects the reset immediately.
This commit is contained in:
2026-04-08 14:58:29 +03:00
parent 9be7c0b1d2
commit 7c9cf0d8b4

View File

@@ -225,9 +225,16 @@ class ConfigManager:
"""
Reset configuration to defaults.
Clears runtime overrides from config_runtime.yaml AND resets the
corresponding globals to their default values so the change takes
effect immediately without a restart.
Args:
key_path: Specific key to reset, or None to reset all runtime config
"""
import globals as g
from config import CONFIG
if key_path:
# Remove specific key from runtime config
self._remove_nested_key(self.runtime_config, key_path)
@@ -239,6 +246,38 @@ class ConfigManager:
self.save_runtime_config()
# ---- Reset live globals to match defaults ----
# Map: config_runtime key path -> (globals attr, default from CONFIG)
_DEFAULTS_MAP = {
"discord.language_mode": ("LANGUAGE_MODE", CONFIG.discord.language_mode),
"autonomous.debug_mode": ("AUTONOMOUS_DEBUG", CONFIG.autonomous.debug_mode),
"voice.debug_mode": ("VOICE_DEBUG_MODE", CONFIG.voice.debug_mode),
"memory.use_cheshire_cat": ("USE_CHESHIRE_CAT", CONFIG.cheshire_cat.enabled),
"gpu.prefer_amd": ("PREFER_AMD_GPU", CONFIG.gpu.prefer_amd),
}
reset_items = []
if key_path:
# Reset only the specific global
if key_path in _DEFAULTS_MAP:
attr, default = _DEFAULTS_MAP[key_path]
setattr(g, attr, default)
reset_items.append(f"{attr}={default}")
else:
# Reset all globals to defaults
for kp, (attr, default) in _DEFAULTS_MAP.items():
setattr(g, attr, default)
reset_items.append(f"{attr}={default}")
# Also reset DM mood to neutral
g.DM_MOOD = "neutral"
g.DM_MOOD_DESCRIPTION = "I'm feeling neutral and balanced today."
reset_items.append("DM_MOOD=neutral")
if reset_items:
logger.info(f"🔄 Reset {len(reset_items)} globals: {', '.join(reset_items)}")
def _remove_nested_key(self, config: Dict, key_path: str):
"""Remove nested key from config."""
keys = key_path.split(".")