Skip to content

The agent that grows with you

fix(cron): treat a fresh serve ticker as scheduler-alive (#121881)

Bartok9fc15ec8fe3ea
diff --git a/hermes_cli/cron.py b/hermes_cli/cron.py
index f452f9b03fd..24ed84c98f1 100644
--- a/hermes_cli/cron.py
+++ b/hermes_cli/cron.py
@@ -59,10 +59,14 @@ def _builtin_gateway_liveness() -> Optional[bool]:
find_gateway_pids, named_profile_served_by_running_multiplexer)
if find_gateway_pids():
return True
+ from cron.jobs import get_ticker_heartbeat_age
+ # Desktop `serve` runs the cron ticker in-process (no `gateway` argv / runtime lock).
+ # A fresh ticker heartbeat is the same evidence status already uses after the pid scan.
+ if _ticker_age_is_fresh(get_ticker_heartbeat_age()):
+ 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
@@ -502,26 +506,38 @@ def cron_status():
else:
_print_ticker_health(pids)
else:
- print(color("✗ No gateway is running on this host — cron jobs will NOT fire", Colors.RED))
- # When scheduling last worked before the host went away: without this, a
- # 7h-overdue job still reads as a normal upcoming "Next run" (#114309).
+ serve_ticker_age = None
with contextlib.suppress(Exception):
- from cron.jobs import TICKER_INTERVAL_SECONDS, get_ticker_heartbeat_age
- hb_age = get_ticker_heartbeat_age()
- if hb_age is not None and hb_age > TICKER_INTERVAL_SECONDS * 3 + 20:
- print(color(" Scheduler last ticked "
- f"{_format_lateness(hb_age)} ago — jobs that came due "
- "since then have not fired.", Colors.YELLOW))
- print("\n Start the ONE host gateway (it multiplexes every profile, this one included):\n"
- " hermes --profile default gateway install # user service\n"
- " sudo hermes --profile default gateway install --system # Linux servers: boot-time service\n"
- " hermes --profile default gateway run # Or run in foreground")
- if active not in ("default", "custom"):
- print("\n It serves this profile automatically. If a per-profile service or gateway\n"
- " from an older release is still installed, fold it in (preflight + dry run):\n"
- " hermes --profile default gateway migrate --multiplex --dry-run\n"
- " hermes --profile default gateway migrate --multiplex\n"
- " Check: hermes cron status from this profile should show its ticker heartbeat.\n")
+ from cron.jobs import get_ticker_heartbeat_age
+ serve_ticker_age = get_ticker_heartbeat_age()
+ if _ticker_age_is_fresh(serve_ticker_age):
+ # Desktop topology: cron ticks inside `hermes serve`, not a CLI gateway process.
+ print(" Scheduler host: the desktop serve backend (in-process ticker)")
+ _print_ticker_health(
+ [],
+ restart_command="restart the Hermes desktop app (or its serve backend)",
+ )
+ else:
+ print(color("✗ No gateway is running on this host — cron jobs will NOT fire", Colors.RED))
+ # When scheduling last worked before the host went away: without this, a
+ # 7h-overdue job still reads as a normal upcoming "Next run" (#114309).
+ with contextlib.suppress(Exception):
+ from cron.jobs import TICKER_INTERVAL_SECONDS, get_ticker_heartbeat_age
+ hb_age = get_ticker_heartbeat_age()
+ if hb_age is not None and hb_age > TICKER_INTERVAL_SECONDS * 3 + 20:
+ print(color(" Scheduler last ticked "
+ f"{_format_lateness(hb_age)} ago — jobs that came due "
+ "since then have not fired.", Colors.YELLOW))
+ print("\n Start the ONE host gateway (it multiplexes every profile, this one included):\n"
+ " hermes --profile default gateway install # user service\n"
+ " sudo hermes --profile default gateway install --system # Linux servers: boot-time service\n"
+ " hermes --profile default gateway run # Or run in foreground")
+ if active not in ("default", "custom"):
+ print("\n It serves this profile automatically. If a per-profile service or gateway\n"
+ " from an older release is still installed, fold it in (preflight + dry run):\n"
+ " hermes --profile default gateway migrate --multiplex --dry-run\n"
+ " hermes --profile default gateway migrate --multiplex\n"
+ " Check: hermes cron status from this profile should show its ticker heartbeat.\n")
print()
_print_active_jobs_summary(list_jobs(include_disabled=False))
diff --git a/tests/hermes_cli/test_cron_satellite_diagnostics.py b/tests/hermes_cli/test_cron_satellite_diagnostics.py
index 685fa0c7fec..284a287779e 100644
--- a/tests/hermes_cli/test_cron_satellite_diagnostics.py
+++ b/tests/hermes_cli/test_cron_satellite_diagnostics.py
@@ -152,6 +152,45 @@ def test_standalone_guidance_matches_profile_membership(served_root, monkeypatch
assert "LEGACY" not in output
+def test_desktop_serve_ticker_is_not_reported_as_no_gateway(tmp_path, monkeypatch, capsys):
+ """Desktop `serve` ticks cron in-process; a fresh ticker heartbeat is not a missing gateway."""
+ from cron import jobs
+ from hermes_cli import cron
+
+ home = tmp_path / "home"
+ home.mkdir()
+ (tmp_path / "locks").mkdir()
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ monkeypatch.setenv("HERMES_GATEWAY_LOCK_DIR", str(tmp_path / "locks"))
+ monkeypatch.delenv("HERMES_PROFILE", raising=False)
+ monkeypatch.delenv("GATEWAY_MULTIPLEX_PROFILES", raising=False)
+ monkeypatch.setattr("hermes_constants.get_default_hermes_root", lambda: home)
+ monkeypatch.setattr(jobs, "CRON_DIR", home / "cron")
+ monkeypatch.setattr(jobs, "JOBS_FILE", home / "cron/jobs.json")
+ monkeypatch.setattr(jobs, "OUTPUT_DIR", home / "cron/output")
+ monkeypatch.setattr("hermes_cli.gateway.find_gateway_pids", lambda: [])
+ monkeypatch.setattr("gateway.status.is_gateway_runtime_lock_active", lambda lock_path=None: False)
+ monkeypatch.setattr("hermes_cli.gateway.named_profile_served_by_running_multiplexer", lambda: False)
+ monkeypatch.setattr("gateway.host_topology.host_gateway_serving", lambda profile_name=None: None)
+ monkeypatch.setattr(cron, "_active_cron_provider_name", lambda: "builtin")
+ jobs.record_ticker_heartbeat(success=True)
+
+ assert cron._builtin_gateway_liveness() is True
+ cron.cron_status()
+ output = capsys.readouterr().out
+ assert "Scheduler host: the desktop serve backend (in-process ticker)" in output
+ assert "will fire automatically" in output
+ assert "No gateway is running on this host" not in output
+ assert "gateway install" not in output
+
+ (jobs.CRON_DIR / "ticker_heartbeat").write_text(str(time.time() - 3600))
+ assert cron._builtin_gateway_liveness() is False
+ cron.cron_status()
+ stale = capsys.readouterr().out
+ assert "No gateway is running on this host" in stale
+ assert "gateway install" in stale
+
+
@pytest.mark.parametrize("detail", ["unreachable " * 30 + "\nsecret second line", ""])
def test_doctor_bounds_persisted_fire_errors(served_root, capsys, detail):
from cron import jobs