The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dashboard): say when the scheduler last ticked on the Cron page
teknium15179b5177dfa
diff --git a/hermes_cli/web_server_cron.py b/hermes_cli/web_server_cron.pyindex 83267d27ad9..26dabeebff2 100644--- a/hermes_cli/web_server_cron.py+++ b/hermes_cli/web_server_cron.py@@ -123,13 +123,19 @@ def _cron_profile_home(profile: Optional[str]) -> Tuple[str, Path]:return canon, profiles_mod.get_profile_dir(canon)-def _annotate_cron_job(job: Dict[str, Any], profile: str, home: Path) -> Dict[str, Any]:+def _annotate_cron_job(+ job: Dict[str, Any], profile: str, home: Path, heartbeat_age: Optional[float] = None,+) -> Dict[str, Any]:return {**job,"profile": profile,"profile_name": profile,"hermes_home": str(home),- "is_default_profile": profile == "default"}+ "is_default_profile": profile == "default",+ # Seconds since this profile's ticker last iterated (None = never/unknown): a+ # `next_run_at` parked in the past is only explained by a scheduler that stopped+ # ticking, so the dashboard can date it (#114309).+ "scheduler_heartbeat_age_s": heartbeat_age}@contextlib.contextmanager@@ -158,10 +164,11 @@ def _call_cron_for_profile(target_profile: Optional[str], func_name: str, *args,result = create_job_with_scheduler_registration(*args, **kwargs)else:result = getattr(cron_jobs, func_name)(*args, **kwargs)+ heartbeat_age = cron_jobs.get_ticker_heartbeat_age()if isinstance(result, list):- return [_annotate_cron_job(j, profile_name, home) for j in result]+ return [_annotate_cron_job(j, profile_name, home, heartbeat_age) for j in result]if isinstance(result, dict):- return _annotate_cron_job(result, profile_name, home)+ return _annotate_cron_job(result, profile_name, home, heartbeat_age)return resultdiff --git a/web/src/i18n/en.ts b/web/src/i18n/en.tsindex d5e4daeffb9..9f208d63acb 100644--- a/web/src/i18n/en.ts+++ b/web/src/i18n/en.ts@@ -310,6 +310,8 @@ export const en: Translations = {next: "Next",/** Replaces `next` when the stored next_run_at is already past the scheduler grace. */overdueSince: "Overdue since",+ /** Banner when the ticker heartbeat is stale; {when} is a relative time such as "7h ago". */+ schedulerLastTicked: "Scheduler last ticked {when} — jobs that came due since then have not fired",pause: "Pause",resume: "Resume",triggerNow: "Trigger now",diff --git a/web/src/i18n/types.ts b/web/src/i18n/types.tsindex a97b79a21e7..ddb367363e4 100644--- a/web/src/i18n/types.ts+++ b/web/src/i18n/types.ts@@ -323,6 +323,7 @@ export interface Translations {last: string;next: string;overdueSince?: string;+ schedulerLastTicked?: string;pause: string;resume: string;triggerNow: string;diff --git a/web/src/lib/api.ts b/web/src/lib/api.tsindex 3e0a2716f38..57440e93ee6 100644--- a/web/src/lib/api.ts+++ b/web/src/lib/api.ts@@ -2327,6 +2327,8 @@ export interface CronJob {workdir?: string | null;last_run_at?: string | null;next_run_at?: string | null;+ /** Seconds since the job's profile ticker last iterated; null when it cannot be dated. */+ scheduler_heartbeat_age_s?: number | null;last_status?: string | null;last_error?: string | null;last_delivery_error?: string | null;diff --git a/web/src/lib/cron-job.test.ts b/web/src/lib/cron-job.test.tsindex f0d74247142..81806f51789 100644--- a/web/src/lib/cron-job.test.ts+++ b/web/src/lib/cron-job.test.ts@@ -5,7 +5,9 @@ import {cronJobHasExecutionContent,cronJobFormFromJob,cronLastResult,+ cronAgoLabel,cronNextRunOverdueMs,+ cronSchedulerStaleAgeS,splitCronList,type CronJobFormState,} from "./cron-job";@@ -220,3 +222,20 @@ describe("cronNextRunOverdueMs", () => {expect(cronNextRunOverdueMs({ next_run_at: "not-a-date", enabled: true }, now)).toBeNull();});});++describe("cronSchedulerStaleAgeS", () => {+ it("dates the oldest stale ticker among jobs expected to fire, and stays quiet otherwise (#114309)", () => {+ expect(+ cronSchedulerStaleAgeS([+ { scheduler_heartbeat_age_s: 25 * 3600, enabled: true, state: "scheduled" },+ { scheduler_heartbeat_age_s: 7 * 3600, enabled: true },+ { scheduler_heartbeat_age_s: 90 * 3600, enabled: true, state: "paused" },+ ]),+ ).toBe(25 * 3600);+ expect(cronSchedulerStaleAgeS([{ scheduler_heartbeat_age_s: 90, enabled: true }])).toBeNull();+ expect(cronSchedulerStaleAgeS([{ scheduler_heartbeat_age_s: null, enabled: true }])).toBeNull();+ expect(cronSchedulerStaleAgeS([{ scheduler_heartbeat_age_s: 25 * 3600, enabled: false }])).toBeNull();+ expect(cronSchedulerStaleAgeS([])).toBeNull();+ expect([7 * 3600 + 120, 90, 3 * 86400].map(cronAgoLabel)).toEqual(["7h ago", "1m ago", "3d ago"]);+ });+});diff --git a/web/src/lib/cron-job.ts b/web/src/lib/cron-job.tsindex 2e9b103f7b6..c137673f73a 100644--- a/web/src/lib/cron-job.ts+++ b/web/src/lib/cron-job.ts@@ -168,3 +168,31 @@ export function cronNextRunOverdueMs(const overdue = nowMs - at;return overdue > CRON_NEXT_RUN_OVERDUE_GRACE_MS ? overdue : null;}++/** Mirrors hermes_cli/cron.py `STALE_AFTER`: ~3 missed ticker iterations (60s) plus slack. */+export const CRON_SCHEDULER_STALE_S = 60 * 3 + 20;++/**+ * Seconds since the scheduler last ticked when that is long enough ago to strand jobs, or null+ * while it ticks on time, when no listed job is expected to fire, or when the server could not+ * date the last tick. Jobs from several profiles report their own ticker; the oldest wins.+ */+export function cronSchedulerStaleAgeS(+ jobs: Pick<CronJob, "scheduler_heartbeat_age_s" | "enabled" | "state">[],+): number | null {+ let stale: number | null = null;+ for (const job of jobs) {+ const age = job.scheduler_heartbeat_age_s;+ if (typeof age !== "number" || age <= CRON_SCHEDULER_STALE_S) continue;+ if (job.enabled === false || job.state === "paused" || job.state === "completed") continue;+ if (stale === null || age > stale) stale = age;+ }+ return stale;+}++/** "7h ago"-style label for an elapsed duration in seconds (no clock read, so it renders pure). */+export function cronAgoLabel(seconds: number): string {+ if (seconds < 3600) return `${Math.max(1, Math.floor(seconds / 60))}m ago`;+ if (seconds < 86400) return `${Math.floor(seconds / 3600)}h ago`;+ return `${Math.floor(seconds / 86400)}d ago`;+}diff --git a/web/src/pages/CronPage.tsx b/web/src/pages/CronPage.tsxindex 6869775bf16..ca57d519706 100644--- a/web/src/pages/CronPage.tsx+++ b/web/src/pages/CronPage.tsx@@ -21,7 +21,9 @@ import type {import {buildCronJobPayload,cronJobHasExecutionContent,+ cronAgoLabel,cronNextRunOverdueMs,+ cronSchedulerStaleAgeS,cronJobFormFromJob,cronLastResult,focusCronField,@@ -531,6 +533,7 @@ const STATUS_TONE: Record<string, "success" | "warning" | "destructive"> = {export default function CronPage() {const [jobs, setJobs] = useState<CronJob[]>([]);+ const schedulerStaleAgeS = cronSchedulerStaleAgeS(jobs);const [triggeringJobKeys, setTriggeringJobKeys] = useState<ReadonlySet<string>>(() => new Set(),);@@ -891,6 +894,15 @@ export default function CronPage() {/>)}+ {schedulerStaleAgeS !== null && (+ <p className="text-sm text-warning font-medium" data-testid="cron-scheduler-stale">+ {(t.cron.schedulerLastTicked ?? en.cron.schedulerLastTicked!).replace(+ "{when}",+ cronAgoLabel(schedulerStaleAgeS),+ )}+ </p>+ )}+<Segmentedvalue={view}onChange={(v) => setView(v as "jobs" | "blueprints")}diff --git a/website/docs/user-guide/features/cron.md b/website/docs/user-guide/features/cron.mdindex 7256397c687..9d7681f8062 100644--- a/website/docs/user-guide/features/cron.md+++ b/website/docs/user-guide/features/cron.md@@ -347,7 +347,7 @@ hermes cron listhermes cron status```-`hermes cron status` reports whether the scheduler is alive (gateway process, ticker heartbeat, last successful tick) and the soonest scheduled run across your active jobs, ordered by actual instant even when jobs store different UTC offsets. A `next_run_at` that is already more than 15 minutes in the past is never shown as an upcoming "Next run": `cron status` prints `⚠ Next run <time> is OVERDUE — passed 7h ago but the job has not fired`, `cron list` labels the row `Overdue:`, the dashboard and the Desktop cron panel (including a Bot's Routines card) show `Overdue since`, and when the gateway is down `status` also says when the scheduler last ticked. That is the signature of a scheduler that stopped ticking — restart the gateway (`hermes gateway restart`) so the next tick picks the overdue job up, or run it right away with `hermes cron run <id>`.+`hermes cron status` reports whether the scheduler is alive (gateway process, ticker heartbeat, last successful tick) and the soonest scheduled run across your active jobs, ordered by actual instant even when jobs store different UTC offsets. A `next_run_at` that is already more than 15 minutes in the past is never shown as an upcoming "Next run": `cron status` prints `⚠ Next run <time> is OVERDUE — passed 7h ago but the job has not fired`, `cron list` and the in-chat `/cron list` label the row `Overdue:`, the dashboard and the Desktop cron panel (including a Bot's Routines card) show `Overdue since`, and when the scheduler has stopped ticking `status` (with the gateway down) and the dashboard Cron page also say when it last ticked. That is the signature of a scheduler that stopped ticking — restart the gateway (`hermes gateway restart`) so the next tick picks the overdue job up, or run it right away with `hermes cron run <id>`.For a named profile served by the default-profile multiplexer, `hermes cron status` names that scheduler host and reports the named profile's own heartbeat health. Missing or stale heartbeats point to `hermes --profile default gateway restart`. `cron list` and `cron create` also warn when that heartbeat is missing or stale; `cron status` additionally checks the last successful tick and reports tick errors.