# `LlmCore.Memory.Hindsight.CircuitBreaker`
[🔗](https://github.com/fosferon/llm_core/blob/v0.3.0/lib/llm_core/memory/hindsight/circuit_breaker.ex#L1)

Circuit breaker pattern for Hindsight MCP connections.

States:
- **Closed**: Normal operation, track failures
- **Open**: Reject requests, return cached/error
- **Half-open**: Allow 1 probe request

## State Transitions

- Closed → Open: After threshold consecutive failures
- Open → Half-open: After reset time elapsed
- Half-open → Closed: On successful probe
- Half-open → Open: On failed probe

# `state`

```elixir
@type state() :: %{
  status: state_name(),
  failure_count: non_neg_integer(),
  last_failure_at: integer() | nil,
  last_success_at: integer() | nil
}
```

# `state_name`

```elixir
@type state_name() :: :closed | :open | :half_open
```

# `allow?`

```elixir
@spec allow?() :: :ok | {:error, :circuit_open}
```

Checks if the circuit allows a request.

Returns:
- `:ok` - proceed with request
- `{:error, :circuit_open}` - circuit is open, use fallback

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `report_failure`

```elixir
@spec report_failure(term()) :: :ok
```

Reports a failed request.

# `report_success`

```elixir
@spec report_success() :: :ok
```

Reports a successful request.

# `reset`

```elixir
@spec reset() :: :ok
```

Manually resets the circuit to closed state.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts the circuit breaker GenServer.

# `status`

```elixir
@spec status() :: %{status: state_name(), failure_count: non_neg_integer()}
```

Returns the current circuit status.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
