Skip to content

The agent that grows with you

fix(webhook): run cron_job triggers under the routed profile's scope; skip route skills

teknium190c313124674
diff --git a/gateway/platforms/webhook.py b/gateway/platforms/webhook.py
index 72f375bb7ae..af7ae260493 100644
--- a/gateway/platforms/webhook.py
+++ b/gateway/platforms/webhook.py
@@ -505,8 +505,11 @@ class WebhookAdapter(BasePlatformAdapter):
async def _fire_cron_job() -> None:
try:
from tools.cronjob_tools import execute_job_for_event
- # A cron job is a full agent run (minutes) — keep it off the gateway event loop.
- result = await asyncio.to_thread(execute_job_for_event, job_ref, event_context)
+ # The job store (cron/jobs.json) and the run belong to the ROUTED profile, not the gateway's
+ # default home; to_thread copies contextvars so the scope follows. A cron job is a full agent
+ # run (minutes) — keep it off the gateway event loop.
+ with self._profile_scope(profile):
+ result = await asyncio.to_thread(execute_job_for_event, job_ref, event_context)
if not result.get("success"):
logger.warning("[webhook] cron-trigger job=%s route=%s did not complete cleanly: %s", job_ref,
route_name, result.get("error"))
@@ -597,7 +600,8 @@ class WebhookAdapter(BasePlatformAdapter):
return web.json_response({"status": "ignored", "reason": "script", "route": route_name})
payload = transformed_payload or payload
prompt = self._render_prompt(route_config.get("prompt", ""), payload, event_type, route_name)
- if skills := route_config.get("skills", []):
+ # cron_job routes: the job's own skills apply; the rendered prompt is only per-run context.
+ if (skills := route_config.get("skills", [])) and not route_config.get("cron_job"):
prompt = self._apply_skills(prompt, skills)
delivery_id = headers.get("X-GitHub-Delivery", headers.get("svix-id", headers.get(
"webhook-id", headers.get("X-Request-ID", str(int(time.time() * 1000))))))
diff --git a/tests/gateway/test_webhook_cron_trigger.py b/tests/gateway/test_webhook_cron_trigger.py
index dbcc7957459..dc9966d0407 100644
--- a/tests/gateway/test_webhook_cron_trigger.py
+++ b/tests/gateway/test_webhook_cron_trigger.py
@@ -149,6 +149,36 @@ class TestCronJobTrigger:
await _drain_background_tasks(adapter)
+ @pytest.mark.asyncio
+ async def test_routed_profile_scope_reaches_the_job_run(self, tmp_path, monkeypatch):
+ """/p/<profile>/ routes must fire the job from THAT profile's cron store, not the gateway's
+ default home (and route-level skills stay out of the per-run context — the job's own apply)."""
+ home = tmp_path / ".hermes"
+ (home / "profiles" / "sec").mkdir(parents=True)
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ monkeypatch.setattr("hermes_cli.profiles._get_default_hermes_home", lambda: home)
+ monkeypatch.setattr("hermes_cli.profiles._get_profiles_root", lambda: home / "profiles")
+ adapter = _make_adapter({"ev": {"secret": _INSECURE_NO_AUTH, "cron_job": "sweeper", "profile": "sec",
+ "skills": ["some-skill"], "prompt": "hello {n}"}})
+ monkeypatch.setattr(adapter, "_resolve_request_profile", lambda request: "sec")
+ monkeypatch.setattr(adapter, "_apply_skills", lambda prompt, skills: pytest.fail("skills applied"))
+ seen = []
+
+ def _fake_execute(job_ref, extra_prompt=None):
+ from hermes_constants import get_hermes_home
+ seen.append((get_hermes_home(), extra_prompt))
+ return {"claimed": True, "success": True, "error": None}
+
+ with patch("tools.cronjob_tools.execute_job_for_event", side_effect=_fake_execute):
+ async with TestClient(TestServer(_create_app(adapter))) as cli:
+ resp = await cli.post("/webhooks/ev", data=b'{"n": 1}',
+ headers={"Content-Type": "application/json", "X-GitHub-Delivery": "d-3"})
+ assert resp.status == 202
+ await _drain_background_tasks(adapter)
+ assert seen and seen[0][0] == (home / "profiles" / "sec").resolve()
+ assert "hello 1" in seen[0][1]
+
+
# ===================================================================
# Startup validation
# ===================================================================