MEDIUM: Runtime Settings Not Persisted - Globals Need Migration #22

Closed
opened 2026-02-16 22:42:10 +02:00 by Koko210 · 1 comment
Owner

Runtime settings (AUTONOMOUS_DEBUG, VOICE_DEBUG_MODE, LANGUAGE_MODE, moods) are stored as globals instead of in ConfigManager, making persistence and tracking difficult.

Where It Occurs

  • bot/globals.py - AUTONOMOUS_DEBUG, VOICE_DEBUG_MODE, LANGUAGE_MODE global variables
  • bot/config_manager.py - Missing runtime state persistence
  • bot/server_manager.py - Debug mode toggles
  • bot/utils/moods.py - Mood state as global

Why This Is a Problem

  1. No Persistence: Runtime changes lost on restart
  2. No Tracking: Cannot see history of runtime changes
  3. Inconsistency: Some settings in globals, some in config.yaml
  4. Race Conditions: Multiple files modify same globals without coordination

What Can Go Wrong

Scenario 1: Lost Debug Settings

  1. User enables voice debug mode for troubleshooting
  2. Bot runs for 24 hours with debug enabled
  3. Bot crashes or restarts
  4. Debug mode not persisted, resets to off
  5. User loses all debug logs from session
  6. Issue that occurred cannot be reproduced

Scenario 2: Mood Inconsistency

  1. User changes mood to "happy" via command
  2. Mood stored in globals.mood
  3. Web UI shows different mood (from config.yaml)
  4. Bot behaves unpredictably
  5. User confused about actual mood

Proposed Fix

Migrate runtime settings to ConfigManager:

# bot/config_manager.py
class ConfigManager:
    def __init__(self):
        self.config = self.load_config()
        self.runtime_state = self.load_runtime_state()  # New method
    
    def load_runtime_state(self):
        """Load runtime state from config_runtime.yaml"""
        state_file = "config_runtime.yaml"
        if os.path.exists(state_file):
            with open(state_file) as f:
                return yaml.safe_load(f)
        return {
            "autonomous_debug": False,
            "voice_debug_mode": False,
            "language_mode": "en",
            "mood": "normal"
        }
    
    def save_runtime_state(self):
        """Persist runtime state to config_runtime.yaml"""
        with open("config_runtime.yaml", "w") as f:
            yaml.dump(self.runtime_state, f)
    
    def get_runtime_state(self, key, default=None):
        return self.runtime_state.get(key, default)
    
    def set_runtime_state(self, key, value):
        self.runtime_state[key] = value
        self.save_runtime_state()

Update all references:

  • globals.AUTONOMOUS_DEBUG → config_manager.get_runtime_state("autonomous_debug")
  • globals.VOICE_DEBUG_MODE → config_manager.get_runtime_state("voice_debug_mode")
  • globals.LANGUAGE_MODE → config_manager.get_runtime_state("language_mode")

Severity

MEDIUM - Runtime state not persisted, changes lost on restart.

Files Affected

bot/globals.py, bot/config_manager.py, bot/server_manager.py, bot/utils/moods.py

Runtime settings (AUTONOMOUS_DEBUG, VOICE_DEBUG_MODE, LANGUAGE_MODE, moods) are stored as globals instead of in ConfigManager, making persistence and tracking difficult. ## Where It Occurs - bot/globals.py - AUTONOMOUS_DEBUG, VOICE_DEBUG_MODE, LANGUAGE_MODE global variables - bot/config_manager.py - Missing runtime state persistence - bot/server_manager.py - Debug mode toggles - bot/utils/moods.py - Mood state as global ## Why This Is a Problem 1. No Persistence: Runtime changes lost on restart 2. No Tracking: Cannot see history of runtime changes 3. Inconsistency: Some settings in globals, some in config.yaml 4. Race Conditions: Multiple files modify same globals without coordination ## What Can Go Wrong ### Scenario 1: Lost Debug Settings 1. User enables voice debug mode for troubleshooting 2. Bot runs for 24 hours with debug enabled 3. Bot crashes or restarts 4. Debug mode not persisted, resets to off 5. User loses all debug logs from session 6. Issue that occurred cannot be reproduced ### Scenario 2: Mood Inconsistency 1. User changes mood to "happy" via command 2. Mood stored in globals.mood 3. Web UI shows different mood (from config.yaml) 4. Bot behaves unpredictably 5. User confused about actual mood ## Proposed Fix Migrate runtime settings to ConfigManager: ```python # bot/config_manager.py class ConfigManager: def __init__(self): self.config = self.load_config() self.runtime_state = self.load_runtime_state() # New method def load_runtime_state(self): """Load runtime state from config_runtime.yaml""" state_file = "config_runtime.yaml" if os.path.exists(state_file): with open(state_file) as f: return yaml.safe_load(f) return { "autonomous_debug": False, "voice_debug_mode": False, "language_mode": "en", "mood": "normal" } def save_runtime_state(self): """Persist runtime state to config_runtime.yaml""" with open("config_runtime.yaml", "w") as f: yaml.dump(self.runtime_state, f) def get_runtime_state(self, key, default=None): return self.runtime_state.get(key, default) def set_runtime_state(self, key, value): self.runtime_state[key] = value self.save_runtime_state() ``` Update all references: - globals.AUTONOMOUS_DEBUG → config_manager.get_runtime_state("autonomous_debug") - globals.VOICE_DEBUG_MODE → config_manager.get_runtime_state("voice_debug_mode") - globals.LANGUAGE_MODE → config_manager.get_runtime_state("language_mode") ## Severity MEDIUM - Runtime state not persisted, changes lost on restart. ## Files Affected bot/globals.py, bot/config_manager.py, bot/server_manager.py, bot/utils/moods.py
Author
Owner

Fixed in commit d44f08a. Added restore_runtime_settings() to ConfigManager that reads config_runtime.yaml on startup and restores persisted values into globals (LANGUAGE_MODE, AUTONOMOUS_DEBUG, VOICE_DEBUG_MODE, USE_CHESHIRE_CAT, PREFER_AMD_GPU, DM_MOOD). Also added missing persistence calls to three API endpoints: /language/set, /voice/debug-mode, and /memory/toggle.

Fixed in commit d44f08a. Added restore_runtime_settings() to ConfigManager that reads config_runtime.yaml on startup and restores persisted values into globals (LANGUAGE_MODE, AUTONOMOUS_DEBUG, VOICE_DEBUG_MODE, USE_CHESHIRE_CAT, PREFER_AMD_GPU, DM_MOOD). Also added missing persistence calls to three API endpoints: /language/set, /voice/debug-mode, and /memory/toggle.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Koko210/miku-discord#22