Bugfix: Session 180: Why were ALL chat messages never synced to Mong...

Documentation for Sessions

🐛 Bugfix: Session 180: Why were ALL chat messages never synced to Mong...

Date: 2026-03-05
Time: 22:29:02 UTC
Session: gspace1-180.2
Agent: storage
Confidence: 98%
Status: ✅ Documented


📋 Decision Context

Question:

Session 180: Why were ALL chat messages never synced to MongoDB backend? New chats created in one browser were invisible in any other browser/device.

Task: Fix chat message persistence — new chats lost on reload, invisible across browsers


🎯 Decision Made

Chosen:

Replaced NetworkSyncStateService.canMakeApiCalls() gate with navigator.onLine in ChatBackendSyncService. The canMakeApiCalls() computed signal required _isBackendAvailable (starts false) AND _isOnline. NetworkSyncStateService.initialize() was never called in gograb-ai app — provideNetworkSyncState() absent from app.config.ts — so _isBackendAvailable stayed false permanently. Every appendMessages() call was immediately queued to the retry queue, and drainRetryQueue() also checked canMakeApiCalls(), creating a deadlock where messages were queued but could never drain.

Options Considered:

  1. Initialize NetworkSyncStateService properly in app.config.ts via provideNetworkSyncState()
  2. Replace canMakeApiCalls() with navigator.onLine (chosen)
  3. Remove NetworkSyncStateService dependency entirely from ChatBackendSyncService
  4. Make canMakeApiCalls() default to true when not initialized

💭 Reasoning

Root cause chain: (1) ChatBackendSyncService injects NetworkSyncStateService (providedIn: root). (2) NetworkSyncStateService._isBackendAvailable = signal(false) on construction. (3) It only becomes true after initialize() runs a health check. (4) initialize() is only called by provideNetworkSyncState() provider. (5) gograb-ai app.config.ts has provideIntelligentStorage() but NOT provideNetworkSyncState(). (6) Therefore canMakeApiCalls() = isOnline && isBackendAvailable = true && false = false, permanently. (7) appendMessages() at line 152 checks canMakeApiCalls() → false → enqueues to retry queue. (8) drainRetryQueue() at line 303 also checks canMakeApiCalls() → false → returns immediately. (9) Result: 100% of messages queued, 0% drained. MongoDB never receives any chat data. Fix: Use navigator.onLine (browser API, always accurate) instead of the broken abstraction. The catchError in the HTTP call already queues failures for retry, making the pre-check gate redundant.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation