Commit 01571b1

mo khan <mo@mokhan.ca>
2025-06-23 22:04:01
fix: resolve memory server persistence bug in lazy loading
- Added `loaded` flag to Server struct to track graph loading state - Fixed ensureGraphLoaded() to properly load from disk on first access - Previously, graph.Entities was never nil due to constructor initialization - Memory server now correctly saves and loads knowledge graph from disk - Entities and relations persist across server restarts as expected Fixes issue where memory.json file was created but never read back. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c0dea17
Changed files (1)
pkg
pkg/memory/server.go
@@ -16,6 +16,7 @@ type Server struct {
 	memoryFile string
 	graph      *KnowledgeGraph
 	mu         sync.RWMutex
+	loaded     bool
 }
 
 // KnowledgeGraph represents the in-memory knowledge graph
@@ -67,9 +68,8 @@ func (ms *Server) ensureGraphLoaded() error {
 	defer ms.mu.Unlock()
 	
 	// Check if graph is already loaded
-	if ms.graph.Entities == nil {
-		ms.graph.Entities = make(map[string]*Entity)
-		ms.graph.Relations = make(map[string]Relation)
+	if !ms.loaded {
+		ms.loaded = true
 		
 		// Load from file if it exists
 		return ms.loadGraphInternal()