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:
- Add guard in ensurePairedThemeExists to skip system default themes (id.startsWith('theme-default-'))
- Fix derivePairedTheme ID generation to recognize system default naming conventions
- Remove auto-pairing entirely for all themes
- 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
libs/theme-system/theme-runtime/src/lib/services/simple-theme-storage.service.tslibs/theme-system/theme-runtime/src/lib/utils-generators/theme-generator.tsapis/backend-api/src/app/themes/themes.service.tsapis/backend-api/src/app/themes/themes.controller.ts
🔗 Related
- Decision ID:
dev_1772050734577_xj4mfi2 - Session: 141
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation