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:
- Wait for FlashStateHydratorService.isHydrated() before initializing
- Add arbitrary setTimeout delay to wait for IndexedDB
- 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
libs/libs-ai/panel-intelligence/src/lib/services/panel-session-persistence.service.tslibs/libs-ai/panel-intelligence/src/lib/services/panel-intelligence.service.tslibs/libs-ai/ai-panel-core/src/lib/components/ai-panel/ai-panel.component.ts
🔗 Related
- Decision ID:
dev_1771556800819_iimo20b - Session: 125
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation