orchestrata_ultimate.session.constants
Reference › orchestrata_ultimate › session › constants
Shared constants of the session package, and generate_session_id, which builds a session identifier in the format that spec 006 prescribes from the given time (or the current time). The identifier is what the Redis and graph stores use as the key for a session, as in redis_store and graph_store.
At a glance
| Source | src/orchestrata_ultimate/session/constants.py |
| Lines of code | 101 |
| Classes | 0 |
| Functions | 1 |
| Imports (internal) | orchestrata_ultimate.core.base.traces |
| Imported by | orchestrata_ultimate.session, orchestrata_ultimate.session.checkpoint, orchestrata_ultimate.session.graph_store, orchestrata_ultimate.session.redis_store, orchestrata_ultimate.session.sync |
| Tests that import it | tests/session/test_constants.py, tests/session/test_session_edge_cases.py, tests/session/test_session_spec006_implementation.py, tests/test_session.py |
Class diagram
No classes; see Functions.
Dependency diagram
API
Functions
| Function | Signature | Summary |
|---|---|---|
generate_session_id traces |
generate_session_id(when: datetime | None = None) -> str |
Generate a session ID conforming to spec 006 format. |
Source
"""Session management constants.
Configuration constants for dual-storage session management.
Includes session ID generation conforming to spec 006.
"""
import re
import uuid
from datetime import datetime
from orchestrata_ultimate.core.base.traces import traces
# Session ID format: session_YYYYMMDD_HHMMSS_{uuid_hex[:8]}
SESSION_ID_PATTERN = re.compile(r"^session_\d{8}_\d{6}_[0-9a-f]{8}$")
@traces(
spec="006",
story="US-001",
reqs=[
"REQ-006-FR1-001",
"REQ-006-FR1-002",
"REQ-006-FR1-003",
"REQ-006-FR1-004",
"REQ-006-FR1-005",
"REQ-006-US-001-002",
],
)
def generate_session_id(when: datetime | None = None) -> str:
"""Generate a session ID conforming to spec 006 format.
Format: ``session_YYYYMMDD_HHMMSS_{uuid_hex[:8]}``
Args:
when: Timestamp to embed. Defaults to ``datetime.now()``.
Returns:
A unique session identifier string, e.g.
``session_20260223_141500_a3f8b21c``.
Examples:
>>> sid = generate_session_id()
>>> SESSION_ID_PATTERN.match(sid) is not None
True
"""
ts = when or datetime.now()
stamp = ts.strftime("%Y%m%d_%H%M%S")
short_uuid = uuid.uuid4().hex[:8]
return f"session_{stamp}_{short_uuid}"
# Redis key prefixes
SESSION_REDIS_PREFIX = "orchestrata:session"
PORTFOLIO_REDIS_PREFIX = "orchestrata:portfolio"
# Redis key patterns
SESSION_KEY = f"{SESSION_REDIS_PREFIX}:{{id}}"
SESSION_ACTIVE_SET = f"{SESSION_REDIS_PREFIX}:active"
SESSION_FACTS_KEY = f"{SESSION_REDIS_PREFIX}:{{id}}:facts"
SESSION_CONTEXT_KEY = f"{SESSION_REDIS_PREFIX}:{{id}}:context"
SESSION_CHECKPOINTS_KEY = f"{SESSION_REDIS_PREFIX}:{{id}}:checkpoints"
SESSION_CARRYOVER_KEY = f"{SESSION_REDIS_PREFIX}:{{id}}:carryover"
PORTFOLIO_SESSIONS_KEY = f"{PORTFOLIO_REDIS_PREFIX}:{{id}}:sessions"
# Timeouts (seconds)
SESSION_DEFAULT_TTL = 86400 # 24 hours
CHECKPOINT_TTL = 604800 # 7 days
FACT_BATCH_TIMEOUT = 5.0 # seconds
LOCK_TIMEOUT = 10 # seconds
LOCK_TTL = 30 # seconds
# Performance targets (milliseconds)
SESSION_OPEN_TARGET_MS = 50
SESSION_CLOSE_TARGET_MS = 100
FACT_EMIT_TARGET_MS = 10
FACT_QUERY_TARGET_MS = 20
HISTORY_QUERY_TARGET_MS = 200
CHECKPOINT_CREATE_TARGET_MS = 50
RECOVERY_TARGET_MS = 500
CONTEXT_OP_TARGET_MS = 20
# Limits
MAX_FACTS_PER_SESSION = 10000
MAX_CHECKPOINTS_PER_SESSION = 100
MAX_ACTIVE_SESSIONS = 50
MAX_CARRYOVER_ITEMS = 500
CHECKPOINT_PRUNE_KEEP = 10
FACT_BATCH_SIZE = 50
SYNC_BATCH_SIZE = 100
# Graph labels and relationship types
SESSION_LABEL = "Session"
FACT_LABEL = "Fact"
PORTFOLIO_LABEL = "Portfolio"
WORKITEM_LABEL = "WorkItem"
BELONGS_TO = "BELONGS_TO"
ABOUT = "ABOUT"
NEXT_SESSION = "NEXT_SESSION"
CARRIED_OVER_FROM = "CARRIED_OVER_FROM"
CARRIED_OVER_TO = "CARRIED_OVER_TO"