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:

  1. Two-signal pattern with _backendSessions (Session 129 approach, rejected: causes flash)
  2. Separate cachedFlashState helper function (over-engineering for 1 consumer)
  3. Extend autoFlashState with built-in backend sync config (violates SRP)
  4. 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 type with .hydrated signal to gate backend loading on IndexedDB hydration. (2) Write backend data directly INTO autoFlashState via atomic state.update() — no separate signal, no flash. (3) Removed duplicate loadBackendSessions() from VittoChatEngineService that raced with persistence service. (4) Fixed debounceMs option being dead code by adding per-key debounce overrides to FlashStateHydratorService. (5) Wired up provideBackendSyncTransport() in app config.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation