diff --git a/cron/scheduler.py b/cron/scheduler.py index 7132213eaa..9a1f3d1bfe 100644 --- a/cron/scheduler.py +++ b/cron/scheduler.py @@ -175,7 +175,16 @@ def _job_profile_context(job_id: str, profile: Optional[str]): from hermes_constants import reset_hermes_home_override, set_hermes_home_override normalized_profile = normalize_profile_name(raw_profile) - profile_home = Path(resolve_profile_env(normalized_profile)).resolve() + try: + profile_home = Path(resolve_profile_env(normalized_profile)).resolve() + except (FileNotFoundError, ValueError) as exc: + logger.warning( + "Job '%s': configured profile %r no longer valid (%s) — " + "falling back to scheduler default", + job_id, raw_profile, exc, + ) + yield None + return override_token = None try: diff --git a/tests/cron/test_cron_profile.py b/tests/cron/test_cron_profile.py index a8f438c185..8e8d3f7ca1 100644 --- a/tests/cron/test_cron_profile.py +++ b/tests/cron/test_cron_profile.py @@ -354,23 +354,28 @@ class TestRunJobProfileContext: assert observed["hermes_home_during_init"] == str(root) assert os.environ["HERMES_HOME"] == str(root) - def test_run_job_rejects_missing_runtime_profile( + def test_run_job_falls_back_on_missing_runtime_profile( self, isolated_cron_profile_home, monkeypatch ): import cron.scheduler as sched root, _profile_home = isolated_cron_profile_home - monkeypatch.setattr(sched, "_hermes_home", None) + observed: dict = {} + self._install_agent_stubs(monkeypatch, observed) - with pytest.raises(FileNotFoundError): - sched.run_job( - { - "id": "missing-profile", - "name": "missing-profile-job", - "profile": "missing", - } - ) + job = { + "id": "missing-profile", + "name": "missing-profile-job", + "profile": "missing", + "schedule_display": "manual", + } + # Should succeed with fallback, not raise + success, _output, response, error = sched.run_job(job) + + assert success is True, f"run_job should fallback, not fail: error={error!r}" + # Verify it used the default home, not the missing profile + assert observed["hermes_home_during_init"] == str(root) assert os.environ["HERMES_HOME"] == str(root)