Skip to content

The agent that grows with you

fix(cron): R3-W3 require satellite heartbeat for list and create

yoniebansc134199886b2
diff --git a/hermes_cli/cron.py b/hermes_cli/cron.py
index 3f6da2a9a46..3839b5abd87 100644
--- a/hermes_cli/cron.py
+++ b/hermes_cli/cron.py
@@ -40,14 +40,9 @@ def _active_cron_provider_name() -> str:
def _builtin_gateway_liveness() -> Optional[bool]:
- """Tri-state liveness of the builtin cron scheduler's trigger (None = unknown).
+ """Tri-state scheduler readiness (None = probe failed).
- The builtin ticker only runs inside the gateway process, so a scheduled job with no live
- gateway can never fire; non-builtin providers fire jobs without the gateway.
-
- Chronos) fire through their own machinery and are deliberately exempt — a missing gateway process means
- nothing for them, so they report active. ``None`` = probe failed; callers must not claim either way. See
- #87033.
+ Local gateways use process liveness; served satellites also require their own fresh heartbeat. External providers use their own machinery and are exempt.
"""
try:
if _active_cron_provider_name() != "builtin":
@@ -61,26 +56,23 @@ def _builtin_gateway_liveness() -> Optional[bool]:
return True
from hermes_cli.gateway import (
find_gateway_pids, named_profile_served_by_running_multiplexer)
- # List/create use this cheap host probe; status separately checks the satellite's ticker heartbeat.
- return bool(find_gateway_pids()) or named_profile_served_by_running_multiplexer()
+ if find_gateway_pids():
+ return True
+ if not named_profile_served_by_running_multiplexer():
+ return False
+ # List/create and status require a fresh heartbeat from the satellite's own store.
+ from cron.jobs import get_ticker_heartbeat_age
+ return _ticker_age_is_fresh(get_ticker_heartbeat_age())
except Exception:
return None
def _warn_if_gateway_not_running() -> None:
- """Warn that scheduled jobs won't fire unless the gateway is running (the #1 cron report).
-
- False is the only warn-worthy liveness state (None = unknown).
-
- The cron ticker only runs inside the gateway (``_start_cron_ticker`` in gateway/run.py); there is no
- standalone cron daemon. Without a running gateway, ``next_run_at`` passes but jobs never fire and
- ``last_run_at`` stays null — the most common cron support report (#51038). Surfacing this at create/list
- time, when the user is right there, prevents it.
- """
+ """Warn at create/list time when the scheduler is not ready; stay silent on an unknown probe result."""
if _builtin_gateway_liveness() is not False:
return
- print(color(" ⚠ Gateway is not running — jobs won't fire automatically.", Colors.YELLOW))
- print(color(" Start it with: hermes gateway install\n"
+ print(color(" ⚠ Scheduler is not ready: no gateway or no fresh profile heartbeat.", Colors.YELLOW))
+ print(color(" If no gateway is running: hermes gateway install\n"
" sudo hermes gateway install --system # Linux servers\n"
" Check status: hermes cron status", Colors.DIM))
@@ -351,6 +343,11 @@ _FD_EXHAUSTION_HINT = (" Hint: the ticker hit file-descriptor exhaustion (EMFIL
"persists, restart the gateway to recover scheduling.")
+def _ticker_age_is_fresh(age: Optional[float]) -> bool:
+ from cron.jobs import TICKER_INTERVAL_SECONDS
+ return age is not None and age <= TICKER_INTERVAL_SECONDS * 3 + 20
+
+
def _print_ticker_health(pids: list, restart_command: str = "hermes gateway restart") -> None:
"""Report builtin-ticker liveness for a gateway process known to be alive.
@@ -359,10 +356,8 @@ def _print_ticker_health(pids: list, restart_command: str = "hermes gateway rest
"""
# See #32612, #32895.
from cron.jobs import (
- get_ticker_heartbeat_age, get_ticker_last_error, get_ticker_success_age,
- TICKER_INTERVAL_SECONDS)
+ get_ticker_heartbeat_age, get_ticker_last_error, get_ticker_success_age)
from cron.scheduler import _is_fd_exhaustion_text as _cron_is_fd_exhaustion_text
- STALE_AFTER = TICKER_INTERVAL_SECONDS * 3 + 20 # ~3 missed iterations + slack (200s @ 60s)
hb_age = get_ticker_heartbeat_age()
ok_age = get_ticker_success_age()
pid_line = f" PID: {', '.join(map(str, pids))}" if pids else None
@@ -378,11 +373,11 @@ def _print_ticker_health(pids: list, restart_command: str = "hermes gateway rest
print(" Cron jobs will NOT fire until the ticker writes its first heartbeat.\n"
" If the gateway just started, wait ~60s and re-run `hermes cron status`.\n"
f" If heartbeat never appears, restart: {restart_command}")
- elif hb_age > STALE_AFTER: # ticker thread is gone
+ elif not _ticker_age_is_fresh(hb_age): # ticker thread is gone
_warn("⚠ Gateway is running but the cron ticker looks STALLED — "
f"no heartbeat for {int(hb_age)}s (expected every ~60s).")
print(f" Cron jobs may NOT be firing. Restart: {restart_command}")
- elif ok_age is not None and ok_age > STALE_AFTER: # loop alive but every tick fails
+ elif ok_age is not None and not _ticker_age_is_fresh(ok_age): # loop alive but every tick fails
_warn("⚠ Gateway and cron ticker are running, but no tick has "
f"succeeded in {int(ok_age)}s — ticks may be failing.")
last_error = get_ticker_last_error()
diff --git a/tests/cron/test_cronjob_gateway_liveness.py b/tests/cron/test_cronjob_gateway_liveness.py
index 0b7cb59d208..58f54b94b18 100644
--- a/tests/cron/test_cronjob_gateway_liveness.py
+++ b/tests/cron/test_cronjob_gateway_liveness.py
@@ -290,11 +290,13 @@ class TestRuntimeLockFirstLiveness:
assert cron_cli._builtin_gateway_liveness() is True
def test_running_multiplexer_counts_as_alive_for_named_profile(self):
- """A satellite profile has no own PID; the default multiplexer ticks it."""
+ """A satellite needs its own fresh heartbeat as well as a live multiplexer."""
from unittest.mock import patch
+ from cron.jobs import record_ticker_heartbeat
import hermes_cli.cron as cron_cli
+ record_ticker_heartbeat(success=True)
with (
patch("hermes_cli.cron._active_cron_provider_name", return_value="builtin"),
patch("gateway.status.is_gateway_runtime_lock_active", return_value=False),
diff --git a/tests/hermes_cli/test_cron.py b/tests/hermes_cli/test_cron.py
index feb3bc61ce3..367033deab0 100644
--- a/tests/hermes_cli/test_cron.py
+++ b/tests/hermes_cli/test_cron.py
@@ -310,7 +310,7 @@ class TestGatewayNotRunningWarning:
monkeypatch.setattr("hermes_cli.gateway.find_gateway_pids", lambda: [])
cron_command(Namespace(cron_command="list", all=True))
out = capsys.readouterr().out
- assert "Gateway is not running" in out
+ assert "Scheduler is not ready" in out
class TestExternalCronProviderStatus:
@@ -338,7 +338,7 @@ class TestExternalCronProviderStatus:
assert "managed scheduler" in out
assert "not firing" not in out.lower()
assert "STALLED" not in out
- assert "Gateway is not running" not in out
+ assert "Scheduler is not ready" not in out
# Still surfaces the active-job summary.
assert "active job(s)" in out
@@ -369,7 +369,7 @@ class TestExternalCronProviderStatus:
)
out = capsys.readouterr().out
assert "Created job" in out
- assert "Gateway is not running" not in out
+ assert "Scheduler is not ready" not in out
def test_cron_list_warns_when_gateway_not_running(monkeypatch, capsys):
@@ -393,7 +393,7 @@ def test_cron_list_warns_when_gateway_not_running(monkeypatch, capsys):
cron_cli.cron_list()
out = capsys.readouterr().out
- assert "Gateway is not running" in out
+ assert "Scheduler is not ready" in out
assert "Nightly docs" in out
diff --git a/tests/hermes_cli/test_cron_satellite_diagnostics.py b/tests/hermes_cli/test_cron_satellite_diagnostics.py
index 18f2d46372b..be2e2133e97 100644
--- a/tests/hermes_cli/test_cron_satellite_diagnostics.py
+++ b/tests/hermes_cli/test_cron_satellite_diagnostics.py
@@ -72,6 +72,32 @@ def test_status_preserves_profile_health_contract(served_root, capsys, monkeypat
assert "STALLED" not in output
[email protected]("heartbeat", ["missing", "fresh", "stale"])
+def test_satellite_list_and_create_require_own_heartbeat(served_root, capsys, monkeypatch, heartbeat):
+ from argparse import Namespace
+ from cron import jobs
+ from hermes_cli import cron
+
+ # A fresh host heartbeat must not hide the satellite's missing or stale heartbeat.
+ host_cron = served_root / "cron"
+ host_cron.mkdir()
+ (host_cron / "ticker_heartbeat").write_text(str(time.time()))
+ if heartbeat != "missing":
+ jobs.record_ticker_heartbeat(success=True)
+ if heartbeat == "stale":
+ (jobs.CRON_DIR / "ticker_heartbeat").write_text(str(time.time() - 3600))
+ monkeypatch.setattr(cron, "_active_cron_provider_name", lambda: "builtin")
+ assert cron._builtin_gateway_liveness() is (heartbeat == "fresh")
+ cron.cron_command(Namespace(cron_command="create", schedule="every 1h", prompt="probe"))
+ created = capsys.readouterr().out
+ cron.cron_list()
+ listed = capsys.readouterr().out
+ for output in (created, listed):
+ assert ("Check status: hermes cron status" in output) == (heartbeat != "fresh")
+ cron.cron_status()
+ assert ("will fire automatically" in capsys.readouterr().out) == (heartbeat == "fresh")
+
+
@pytest.mark.parametrize("home_kind", ["default", "custom", "named"])
def test_standalone_guidance_matches_profile_membership(served_root, monkeypatch, capsys, home_kind):
from hermes_cli.cron import cron_status