The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): scope standalone turns after hosted activation
KoNit-K99f68e730bed
diff --git a/gateway/run_turn.py b/gateway/run_turn.pyindex 3eac3a283c4..910582a00b6 100644--- a/gateway/run_turn.py+++ b/gateway/run_turn.py@@ -2163,12 +2163,18 @@ class GatewayTurnMixin:self._clear_session_env(_session_env_tokens)def _profile_scope_for_source(self, source: SessionSource):- """``_profile_runtime_scope`` for ``source``'s profile when multiplexing, else a no-op context.+ """``_profile_runtime_scope`` for ``source``'s profile when a secret scope is required.Under multiplexing config/skills/memory resolve to the source profile's home AND credentials- come from its secret scope (never process-global ``os.environ``)."""+ come from its secret scope (never process-global ``os.environ``). Hosted-room activity can+ activate the same process-wide credential guard for a standalone gateway, which must bind+ its default profile rather than leave a later credential read unscoped."""+ from agent.secret_scope import is_multiplex_activefrom gateway.run import _profile_runtime_scope- if getattr(getattr(self, "config", None), "multiplex_profiles", False):+ if (+ getattr(getattr(self, "config", None), "multiplex_profiles", False)+ or is_multiplex_active()+ ):return _profile_runtime_scope(self._resolve_profile_home_for_source(source))return nullcontext()diff --git a/tests/gateway/test_multiplex_background_task_scope.py b/tests/gateway/test_multiplex_background_task_scope.pyindex bf5c70e7241..3e32361a007 100644--- a/tests/gateway/test_multiplex_background_task_scope.py+++ b/tests/gateway/test_multiplex_background_task_scope.py@@ -9,6 +9,7 @@ import asynciofrom pathlib import Pathfrom unittest import mock+from agent import secret_scopefrom gateway.config import GatewayConfigfrom gateway.run import GatewayRunner@@ -47,3 +48,26 @@ class TestBackgroundTaskProfileScope:inner.assert_awaited_once()+def test_standalone_gateway_binds_default_scope_after_hosted_activation(+ tmp_path, monkeypatch+):+ """Regression for #112878: hosted rooms can activate fail-closed scopes globally.++ A gateway configured without multiplexing must still bind its default profile+ when a hosted room has already activated the process-wide secret guard.+ """+ from tui_gateway import launch_profile_policy++ home = tmp_path / "default"+ home.mkdir()+ (home / ".env").write_text("OPENAI_API_KEY=default-key\n", encoding="utf-8")+ monkeypatch.setattr(secret_scope, "_MULTIPLEX_ACTIVE", False)+ monkeypatch.setattr(launch_profile_policy, "_snapshot", None)++ runner = _make_runner(multiplex=False)+ source = mock.MagicMock()+ with mock.patch.object(runner, "_resolve_profile_home_for_source", return_value=home):+ launch_profile_policy.activate_multi_profile_hosting()+ with runner._profile_scope_for_source(source):+ assert secret_scope.get_secret("OPENAI_API_KEY") == "default-key"+