The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): scope restart-safe worker environment
fangliquanflqc17629a0a2ee
diff --git a/cron/scheduler.py b/cron/scheduler.pyindex ebdd73f9858..04dcdce88bd 100644--- a/cron/scheduler.py+++ b/cron/scheduler.py@@ -3065,7 +3065,13 @@ def _launch_external_cron_worker(job: dict) -> bool:str(ack_path),]- from agent.secret_scope import is_multiplex_active+ from agent.secret_scope import (+ build_profile_secret_scope,+ is_multiplex_active,+ reset_secret_scope,+ set_secret_scope,+ )+ from hermes_cli.env_loader import hydrate_profile_secret_sourcesfrom tools.environments.local import build_subprocess_envfrom tools.process_registry import (restart_safe_gateway_child_argv,@@ -3107,11 +3113,17 @@ def _launch_external_cron_worker(job: dict) -> bool:payload_path.unlink(missing_ok=True)raise- worker_env = build_subprocess_env(- scrub_secrets=multiplex_active,- inherit_profile_home=True,- extra={"HERMES_HOME": str(_get_hermes_home().resolve())},- )+ profile_home = _get_hermes_home().resolve()+ hydrate_profile_secret_sources(profile_home)+ secret_token = set_secret_scope(build_profile_secret_scope(profile_home))+ try:+ worker_env = build_subprocess_env(+ scrub_secrets=multiplex_active,+ inherit_profile_home=True,+ extra={"HERMES_HOME": str(profile_home)},+ )+ finally:+ reset_secret_scope(secret_token)worker_env = systemd_user_bus_env(worker_env)try:process = subprocess.Popen(diff --git a/tests/cron/test_restart_safe_worker.py b/tests/cron/test_restart_safe_worker.pyindex 30cf2ed0677..4ff7b14839d 100644--- a/tests/cron/test_restart_safe_worker.py+++ b/tests/cron/test_restart_safe_worker.py@@ -188,9 +188,14 @@ def test_launch_external_worker_uses_restart_safe_scope_and_acknowledges(tmp_path, monkeypatch):import cron.scheduler as scheduler+ from tools.env_passthrough import clear_env_passthrough, register_env_passthroughjob = {"id": "job-1", "execution_id": "exec-1", "prompt": "work"}monkeypatch.setattr(scheduler, "_get_hermes_home", lambda: tmp_path)+ (tmp_path / ".env").write_text(+ "SERVICE_TOKEN=target-profile-token\n", encoding="utf-8"+ )+ register_env_passthrough(["SERVICE_TOKEN"])wrapped_commands = []def wrap(command, *, unit_suffix):@@ -239,17 +244,20 @@ def test_launch_external_worker_uses_restart_safe_scope_and_acknowledges(get = Mock(side_effect=lambda _execution_id: next(observed_statuses))monkeypatch.setattr(scheduler, "get_execution", get)monkeypatch.setenv("ANTHROPIC_API_KEY", "should-not-cross-profile")+ monkeypatch.setenv("SERVICE_TOKEN", "default-profile-token")from agent.secret_scope import set_multiplex_activeset_multiplex_active(True)try:assert scheduler._launch_external_cron_worker(job) is Truefinally:+ clear_env_passthrough()set_multiplex_active(False)assert wrapped_commands[0][1] == "cron-job-1-exec-exec-1"assert spawned[0][0][0:2] == ["scope", "--"]assert spawned[0][1]["start_new_session"] is Trueassert "ANTHROPIC_API_KEY" not in spawned[0][1]["env"]+ assert spawned[0][1]["env"]["SERVICE_TOKEN"] == "target-profile-token"handoff.assert_called_once_with("exec-1")assert get.call_count == 2assert payloads[0]["multiplex_active"] is True