Architecture: How to fix autoFlashState and MongoDB being permanently out ...
Documentation for Sessions
🏗️ Architecture: How to fix autoFlashState and MongoDB being permanently out ...
Date: 2026-03-03
Time: 23:33:57 UTC
Session: gspace1-172.2
Agent: storage
Confidence: 95%
Status: ✅ Documented
📋 Decision Context
Question:
How to fix autoFlashState and MongoDB being permanently out of sync, causing session flash on page reload?
Task: Fix autoFlashState MongoDB IndexedDB sync - unified cache layer
🎯 Decision Made
Chosen:
Unified single-signal architecture: autoFlashState as cache layer for MongoDB. Added .hydrated signal to autoFlashState, gated backend loading on hydration, write backend data INTO autoFlashState instead of separate _backendSessions signal. Eliminated 3-store architecture (localStorage + autoFlashState + _backendSessions) down to 2 stores (localStorage for 1 key + autoFlashState for session data). Fixed debounceMs dead code. Consolidated duplicate backend loading path in VittoChatEngineService.
Options Considered:
- Two-signal pattern with _backendSessions (Session 129 approach, rejected: causes flash)
- Separate cachedFlashState helper function (over-engineering for 1 consumer)
- Extend autoFlashState with built-in backend sync config (violates SRP)
- autoFlashState as cache with hydration gate (chosen: minimal, correct, backward compatible)
💭 Reasoning
ROOT CAUSE: loadBackendSessions() never wrote backend data into autoFlashState. It stored data in _backendSessions signal, merged via computed(). IndexedDB kept stale data forever. On reload: stale sessions appeared from IndexedDB (~100ms), then disappeared when backend responded and cleanup ran (~500ms) = visual flash. FIX: (1) Added AutoFlashSignal
📁 Files Involved
libs/libs-foundational/storage-system/src/flash/helpers/auto-flash-state.tslibs/libs-ai/vitto-chat/src/lib/services/vitto-chat-persistence.service.tslibs/libs-ai/vitto-chat/src/lib/services/vitto-chat-engine.service.tslibs/libs-foundational/storage-system/src/flash/services/flash-state-hydrator.service.tsapps/gograb-ai/src/app/app.config.ts
🔗 Related
- Decision ID:
dev_1772580837657_pjftggv - Session: 172
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation