Skip to content

The agent that grows with you

fix(cli): a queue-mode Enter while busy is a gateway admission like /queue

Teknium9eb57f959497
diff --git a/hermes_cli/cli_tui_mixin.py b/hermes_cli/cli_tui_mixin.py
index a456e92ac6b..b199f656036 100644
--- a/hermes_cli/cli_tui_mixin.py
+++ b/hermes_cli/cli_tui_mixin.py
@@ -1504,11 +1504,9 @@ class CLITuiMixin:
def _tui_enter_while_busy(self, text: str, images: list, payload) -> None:
"""Route a submission typed while the agent runs, per ``busy_input_mode``.
- steer → agent.steer(text) mid-run (images can't ride along and a missing/rejecting
- steer() falls back to queue so nothing is lost). interrupt → agent.redirect() when the
- agent supports active-turn redirect, else the legacy interrupt queue (older agents,
- multimodal follow-ups, or a turn that finished in the race). queue → next turn.
- """
+ steer → agent.steer(text) mid-run (images can't ride along; a missing/rejecting steer() falls back
+ to queue). interrupt → agent.redirect() when supported, else the legacy interrupt queue. queue →
+ next turn: text-only on the gateway's session is a ``/queue`` FIFO admission (#134889 N5)."""
from cli import CLI_CONFIG, _ACCENT, _DIM, _RST, _cprint, _hermes_home
_effective_mode = self.busy_input_mode
redirected = False
@@ -1528,7 +1526,9 @@ class CLITuiMixin:
_cprint(f" {_ACCENT}{t('cli.tui.steered', preview=preview)}{_RST}")
else:
_effective_mode = "queue"
- if _effective_mode == "queue":
+ if _effective_mode == "queue" and text and not images and self._gateway_queue_store() is not None:
+ self._queue_enqueue(text)
+ elif _effective_mode == "queue":
self._pending_input.put(payload)
preview = text if text else _tn("cli.tui.images_attached_preview", len(images))
preview = preview[:80] + ('...' if len(preview) > 80 else '')
diff --git a/tests/hermes_cli/test_cli_queue_gateway_fifo.py b/tests/hermes_cli/test_cli_queue_gateway_fifo.py
index 3747930369f..f8ef594e43c 100644
--- a/tests/hermes_cli/test_cli_queue_gateway_fifo.py
+++ b/tests/hermes_cli/test_cli_queue_gateway_fifo.py
@@ -536,3 +536,57 @@ def test_a_queue_submit_the_owner_refused_still_says_nothing_was_queued():
assert [m for m, _ in client.calls].count("prompt.submit") == 1 # a verdict is never retried
finally:
conn.close()
+
+
+def _busy_enter(cli, mode, text, images=()):
+ """Enter typed while the turn runs, through main's ``_tui_enter_while_busy``."""
+ cli.busy_input_mode = mode
+ cli.agent = getattr(cli, "agent", None)
+ with patch("agent.onboarding.is_seen", lambda *a: True), patch("cli._cprint"):
+ cli._tui_enter_while_busy(text, list(images), (text, list(images)) if images else text)
+
+
+async def test_probe_queue_mode_enter_then_queue_keep_entry_order(tmp_path, monkeypatch):
+ """Review round 2, major 1: a queue-mode Enter typed before ``/queue X`` used to stay in
+ ``_pending_input`` while X went to the owner's FIFO, so X ran first (and the typed item had no
+ ``session_admissions`` row). With a gateway store attached it is an admission too, in entry order."""
+ owners = await _Owners().start(tmp_path, monkeypatch)
+ conn = GatewayConnection(connect=owners.dial)
+ try:
+ store = GatewaySessionStore(conn)
+ await asyncio.to_thread(store.attach, owners.sid)
+ cli = _busy_cli(store, owners.sid)
+ await asyncio.to_thread(_busy_enter, cli, "queue", "typed first")
+ await asyncio.to_thread(_command, cli, f"/queue {TEXT}")
+ assert cli._pending_input.empty()
+ listed = await asyncio.to_thread(_command, cli, "/queue list")
+ assert listed.index("typed first") < listed.index(TEXT), f"entry order lost: {listed}"
+ finally:
+ await owners.close(conn)
+
+
+def test_a_steer_that_falls_back_to_queue_is_a_gateway_admission_and_images_stay_local():
+ """The steer fallback inherits the queue-mode path; an image follow-up (no text-only admission) and
+ a run with no gateway store keep main's ``_pending_input``."""
+ from tests.hermes_cli.test_gateway_agent import SID
+ from tests.hermes_cli.test_gateway_tools_notify import _connected, _idle_cli
+ conn, client = _connected()
+ try:
+ cli = _idle_cli(conn)
+ cli._agent_running = True
+ cli.agent = SimpleNamespace(steer=lambda text: False) # the running turn refused the steer
+ _busy_enter(cli, "steer", "steer me")
+ assert cli._pending_input.empty() and list(conn.state(SID).queued_inputs.values()) == ["steer me"]
+ _busy_enter(cli, "queue", "look", images=["/img.png"])
+ assert cli._pending_input.get_nowait() == ("look", ["/img.png"])
+ submits = [m for m, _ in client.calls].count("prompt.submit")
+ assert submits == 1
+ finally:
+ conn.close()
+ local = _idle_cli(conn)
+ local._session_db = object() # not a gateway viewer
+ local._agent_running = True
+ _busy_enter(local, "queue", "plain")
+ assert local._pending_input.get_nowait() == "plain"
+