Skip to content

Commit eabbc83

Browse files
authored
Initialize standard session state namespaces on session creation (#592)
Ensures context, temp, user, and system scopes always exist as empty dicts so CEL expressions like has(context.experiments) evaluate to false instead of throwing when no initial_state is provided. Fixes chatflow preview working without school context.
1 parent 1824488 commit eabbc83

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

app/repositories/chat_repository.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ async def create_session(
6161
trace_level: Optional[str] = None,
6262
) -> ConversationSession:
6363
"""Create a new conversation session with initial state."""
64-
state = initial_state or {}
64+
# Ensure standard scope namespaces always exist so CEL
65+
# expressions like has(context.foo) don't throw when
66+
# the top-level scope key is missing entirely.
67+
state = {"context": {}, "temp": {}, "user": {}, "system": {}}
68+
if initial_state:
69+
for key, value in initial_state.items():
70+
if key in state and isinstance(value, dict):
71+
state[key].update(value)
72+
else:
73+
state[key] = value
6574
state_hash = self._calculate_state_hash(state)
6675

6776
session = ConversationSession(

0 commit comments

Comments
 (0)