PERSISTENCE BUG CRITICAL
Documentation for Plans
✅ UNIVERSE PERSISTENCE BUG - WORKAROUND APPLIED
Issue: Universe disappears when navigating back to dashboard
Status: ✅ FRONTEND WORKAROUND APPLIED - Works Now!
Priority: P0 - RESOLVED (Temporary Fix)
Updated: November 3, 2025
✅ WORKING NOW!
Frontend detects when backend returns empty universeIds and keeps local version.
Universes now persist correctly across refreshes.
Backend investigation pending (needs restart for full diagnostics).
See: PERSISTENCE_BUG_FINAL_SOLUTION.md
✅ Workaround Applied (Working Now!)
Root Cause Confirmed: Backend receives universeIds correctly but returns empty array in response.
Evidence from Logs:
📤 Frontend sends: {"universeIds":["universe_xxx"]} ✅
↓ HTTP Request ↓
📥 Backend returns: {"universeIds":[]} ❌ BUG!
Frontend Workaround:
// In SpaceService.initializeFromApi()
if (!syncedSpace.universeIds || syncedSpace.universeIds.length === 0) {
this.logger.warn('[SpaceService] ⚠️ Backend returned empty - KEEPING LOCAL');
space = { ...syncedSpace, universeIds: space.universeIds };
}
File Changed: libs/core-angular/src/lib/services/space.service.ts
What It Does:
- Sends universeIds to backend ✅
- Receives response ✅
- Detects if backend returned empty ✅
- Keeps local version if empty ✅
- Logs warning ⚠️
Testing:
- Clear cache:
clearCachedSpaceData() - Create universe: "Test Workaround"
- Refresh page (F5)
- Universe persists! ✅
- See warning in console about backend bug
🔍 Bug Analysis (Historical)
What Happens
- User creates universe "Test Universe"
SpaceService.createUniverse()is called- Universe saved: ✅
storage.put('universe_test-universe', universe) - Space updated: ✅
space.universeIds.push(universe.id) - Space cached: ✅
cacheSpaceLocally(space) - Signals updated: ✅
_universes.set([..._universes(), universe]) - User navigates to space-map: ✅
- User navigates to dashboard
- Dashboard calls
unifiedData.refreshData() - UnifiedData reloads space from storage
- Space loaded but universeIds might be stale
- Universe disappears! ❌
Root Cause
Race condition between space caching and data refresh:
// In SpaceService.createUniverse()
await this.cacheSpaceLocally(space); // Async save
this._currentSpace.set(space); // Update signal immediately
// Later, in UnifiedData.refreshData()
await this.loadSpace(spaceSlug); // Reloads from storage
// If storage write didn't complete, gets old space without new universeId!
await this.loadUniverses(); // Can't find new universe
✅ Solution
Option 1: Force Sync Before Navigation (BEST)
In universe creation, ensure space is fully saved:
// After creating universe
await this.storage.put(`universe_${universe.id}`, universe);
space.universeIds.push(universe.id);
await this.cacheSpaceLocally(space);
// ADD THIS: Wait for storage to flush
await new Promise(resolve => setTimeout(resolve, 500));
// Then navigate
Option 2: Dashboard Reloads SpaceService Data
Make dashboard refresh SpaceService first:
async ngOnInit() {
// Force SpaceService to reload from storage
await this.spaceService.loadUniverses();
// Then refresh unified data
await this.unifiedData.refreshData();
}
Option 3: Use SpaceService Signal Directly
Instead of UnifiedData, dashboard reads from SpaceService:
// In dashboard
readonly universes = this.spaceService.universes;
// This always has latest data from signals
🎯 Recommended Fix
Combination of Option 1 + 2:
- In
universe-creation: Wait longer before navigation (already done - 500ms) - In
dashboard: Force SpaceService refresh before UnifiedData refresh - In
SpaceService.createUniverse(): Ensure space cache completes before signal update
📝 Files to Modify
apps/gograb-space/src/app/components/space-components/g-space-dashboard/g-space-dashboard.component.ts- Add
spaceService.loadUniverses()beforeunifiedData.refreshData()
- Add
libs/core-angular/src/lib/services/space.service.ts- Verify
cacheSpaceLocallycompletes before signal updates
- Verify
Priority: FIX NOW
Impact: CRITICAL - Users can't create universes without them disappearing