# `Jidoka.Session.Data`
[🔗](https://github.com/agentjido/jidoka/blob/v0.9.0/lib/jidoka/session/data.ex#L1)

Serializable session envelope for running an agent across requests.

A session is data. It stores the agent spec, request history, hibernated
snapshots, pending review requests, and the latest result/error. It does not
own processes or runtime capabilities.

# `status`

```elixir
@type status() ::
  :new | :running | :hibernated | :waiting | :finished | :cancelled | :error
```

# `t`

```elixir
@type t() :: %Jidoka.Session.Data{
  agent_id: binary(),
  error: nil | nil | any(),
  lease: nil | nil | term(),
  lineage: nil | nil | term(),
  metadata: map(),
  pending_reviews: [term()],
  requests: [term()],
  result: nil | nil | term(),
  revision: integer(),
  schema_version: integer(),
  session_id: binary(),
  snapshots: [term()],
  spec: term(),
  status:
    (((((:new | :running) | :hibernated) | :waiting) | :finished) | :cancelled)
    | :error
}
```

# `bump_revision`

```elixir
@spec bump_revision(t()) :: t()
```

Increments the durable session revision.

# `clear_lease`

```elixir
@spec clear_lease(t()) :: t()
```

Removes active lease ownership from a session.

# `fork`

```elixir
@spec fork(t(), Jidoka.Snapshot.t(), Jidoka.Session.Lineage.t(), keyword()) ::
  {:ok, t()} | {:error, term()}
```

Builds a new session from a copied, safe snapshot and lineage data.

# `from_input`

```elixir
@spec from_input(t() | keyword() | map()) :: {:ok, t()} | {:error, term()}
```

Normalizes an existing session, keyword list, or map.

# `latest_snapshot`

```elixir
@spec latest_snapshot(t()) :: Jidoka.Snapshot.t() | nil
```

Returns the most recent session snapshot, if one exists.

# `merge_snapshots`

```elixir
@spec merge_snapshots([Jidoka.Snapshot.t()], [Jidoka.Snapshot.t()]) :: [
  Jidoka.Snapshot.t()
]
```

Merges snapshot evidence without adding duplicate snapshot ids.

# `new`

```elixir
@spec new(keyword() | map()) :: {:ok, t()} | {:error, term()}
```

Builds a durable session from keyword or map attributes.

# `new!`

```elixir
@spec new!(keyword() | map()) :: t()
```

Builds a durable session and raises if the attributes are invalid.

# `put_cancellation`

```elixir
@spec put_cancellation(t(), Jidoka.Cancellation.t() | term()) :: t()
```

Records typed cancellation evidence and marks the session as cancelled.

# `put_durable_checkpoint`

```elixir
@spec put_durable_checkpoint(t(), Jidoka.Snapshot.t()) :: t()
```

Records a durable in-run checkpoint while lease ownership stays active.

# `put_error`

```elixir
@spec put_error(t(), term()) :: t()
```

Records a session error and marks the session as failed.

# `put_lease`

```elixir
@spec put_lease(t(), Jidoka.Session.Lease.t()) :: t()
```

Adds active lease ownership to a running session.

# `put_request`

```elixir
@spec put_request(t(), Jidoka.Turn.Request.t()) :: t()
```

Adds a request and marks the session as running.

# `put_result`

```elixir
@spec put_result(t(), Jidoka.Turn.Result.t()) :: t()
```

Adds a completed turn result and updates semantic agent state.

# `put_snapshot`

```elixir
@spec put_snapshot(t(), Jidoka.Snapshot.t()) :: t()
```

Adds a snapshot and marks the session as hibernated.

# `schema`

```elixir
@spec schema() :: Zoi.schema()
```

Returns the Zoi schema for a durable session.

# `schema_version`

```elixir
@spec schema_version() :: pos_integer()
```

Returns the current durable session schema version.

# `start`

```elixir
@spec start(
  Jidoka.Agent.Spec.t(),
  keyword()
) :: {:ok, t()} | {:error, term()}
```

Starts durable session data for an agent specification.

# `statuses`

```elixir
@spec statuses() :: [status()]
```

Returns the possible durable session statuses.

---

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