ADR-034: Canonical session ownership and bounded admission¶
Metadata¶
- Status: Proposed
- Date: 2026-11-14
- Decision Makers: Vijaykumar Singh
- Related Documents: FEP-0039, VAS-05b, VAS-06/06a
Context¶
The web server already replaced module-level session dictionaries with
web/server/session_store.py. That store owns one lock, removes a session and
its token index atomically, and allows agent initialization and shutdown to run
outside its critical section. It also enforces a global session cap atomically
in add().
Four boundaries remain unresolved:
- A
WebSessioncontains onlysession_id. It has no authenticated principal
or workspace owner. - The signed session token covers only
session_id:issued_at. Anyone that can
present that token and pass transport authentication can reuse the session.
The/session/tokenroute can also mint a token for any known supplied ID. /chat/streamand the metrics route accept a bare session ID. This is
compatible with today's one shared API key or keyless local mode, but it
cannot become a multi-principal service boundary.- Capacity is checked before
VictorClient.initialize(), but the authoritative
add()happens only after initialization. A burst can therefore initialize
many expensive agents, then discard all but the permitted number. There is
also no per-principal bound, connection bound, initialization lease, or
active-turn admission contract.
VAS-05b has not yet delivered verified Kanidm/scoped-key identity. This ADR
defines the shape those future routes must adopt; it does not claim that the
current server is multi-principal or authorize implementation of a new public
wire contract.
Decision¶
1. Session scope is immutable and server-owned¶
Every admitted session has one immutable scope:
principal_idis resolved by the server authentication dependency. Request
bodies, query parameters, browser clients, and SDK callers cannot set it.workspace_idis the canonical server-side workspace identity. A client may
request a workspace, but the server resolves that request to a stored,
operator-controlled workspace ID and audience; it never trusts an arbitrary
client string as authorization.session_idis generated by the server and is meaningful only with its scope
and the store's restart epoch.- In explicit keyless local mode, the principal is the single value
local:user; in current shared-API-key mode it is the configured service
principal. Neither mode is hosted multi-user authorization. Until VAS-05b
lands, all bearers of that shared key map to that one principal.
The store keys sessions by (principal_id, workspace_id, session_id), not by a
bare session ID. A known or guessed ID belonging to another scope returns the
same not-found/refusal result as an absent session and performs no state change.
2. Session tokens bind the full scope and store epoch¶
Replace the current session_id:issued_at HMAC payload with a versioned,
canonical envelope containing at least:
The signature covers the canonical encoding. Validation rejects a missing field,
wrong version, audience mismatch, expiry, scope mismatch, unknown nonce, revoked
nonce, or store-epoch mismatch before the store is queried.
Transport authentication and session authorization are separate checks. Passing
the API/OIDC boundary does not make another principal's session token valid. A
session token is also not an identity credential and cannot enlarge the bearer's
principal or workspace grant.
3. Capacity is reserved before initialization¶
Session admission uses this state machine:
The store atomically reserves capacity before VictorClient construction and
releases the reservation if initialization fails or its bounded lease expires.
Agent construction and initialization remain outside the store lock.
Limits are independent and explicit:
- global active-plus-reserved sessions;
- per-principal active-plus-reserved sessions;
- active connections per session;
- one active turn per session.
The global limit protects the process. The per-principal limit prevents one
subject from consuming every global slot. Reserved sessions are observable and
time-bounded so a stalled initialize cannot become a permanent denial.
4. Acquisition checks exact scope before state exposure¶
All session reads, metrics, stream attachment, token reissue, reset, and
cancellation operations resolve the server principal/workspace first and then
acquire the exact scoped session. Bare session-ID lookup is not a multi-principal
authorization path.
Exact-scope acquisition returns one of:
- session handle for the current authenticated scope;
- typed not-found/refusal, without revealing another scope;
- typed capacity/refusal result, without mutating the target session.
The current keyless/shared-key modes may preserve existing route shapes by
supplying their explicit single principal internally, but store tests must still
prove cross-scope denial so later authentication cannot silently expose old
lookups.
5. Connections and turns have separate ownership¶
Multiple connections for the same exact scope may observe one active session,
bounded by max_connections_per_session. Heartbeats and connection release
affect only connection ownership.
A session admits one active turn at a time:
- the turn lease is acquired before model/tool work;
- a second turn receives a typed conflict and performs no effect;
- caller cancellation releases the lease and stops owned work;
- stream disconnect alone is neither successful completion nor durable
cancellation.
This keeps browser/editor reconnect behavior separate from execution semantics.
Concurrent-turn support would be a later, explicit contract change with
state-merge and tool-conflict rules; it is not implied by multiple sockets.
6. Removal and restart are explicit¶
Idle cleanup, explicit close, and shutdown remove the session and revoke its
token indexes atomically, then shut the agent down outside the lock. A draining
session cannot admit another turn or connection.
The in-memory store has a random startup epoch included in every token. A
process restart invalidates process-local tokens; it must not resurrect sessions
from a signed token alone. Durable run/session recovery is a separate VAS-07
store contract and can only continue when ownership, admitted policy, replay
safety, and exact outcome/receipt evidence are restored. This ADR claims no
cross-restart session continuity.
Rationale¶
- Exact server-resolved scope prevents a session ID or token from becoming a
cross-principal capability. - Binding workspace identity into the session prevents one workspace's client
from reusing another workspace's conversation or agent state. - Reserving before initialization bounds both retained state and expensive cold
starts; the existing post-initializationadd()cannot do that. - Separate connection and turn ownership permits reconnect/observation while
avoiding ambiguous concurrent writes to one conversational agent. - Store-epoch invalidation is conservative and truthful for the current
in-memory implementation. Durable recovery can be added later without
weakening this baseline.
Consequences¶
- Positive: future authentication can be threaded through one canonical
scope rather than retrofitting every route; admission and cold initialization
become bounded; denial behavior is deterministic; token theft across subject,
workspace, service restart, or revoked session fails closed. - Negative: exact-scope tokens require migration and cannot be issued by the
current bare-ID route indefinitely; reserved-but-initializing sessions need
leases and observability; one active turn can reject requests that previously
overlapped. - Neutral: embedded Python framework use, in-process
VictorClient, durable
runs, and the existing agent runtime do not change. This ADR governs service
session admission and ownership only.
Implementation¶
Implement only in reviewed VAS-06 slices:
- VAS-06b — internal store contract: add typed
SessionScope, scoped keys,
exact-scope lookup, reservations, per-principal/global bounds, connection
bounds, turn leases, revocation, and restart epoch to the existing test owner.
No wire route changes. - VAS-06c — route ownership convergence: map explicit keyless/shared-key
modes to their single internal principal and remove bare-ID authorization at
every web route. Public multi-principal activation remains gated on VAS-05b. - VAS-06d — token/wire migration: move clients to the versioned scoped
token only after FEP-0039 records the compatibility and migration decision. - VAS-07 boundary: durable session/run recovery must restore the same scope
and cannot infer continuity from an old process-local HMAC.
Required real-boundary tests include concurrent reservation at global and
principal limits, initialize failure/cancel lease release, exact-scope denial,
same-scope reconnect, connection-limit refusal, second-turn conflict, token
scope/epoch/revocation failures, idle close, shutdown drain, and restart
invalidation. No lock may be held across initialize, model/tool work, agent
shutdown, or provider close.
Alternatives Considered¶
- Continue bare session IDs and enforce ownership in routes: duplicates the
decision at every HTTP, SSE, WebSocket, metrics, token, and recovery route;
one missed lookup becomes cross-owner access. - Trust a client-supplied principal/workspace: rejected. Those fields would
become authorization, allowing spoofing even when transport authentication is
correct. - Use the transport principal alone without workspace scope: preserves
cross-workspace confusion inside one user's sessions. - Keep authoritative capacity after initialization: leaves the expensive
cold-start burst unbounded and wastes initialized agents before rejecting them. - Allow concurrent turns: requires a second model for conversation-state
merge, tool conflicts, and event ordering. It is not a safe implicit default. - Make signed tokens valid across restart: turns a bearer artifact into
durable state and weakens revocation. Durable recovery must be explicit.
References¶
- FEP-0039: Unified agent-service API
- Victor agent-service tracker
web/server/session_store.pyweb/server/main.py
Revision History¶
| Date | Version | Changes | Author |
|---|---|---|---|
| 2026-11-14 | 1.0 | Proposed canonical scope, tokens, admission, connection/turn ownership, and restart behavior | Vijaykumar Singh |