mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 06:51:16 +08:00
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:
@@ -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)
|
||||
|
||||
|
||||
@@ -1088,9 +1088,10 @@ def terminal_tool(
|
||||
# Spawn a tracked background process via the process registry.
|
||||
# For local backends: uses subprocess.Popen with output buffering.
|
||||
# For non-local backends: runs inside the sandbox via env.execute().
|
||||
from tools.approval import get_current_session_key
|
||||
from tools.process_registry import process_registry
|
||||
|
||||
session_key = os.getenv("HERMES_SESSION_KEY", "")
|
||||
session_key = get_current_session_key(default="")
|
||||
effective_cwd = workdir or cwd
|
||||
try:
|
||||
if env_type == "local":
|
||||
|
||||
Reference in New Issue
Block a user