Skip to content

The agent that grows with you

fix(cron): reuse the gateway's hook registration helper inside the secret scope

kshitijk4poor8840751b8d54
diff --git a/cron/scheduler.py b/cron/scheduler.py
index b2e3349b0c6..2f4a7f8d162 100644
--- a/cron/scheduler.py
+++ b/cron/scheduler.py
@@ -3941,25 +3941,15 @@ def _run_external_worker_payload(payload_path: Path, ack_path: Path) -> bool:
discover_plugins()
hydrate_profile_secret_sources(profile_home)
- # Config-declared hooks (``hooks:`` shell hooks + ``hooks.outbound``) live in the owning
- # profile's config.yaml, which this one-shot process never registered — cron sessions
- # silently lost them the moment fires were handed here instead of running in-process in
- # the gateway (#131764, same gap `hermes serve` had in #102504). Under the home override
- # both loaders resolve the OWNING profile's config; consent must come from that profile's
- # allowlist / HERMES_ACCEPT_HOOKS / hooks_auto_accept because there is no TTY here.
- # Never raises: a broken hooks block must not take the cron execution down with it
- # (register_from_config already skips malformed entries; this guard covers config load).
- try:
- from agent.shell_hooks import register_from_config as register_shell_hooks
- from agent.outbound_webhooks import register_from_config as register_outbound_webhooks
- from hermes_cli.config import load_config
-
- hooks_cfg = load_config()
- register_shell_hooks(hooks_cfg, accept_hooks=False)
- register_outbound_webhooks(hooks_cfg)
- except Exception:
- logger.warning("Cron external worker: config hook registration failed", exc_info=True)
secret_token = set_secret_scope(build_profile_secret_scope(profile_home), profile_home=str(profile_home))
+ # This process never ran gateway startup, so the OWNING profile's ``hooks:`` block (shell
+ # hooks + ``hooks.outbound``) was never registered and cron sessions silently lost it
+ # (#131764). Same helper the gateway uses per profile; it must run inside the secret scope
+ # because ``secret_env`` targets resolve through ``get_secret`` (raises unscoped under multiplex).
+ from gateway.run_startup import GatewayStartupMixin
+
+ GatewayStartupMixin._register_config_hooks(
+ "Cron external worker: config hook registration failed", level=logging.WARNING)
with use_cron_store(profile_home):
if adopt_claimed_execution(execution_id) is None:
logger.error(
diff --git a/tests/cron/test_external_worker_config_hooks.py b/tests/cron/test_external_worker_config_hooks.py
index 337422a2ebc..df9de18f71a 100644
--- a/tests/cron/test_external_worker_config_hooks.py
+++ b/tests/cron/test_external_worker_config_hooks.py
@@ -34,10 +34,13 @@ def homes(tmp_path, monkeypatch):
" outbound:\n"
f" - url: {OUTBOUND_URL}\n"
" events: [on_session_end]\n"
+ # Resolved through get_secret: raises outside a secret scope while multiplexing.
+ " secret_env: CRON_HOOK_SECRET\n"
# Non-interactive consent: the worker has no TTY, and the pair is not allowlisted.
"hooks_auto_accept: true\n",
encoding="utf-8",
)
+ (profile / ".env").write_text("CRON_HOOK_SECRET=profile-secret\n", encoding="utf-8")
yield launch, profile
import agent.outbound_webhooks as outbound_webhooks
import agent.shell_hooks as shell_hooks
@@ -74,29 +77,3 @@ def test_worker_registers_owning_profile_config_hooks(homes, tmp_path, monkeypat
for home, event, _matcher, command in shell_hooks._registered)
assert any(home == profile_key and event == "on_session_end" and url == OUTBOUND_URL
for home, event, url in outbound_webhooks._registered)
-
-
-def test_worker_survives_a_broken_hooks_config(homes, tmp_path, monkeypatch):
- """A malformed hooks block must not take the cron execution down with it."""
- launch, profile = homes
- import cron.scheduler as scheduler
-
- (profile / "config.yaml").write_text(
- "hooks:\n"
- " on_session_start: not-a-list\n"
- "hooks_auto_accept: true\n",
- encoding="utf-8",
- )
- payload = tmp_path / "payload.json"
- payload.write_text(
- json.dumps({"job": {"id": "job-1", "execution_id": "exec-1"},
- "profile_home": str(profile)}),
- encoding="utf-8",
- )
- monkeypatch.setattr(
- "cron.executions.adopt_claimed_execution",
- lambda execution_id: {"id": execution_id, "status": "running"},
- )
- monkeypatch.setattr(scheduler, "run_one_job", lambda *a, **k: True)
-
- assert scheduler._run_external_worker_payload(payload, tmp_path / "exec-1.ready") is True