fix: add type hints to session key helpers, extend context-local key to terminal_tool

- Add contextvars.Token[str] type hints to set/reset_current_session_key
- Use get_current_session_key(default='') in terminal_tool.py for background
  process session tracking, fixing the same env var race for concurrent
  gateway sessions spawning background processes
This commit is contained in:
Teknium
2026-04-03 15:07:18 -07:00
committed by Teknium
parent 3bfb39a25f
commit fb654c15d8
2 changed files with 4 additions and 3 deletions

View File

@@ -29,12 +29,12 @@ _approval_session_key: contextvars.ContextVar[str] = contextvars.ContextVar(
)
def set_current_session_key(session_key: str):
def set_current_session_key(session_key: str) -> contextvars.Token[str]:
"""Bind the active approval session key to the current context."""
return _approval_session_key.set(session_key or "")
def reset_current_session_key(token) -> None:
def reset_current_session_key(token: contextvars.Token[str]) -> None:
"""Restore the prior approval session key context."""
_approval_session_key.reset(token)