The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): /cron run reports a refused run instead of "Triggered … next scheduler tick"
teknium163f09c2d2c7e
diff --git a/hermes_cli/cli_commands_mixin.py b/hermes_cli/cli_commands_mixin.pyindex 12dff10176c..2f88a542cda 100644--- a/hermes_cli/cli_commands_mixin.py+++ b/hermes_cli/cli_commands_mixin.py@@ -1780,12 +1780,17 @@ class CLICommandsMixin:if action == "remove":removed = result.get("removed_job", {})return print(f"(^_^)b Removed job: {removed.get('name', job_id)} ({job_id})")+ job = result["job"]+ if action == "run" and job.get("execution_skipped"):+ # A refused run-now (claim lost, paused, gone) must not read as accepted.+ return print(f"(x_x) Did not run job: {job['name']} ({job_id})\n {job['execution_skipped']}")verb = {"pause": "Paused", "resume": "Resumed", "run": "Triggered"}[action]- print(f"(^_^)b {verb} job: {result['job']['name']} ({job_id})")+ print(f"(^_^)b {verb} job: {job['name']} ({job_id})")if action == "resume":- print(f" Next run: {result['job'].get('next_run_at')}")+ print(f" Next run: {job.get('next_run_at')}")elif action == "run":- print(" It will run on the next scheduler tick.")+ from hermes_cli.cron import _run_outcome+ print(f" {_run_outcome(job)}")# ---- delegating handlers: /suggestions, /blueprint, /curator, /kanban, /skills, /memory --def _handle_suggestions_command(self, cmd: str):diff --git a/tests/cron/test_cron_run_stale_claim_reap.py b/tests/cron/test_cron_run_stale_claim_reap.pyindex 97baf798302..1e29c9c74bf 100644--- a/tests/cron/test_cron_run_stale_claim_reap.py+++ b/tests/cron/test_cron_run_stale_claim_reap.py@@ -141,3 +141,34 @@ def test_try_dispatch_background_run_calls_recovery_before_claiming(monkeypatch)"recover_interrupted_executions() must be called before any claim ""attempt in the one-shot dispatch path")+++def test_one_shot_cli_path_reaps_dead_owner_row_before_returning_sync(tmp_path, monkeypatch):+ """The real one-shot `hermes cron run` shape (``_SESSION_ASYNC_DELIVERY`` scoped to False,+ as hermes_cli/cron.py::_job_action does) must still reap a 'running' row whose owner pid+ is provably dead before falling back to the sync run — the early return used to skip it."""+ import subprocess as sp+ import sqlite3++ from cron import executions+ from gateway.session_context import _SESSION_ASYNC_DELIVERY+ from tools import cronjob_tools++ monkeypatch.setattr(executions, "EXECUTIONS_FILE", tmp_path / "executions.db")+ row = executions.create_execution("dead-owner-job", source="direct")+ proc = sp.Popen([sys.executable, "-c", "pass"])+ proc.wait()+ dead_pid = proc.pid # exited: provably dead+ with sqlite3.connect(tmp_path / "executions.db") as conn:+ conn.execute(+ "UPDATE executions SET status='running', process_id='other-process', pid=?, "+ "process_started_at=1 WHERE id=?", (dead_pid, row["id"]))++ token = _SESSION_ASYNC_DELIVERY.set(False)+ try:+ assert cronjob_tools._try_dispatch_background_run(+ {"id": "dead-owner-job", "name": "dead owner job", "deliver": "local"}) is None+ finally:+ _SESSION_ASYNC_DELIVERY.reset(token)++ assert executions.get_execution(row["id"])["status"] == "unknown"diff --git a/tests/hermes_cli/test_cron.py b/tests/hermes_cli/test_cron.pyindex 897a5af841d..96d4e63dd92 100644--- a/tests/hermes_cli/test_cron.py+++ b/tests/hermes_cli/test_cron.py@@ -588,3 +588,24 @@ class TestSlashCronListLastStatus:out = self._run_list(tmp_cron_dir, capsys)assert "(ok)" in out+++class TestSlashCronRunSkipped:+ """``/cron run`` on a job whose claim is refused (paused here; a live claim held by another+ run is the same shape) must print the refusal, never ``Triggered … next scheduler tick``."""++ def test_refused_run_prints_reason_not_triggered(self, tmp_cron_dir, capsys):+ from hermes_cli.cli_commands_mixin import CLICommandsMixin++ class _Host(CLICommandsMixin):+ pass++ job = create_job(prompt="Nightly brief", schedule="every 1h", deliver="local")+ jobs = load_jobs()+ jobs[0]["enabled"] = False+ save_jobs(jobs)++ _Host()._handle_cron_command(f"/cron run {job['id']}")+ out = capsys.readouterr().out+ assert "Job is paused/disabled; resume it before running." in out+ assert "Triggered" not in out and "next scheduler tick" not in outdiff --git a/website/docs/user-guide/features/cron.md b/website/docs/user-guide/features/cron.mdindex 6dda6a73fe3..f4f4aafdd45 100644--- a/website/docs/user-guide/features/cron.md+++ b/website/docs/user-guide/features/cron.md@@ -383,10 +383,11 @@ The worker is the gateway's own interpreter running `python -m cron.scheduler`,Hermes records each claimed cron attempt in the profile-local`~/.hermes/cron/executions.db` before executor or provider dispatch. Attemptsmove through `claimed`, `running`, and one immutable terminal state:-`completed`, `failed`, or `unknown`. After restart, Hermes marks an abandoned-attempt `unknown` only when the original PID and process-start fingerprint prove-that its owner is gone. Unknown attempts are audit records and are never-automatically rerun.+`completed`, `failed`, or `unknown`. After restart — and before every manual+`hermes cron run` / `/cron run`, so a one-shot invocation with no scheduler+running heals the ledger too — Hermes marks an abandoned attempt `unknown` only+when the original PID and process-start fingerprint prove that its owner is+gone. Unknown attempts are audit records and are never automatically rerun.Inspect recent attempts with `hermes cron runs [job-id] --limit 20` (alias:`history`). Terminal history is bounded; active attempts are never pruned. The