Skip to content

The agent that grows with you

fix(cli): keep the answer deadline for /cron reads

kshitijk4poora36db282b905
diff --git a/hermes_cli/gateway_setting_commands.py b/hermes_cli/gateway_setting_commands.py
index c216d8617c6..fc6f5466627 100644
--- a/hermes_cli/gateway_setting_commands.py
+++ b/hermes_cli/gateway_setting_commands.py
@@ -8,10 +8,12 @@ command, every surface) and the CLI prints its reply. Client-side state the CLI
``/refine`` and ``/review`` take the same route: their background reviewer must run beside the
session's agent in the gateway (as on messaging), where its result is delivered back to the session.
``/cron`` too: the profile's cron store belongs to the gateway that fires its jobs, so the gateway runs
-main's handler (one writer); ``/cron run`` lasts as long as the job, so it waits with no deadline.
+main's handler (one writer); ``/cron run`` lasts as long as the job, so a write waits with no deadline.
"""
from __future__ import annotations
+import shlex
+
# Canonical command -> mirror(cli, arg) run after the owner applied it (None: nothing local).
_BUSY_MODES = frozenset({"queue", "steer", "interrupt"})
@@ -31,14 +33,26 @@ def _watch_reviewer(cli, _arg):
GATEWAY_SETTINGS = {"personality": None, "busy": _mirror_busy, "approvals": None, "footer": None, "fast": None,
"refine": None, "review": _watch_reviewer, "cron": None}
-# Answered when their work is done, however long (``/cron run`` runs the job): no deadline, on a socket of
-# their own so the session's prompts never queue behind them (GatewayConnection.call_until); Ctrl+C stops waiting.
-_UNBOUNDED = frozenset({"cron"})
-def _call(cli, connection, canonical, command):
- if canonical not in _UNBOUNDED:
+def _unbounded(canonical, arg):
+ """True for a form answered only once its work is done, however long: a /cron write (``run`` runs the
+ job). Its reads keep the deadline, and so does an unclosed quote, which the owner refuses at once."""
+ if canonical != "cron":
+ return False
+ from gateway.session_cron_commands import cron_read
+ try:
+ return cron_read(shlex.split(arg)) is None
+ except ValueError:
+ return False
+
+
+def _call(cli, connection, canonical, arg):
+ command = canonical + (" " + arg if arg else "")
+ if not _unbounded(canonical, arg):
return connection.call("slash.exec", session_id=cli.session_id, command=command)
+ # No deadline, on a socket of its own so the session's prompts never queue behind it
+ # (GatewayConnection.call_until); Ctrl+C stops waiting.
from hermes_cli.gateway_plugin_commands import call_unbounded
return call_unbounded(cli, connection, canonical, command)
@@ -57,7 +71,7 @@ def run(cli, canonical, cmd):
parts = (cmd or "").strip().split(None, 1)
arg = parts[1].strip() if len(parts) > 1 else ""
try:
- reply = _call(cli, connection, canonical, canonical + (" " + arg if arg else ""))
+ reply = _call(cli, connection, canonical, arg)
except GatewayClientError as exc:
_cprint(f" /{canonical}: {exc}")
return True
diff --git a/tests/hermes_cli/test_gateway_setting_commands.py b/tests/hermes_cli/test_gateway_setting_commands.py
index 238e9610b50..787122e83ae 100644
--- a/tests/hermes_cli/test_gateway_setting_commands.py
+++ b/tests/hermes_cli/test_gateway_setting_commands.py
@@ -77,3 +77,19 @@ def test_ctrl_c_during_a_cron_wait_prints_the_stopped_line_and_propagates(monkey
with pytest.raises(KeyboardInterrupt):
gateway_setting_commands.run(cli, "cron", "/cron run probe")
assert "/cron: stopped waiting" in capsys.readouterr().out and cli._gateway_command_wait is None
+
+
+def test_cron_reads_keep_the_answer_deadline(monkeypatch, capsys):
+ """Only a /cron write waits with no deadline (a /cron run lasts as long as its job): bare /cron and
+ /cron list answer on the session's connection with its deadline, as /fast does, so a frozen gateway
+ gives up instead of hanging until Ctrl+C."""
+ class _BoundedConn(_Conn):
+ def call_until(self, method, wake, **params):
+ raise AssertionError("a /cron read must keep the answer deadline")
+ conn = _BoundedConn()
+ monkeypatch.setattr("hermes_cli.gateway_side.connection_for", lambda cli: conn)
+ cli = SimpleNamespace(session_id="local-s", _gateway_command_wait=None)
+ for typed in ("/cron", "/cron list", "/cron LIST -a", '/cron add "every 2h'):
+ assert gateway_setting_commands.run(cli, "cron", typed) is True
+ assert [params["command"] for _m, params in conn.calls] == [
+ "cron", "cron list", "cron LIST -a", 'cron add "every 2h']