mstar.model.cosmos3.sessions#
Per-session world state for windowed rollouts.
A session_id on a windowed request names a world the client may come back
to (resume_session). The DiT node keeps the rollout’s last window under
it and the streaming decoder its decode context, each in a SessionStore.
The store is bounded and LRU-ordered, and it knows which sessions have a
request in flight: those are never evicted and refuse a second request, so
two rollouts cannot write the same world at once. Idle sessions expire after
their timeout, so a client that crashes mid-rollout does not leave a state
behind forever.
Classes
|
Bounded, LRU-ordered session state with in-flight pins and a TTL. |
- class mstar.model.cosmos3.sessions.SessionStore(capacity, default_ttl_s, max_ttl_s, clock=time.monotonic)[source]#
Bases:
objectBounded, LRU-ordered session state with in-flight pins and a TTL.
A request that names a session
begin``s it, which pins it for the request's duration (a second request on a live session is refused), reads the stored state with ``get(which promotes it, so every node’s store ages the same way), and eitherput``s the new state when it is done or ``end``s the session. ``releaseunpins whatever a removed request held. Only idle sessions count againstcapacityand can be evicted (expired ones first, then the oldest); live ones never are, so the store holds at mostcapacityidle plus the in-flight sessions.- begin(session_id, request_id)[source]#
Pin
session_idforrequest_iduntil it stores or ends the session (or is removed). Refused while another request holds it.
- end(session_id)[source]#
Forget the session, stored state and pin alike.
- Parameters:
session_id (str)
- Return type:
None
- get(session_id)[source]#
The stored state, promoting the session; None when the session is unknown, expired or has not stored anything yet.
- put(session_id, value, ttl_s=None)[source]#
Store the session’s state and unpin it: the request under it is done with the session. Idle sessions over capacity go, oldest first.