feat: bootstrap temporal graph via dht-backed init

This commit is contained in:
anthonyrawlins
2025-09-28 13:52:53 +10:00
parent b0b1265c08
commit 2207d31f76
2 changed files with 216 additions and 0 deletions

View File

@@ -42,6 +42,7 @@ import (
"chorus/pkg/election"
slurpContext "chorus/pkg/slurp/context"
"chorus/pkg/slurp/storage"
"chorus/pkg/slurp/temporal"
"chorus/pkg/ucxl"
)
@@ -71,6 +72,8 @@ type SLURP struct {
// Core components
contextResolver ContextResolver
temporalGraph TemporalGraph
temporalSystem *temporal.TemporalGraphSystem
temporalStore storage.ContextStore
storage DistributedStorage
intelligence ContextGenerator
retrieval QueryEngine
@@ -456,6 +459,10 @@ func (s *SLURP) Initialize(ctx context.Context) error {
return fmt.Errorf("failed to load persisted contexts: %w", err)
}
if err := s.initializeTemporalSystem(s.ctx); err != nil {
return fmt.Errorf("failed to initialize temporal system: %w", err)
}
// TODO: Initialize components in dependency order
// 1. Initialize storage layer first
// 2. Initialize context resolver with storage
@@ -1179,6 +1186,60 @@ func (s *SLURP) setupPersistentStorage() error {
return nil
}
// initializeTemporalSystem wires the temporal graph to the DHT-backed persistence layer.
func (s *SLURP) initializeTemporalSystem(ctx context.Context) error {
if s.temporalGraph != nil {
return nil
}
if s.localStorage == nil {
return fmt.Errorf("temporal persistence requires local storage")
}
if s.temporalStore == nil {
s.temporalStore = storage.NewInMemoryContextStore()
}
cfg := temporal.DefaultTemporalConfig()
if cfg.PersistenceConfig == nil {
cfg.PersistenceConfig = &temporal.PersistenceConfig{}
}
cfg.PersistenceConfig.EnableWriteBuffer = false
cfg.PersistenceConfig.EnableAutoSync = false
cfg.PersistenceConfig.EnableAutoBackup = false
cfg.PersistenceConfig.EnableLocalStorage = true
cfg.PersistenceConfig.EnableDistributedStorage = s.dht != nil
cfg.PersistenceConfig.EnableEncryption = false
cfg.PersistenceConfig.BatchSize = 1
cfg.PersistenceConfig.FlushInterval = 30 * time.Second
if len(cfg.PersistenceConfig.EncryptionRoles) == 0 {
cfg.PersistenceConfig.EncryptionRoles = []string{"default"}
}
nodeID := s.config.Agent.ID
if nodeID == "" {
nodeID = fmt.Sprintf("slurp-node-%d", time.Now().UnixNano())
}
system, err := temporal.NewDHTBackedTemporalGraphSystem(
s.runtimeContext(ctx),
s.temporalStore,
s.localStorage,
s.dht,
nodeID,
cfg,
)
if err != nil {
return fmt.Errorf("failed to build DHT temporal system: %w", err)
}
s.temporalSystem = system
s.temporalGraph = system.Graph
return nil
}
// loadPersistedContexts warms caches from disk (Roadmap: SEC-SLURP 1.1).
func (s *SLURP) loadPersistedContexts(ctx context.Context) error {
if s.localStorage == nil {