Bugfix: Why does AI panel chat lose all messages on page refresh?

Documentation for Sessions

🐛 Bugfix: Why does AI panel chat lose all messages on page refresh?

Date: 2026-02-20
Time: 03:06:40 UTC
Session: gspace1-125.133
Agent: storage
Confidence: 95%
Status: ✅ Documented


📋 Decision Context

Question:

Why does AI panel chat lose all messages on page refresh?

Task: Fix AI panel chat persistence - history lost on refresh


🎯 Decision Made

Chosen:

Fix async hydration race condition across 3 layers: PanelSessionPersistenceService, PanelIntelligenceService, and ai-panel component

Options Considered:

  1. Wait for FlashStateHydratorService.isHydrated() before initializing
  2. Add arbitrary setTimeout delay to wait for IndexedDB
  3. Redesign autoFlashState to be synchronous

💭 Reasoning

autoFlashState loads from IndexedDB asynchronously (5-50ms), but PanelSessionPersistenceService constructor effect fires synchronously with DEFAULT_STATE (empty sessions), sets _isInitialized=true, and creates a new blank session BEFORE IndexedDB loads. PanelIntelligenceService then reads empty messages and adds a welcome message. When IndexedDB data finally arrives, nobody re-reads it. Fix: (1) Gate _isInitialized on FlashStateHydratorService.isHydrated() signal, (2) Use reactive effects instead of one-shot constructor reads, (3) Increase fallback timeout from 500ms to 3s.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation