orchestrator

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package orchestrator implements the DIP Heartbeat Orchestrator.

The orchestrator runs a background loop with 4 modules:

  1. Auto-Discovery — monitors configured peer endpoints for new Merkle-compatible nodes
  2. Sync Manager — auto-syncs L0-L1 facts between trusted peers on changes
  3. Stability Watchdog — monitors entropy and triggers apoptosis recovery
  4. Jittered Heartbeat — randomizes intervals to avoid detection patterns

The orchestrator works with domain-level components directly (not through MCP tools). It is started as a goroutine from main.go and runs until context cancellation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteDefaultConfig

func WriteDefaultConfig(path string) error

WriteDefaultConfig writes a default config.json to the given path.

Types

type Config

type Config struct {
	// HeartbeatInterval is the base interval between heartbeat cycles.
	HeartbeatInterval time.Duration `json:"heartbeat_interval"`

	// JitterPercent is the percentage of HeartbeatInterval to add/subtract randomly.
	// e.g., 30 means ±30% jitter around the base interval.
	JitterPercent int `json:"jitter_percent"`

	// EntropyThreshold triggers apoptosis recovery when exceeded (0.0-1.0).
	EntropyThreshold float64 `json:"entropy_threshold"`

	// KnownPeers are pre-configured peer genome hashes for auto-discovery.
	// Format: "node_name:genome_hash"
	KnownPeers []string `json:"known_peers"`

	// SyncOnChange triggers sync when new local facts are detected.
	SyncOnChange bool `json:"sync_on_change"`

	// MaxSyncBatchSize limits facts per sync payload.
	MaxSyncBatchSize int `json:"max_sync_batch_size"`
}

Config holds orchestrator configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

func LoadConfigFromFile

func LoadConfigFromFile(path string) Config

LoadConfigFromFile reads .rlm/config.json and returns a Config. Missing or invalid file → returns defaults silently.

type HeartbeatResult

type HeartbeatResult struct {
	Cycle              int           `json:"cycle"`
	StartedAt          time.Time     `json:"started_at"`
	Duration           time.Duration `json:"duration"`
	PeersDiscovered    int           `json:"peers_discovered"`
	FactsSynced        int           `json:"facts_synced"`
	EntropyLevel       float64       `json:"entropy_level"`
	ApoptosisTriggered bool          `json:"apoptosis_triggered"`
	GenomeIntact       bool          `json:"genome_intact"`
	GenesHealed        int           `json:"genes_healed"`
	FactsExpired       int           `json:"facts_expired"`
	FactsArchived      int           `json:"facts_archived"`
	SynapsesCreated    int           `json:"synapses_created"` // v3.4: Module 9
	NextInterval       time.Duration `json:"next_interval"`
	Errors             []string      `json:"errors,omitempty"`
}

HeartbeatResult records what happened in one heartbeat cycle.

type JSONConfig

type JSONConfig struct {
	HeartbeatIntervalSec int     `json:"heartbeat_interval_sec,omitempty"`
	JitterPercent        int     `json:"jitter_percent,omitempty"`
	EntropyThreshold     float64 `json:"entropy_threshold,omitempty"`
	MaxSyncBatchSize     int     `json:"max_sync_batch_size,omitempty"`
	SynapseIntervalMult  int     `json:"synapse_interval_multiplier,omitempty"` // default: 12
}

JSONConfig is the v3.4 file-based configuration for the Orchestrator. Loaded from .rlm/config.json. Overrides compiled defaults.

type Orchestrator

type Orchestrator struct {
	// contains filtered or unexported fields
}

Orchestrator runs the DIP heartbeat pipeline.

func New

func New(cfg Config, peerReg *peer.Registry, store memory.FactStore) *Orchestrator

New creates a new orchestrator.

func NewWithAlerts

func NewWithAlerts(cfg Config, peerReg *peer.Registry, store memory.FactStore, bus *alert.Bus) *Orchestrator

NewWithAlerts creates an orchestrator with an alert bus for DIP-Watcher.

func (*Orchestrator) AlertBus

func (o *Orchestrator) AlertBus() *alert.Bus

AlertBus returns the alert bus (may be nil).

func (*Orchestrator) History

func (o *Orchestrator) History() []HeartbeatResult

History returns recent heartbeat results.

func (*Orchestrator) IsRunning

func (o *Orchestrator) IsRunning() bool

IsRunning returns whether the orchestrator is active.

func (*Orchestrator) SetSynapseStore

func (o *Orchestrator) SetSynapseStore(store synapse.SynapseStore)

SetSynapseStore enables Module 9 (Synapse Scanner) at runtime.

func (*Orchestrator) Start

func (o *Orchestrator) Start(ctx context.Context)

Start begins the heartbeat loop. Blocks until context is cancelled.

func (*Orchestrator) Stats

func (o *Orchestrator) Stats() map[string]interface{}

Stats returns current orchestrator status.

func (*Orchestrator) Status

func (o *Orchestrator) Status() OrchestratorStatus

Status returns current orchestrator state (v3.4: observability).

type OrchestratorStatus

type OrchestratorStatus struct {
	Running         bool             `json:"running"`
	Cycle           int              `json:"cycle"`
	Config          Config           `json:"config"`
	LastResult      *HeartbeatResult `json:"last_result,omitempty"`
	HistorySize     int              `json:"history_size"`
	HasSynapseStore bool             `json:"has_synapse_store"`
}

OrchestratorStatus is the v3.4 observability snapshot.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL