The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(sessions): one-shot runs stop inheriting the tui/desktop session source
teknium1c5f6336fa5d8
diff --git a/hermes_cli/oneshot.py b/hermes_cli/oneshot.pyindex c329d7c4b80..e06d7158189 100644--- a/hermes_cli/oneshot.py+++ b/hermes_cli/oneshot.py@@ -253,6 +253,9 @@ def run_oneshot(# Non-interactive by definition — an approval prompt would hang forever.os.environ["HERMES_YOLO_MODE"] = "1"os.environ["HERMES_ACCEPT_HOOKS"] = "1"+ # Same finite-chat marker as `hermes chat -q` (cli.py): the session-source resolver uses it to drop an+ # inherited tui/desktop transport label, and delegate dispatch to route detached results inline.+ os.environ["HERMES_SINGLE_QUERY_SESSION"] = "1"# Nothing here drains process_registry.completion_queue (only cli.py's process_loop and the# gateway watchers do), so left unbound delegate_task would be forced background and everydiff --git a/run_agent.py b/run_agent.pyindex 9c7aac289a1..034796ea5cd 100644--- a/run_agent.py+++ b/run_agent.py@@ -43,14 +43,23 @@ def _launch_cwd_for_session(source: str) -> Optional[str]:return None+# Sources that label the human conversation an interactive UI transport hosts. A finite ``hermes chat -q`` /+# one-shot child spawned from such a session inherits HERMES_SESSION_SOURCE (the terminal tool bridges the+# session env into child processes) but is NOT that conversation: labelling it ``tui``/``desktop`` lists it+# in the TUI/WebUI pickers as a resumable chat and lets ``hermes -c`` in the TUI continue it (#112550).+# Automation sources (kanban, tool, cron, a2a, ...) are inherited on purpose.+_UI_TRANSPORT_SOURCES = frozenset({"tui", "desktop"})++def _session_source_for_agent(platform: Optional[str]) -> str:try:from gateway.session_context import get_session_env-- source = get_session_env("HERMES_SESSION_SOURCE", "")except Exception:- source = os.environ.get("HERMES_SESSION_SOURCE", "")- return str(source or "").strip() or platform or "cli"+ get_session_env = os.environ.get+ source = str(get_session_env("HERMES_SESSION_SOURCE", "") or "").strip()+ if source in _UI_TRANSPORT_SOURCES and get_session_env("HERMES_SINGLE_QUERY_SESSION", "") == "1":+ source = ""+ return source or platform or "cli"def _gateway_origin_json(agent: "AIAgent") -> Optional[str]:diff --git a/tests/agent/test_session_source.py b/tests/agent/test_session_source.pyindex 1aa71b46114..5774e5a2175 100644--- a/tests/agent/test_session_source.py+++ b/tests/agent/test_session_source.py@@ -29,3 +29,21 @@ def test_session_source_falls_back_to_platform(monkeypatch):assert _session_source_for_agent("tui") == "tui"++[email protected]("inherited", ["tui", "desktop"])+def test_oneshot_child_drops_inherited_ui_transport_source(monkeypatch, inherited):+ """A finite `hermes chat -q` spawned from a TUI/Desktop session inherits the transport's+ HERMES_SESSION_SOURCE but is not that conversation: it keeps its own platform label (#112550)."""+ monkeypatch.setenv("HERMES_SESSION_SOURCE", inherited)+ monkeypatch.setenv("HERMES_SINGLE_QUERY_SESSION", "1")++ assert _session_source_for_agent("cli") == "cli"++[email protected]("inherited", ["kanban", "tool", "a2a"])+def test_oneshot_child_keeps_inherited_automation_source(monkeypatch, inherited):+ monkeypatch.setenv("HERMES_SESSION_SOURCE", inherited)+ monkeypatch.setenv("HERMES_SINGLE_QUERY_SESSION", "1")++ assert _session_source_for_agent("cli") == inheriteddiff --git a/website/docs/user-guide/sessions.md b/website/docs/user-guide/sessions.mdindex 7740c626cf4..2da82c6ff2b 100644--- a/website/docs/user-guide/sessions.md+++ b/website/docs/user-guide/sessions.md@@ -74,7 +74,7 @@ Each session is tagged with its source platform:| Source | Description ||--------|-------------|-| `cli` | Interactive CLI (`hermes` or `hermes chat`) |+| `cli` | Interactive CLI (`hermes` or `hermes chat`), and one-shot runs (`hermes chat -q`, `hermes -z`). A one-shot child launched from inside a TUI or Desktop session is still tagged `cli`, not `tui`/`desktop` — it is not that conversation, so it never shows up in the TUI/WebUI picker as a resumable chat. Pass `--source tool` to keep one-shot integration runs out of session lists entirely. || `telegram` | Telegram messenger || `discord` | Discord server/DM || `slack` | Slack workspace |