The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(web): preserve repeat count when creating cron jobs from dashboard
Austin Pickettfbf261a33f51
diff --git a/apps/desktop/src/types/hermes.ts b/apps/desktop/src/types/hermes.tsindex 81647d34e62..8e7f81ca492 100644--- a/apps/desktop/src/types/hermes.ts+++ b/apps/desktop/src/types/hermes.ts@@ -1039,6 +1039,7 @@ export interface CronJobCreatePayload {name?: stringprompt: stringprovider?: string+ repeat?: numberschedule: string}diff --git a/hermes_cli/web_models.py b/hermes_cli/web_models.pyindex 202a629694f..25bab5fb15c 100644--- a/hermes_cli/web_models.py+++ b/hermes_cli/web_models.py@@ -3,7 +3,7 @@from __future__ import annotationsimport math-from typing import Any, Dict, List, Literal, Optional+from typing import Any, Dict, List, Literal, Optional, Unionfrom pydantic import BaseModel, SecretStr, StrictBool, field_validator@@ -314,6 +314,11 @@ class CronJobCreate(BaseModel):schedule: strname: str = ""deliver: str = "local"+ # Finite repeat count (runs N times then completes); None = unlimited. Accepts the+ # same user-facing strings the CLI accepts ('forever'/'once'/'3'). Normalization and+ # validation happen in cron.jobs.create_job via normalize_repeat_value — the shared+ # chokepoint with the CLI and update paths — so an unparseable value 400s there.+ repeat: Optional[Union[int, str]] = Noneskills: Optional[List[str]] = Nonemodel: Optional[str] = Noneprovider: Optional[str] = Nonediff --git a/hermes_cli/web_server_cron.py b/hermes_cli/web_server_cron.pyindex 60e30dba533..837eaee8b02 100644--- a/hermes_cli/web_server_cron.py+++ b/hermes_cli/web_server_cron.py@@ -249,6 +249,17 @@ def _create_cron_job_sync(body: CronJobCreate, profile: Optional[str] = None):context_from = _cron_string_list(body.context_from)_validate_dashboard_cron_context_from(context_from, profile_name)no_agent = bool(body.no_agent)+ # Finite repeat: non-positive counts are a client error (the core chokepoint+ # would silently make them unlimited — indistinguishable from omission);+ # everything else (int, 'forever'/'once'/'3') coerces through the shared+ # normalize_repeat_value, the same validation the CLI uses.+ repeat = body.repeat+ if repeat is not None:+ if isinstance(repeat, int) and not isinstance(repeat, bool) and repeat < 1:+ raise HTTPException(+ status_code=400, detail="repeat must be a positive integer")+ from cron.jobs import normalize_repeat_value+ repeat = normalize_repeat_value(repeat)_validate_dashboard_cron_effective_job({"prompt": body.prompt, "skills": skills, "script": script, "no_agent": no_agent})return _mutate_cron_for_profile(@@ -257,6 +268,7 @@ def _create_cron_job_sync(body: CronJobCreate, profile: Optional[str] = None):prompt=body.prompt or "",schedule=body.schedule,name=body.name,+ repeat=body.repeat,deliver=_cron_optional_text(body.deliver) or "local",skills=skills,model=_cron_optional_text(body.model),diff --git a/tests/hermes_cli/test_web_server_cron_repeat.py b/tests/hermes_cli/test_web_server_cron_repeat.pynew file mode 100644index 00000000000..f5f7739651a--- /dev/null+++ b/tests/hermes_cli/test_web_server_cron_repeat.py@@ -0,0 +1,120 @@+"""Regression coverage for finite repeat counts in the dashboard cron create API (#68012)."""++import pytest+++def isolated_profiles(tmp_path, monkeypatch, _isolate_hermes_home):+ """Route dashboard cron storage to an isolated default profile."""+ from hermes_constants import get_hermes_home+ from hermes_cli import profiles++ default_home = get_hermes_home()+ (default_home / "cron").mkdir(parents=True, exist_ok=True)+ (default_home / "config.yaml").write_text(+ "model: test-model\n",+ encoding="utf-8",+ )++ monkeypatch.setattr(profiles, "_get_default_hermes_home", lambda: default_home)+ monkeypatch.setattr(profiles, "_get_profiles_root", lambda: default_home / "profiles")+ return default_home+++def client(monkeypatch, isolated_profiles):+ try:+ from starlette.testclient import TestClient+ except ImportError:+ pytest.skip("fastapi/starlette not installed")++ import hermes_state+ from hermes_constants import get_hermes_home+ from hermes_cli.web_server import app, _SESSION_HEADER_NAME, _SESSION_TOKEN++ monkeypatch.setattr(+ hermes_state,+ "DEFAULT_DB_PATH",+ get_hermes_home() / "state.db",+ )+ test_client = TestClient(app)+ test_client.headers[_SESSION_HEADER_NAME] = _SESSION_TOKEN+ return test_client+++def test_create_preserves_finite_repeat_count(client):+ """A finite repeat must survive request parsing and storage (route-level persistence)."""+ response = client.post(+ "/api/cron/jobs",+ json={+ "prompt": "run the check",+ "schedule": "every 1h",+ "name": "two checks",+ "repeat": 2,+ },+ )++ assert response.status_code == 200+ assert response.json()["repeat"] == {"times": 2, "completed": 0}++ listed = client.get("/api/cron/jobs", params={"profile": "default"}).json()+ assert [job["repeat"] for job in listed if job["name"] == "two checks"] == [+ {"times": 2, "completed": 0}+ ]+++def test_create_without_repeat_remains_unlimited(client):+ response = client.post(+ "/api/cron/jobs",+ json={+ "prompt": "run forever",+ "schedule": "every 1h",+ },+ )++ assert response.status_code == 200+ assert response.json()["repeat"] == {"times": None, "completed": 0}++[email protected]("repeat", [0, -1, 1.5, "not-a-count"])+def test_create_rejects_invalid_repeat_count(client, repeat):+ """Invalid counts must 4xx instead of silently becoming unlimited jobs."""+ response = client.post(+ "/api/cron/jobs",+ json={+ "prompt": "must not run forever",+ "schedule": "every 1h",+ "repeat": repeat,+ },+ )++ assert response.status_code in (400, 422)+ detail = response.json()["detail"]+ if isinstance(detail, str):+ assert "repeat" in detail.lower()+ else:+ assert any(+ error.get("loc", [None])[-1] == "repeat" or "repeat" in str(error).lower()+ for error in detail+ )+ assert client.get(+ "/api/cron/jobs",+ params={"profile": "default"},+ ).json() == []++[email protected]("repeat,expected_times", [("2", 2), ("once", 1), ("forever", None)])+def test_create_accepts_cli_string_repeat_forms(client, repeat, expected_times):+ """The dashboard create path validates repeat through the same normalize_repeat_value+ the CLI uses: numeric strings coerce, 'once' → 1, 'forever' → unlimited."""+ response = client.post(+ "/api/cron/jobs",+ json={+ "prompt": "string repeat form",+ "schedule": "every 1h",+ "repeat": repeat,+ },+ )++ assert response.status_code == 200+ assert response.json()["repeat"] == {"times": expected_times, "completed": 0}