Skip to content

The agent that grows with you

refactor(cron): apply scheduler diagnostic review suggestions

yoniebansafc5efa178b3
diff --git a/hermes_cli/cron.py b/hermes_cli/cron.py
index 987ad5186fd..fa94c3dc31a 100644
--- a/hermes_cli/cron.py
+++ b/hermes_cli/cron.py
@@ -61,7 +61,7 @@ def _builtin_gateway_liveness() -> Optional[bool]:
return True
from hermes_cli.gateway import (
find_gateway_pids, named_profile_served_by_running_multiplexer)
- # Satellite profile: no local gateway.pid, but the default multiplexer ticks its store.
+ # 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()
except Exception:
return None
@@ -442,6 +442,8 @@ def cron_status():
if served_by_multiplexer:
print(" Scheduler host: default-profile multiplexer")
_print_ticker_health(pids, restart_command="hermes --profile default gateway restart")
+ print(color(" If the Desktop app is open, it may have taken over scheduling for this profile; "
+ "check that the profile is enabled in its scheduler.", Colors.DIM))
else:
_print_ticker_health(pids)
else:
@@ -457,6 +459,8 @@ def cron_status():
" configure a running default gateway to tick this profile:\n"
" hermes --profile default config set gateway.multiplex_profiles true\n"
" hermes --profile default gateway restart\n"
+ " To migrate existing per-profile services with preflight checks:\n"
+ " hermes --profile default gateway migrate --multiplex\n"
" Check: hermes cron status from this profile should show its ticker heartbeat.\n")
print()
@@ -544,20 +548,11 @@ def _cron_doctor_issues_for_job(job: Dict[str, Any]) -> List[str]:
issues.append("last delivery unverified (adapter acked without evidence): "
+ _unverified_targets(unverified))
# Dispatch records measure lateness, not whether the scheduler process was running.
- if isinstance(job.get("last_dispatch"), dict):
- kind = job["last_dispatch"].get("kind")
- if kind == "catch_up":
- lateness = job["last_dispatch"].get("lateness_seconds", 0)
- scheduled = job["last_dispatch"].get("scheduled_at", "?")
- issues.append(
- f"last fire was a catch-up after a missed schedule (scheduled {scheduled}, "
- f"{_format_lateness(lateness)} late)")
- elif kind == "late":
- lateness = job["last_dispatch"].get("lateness_seconds", 0)
- scheduled = job["last_dispatch"].get("scheduled_at", "?")
- issues.append(
- f"last fire was late (scheduled {scheduled}, {_format_lateness(lateness)} late) — "
- f"scheduler was delayed")
+ if isinstance(dispatch := job.get("last_dispatch"), dict):
+ labels = {"catch_up": "a catch-up after a missed schedule", "late": "late"}
+ if label := labels.get(dispatch.get("kind", "")):
+ issues.append(f"last fire was {label} (scheduled {dispatch.get('scheduled_at', '?')}, "
+ f"{_format_lateness(dispatch.get('lateness_seconds', 0))} late)")
if isinstance(fire_err := job.get("last_fire_error"), dict) and fire_err.get("detail"):
# The handoff error survives next_run_at advancing beyond the failed dispatch.
issues.append(f"missed scheduled fire at {fire_err.get('at', '?')}: {_short_reason(fire_err['detail'])}")
diff --git a/tests/hermes_cli/test_cron_satellite_diagnostics.py b/tests/hermes_cli/test_cron_satellite_diagnostics.py
index 5201f028bac..13d2513b2f3 100644
--- a/tests/hermes_cli/test_cron_satellite_diagnostics.py
+++ b/tests/hermes_cli/test_cron_satellite_diagnostics.py
@@ -7,7 +7,7 @@ import pytest
@pytest.fixture
-def profile(tmp_path, monkeypatch):
+def served_root(tmp_path, monkeypatch):
from cron import jobs
root = tmp_path / "home"
@@ -35,7 +35,7 @@ def profile(tmp_path, monkeypatch):
@pytest.mark.parametrize("mode", ["missing", "fresh", "stale", "disabled", "excluded", "local", "external", "unrelated_pid"])
-def test_status_preserves_profile_health_contract(profile, capsys, monkeypatch, mode):
+def test_status_preserves_profile_health_contract(served_root, capsys, monkeypatch, mode):
from cron import jobs
from hermes_cli import cron
@@ -44,9 +44,9 @@ def test_status_preserves_profile_health_contract(profile, capsys, monkeypatch,
if mode == "stale":
(jobs.CRON_DIR / "ticker_heartbeat").write_text(str(time.time() - 3600))
if mode == "disabled":
- profile.joinpath("config.yaml").write_text("gateway:\n multiplex_profiles: false\n")
+ served_root.joinpath("config.yaml").write_text("gateway:\n multiplex_profiles: false\n")
if mode == "excluded":
- profile.joinpath("gateway_state.json").write_text(json.dumps({"served_profiles": ["other"]}))
+ served_root.joinpath("gateway_state.json").write_text(json.dumps({"served_profiles": ["other"]}))
if mode == "local":
monkeypatch.setattr("hermes_cli.gateway.find_gateway_pids", lambda: [os.getpid()])
if mode == "external":
@@ -62,6 +62,8 @@ def test_status_preserves_profile_health_contract(profile, capsys, monkeypatch,
assert "hermes --profile default gateway restart" in output
if mode == "missing":
assert "has not reported a heartbeat" in output
+ assert "Desktop app is open" in output
+ assert "enabled in its scheduler" in output
if mode == "stale":
assert "STALLED" in output
if mode in {"disabled", "excluded"}:
@@ -75,10 +77,10 @@ def test_status_preserves_profile_health_contract(profile, capsys, monkeypatch,
@pytest.mark.parametrize("home_kind", ["default", "custom", "named"])
-def test_standalone_guidance_matches_profile_membership(profile, monkeypatch, capsys, home_kind):
+def test_standalone_guidance_matches_profile_membership(served_root, monkeypatch, capsys, home_kind):
from hermes_cli.cron import cron_status
- homes = {"default": profile, "custom": profile.parent / "custom", "named": profile / "profiles/probe"}
+ homes = {"default": served_root, "custom": served_root.parent / "custom", "named": served_root / "profiles/probe"}
home = homes[home_kind]
home.mkdir(exist_ok=True)
monkeypatch.setenv("HERMES_HOME", str(home))
@@ -91,11 +93,11 @@ def test_standalone_guidance_matches_profile_membership(profile, monkeypatch, ca
@pytest.mark.parametrize("detail", ["unreachable " * 30 + "\nsecret second line", "", None])
-def test_doctor_bounds_persisted_fire_errors(profile, capsys, detail):
+def test_doctor_bounds_persisted_fire_errors(served_root, capsys, detail):
from cron import jobs
from hermes_cli.cron import _short_reason, cron_doctor
- job = jobs.create_job(prompt="probe", schedule="every 1h")
+ jobs.create_job(prompt="probe", schedule="every 1h")
records = jobs.load_jobs()
records[0]["last_fire_error"] = {"at": "test-time", "detail": detail}
jobs.save_jobs(records)
@@ -110,7 +112,7 @@ def test_doctor_bounds_persisted_fire_errors(profile, capsys, detail):
@pytest.mark.parametrize("dispatch", ["catch_up", "late", "forward_error"])
-def test_doctor_reports_persisted_dispatch_health(profile, capsys, dispatch):
+def test_doctor_reports_persisted_dispatch_health(served_root, capsys, dispatch):
from cron import jobs
from hermes_cli.cron import cron_doctor