Skip to content
Hexel StudioDocs

Durable sessions

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.

On this page

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.

How it works

PartWhat it is
Durable sessionThe task. It belongs to one agent deployment and runtime principal, and acts for the same person (or no one) for its whole life.
LegOne process's runtime session in the durable session. Its runtime tokens carry the durable_session_id.
Session StoreThe 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 leaseOne 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:

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).

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 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:

RouteWhat it does
POST .../lease:acquire, POST .../lease:releaseTake, renew or give up the writer lease.
POST .../events, GET .../eventsAppend 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 .../summaryRecord the session's summary.
GET .../streamFollow new events live (server-sent events).
GET /v1/titan/agent/sessionsThe 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).

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