Skip to content

The agent that grows with you

fix(runtime): owner-side execution and RPC handlers run under the owning profile's scope

Teknium6fb99bbbf9e3
diff --git a/gateway/session_controls.py b/gateway/session_controls.py
index 8a806ec72a1..a723470f738 100644
--- a/gateway/session_controls.py
+++ b/gateway/session_controls.py
@@ -64,12 +64,18 @@ class AuthorityConnection:
handlers['image.attach_bytes'] = partial(attach_bytes, self)
try:
from gateway.session_group_controls import GROUP_METHODS, dispatch_group_control
- if method in GROUP_METHODS or method == 'profiles.list':
- result = await dispatch_group_control(self, method, params)
- return {'jsonrpc': '2.0', 'id': rid, 'result': result}
- if method not in handlers:
- raise RuntimeStoreError('invalid_params')
- result = await handlers[method](ref, params)
+ # Every handler reads config/jobs/policy for the OWNING profile: enter its home so
+ # ``_load_gateway_config`` / ``build_policy(get_hermes_home())`` never snapshot the
+ # launch profile's config into a served secondary's session. Under a single profile
+ # the scope is that profile's own home, so behaviour is unchanged.
+ from gateway.session_authorities import owner_scope
+ with owner_scope(self.authority):
+ if method in GROUP_METHODS or method == 'profiles.list':
+ result = await dispatch_group_control(self, method, params)
+ return {'jsonrpc': '2.0', 'id': rid, 'result': result}
+ if method not in handlers:
+ raise RuntimeStoreError('invalid_params')
+ result = await handlers[method](ref, params)
return {'jsonrpc': '2.0', 'id': rid, 'result': result}
except RuntimeStoreError as exc:
return {'jsonrpc': '2.0', 'id': rid, 'error': {
diff --git a/gateway/session_ingress.py b/gateway/session_ingress.py
index cccb0488526..82b39e9fae6 100644
--- a/gateway/session_ingress.py
+++ b/gateway/session_ingress.py
@@ -44,9 +44,15 @@ async def execute_admission(authority, ref, row):
from gateway.session_automation import restore_local_automation
event = restore_local_automation(authority, ref, row)
provenance = row['payload'].get('native_text_v1', {}).get('provenance')
+ from gateway.run import _profile_runtime_scope
+ # Under multiplex, owner-side execution runs under the OWNING profile's home (agent build,
+ # config, secrets, state.db), never the launch profile's ambient scope; native provenance
+ # refines it. A single-profile gateway keeps its ambient scope byte-for-byte.
scope = nullcontext()
+ if getattr(getattr(authority.runner, 'config', None), 'multiplex_profiles', False):
+ from gateway.session_authorities import owner_scope
+ scope = owner_scope(authority, hydrate_secrets=True)
if provenance is not None:
- from gateway.run import _profile_runtime_scope
from gateway.session_ingress_context import restore_provenance
home = restore_provenance(authority.runner, event.source, provenance)
scope = _profile_runtime_scope(home)
diff --git a/gateway/session_managed_worker.py b/gateway/session_managed_worker.py
index fd1b4a30b35..076c6357cc1 100644
--- a/gateway/session_managed_worker.py
+++ b/gateway/session_managed_worker.py
@@ -172,9 +172,30 @@ def _prompt_frame(authority, ref, row, worker, frame):
return True
+def _worker_env(authority):
+ """Child env for the OWNING profile under multiplex: its HERMES_HOME plus its ``.env``
+ secrets over a scrubbed base, never the launch profile's process environment (the same
+ rule MCP stdio children and shell hooks follow). Single-profile gateways inherit the
+ process env byte-for-byte, exactly as before."""
+ from pathlib import Path
+ from agent.secret_scope import is_multiplex_active
+ home = Path(str(authority.profile_id))
+ if not is_multiplex_active() or not home.is_absolute():
+ return None
+ from agent.secret_scope import build_profile_secret_scope
+ from tools.environments.local import build_subprocess_env
+ env = build_subprocess_env(scrub_secrets=True)
+ env.update({k: v for k, v in build_profile_secret_scope(home).items() if v is not None})
+ env['HERMES_HOME'] = str(home)
+ from hermes_constants import apply_subprocess_home_env
+ apply_subprocess_home_env(env)
+ return env
+
+
async def execute_managed(authority, ref, row, policy):
+ env = await asyncio.to_thread(_worker_env, authority)
process = await asyncio.to_thread(subprocess.Popen, [sys.executable, '-m', 'agent.managed_worker'],
- cwd=Path(__file__).resolve().parents[1], stdin=subprocess.PIPE,
+ cwd=Path(__file__).resolve().parents[1], stdin=subprocess.PIPE, env=env,
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, close_fds=True)
worker = ManagedWorker(process)
workers = getattr(authority, '_managed_workers', None)