Skip to content

The agent that grows with you

fix(cron): resolve every per-job dashboard call to the profile that holds the job

teknium1290be1ad18d2
diff --git a/hermes_cli/web_routers/cron.py b/hermes_cli/web_routers/cron.py
index 2a89ada02f1..4dd58af3a51 100644
--- a/hermes_cli/web_routers/cron.py
+++ b/hermes_cli/web_routers/cron.py
@@ -66,16 +66,8 @@ def _normalize_dashboard_cron_updates(updates: Dict[str, Any], profile_home: Pat
return normalized
-def _job_profile(job_id: str, profile: Optional[str]) -> str:
- """Profile owning ``job_id`` (explicit or discovered); 404 when none."""
- selected = profile or _find_cron_job_profile(job_id)
- if not selected:
- raise _job_not_found()
- return selected
-
-
-def _job_runs_profile(job_id: str, profile: Optional[str]) -> Optional[str]:
- """Profile whose state.db holds ``job_id``'s run sessions.
+def _job_owner_profile(job_id: str, profile: Optional[str]) -> Optional[str]:
+ """Profile that holds ``job_id`` (its jobs.json and the state.db with its run sessions).
``profile`` is a caller *hint*, not proof of ownership: the Desktop lists
jobs cross-profile (``?profile=all``) while its per-item calls carry the
@@ -93,6 +85,16 @@ def _job_runs_profile(job_id: str, profile: Optional[str]) -> Optional[str]:
return _find_cron_job_profile(job_id)
+def _job_profile(job_id: str, profile: Optional[str]) -> str:
+ """Owning profile for the get/update/pause/resume/trigger/delete family; 404 when no profile
+ holds the job. Same hint validation as the run lookup, so a wrong-profile hint from the
+ cross-profile list cannot 404 (or act on the wrong store for) a job the server can locate."""
+ selected = _job_owner_profile(job_id, profile)
+ if not selected:
+ raise _job_not_found()
+ return selected
+
+
def _found(job):
if not job:
raise _job_not_found()
@@ -129,7 +131,7 @@ def _list_cron_job_runs_sync(job_id: str, profile: Optional[str] = None, limit:
SessionInfo. Backed by ``SessionDB.list_cron_job_runs`` — a bounded id-range
scan, so cost scales with the requested window, not total cron history.
"""
- selected = _job_runs_profile(job_id, profile)
+ selected = _job_owner_profile(job_id, profile)
# job_id may be a human name; resolve to the canonical id used in run-session ids.
canonical = job_id
if selected:
diff --git a/tests/hermes_cli/test_web_server_cron_profiles.py b/tests/hermes_cli/test_web_server_cron_profiles.py
index 40d8c3d6b9a..9185b586488 100644
--- a/tests/hermes_cli/test_web_server_cron_profiles.py
+++ b/tests/hermes_cli/test_web_server_cron_profiles.py
@@ -1188,3 +1188,29 @@ async def test_cron_run_history_resolves_the_jobs_owner_profile(isolated_profile
assert [run["id"] for run in omitted["runs"]] == [f"cron_{worker_job['id']}_1"]
assert [run["id"] for run in own["runs"]] == [f"cron_{default_job['id']}_1"]
assert opened == ["worker_alpha", "worker_alpha", "default"]
+
+
+async def test_cron_job_mutations_resolve_the_owner_when_the_hint_is_another_profile(isolated_profiles):
+ """#115345 sibling: the per-job get/pause/resume/delete calls carry the same ambient-profile
+ hint as the run lookup. A hint that does not hold the job must resolve to the owner instead of
+ 404ing (or acting on the wrong profile's store); a hint that does hold it still wins."""
+ worker_job = _web_server_cron._call_cron_for_profile(
+ "worker_alpha", "create_job", prompt="owned by worker", schedule="every 1h", name="worker-mutations",
+ )
+ job_id = worker_job["id"]
+
+ got = await _rt_cron.get_cron_job(job_id, profile="default")
+ assert got["id"] == job_id and got["name"] == "worker-mutations"
+
+ paused = await _rt_cron.pause_cron_job(job_id, profile="default")
+ assert paused["id"] == job_id and paused.get("enabled") is False
+ owner_view = _web_server_cron._call_cron_for_profile("worker_alpha", "get_job", job_id)
+ assert owner_view["enabled"] is False # mutation landed in the owner's jobs.json
+ assert _web_server_cron._call_cron_for_profile("default", "list_jobs", True) == [] # not copied into the hint profile
+
+ await _rt_cron.delete_cron_job(job_id, profile="default")
+ assert _web_server_cron._call_cron_for_profile("worker_alpha", "get_job", job_id) is None
+ with pytest.raises(HTTPException) as exc:
+ await _rt_cron.get_cron_job(job_id, profile="default")
+ assert exc.value.status_code == 404