# `Jido.Messaging.SessionManager`
[🔗](https://github.com/agentjido/jido_messaging/blob/v1.0.0/lib/jido_messaging/session_manager.ex#L1)

Partitioned route-state manager for deterministic session routing.

Route state is sharded by session key hash so updates and lookups avoid a
singleton bottleneck. Each partition enforces TTL and bounded capacity.

# `fallback_reason`

```elixir
@type fallback_reason() :: :stale | :miss | :thread_scope_miss | :session_unavailable
```

# `prune_result`

```elixir
@type prune_result() :: %{pruned: non_neg_integer(), partitions: pos_integer()}
```

# `resolution`

```elixir
@type resolution() :: %{
  :external_room_id =&gt; term(),
  :route =&gt; route(),
  :partition =&gt; non_neg_integer(),
  :session_key =&gt; session_key(),
  :source =&gt; :state_hit | :partition_fallback | :provided_fallback,
  :fallback =&gt; boolean(),
  :stale =&gt; boolean(),
  optional(:fallback_reason) =&gt; fallback_reason()
}
```

# `route`

```elixir
@type route() :: %{
  :external_room_id =&gt; term(),
  optional(:channel_type) =&gt; atom(),
  optional(:bridge_id) =&gt; String.t(),
  optional(:room_id) =&gt; String.t() | nil,
  optional(:thread_id) =&gt; String.t() | nil,
  optional(atom()) =&gt; term()
}
```

# `route_record`

```elixir
@type route_record() :: %{
  route: route(),
  updated_at_ms: integer(),
  expires_at_ms: integer()
}
```

# `session_key`

```elixir
@type session_key() :: Jido.Messaging.SessionKey.t()
```

# `config`

```elixir
@spec config(module()) :: keyword()
```

Return manager config merged from defaults, global opts, and instance opts.

# `get`

```elixir
@spec get(module(), session_key()) ::
  {:ok, route_record()}
  | {:error, :not_found | :expired | :partition_unavailable}
```

Fetch fresh route state for a session key.

# `partition_count`

```elixir
@spec partition_count(module()) :: pos_integer()
```

Return configured partition count.

# `partition_pid`

```elixir
@spec partition_pid(module(), session_key() | non_neg_integer()) :: pid() | nil
```

Return the PID for a partition worker, if running.

# `prune`

```elixir
@spec prune(module()) :: prune_result()
```

Trigger pruning across all partitions and return total expired deletions.

# `resolve`

```elixir
@spec resolve(module(), session_key(), [route()] | route()) ::
  {:ok, resolution()} | {:error, term()}
```

Resolve a route for a session key, using fallbacks when needed.

# `route_partition`

```elixir
@spec route_partition(module(), session_key()) :: non_neg_integer()
```

Resolve the partition index for a session key.

# `set`

```elixir
@spec set(module(), session_key(), route(), keyword()) :: :ok | {:error, term()}
```

Store route state for a session key.

---

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