PERSISTENCE BUG DIAGNOSTIC CHANGES

Documentation for Plans

๐Ÿ”ฌ Universe Persistence Bug - Diagnostic Changes

Date: November 3, 2025
Status: DIAGNOSTIC LOGGING ADDED
Next Step: TEST & ANALYZE LOGS


๐Ÿ“Š Summary

Added comprehensive diagnostic logging to SpaceService to identify exactly why universes disappear after page refresh. The enhanced logging will reveal the root cause by tracking every step of universe loading and validation.


๐Ÿ”ง Changes Made

1. Enhanced SpaceService Logging

File: libs/core-angular/src/lib/services/space.service.ts

loadUniverses() Method

Added detailed logging for:

initializeFromApi() Method

Enhanced merge logging to show:

Key diagnostic logs to watch for:

๐Ÿ” Loading universes for space: {spaceId, spaceSlug, universeIds, ...}
๐Ÿ” Checking universe from storage: {universeId, found, ...}
๐Ÿ” Validating universe: {universeSpaceId, currentSpaceId, hasSpaceId, idsMatch, willBeIncluded}
โœ… Universe INCLUDED: <name>
โŒ Universe missing spaceId property, filtering out
โŒ Universe does not belong to current space, filtering out
โŒ Universe not found in storage
๐Ÿ” Merging validated universeIds from local storage: {backendIds, localIds, validLocalIds, mergedIds}
๐Ÿ” Backend returned after sync: {returnedUniverseIds, returnedCount, sentCount}

2. Debug Utility

File: libs/core-angular/src/lib/utils/debug-universe-storage.ts

Created a comprehensive debug utility that can be run in the console:

debugUniverseStorage()

What it shows:

Usage:

  1. Open DevTools Console
  2. Run: debugUniverseStorage()
  3. Inspect the grouped output

3. Global Exposure

Files:

Exposed services globally for debugging:


๐Ÿงช Testing Instructions

See PERSISTENCE_BUG_TESTING.md for detailed test procedure.

Quick test:

  1. Clear browser data: clearCachedSpaceData()
  2. Create universe: "Test Universe Persist"
  3. Navigate to Space Map (universe visible)
  4. Refresh page (F5)
  5. Check console for diagnostic logs
  6. Navigate to Dashboard
  7. Run: debugUniverseStorage() to inspect state

๐Ÿ” Expected Findings

The diagnostic logs will reveal ONE of these issues:

1. Universe Missing spaceId

Log pattern:

โŒ Universe missing spaceId property, filtering out
  universeSpaceId: undefined

Fix: Ensure universe is created with spaceId in createUniverse()

2. Space ID Mismatch

Log pattern:

โŒ Universe does not belong to current space
  universeSpaceId: "different-id"
  currentSpaceId: "69067c087ebb621cd9ff8c3f"

Fix: Ensure space ID consistency across sessions

3. Universe Not in Storage

Log pattern:

โŒ Universe not found in storage
  storageKey: "universe_universe_xxxxx"

Fix: Ensure universe save completes before navigation

4. Backend Loses Data

Log pattern:

๐Ÿ” Backend returned after sync:
  returnedUniverseIds: []
  sentCount: 1

Fix: Backend not persisting universeIds properly

5. Merge Filters Out Valid Universe

Log pattern:

๐Ÿ” Merging validated universeIds from local storage:
  validLocalIds: []
  filteredOut: 1

Fix: Merge validation logic too strict


๐Ÿ“ What to Share

When you test and see the issue, please share:

  1. Complete console logs from:

    • Universe creation
    • Navigation to space-map
    • Page refresh
    • Navigation to dashboard
  2. debugUniverseStorage() output showing:

    • Current space details
    • Universe validation results
    • Summary statistics
  3. Screenshot of dashboard showing:

    • Universe count (should be 1, probably shows 0)
    • Any error messages

๐Ÿ’ก Next Steps

After analyzing the logs, we will:

  1. Identify root cause from diagnostic output
  2. Implement targeted fix for the specific issue
  3. Remove diagnostic logging (keep it clean for production)
  4. Add automated test to prevent regression

Current Status: Ready for diagnostic testing
Estimated Time: 5-10 minutes to test and capture logs
Expected Outcome: Clear identification of failure point


๐ŸŽฏ Goal

By the end of this diagnostic session, we will know exactly where and why the universe is being lost, allowing us to implement a precise fix rather than guessing.