HIGH: Unify the triple configuration system into a single source of truth #33

Open
opened 2026-02-20 14:44:27 +02:00 by Koko210 · 0 comments
Owner

Problem

Three independent configuration systems coexist, creating confusion about which is authoritative:

  1. bot/config.py (Pydantic models) — Type-safe, loaded at import time from config.yaml + .env via BaseSettings. Defines nested models: ServicesConfig, CheshireCatConfig, ModelsConfig, DiscordConfig, AutonomousConfig, VoiceConfig, MemoryConfig, ServerConfig, GPUConfig.

  2. bot/globals.py (mutable module-level variables) — Loaded from os.getenv() with fallback defaults. This is the de facto source of truth since nearly all code reads from globals.* directly.

  3. bot/config_manager.py (runtime overrides) — Priority: Runtime > Static > Defaults. Persists changes to config_runtime.yaml. Added for Web UI support.

The Pydantic config models are largely decorative — most code bypasses them entirely and reads globals.* directly. This means:

  • Type validation is not actually enforced at runtime
  • Config changes via the Web UI go through config_manager but globals.* may not reflect them
  • Adding a new config value requires updating up to 3 places

Proposed Solution

  1. Make Pydantic config the canonical singleton source of truth
  2. Make globals.py read from the Pydantic config instance (e.g., globals.LLAMA_SWAP_URL = config.services.llama_swap_url)
  3. Have config_manager.py mutate the Pydantic config instance and persist to config_runtime.yaml
  4. On startup: load config.yaml -> overlay config_runtime.yaml -> overlay .env secrets -> create Pydantic config instance -> populate globals from it

This preserves all three layers but establishes a clear data flow: YAML -> Pydantic -> globals (read-only view).

Impact

  • Risk: Low (requires careful testing of all config-dependent paths)
  • Effort: High (many modules reference globals.* — need systematic migration)
  • Benefit: Single source of truth, type safety actually enforced, clear config lifecycle

Files Affected

  • bot/config.py (becomes the authoritative config)
  • bot/globals.py (becomes derived from config.py)
  • bot/config_manager.py (mutates Pydantic instance)
  • All files that read globals.* config values
## Problem Three independent configuration systems coexist, creating confusion about which is authoritative: 1. **bot/config.py** (Pydantic models) — Type-safe, loaded at import time from config.yaml + .env via BaseSettings. Defines nested models: ServicesConfig, CheshireCatConfig, ModelsConfig, DiscordConfig, AutonomousConfig, VoiceConfig, MemoryConfig, ServerConfig, GPUConfig. 2. **bot/globals.py** (mutable module-level variables) — Loaded from os.getenv() with fallback defaults. This is the de facto source of truth since nearly all code reads from globals.* directly. 3. **bot/config_manager.py** (runtime overrides) — Priority: Runtime > Static > Defaults. Persists changes to config_runtime.yaml. Added for Web UI support. The Pydantic config models are largely decorative — most code bypasses them entirely and reads globals.* directly. This means: - Type validation is not actually enforced at runtime - Config changes via the Web UI go through config_manager but globals.* may not reflect them - Adding a new config value requires updating up to 3 places ## Proposed Solution 1. Make Pydantic config the canonical singleton source of truth 2. Make globals.py read from the Pydantic config instance (e.g., globals.LLAMA_SWAP_URL = config.services.llama_swap_url) 3. Have config_manager.py mutate the Pydantic config instance and persist to config_runtime.yaml 4. On startup: load config.yaml -> overlay config_runtime.yaml -> overlay .env secrets -> create Pydantic config instance -> populate globals from it This preserves all three layers but establishes a clear data flow: YAML -> Pydantic -> globals (read-only view). ## Impact - Risk: Low (requires careful testing of all config-dependent paths) - Effort: High (many modules reference globals.* — need systematic migration) - Benefit: Single source of truth, type safety actually enforced, clear config lifecycle ## Files Affected - bot/config.py (becomes the authoritative config) - bot/globals.py (becomes derived from config.py) - bot/config_manager.py (mutates Pydantic instance) - All files that read globals.* config values
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#33