Skip to content

The agent that grows with you

fix(cron): do not fall back to the default adapters when owner-profile resolution fails

Fabio Ito7d7166be5e7d
diff --git a/tests/tools/test_cronjob_run_immediate.py b/tests/tools/test_cronjob_run_immediate.py
index df29ef7e107..b04bd1ac203 100644
--- a/tests/tools/test_cronjob_run_immediate.py
+++ b/tests/tools/test_cronjob_run_immediate.py
@@ -158,6 +158,31 @@ class TestCronjobRunExecutesImmediately:
assert res["success"] is True
assert m_run.call_args.kwargs["adapters"] is work_adapters
+ def test_execute_job_now_fails_instead_of_falling_back_when_owner_resolution_raises(self):
+ """Fail closed: if the owner profile cannot be resolved, the run is marked failed with the
+ error surfaced — it must NOT silently fall back to ``runner.adapters`` (the default bot)."""
+ default_adapters = {"telegram": object()}
+
+ def boom(profile):
+ raise RuntimeError("profile adapters unavailable")
+
+ runner = SimpleNamespace(adapters=default_adapters, _gateway_loop=object(),
+ _adapters_for_profile=boom)
+
+ with patch("tools.cronjob_tools.claim_job_for_fire", return_value={**_JOB, "fire_claim": {"by": "manual-owner"}}), \
+ patch("gateway.run._gateway_runner_ref", return_value=runner), \
+ patch("cron.scheduler.run_one_job", return_value=True) as m_run, \
+ patch("tools.cronjob_tools.mark_job_run") as m_mark, \
+ patch("tools.cronjob_tools.get_job", return_value=dict(_JOB)):
+ res = _execute_job_now(dict(_JOB))
+
+ assert res["claimed"] is True
+ assert res["success"] is False
+ assert "profile adapters unavailable" in res["error"]
+ m_run.assert_not_called()
+ m_mark.assert_called_once()
+ assert m_mark.call_args.args[1] is False
+
def test_execute_job_now_remains_standalone_without_gateway(self):
"""CLI-only runs retain the standalone delivery path."""
completed = {"id": "job-run-1", "last_status": "ok", "last_error": None}
diff --git a/tools/cronjob_tools.py b/tools/cronjob_tools.py
index eaad3dbbe47..17e472af11f 100644
--- a/tools/cronjob_tools.py
+++ b/tools/cronjob_tools.py
@@ -301,13 +301,13 @@ def _run_claimed_job(job: Dict[str, Any], extra_prompt: Optional[str] = None) ->
# that profile's home, so delivering through ``runner.adapters`` sends the result out the
# default bot (a Telegram DM reaches the user from the wrong bot). Resolve the owner's map
# the same way notifications and goals do — fail closed, no fallback to the default bot.
+ # A runner without ``_adapters_for_profile`` (shims, tests) keeps ``runner.adapters``; a
+ # resolution failure is NOT a reason to fall back: it propagates to the ``except`` below,
+ # which marks the run failed and surfaces the error instead of misdelivering.
if runner is not None and hasattr(runner, "_adapters_for_profile"):
- try:
- from hermes_constants import get_hermes_home, profile_name_for_home
+ from hermes_constants import get_hermes_home, profile_name_for_home
- adapters = runner._adapters_for_profile(profile_name_for_home(get_hermes_home()))
- except Exception:
- pass
+ adapters = runner._adapters_for_profile(profile_name_for_home(get_hermes_home()))
gateway_loop = getattr(runner, "_gateway_loop", None) if runner is not None else None
try:
# run_one_job records last_run_at/last_status via mark_job_run; `job` is the