Files
CHORUS/pkg/slurp/leader/doc.go
anthonyrawlins 9bdcbe0447 Integrate BACKBEAT SDK and resolve KACHING license validation
Major integrations and fixes:
- Added BACKBEAT SDK integration for P2P operation timing
- Implemented beat-aware status tracking for distributed operations
- Added Docker secrets support for secure license management
- Resolved KACHING license validation via HTTPS/TLS
- Updated docker-compose configuration for clean stack deployment
- Disabled rollback policies to prevent deployment failures
- Added license credential storage (CHORUS-DEV-MULTI-001)

Technical improvements:
- BACKBEAT P2P operation tracking with phase management
- Enhanced configuration system with file-based secrets
- Improved error handling for license validation
- Clean separation of KACHING and CHORUS deployment stacks

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-06 07:56:26 +10:00

114 lines
5.0 KiB
Go

// Package leader provides leader-specific context management duties for the SLURP system.
//
// This package implements the leader node responsibilities within the CHORUS cluster,
// where only the elected leader performs context generation, coordinates distributed
// operations, and manages cluster-wide contextual intelligence tasks. It integrates
// with the CHORUS election system to ensure consistent leadership and proper failover.
//
// Key Features:
// - Leader-only context generation to prevent conflicts and ensure consistency
// - Distributed context coordination across cluster nodes
// - Context generation queue management and prioritization
// - Leader failover and state transfer for high availability
// - Cluster-wide context synchronization and consistency
// - Resource allocation and load balancing for context operations
// - Inter-node communication for context distribution
// - Health monitoring and cluster state management
//
// Core Components:
// - ContextManager: Main leader interface for context management duties
// - GenerationCoordinator: Coordinates context generation across cluster
// - QueueManager: Manages context generation request queues
// - FailoverManager: Handles leader failover and state transfer
// - ClusterCoordinator: Manages cluster-wide operations
// - HealthMonitor: Monitors cluster and context system health
//
// Integration Points:
// - pkg/election: Leader election and state management
// - pkg/dht: Distributed context storage and retrieval
// - pkg/slurp/intelligence: Context generation engines
// - pkg/slurp/distribution: Context distribution across cluster
// - pkg/slurp/storage: Persistent context data management
//
// Example Usage:
//
// manager := leader.NewContextManager(election, dht, intelligence, storage)
// ctx := context.Background()
//
// // Check if this node is the leader
// if manager.IsLeader() {
// // Request context generation (only leaders can fulfill this)
// req := &ContextGenerationRequest{
// UCXLAddress: "ucxl://project/src/main.go",
// FilePath: "/project/src/main.go",
// Priority: PriorityHigh,
// RequestedBy: "developer-node-1",
// Role: "developer",
// }
//
// err := manager.RequestContextGeneration(req)
// if err != nil {
// log.Fatal(err)
// }
//
// // Monitor generation progress
// status, err := manager.GetGenerationStatus()
// fmt.Printf("Active tasks: %d, Queued: %d\n",
// status.ActiveTasks, status.QueuedTasks)
// }
//
// // Non-leader nodes can request context generation from leader
// if !manager.IsLeader() {
// result, err := manager.RequestFromLeader(req)
// if err != nil {
// log.Printf("Failed to request from leader: %v", err)
// }
// }
//
// Leader Election Integration:
// The context manager automatically integrates with the CHORUS election system,
// responding to leadership changes, handling graceful transitions, and ensuring
// no context generation operations are lost during failover events. State
// transfer includes queued requests, active jobs, and coordination metadata.
//
// Context Generation Coordination:
// The leader coordinates context generation by:
// - Receiving requests from cluster nodes
// - Prioritizing and queuing generation tasks
// - Distributing workload across available resources
// - Ensuring no duplicate generation for the same context
// - Managing dependencies between related contexts
// - Coordinating with intelligence engines and storage systems
//
// High Availability Design:
// The system is designed for high availability with:
// - Automatic leader failover with minimal downtime
// - State replication and synchronization across nodes
// - Graceful degradation when leader is unavailable
// - Request queuing and replay during leadership transitions
// - Health monitoring and automatic recovery mechanisms
//
// Performance Characteristics:
// - O(log N) request routing and leader discovery
// - Batched context generation for efficiency
// - Parallel processing with configurable concurrency limits
// - Request deduplication and caching for performance
// - Background processing to minimize client wait times
// - Resource-aware load balancing across cluster nodes
//
// Consistency Guarantees:
// The leader ensures consistency by:
// - Single point of control for context generation
// - Atomic updates to context state across the cluster
// - Ordered processing of conflicting context updates
// - Vector clock synchronization for temporal consistency
// - Conflict detection and resolution for concurrent changes
//
// Security Integration:
// All leader operations integrate with the CHORUS security model:
// - Role-based authorization for context generation requests
// - Encrypted communication between leader and cluster nodes
// - Audit logging of all leadership decisions and actions
// - Secure state transfer during failover events
// - Access control enforcement for cluster coordination
package leader