Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions gateway/session_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
platform = get_session_env("HERMES_SESSION_PLATFORM", "")
"""

from contextlib import contextmanager
from contextvars import ContextVar
from typing import Any

Expand Down Expand Up @@ -66,6 +67,22 @@ def session_context_engaged() -> bool:
"""
return _session_context_engaged


@contextmanager
def bind_ui_session_id(ui_session_id: str):
"""Temporarily bind only the WebUI return address in this execution context.

Unlike :func:`set_session_vars`, this helper is nestable and deliberately
leaves execution-isolation keys untouched. Delegated child workers use it
so detached process notifications return to the parent tab without making
the child share the parent's process ownership scope.
"""
token = _SESSION_UI_SESSION_ID.set(ui_session_id or "")
try:
yield
finally:
_SESSION_UI_SESSION_ID.reset(token)

# ---------------------------------------------------------------------------
# Per-task session variables
# ---------------------------------------------------------------------------
Expand Down
Loading