The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): order status next run by actual instant
funky-xamarin8f6f9e5b36da
diff --git a/hermes_cli/cron.py b/hermes_cli/cron.pyindex 02c7a94a18e..4de42aa0ddb 100644--- a/hermes_cli/cron.py+++ b/hermes_cli/cron.py@@ -466,10 +466,20 @@ def _print_active_jobs_summary(jobs) -> None:if not jobs:print(" No active jobs")return- next_runs = [j.get("next_run_at") for j in jobs if j.get("next_run_at")]+ from datetime import timezone+ from cron.jobs import _parse_aware++ next_runs = []+ for job in jobs:+ raw = job.get("next_run_at")+ parsed = _parse_aware(raw)+ if parsed is not None:+ # A shared ZoneInfo compares wall times across a DST fold; use UTC+ # for ordering, but keep the stored timestamp for display.+ next_runs.append((parsed.astimezone(timezone.utc), raw))print(f" {len(jobs)} active job(s)")if next_runs:- print(f" Next run: {min(next_runs)}")+ print(f" Next run: {min(next_runs, key=lambda run: run[0])[1]}")# Post-downtime late fires show at status level, not just per-job in `cron list`.late = [j for j in jobs if isinstance(j.get("last_dispatch"), dict)and j["last_dispatch"].get("kind") in ("late", "catch_up")]diff --git a/tests/hermes_cli/test_cron_status_next_run.py b/tests/hermes_cli/test_cron_status_next_run.pynew file mode 100644index 00000000000..b73370499ad--- /dev/null+++ b/tests/hermes_cli/test_cron_status_next_run.py@@ -0,0 +1,47 @@+"""Cron status orders persisted next runs by instant, including a DST fold."""++from datetime import datetime+from zoneinfo import ZoneInfo++import pytest++from cron import jobs as job_store+from hermes_cli.cron import _print_active_jobs_summary++[email protected]("later,earlier", [+ ("2026-11-01T01:15:00-05:00", "2026-11-01T01:45:00-04:00"),+ ("2026-11-02T09:00:00-05:00", "2026-11-02T08:00:00-05:00"),+ ("2026-11-02T08:00:00-05:00", "2026-11-02T12:30:00+00:00"),+])+def test_status_earliest_persisted_instant(later, earlier, monkeypatch, capsys):+ # Only freeze the clock: creation, persistence, normalization and listing are real.+ now = datetime(2026, 10, 31, tzinfo=ZoneInfo("America/New_York"))+ monkeypatch.setattr(job_store, "_hermes_now", lambda: now)+ late_job = job_store.create_job(prompt="later", schedule=later)+ early_job = job_store.create_job(prompt="earlier", schedule=earlier)+ jobs = job_store.list_jobs()+ assert {job["id"] for job in jobs} == {late_job["id"], early_job["id"]}+ expected = next(job["next_run_at"] for job in jobs if job["id"] == early_job["id"])++ _print_active_jobs_summary(jobs)++ out = capsys.readouterr().out+ assert "2 active job(s)" in out+ assert f"Next run: {expected}\n" in out+ assert job_store.list_jobs() == jobs # Rendering never reschedules a job.++[email protected]("jobs,expected", [+ ([], " No active jobs\n"),+ ([{}, {"next_run_at": None}, {"next_run_at": ""}], " 3 active job(s)\n"),+ ([{"next_run_at": "bad"}, {"next_run_at": 123}], " 2 active job(s)\n"),+ ([{"next_run_at": "bad"}, {"next_run_at": "2026-11-01T06:15:00Z"}],+ " 2 active job(s)\n Next run: 2026-11-01T06:15:00Z\n"),+ ([{"next_run_at": "2026-11-01T06:15:00Z"},+ {"next_run_at": "2026-11-01T01:15:00-05:00"}],+ " 2 active job(s)\n Next run: 2026-11-01T06:15:00Z\n"),+])+def test_status_missing_invalid_and_equivalent_instants(jobs, expected, capsys):+ _print_active_jobs_summary(jobs)+ assert capsys.readouterr().out == expected