Skip to content

The agent that grows with you

fix(gateway): setup.status / setup.runtime_check scope the launch profile under multiplex

KoNit-K5910de20bc98
diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.py
index eba5eec7bdd..aedced354fe 100644
--- a/tests/tui_gateway/test_tui_gateway_server.py
+++ b/tests/tui_gateway/test_tui_gateway_server.py
@@ -9289,6 +9289,45 @@ def test_setup_runtime_check_reports_target_model_on_credential_failure(monkeypa
assert resp["result"]["ok"] is False
assert resp["result"]["model"] == "z-ai/glm-5.2"
+def test_setup_runtime_check_scopes_launch_profile_in_multiplex_backend(monkeypatch, tmp_path):
+ """The launch profile needs a scope too when its Codex route reads an override."""
+ from agent import secret_scope
+ from tui_gateway import launch_profile_policy
+
+ launch_home = tmp_path / ".hermes"
+ launch_home.mkdir()
+ monkeypatch.setenv("HERMES_CODEX_BASE_URL", "https://codex.launch.test/v1")
+ monkeypatch.setattr(server, "_hermes_home", launch_home)
+ monkeypatch.setattr(launch_profile_policy, "_snapshot", None)
+ monkeypatch.setattr("hermes_cli.main._has_any_provider_configured", lambda **_kw: True)
+ monkeypatch.setattr(server, "_resolve_startup_runtime", lambda: ("gpt-5.3-codex", None))
+
+ def resolve_codex(requested=None, **_kwargs):
+ assert requested == "openai-codex"
+ return {
+ "provider": "openai-codex",
+ "api_key": "codex-oauth-token",
+ "base_url": secret_scope.get_secret("HERMES_CODEX_BASE_URL"),
+ "source": "credential-pool",
+ }
+
+ monkeypatch.setattr("hermes_cli.runtime_provider.resolve_runtime_provider", resolve_codex)
+ secret_scope.set_multiplex_active(True)
+ try:
+ response = server.handle_request(
+ {"id": "1", "method": "setup.runtime_check", "params": {"provider": "openai-codex"}}
+ )
+ finally:
+ secret_scope.set_multiplex_active(False)
+
+ assert response["result"] == {
+ "ok": True,
+ "provider": "openai-codex",
+ "model": "gpt-5.3-codex",
+ "source": "credential-pool",
+ "free_tier": False,
+ }
+
def test_setup_readiness_scopes_to_requested_profile(monkeypatch, tmp_path):
"""#94071: the Desktop preflights a freshly created bot on its target
diff --git a/tui_gateway/methods_config.py b/tui_gateway/methods_config.py
index 87daa9480d6..c0ed5086590 100644
--- a/tui_gateway/methods_config.py
+++ b/tui_gateway/methods_config.py
@@ -248,18 +248,19 @@ def _readiness_check(rid, params, probe):
stay isolated); ``scoped`` is the ``{"profile": ...}`` payload stamp (``{}`` for the launch
profile). An unknown profile answers ``ok=False`` (never a JSON-RPC error, never a quiet answer
for the launch profile instead)."""
- import contextlib
profile = str(params.get("profile") or "").strip() if isinstance(params, dict) else ""
- scope = contextlib.nullcontext()
+ home = None
if profile:
from hermes_cli import profiles as profiles_mod
if not profiles_mod.profile_exists(profile):
return _ok(rid, {"ok": False, "profile": params.get("profile"),
"error": f"Profile '{profile}' does not exist on this backend."})
home = _profile_home(profile)
- if home is not None:
- scope = _session_profile_runtime_scope({"profile_home": str(home)})
- with scope:
+ # ``profile_home=None`` is the launch profile: once this process multiplexes its probe must
+ # run under its own frozen secret scope too (``_profile_runtime_scope_tokens`` binds nothing in
+ # a single-profile process), or the first profile-scoped read inside the resolver
+ # (``HERMES_CODEX_BASE_URL`` for openai-codex) fails closed and the UI shows onboarding.
+ with _session_profile_runtime_scope({"profile_home": str(home) if home is not None else None}):
payload = probe(profile, {"profile": profile} if profile else {})
return _ok(rid, payload)