# mimirs-ha

The High-Availability (HA) layer for MimirsWell. It provides state replication via a Write-Ahead Log (WAL) and cluster-wide coordination through the ThingNode consensus engine.

## Boundaries
- **Does**: Manage the `Saga` write-ahead log for persistent state transitions.
- **Does**: Provide the `EventBus` for real-time signal broadcasting between agent components.
- **Does NOT**: Handle the actual application of state to the database (it emits signals for other crates to handle).

## Public API

### Components
- `Saga`: The Write-Ahead Log manager. Handles binary serialization and persistence of `SagaEntry` items.
- `ThingNode`: The consensus coordinator (Raft-inspired). Reaches agreement on state changes across the cluster.
- `EventBus`: A high-performance broadcast channel for `MemorySignal` events.

### Signals
- `MemorySignal`: Enum representing system events like `MemoryStored`, `ConsolidationCompleted`, or `ConsensusReached`.

## Usage Example

```rust
use mimirs_ha::{EventBus, MemorySignal};
use mimirs_core::AgentId;

#[tokio::main]
async fn main() {
    let bus = EventBus::new();
    let mut rx = bus.subscribe();
    
    // Broadcast a signal
    bus.broadcast(MemorySignal::ConsolidationCompleted {
        agent_id: AgentId::new(),
        memories_processed: 42,
    }).unwrap();
    
    // Receive the signal
    if let Ok(MemorySignal::ConsolidationCompleted { memories_processed, .. }) = rx.recv().await {
        println!("Consolidated {} memories", memories_processed);
    }
}
```

## Known Limitations
- The `ThingNode` consensus mechanism is currently a single-node implementation that broadcasts to the local `EventBus`; multi-node network transport is handled by the `mimirs-bridge` crate.
