---
title: Durable sessions
description: Run an agent task that outlives one process. Start a durable
  session, attach to it from another pod or device, keep its history and
  checkpoints in Titan, and suspend, kill or inspect it.
url: https://hexelstudio.com/docs/titan/durable-sessions
---

A runtime session normally lives as long as the agent process that opened it. A **durable session** (`dss_...`) is a long-running task that outlives any one process: each process that works on it is a **leg** (a runtime session of its own), and when a pod restarts or the work moves to another machine, a new leg **attaches** and carries on with the same approvals, limits and controls.

<Note>
Durable sessions are in private preview. Hexel Studio turns them on per agent deployment: ask [support@mail.hexelstudio.com](mailto:support@mail.hexelstudio.com) with the agent deployment's id (`dep_...`). For other deployments, asking for a durable session is refused with `INVALID_IDENTITY_EXCHANGE` and the session routes answer `404`.
</Note>

## How it works

| Part | What it is |
| --- | --- |
| Durable session | The task. It belongs to one agent deployment and runtime principal, and acts for the same person (or no one) for its whole life. |
| Leg | One process's runtime session in the durable session. Its runtime tokens carry the `durable_session_id`. |
| Session Store | The durable session's history in Titan: an ordered event log, named checkpoints and a summary. It holds metadata and content references (SHA-256, size, location), never the content bytes. |
| Writer lease | One leg at a time writes. A leg that takes over gets the next lease epoch, and writes from the old leg are refused. |

The session profile of the deployment sets how long a durable session may sit idle and its maximum lifetime; past either it is `expired`.

## Start and attach

Both happen at the identity exchange (`POST /v1/titan/broker/runtime-identities/exchange`), where an agent process gets its runtime token. The `session` object chooses the mode:

<Tabs>
  <Tab title="Start a durable session">
    ```json
    {
      "version": 1,
      "source_type": "kubernetes_service_account",
      "requested_token_type": "urn:titan:token-type:runtime-identity",
      "audience": "urn:titan:gateway:td-0123456789abcdef0123456789abcdef",
      "session": { "mode": "new", "durable": {} }
    }
    ```

    The answer has the runtime token (`access_token`), the leg's `session_id` and the new `durable_session_id`. Store the `durable_session_id` where your next process can find it (for example in your job's state).
  </Tab>
  <Tab title="Attach from another process">
    ```json
    {
      "version": 1,
      "source_type": "kubernetes_service_account",
      "requested_token_type": "urn:titan:token-type:runtime-identity",
      "audience": "urn:titan:gateway:td-0123456789abcdef0123456789abcdef",
      "session": { "mode": "attach", "durable_session_id": "dss_..." }
    }
    ```

    Any instance of the same agent deployment and runtime principal can attach. The new leg gets its own runtime token; the durable session's approvals and controls carry over.
  </Tab>
</Tabs>

`mode: "continue"` with a `session_id` renews the same leg from the same instance, as for any runtime session. The request is sent with the media type `application/vnd.titan.identity-exchange+json;version=1` and the workload's credential as the bearer; see [Identity](https://hexelstudio.com/docs/api/titan-agent/identity) in the API reference.

## Keep the task's history

A leg reads and writes its durable session through the agent API at `https://api.hexelstudio.com/v1/titan/agent/sessions/{id}/...`, with its runtime token:

| Route | What it does |
| --- | --- |
| `POST .../lease:acquire`, `POST .../lease:release` | Take, renew or give up the writer lease. |
| `POST .../events`, `GET .../events` | Append events (atomically, idempotent per `op_id`, optional `expected_seq` compare-and-swap) and read them in order after `after_seq`. |
| `POST .../checkpoints`, `GET .../checkpoints/{name}` | Take a named, immutable checkpoint of what the session has done so far, and read it back. The name is the idempotency key. |
| `POST .../summary` | Record the session's summary. |
| `GET .../stream` | Follow new events live (server-sent events). |
| `GET /v1/titan/agent/sessions` | The durable sessions this agent may read. |

While a writer lease is live, every write carries its `lease_epoch`; a write from a leg that lost the lease is refused with `409 LEASE_FENCED`, and taking a lease another leg holds is `409 LEASE_HELD`. A leg reads every durable session of its deployment and principal that acts for the same person, and writes only its own.

## Inspect and control

Administrators see and control durable sessions like any other session:

```bash
hexel titan session durable list --state active
hexel titan session durable get dss_...

hexel titan session suspend dss_...        # hold it; legs can't continue until resumed
hexel titan session resume dss_...
hexel titan kill dss_... --type durable_session
```

With the API: `GET /v1/titan/admin/durable-sessions` (filter by `state`: `active`, `idle`, `suspended`, `closed`, `killed`, `expired`) and `GET /v1/titan/admin/durable-sessions/{id}` for one session with its legs and Session Store head, each with the `Titan-Enforcement-Deployment` header. Suspend, resume and revoke with `POST /v1/titan/admin/sessions/{id}/restrict`, and kill or quarantine with `/v1/titan/admin/agent-controls:*` and `target_type: "durable_session"` ([Kill switch](https://hexelstudio.com/docs/titan/kill-switch)).

Killing a durable session ends it (state `killed`) and kills its live legs at once, so no leg can attach to it again. Revoking one (`hexel titan session revoke dss_...`) closes it and revokes its legs.

## API reference

- [Titan agent API](https://hexelstudio.com/docs/api/titan-agent/agent): the session, event, checkpoint and lease routes.
- [Titan platform API](https://hexelstudio.com/docs/api/titan/administration): the administration routes.
