# Control session affinity and admission

Source: https://usecns.dev/thalamus-topic-control-session-affinity-and-admission/

[Start here](https://usecns.dev/manual-thalamus/)
[CLI commands](https://usecns.dev/commands-thalamus/)
[Configuration & integration](https://usecns.dev/thalamus-topics/)

Supply an explicit stable key when distinct sessions have identical roots. Do not use one global `user` value for all independent conversations. Session IDs are emitted in headers/status; avoid embedding secrets in them.

Session-key precedence is:

1. First nonblank header: `x-session-id`, `x-agent-session-id`, `x-conversation-id`.
2. First nonblank **string** JSON field: `session_id`, `conversation_id`, `user`.
3. For a nonempty `messages` array, `conv-` plus 16 hex SHA-256 characters from the first system text, a NUL, and first user content (structured content is canonicalized). Later turns do not change that root.
4. For a nonempty string `prompt`, `prompt-` plus a hash of its first 512 characters.
5. A fresh anonymous key if none applies.

Sticky selection prefers a valid warm pin; otherwise lexicographically minimizes `(in_flight, pinned_sessions, gpu_cache_usage_perc, running_plus_waiting, total_requests)` with deterministic node-name ties. Pins expire after 7200 idle seconds by default. A waking session can be stolen when its node reaches the soft threshold (default 3) and another has at least two fewer inflight streams, or when it reaches the hard threshold and another has a slot.

With the intelligence hard limit (default 3 per node), requests wait centrally when all eligible capacity is occupied and bind when a slot becomes available. Queue wait appears in `x-thalamus-queue-wait-ms`; the router's admission timeout is 120 seconds and returns 503. This is late binding, not a durable job queue or a guaranteed FIFO fairness contract. `0` disables hard admission limiting. The queue and pin mechanisms do not apply to verification/knowledge.