hermes-agent/tests/tui_gateway/test_slash_review_owner.py
Teknium d0df324862 fix(tui-gateway): /review shows its reviewer in the Desktop subagent stack
`slash.exec` runs on the RPC pool, outside any turn, so `/review` dispatched the
reviewer with no HERMES_UI_SESSION_ID and no steer authority bound. delegate_task
registered the child with `owner_session_id=None`, `subagent.list` (owner-scoped)
returned nothing for the parent session, and the Desktop status stack's 5s
snapshot poll reconciled the live `subagent.start` row away — the user saw only
"Review started. Results will return here." with no subagent card.

Bind the same session identity a turn binds (`_set_session_context(...,
ui_session_id=sid)` + `_current_runtime_session_record`) around `start_review`,
and clear it after. The reviewer now registers under the parent sid with the
request transport as authority, so `subagent.list`, steer, stop and the Desktop
roster all see it.

Live repro (tui_gateway stdio, real OpenRouter reviewer):
  before: registry owner_session_id=None, owner_transport=NoneType;
          subagent.list -> {"subagents": []}
  after:  owner_session_id=<parent sid>, owner_transport=StdioTransport;
          subagent.list -> [{"goal": "Review recent work", "status": "running", ...}]
2026-09-09 02:00:21 -07:00

50 lines
2.1 KiB
Python

"""/review from slash.exec runs on the RPC pool, outside any turn. The reviewer it dispatches must
still be registered under the parent Desktop/TUI session (HERMES_UI_SESSION_ID + exact steer
authority), or `subagent.list` hides it and the Desktop status stack shows nothing for /review."""
from __future__ import annotations
import threading
from unittest.mock import patch
from tui_gateway import server
from tui_gateway.transport import StdioTransport
def _live_session(agent):
return {
"agent": agent, "session_key": "review-key", "history": [{"role": "user", "content": "hi"}],
"history_lock": threading.Lock(), "running": False, "transport": StdioTransport(lambda: None, threading.Lock()),
"cwd": "", "source": "desktop",
}
def test_slash_review_dispatches_under_the_parent_session_identity(monkeypatch):
sid = "review-sid"
session = _live_session(object())
server._sessions[sid] = session
seen = {}
def fake_start_review(agent, snapshot, prompt):
from gateway.session_context import get_session_env
seen["ui_session_id"] = get_session_env("HERMES_UI_SESSION_ID", "")
seen["authority"] = server._current_session_steer_authority(sid)
return {"status": "dispatched", "delegation_id": "deleg_x"}
token = server.bind_transport(session["transport"])
try:
with (
patch.object(server, "_session_uses_compute_host", return_value=False),
patch("agent.review_engine.start_review", fake_start_review),
):
out = server._live_slash_command_output(sid, session, "review", "")
from gateway.session_context import get_session_env
assert get_session_env("HERMES_UI_SESSION_ID", "") == "" # scope cleared after dispatch
assert server._current_runtime_session_record.get() is None
finally:
server.reset_transport(token)
server._sessions.pop(sid, None)
assert out == "Review started. Results will return here."
assert seen["ui_session_id"] == sid
assert seen["authority"] == (session["transport"], session)