From 9be7c0b1d29f6c52a2c3e26ba0762aaf051a5e70 Mon Sep 17 00:00:00 2001 From: koko210Serve Date: Wed, 8 Apr 2026 14:53:13 +0300 Subject: [PATCH] fix: make /config/state return live runtime values from globals config_manager.runtime_state was a plain dict initialized with hardcoded defaults (dm_mood='neutral', evil_mode=False, etc.) that were never updated by any code path except current_gpu. The /config/state endpoint and get_full_config() both returned this stale dict, so the API always reported neutral mood and english mode regardless of actual state. Replaced the static dict with a @property that reads live values from globals (DM_MOOD, EVIL_MODE, BIPOLAR_MODE, LANGUAGE_MODE) on every access. GPU state is still managed via _current_gpu and persisted to gpu_state.json. get_state() and set_state() continue to work for the GPU path. --- bot/config_manager.py | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/bot/config_manager.py b/bot/config_manager.py index b644ddd..4c615ee 100644 --- a/bot/config_manager.py +++ b/bot/config_manager.py @@ -48,16 +48,10 @@ class ConfigManager: self.static_config: Dict = self._load_static_config() self.runtime_config: Dict = self._load_runtime_config() - # Runtime state (not persisted) - self.runtime_state: Dict = { - "dm_mood": "neutral", - "evil_mode": False, - "bipolar_mode": False, - "language_mode": "english", - "current_gpu": "nvidia", - } + # GPU state (the only piece of runtime_state that is persisted to its own file) + self._current_gpu: str = "nvidia" - # Load persisted state + # Load persisted state (GPU) self._load_runtime_state() logger.info("✅ ConfigManager initialized") @@ -100,8 +94,8 @@ class ConfigManager: if gpu_state_file.exists(): with open(gpu_state_file, "r") as f: gpu_state = json.load(f) - self.runtime_state["current_gpu"] = gpu_state.get("current_gpu", "nvidia") - logger.debug(f"✅ Loaded GPU state: {self.runtime_state['current_gpu']}") + self._current_gpu = gpu_state.get("current_gpu", "nvidia") + logger.debug(f"✅ Loaded GPU state: {self._current_gpu}") except Exception as e: logger.error(f"❌ Failed to load GPU state: {e}") @@ -261,13 +255,31 @@ class ConfigManager: # ========== Runtime State Management ========== + @property + def runtime_state(self) -> Dict: + """ + Return live runtime state assembled from globals (the actual source of truth). + + Previously this was a static dict that was never updated, causing /config/state + to always return stale defaults. Now it reads the real values each time. + """ + import globals as g + return { + "dm_mood": getattr(g, "DM_MOOD", "neutral"), + "evil_mode": getattr(g, "EVIL_MODE", False), + "bipolar_mode": getattr(g, "BIPOLAR_MODE", False), + "language_mode": getattr(g, "LANGUAGE_MODE", "english"), + "current_gpu": self._current_gpu, + } + def get_state(self, key: str, default: Any = None) -> Any: - """Get runtime state value (not persisted to config).""" + """Get runtime state value.""" return self.runtime_state.get(key, default) def set_state(self, key: str, value: Any): - """Set runtime state value.""" - self.runtime_state[key] = value + """Set runtime state value. Only current_gpu is managed here; other state lives in globals.""" + if key == "current_gpu": + self._current_gpu = value logger.debug(f"📊 State: {key} = {value}") # ========== Server Configuration ==========