Bugfix: Auto-pairing logic created bogus theme-default-light-dark do...

Documentation for Sessions

🐛 Bugfix: Auto-pairing logic created bogus theme-default-light-dark do...

Date: 2026-02-25
Time: 20:18:54 UTC
Session: gspace1-141.11
Agent: backend
Confidence: 95%
Status: ✅ Documented


📋 Decision Context

Question:

Auto-pairing logic created bogus theme-default-light-dark document by appending '-dark' to system default IDs — how to prevent and clean up?

Task: Prevent auto-pairing of system default themes


🎯 Decision Made

Chosen:

Add guard in ensurePairedThemeExists to skip system default themes (id.startsWith('theme-default-'))

Options Considered:

  1. Add guard in ensurePairedThemeExists to skip system default themes (id.startsWith('theme-default-'))
  2. Fix derivePairedTheme ID generation to recognize system default naming conventions
  3. Remove auto-pairing entirely for all themes
  4. Add a blocklist of IDs that should never be auto-paired

💭 Reasoning

ROOT CAUSE: The auto-pairing logic in SimpleThemeStorageService.ensurePairedThemeExists() called derivePairedTheme() for ALL themes, including system defaults. derivePairedTheme takes the existing ID as 'base' and appends '-dark' or '-light'. For theme-default-light, this produced 'theme-default-light-dark' instead of recognizing that theme-default-dark already exists. The generated dark variant then persisted to both IndexedDB and MongoDB via persistThemeToSpace(). The guard checks three conditions: metadata.isSystem, metadata.isDefault, or id.startsWith('theme-default-'). This is defensive — any one condition catches system defaults even if metadata is incomplete. Additionally, generateAndSavePair now checks if the derived ID already exists before writing, preventing silent overwrites of legitimate themes. Cleanup: Added cleanupBogusDocuments() method and POST /themes/admin/cleanup endpoint for removing stale documents. Also ran direct MongoDB cleanup to delete theme-default-light-dark. WHAT WOULD MAKE THIS WRONG: If new system themes are introduced with different naming patterns (e.g. 'system-theme-xyz'), the startsWith guard wouldn't catch them. The metadata.isSystem flag is the canonical check; the ID prefix is a safety net.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation