Threads & runs¶
skeino models conversations the same way the LangGraph Platform does: a thread holds the evolving state, a run is one execution against that thread, and a checkpoint is an immutable snapshot of the graph state at a point in time.
The data model¶
Thread (thread_id)
├── metadata, config, status, ttl ← stored in the metadata store
└── checkpoint stream ← stored in the checkpointer
├── checkpoint (stamped run_id)
├── checkpoint (stamped run_id)
└── ...
Run (run_id, belongs to a thread)
└── assistant_id, status, kwargs, error ← stored in the metadata store
- A thread owns a single checkpoint namespace. Every run against the thread reads and appends to the same checkpoint stream, so the thread's "current state" is simply its most recent checkpoint — regardless of which run wrote it.
- A run is one invocation of the graph against a thread. Multiple runs execute sequentially against the same thread (see Concurrency below). Each run records the parameters it was invoked with and its terminal status.
- A checkpoint is a LangGraph checkpoint tuple (config, values, metadata).
skeino stamps each checkpoint's metadata with the
run_idthat produced it, so clients (including LangGraph Studio) can group checkpoints by run.
Tracing a run into LangGraph Studio. When LangSmith tracing is enabled for
the server, a run may carry langsmith_tracer: {project_name, example_id} —
LangGraph Studio sets it on every run it starts. The run's whole trace is then
written to that project and to the server's default project (LangSmith write
replicas), linked to the dataset example when example_id is given, and the run
reports where it went as langsmith_session_name. GET /info advertises this
as flags.langsmith_tracing_session_on_runs; Studio will not show in-app traces
without it. With tracing off the field is accepted and ignored.
Two stores, two responsibilities¶
State is deliberately split across two backends:
| Concern | Stored in | Backends |
|---|---|---|
| Thread & run rows (metadata, status, config, kwargs) | metadata store | Postgres (app_threads, app_runs tables) or in-memory |
| Graph state / checkpoints | checkpointer | Postgres saver or in-memory MemorySaver |
A single checkpointer_scheme selects both halves (e.g. postgres uses
Postgres for both); the default memory keeps both in-memory (ephemeral). See
Persistence & checkpointers for the details.
Thread lifecycle¶
A thread is created with POST /threads. The request can:
- supply an explicit
thread_id(otherwise one is generated), - attach
metadata, - choose
if_existsbehaviour ("raise"— the default — or"do_nothing"), - configure a
ttl, and - seed initial state via
supersteps(a list of node updates applied before any run executes).
Thread status is one of idle, busy, interrupted, or error. A thread
reports interrupted once a run ends parked on a graph interrupt(),
waiting for a human decision; the pending request rides the __interrupt__
channel of the run's values/updates events and of the output returned by
runs/wait and runs/join, and stays readable on the thread afterwards, and
the next run resumes it with command.resume. You can read
a thread's metadata-plus-latest-values with GET /threads/{id}, its full latest
checkpoint with GET /threads/{id}/state, and walk its checkpoint history with
GET/POST /threads/{id}/history. To read state at a specific point in time,
use GET /threads/{id}/state/{checkpoint_id} (or the POST .../state/checkpoint
variant with a full config body).
You can update a thread's metadata with PATCH /threads/{id}, delete it (along
with its runs and checkpoints) with DELETE /threads/{id}, and edit its state
directly with POST /threads/{id}/state — a human-in-the-loop write that applies
values (optionally as_node, and from a specific checkpoint) and returns the
new checkpoint config.
Threads are searchable with POST /threads/search, which filters by ids,
metadata, state values, and status, with pagination and field selection.
You can fork a thread with POST /threads/{id}/copy. This creates a new,
independent thread seeded with the source's latest state (its metadata is
copied and stamped with forked_from), so you can branch and explore — a
what-if continuation, an isolated debug replay — without mutating the original.
The copy is shallow: the current state carries over, not the full checkpoint
history.
Run lifecycle¶
A run is created against an existing thread. Runs execute in the background:
the graph runs in an asyncio task while the request returns. Pick how you want
to consume the result:
POST /threads/{id}/runs— background create. Returns immediately with apending/runningRunModel; pollGET .../runs/{run_id}or join.POST /threads/{id}/runs/wait— run to completion and return the final graph state values (the run output, matching the LangGraph SDKruns.wait). A run that ends parked on aninterrupt()also reports it under__interrupt__.POST /threads/{id}/runs/stream— execute and stream events over SSE (see Streaming).GET /threads/{id}/runs/{run_id}/join— wait for an in-flight run to reach a terminal state and return its final graph state values,__interrupt__included when it parked.
A run progresses through these statuses:
pending → running → success · error · interrupted (and timeout)
The run row records the assistant_id, the serialized invocation kwargs
(input, config, checkpoint selection, stream options), the multitask_strategy,
and — on failure — an error message. List a thread's runs with
GET /threads/{id}/runs and fetch one with GET /threads/{id}/runs/{run_id}.
Cancel and delete¶
POST /threads/{id}/runs/{run_id}/cancel?action=interruptcancels an in-flight run and leaves itinterrupted;action=rollbackcancels it and deletes the run row. Passwait=trueto block until the cancellation has settled.DELETE /threads/{id}/runs/{run_id}removes a terminal run row (it returns 409 while the run is still active — cancel it first).
Streaming runs (/runs/stream) execute in a server-side task like background
runs, so they can be cancelled, joined (/join for the output,
/runs/{run_id}/stream for the events), and outlive a disconnecting client
unless the run asked for on_disconnect: "cancel". See
Streaming.
Orphaned runs¶
A run executes in the process that started it. A graceful shutdown marks its
in-flight runs interrupted, but a crash, OOM kill, or hard restart cannot. To
keep such rows from staying pending/running forever (with pollers waiting
on them and their thread stuck busy), every process heartbeats
the runs it owns: every run_heartbeat_seconds (default 30) it bumps their
updated_at. A pending/running run whose updated_at is older than
orphaned_run_timeout_seconds (default 120) has lost its process. The sweep
runs at startup and on every heartbeat tick, and it sets such a run to error
with an "orphaned" message. If the run's thread has nothing else in flight, the
thread moves from busy to error. If that thread update fails, the sweeping
process retries it on every later tick until it succeeds. A run that was swept
before it started (still queued, say) never executes: its owner sees the final
row, reports that outcome (on its stream, for streaming runs), and leaves the
thread alone.
The retry record lives in the sweeping process. If that process dies too, if a
run's process dies after saving success but before settling its thread, or if
a failed or interrupted run's own thread update failed (it has no in-process
retry), the sweep also releases any thread that has been busy for longer than
orphaned_run_timeout_seconds with no run in flight. The thread settles as its
latest run would have left it: as after a clean finish if that run succeeded,
idle if it was interrupted, and error otherwise.
Settling a thread after success reads the graph state to decide between
idle and interrupted. If that read (or the thread update) fails, the thread
stays busy and the settle is retried on the next liveness pass, rather than
guessing idle and losing a pending interrupt.
The sweep is safe with several workers on one database. It never touches the
sweeping process's own runs, and live runs elsewhere keep heartbeating. Each
row is also claimed with a conditional update, so only one sweeper reports it.
On Postgres the comparison uses the database clock, so worker clock skew does
not matter. LangGraph Platform re-queues an orphaned run and fails it once its
retries are exhausted. skeino keeps no run input to retry with, so it fails the
run directly. Set orphaned_run_timeout_seconds=None to disable the sweep.
Stateless runs¶
When there is nothing to continue — a one-shot question, a scheduled job, a report generated in a single pass — a thread is overhead the caller has to manage and then remember to clean up. The top-level routes do that for you:
POST /runs— execute to completion, return theRunModel.POST /runs/wait— execute to completion, return the graph's final state.POST /runs/stream— execute and stream events over SSE.POST /runs/batch— execute a list of payloads, return their outputs in order.
Each runs against a thread created for it and deleted on the way out, together
with its checkpoints — on success, on failure, and when a stream is abandoned
part-way. The thread id never reaches the caller, so checkpoint is rejected
with a 400 and if_not_exists is ignored: there is no prior history to resume,
and no thread the caller could have created.
Anything you might want to resume, inspect, or continue belongs on a thread instead.
Input vs. command¶
A run is driven by either an input payload (new state to merge in) or a
command (update / resume / goto) used to resume an interrupted graph.
input.messages is converted to LangChain message objects automatically; see
Streaming → serialization.
if_not_exists¶
By default a run against a missing thread is rejected. Set
if_not_exists: "create" on the run request to have skeino create the thread on
demand.
Concurrency: one run at a time¶
skeino runs at most one executing run per thread. With the enqueue
strategy, additional background runs can sit pending, queued behind the
execution lock — only one runs at any moment. Each thread has its own execution
lock held by the running task; admission decisions are serialized by a per-thread
admission lock, so a queued caller can't observe a stale "free" slot.
The multitask_strategy on the run request decides what happens when a thread is
already busy:
| Strategy | Behaviour when the thread is busy |
|---|---|
enqueue (default) |
Wait for the active run to finish, then proceed. |
reject |
Fail immediately with 409 Conflict. |
rollback |
Cancel and delete the active run, then start the new one. |
interrupt |
Cancel the active run (left interrupted), then start the new one. |
interrupt/rollback cancel active runs, streaming ones included, and also a
streaming run still queued for the thread lock or still being created: it is
dropped before it starts, and its own POST .../runs/stream gets 409.
Single-process scope
Locks are in-process asyncio locks, which is correct for a single-process
deployment. A clustered, multi-process deployment would need a shared lock
service; that is out of scope for v1.
Token usage¶
skeino measures each run's token usage with a LangChain
UsageMetadataCallbackHandler attached to the run's config. The handler
records every LLM call made during the run — including calls whose responses
never reach checkpoint state — and is scoped to that run, so multi-turn
threads report per-run totals. The total is surfaced:
- on
POST /threads/{id}/runsvia theX-Tokens-Usedresponse header, and - on the streaming endpoint inside the terminal
endevent'susagefield.
When the handler records nothing (providers that don't populate
usage_metadata plus model_name on their messages), skeino falls back to
summing the total tokens across all AI messages in the final state,
normalising the different provider formats (LangChain usage_metadata,
Gemini, OpenAI/Groq/Bedrock). The fallback covers the thread's whole message
history, so on multi-turn threads it reports cumulative totals rather than
the run's own.
Related reference¶
- HTTP endpoints (v1) — every route, request, and response shape.
- Python API — the schema models referenced above.