The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): overlay the routed no_agent scope inside build_subprocess_env
John Paul Soliva136135e6539d
diff --git a/cron/scheduler_script.py b/cron/scheduler_script.pyindex ea0d276e9ad..4d3c8175f89 100644--- a/cron/scheduler_script.py+++ b/cron/scheduler_script.py@@ -472,24 +472,13 @@ def _run_job_script(# reader threads on non-UTF-8 Windows (#45099)."encoding": "utf-8","errors": "replace"}- # A routed profile's script (desktop multi-profile ticker, multiplex gateway) must see ITS- # profile's .env + vault values — the process env holds the launch profile's. Drop the- # launch profile's dotenv-owned residue first (a name only the launch .env defines must- # come through UNSET, not with the launch value — the scrub only knows classified secrets),- # then overlay the installed scope, then sanitize, so routed values pass the same scrub /- # passthrough rules as any other (#114209 declared names included). No-op outside multiplex- # or for the launch profile's own fires; the parent process is never mutated.- from agent.secret_scope import current_secret_scope, is_multiplex_active- from tools.environments.local import restore_managed_env, strip_launch_profile_env- base = strip_launch_profile_env(dict(os.environ))- if is_multiplex_active():- # Single-profile: the scope IS os.environ, so overlaying it would only re-sanitize- # values the child already inherits byte-identical.- base.update(current_secret_scope() or {})- # Administrator-managed values keep their precedence over the routed profile's own .env,- # exactly as they do in the launch process (``_apply_managed_env`` applies them last).- restore_managed_env(base)- env = build_subprocess_env(base=base)+ # The process env is the LAUNCH profile's. For a job owned by a routed profile, drop that+ # profile's .env residue from the base first (no-op for the launch profile's own jobs), then+ # overlay the routed profile's own scope (which never enters os.environ under multiplex+ # semantics) before the sanitizer, which also overlays the names the owning profile declares+ # in terminal.env_passthrough from that scope (#114209). The factory snapshots the process+ # env itself — no raw copy at the spawn site (test_subprocess_env_guard).+ env = build_subprocess_env(strip_launch_profile=True)env.update(env_overlay)# Subprocess cwd only (default: scripts-dir parent). NEVER os.chdir() the process.# Use the job's workdir as the subprocess cwd when configured, otherwise default to the scripts-dirdiff --git a/tools/environments/local.py b/tools/environments/local.pyindex 0945e233f2c..792a8358b9c 100644--- a/tools/environments/local.py+++ b/tools/environments/local.py@@ -358,10 +358,21 @@ def build_subprocess_env(bridges HERMES_HOME + HOME and ``extra`` is applied last so caller overrides win.``strip_launch_profile`` drops the LAUNCH profile's ``.env`` residue from the base first(:func:`strip_launch_profile_env`; a no-op unless a routed home is active) so a child that- acts for a routed profile sees only that profile's declared names, never the launch profile's."""+ acts for a routed profile sees only that profile's declared names, never the launch profile's.+ Under multiplex semantics it then overlays the bound secret scope (the routed profile's own+ ``.env`` + source values, which never enter ``os.environ``) and re-applies the managed keys,+ all BEFORE the scrub, so those values pass the same scrub / passthrough rules as any other."""env: dict[str, str] = dict(base) if base is not None else os.environ.copy()if strip_launch_profile:strip_launch_profile_env(env)+ from agent.secret_scope import current_secret_scope, is_multiplex_active+ if is_multiplex_active():+ # Single-profile: the scope IS os.environ, so overlaying it would only re-sanitize+ # values the child already inherits byte-identical.+ env.update(current_secret_scope() or {})+ # Administrator-managed values keep their precedence over the routed profile's own .env,+ # exactly as they do in the launch process (``_apply_managed_env`` applies them last).+ restore_managed_env(env)if scrub_secrets:return _sanitize_subprocess_env(env, dict(extra) if extra else None)if inherit_profile_home: