The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): a bypass session's model pick never reads the profile's providers
Tekniumb8ec8a408fa8
diff --git a/gateway/session_mutation_model.py b/gateway/session_mutation_model.pyindex 647a7b11bf0..cf3ec3eeac9 100644--- a/gateway/session_mutation_model.py+++ b/gateway/session_mutation_model.py@@ -53,7 +53,7 @@ async def prepare_model(authority, live, payload, prepared):# providers, as CLI/TUI ``/model`` do (#139740). A following session's ``config`` already is# the profile's current read; every other session keeps ``config`` for its own route below.resolution = config if old.follows_profile else await asyncio.to_thread(- _provider_resolution_config, authority, config)+ _provider_resolution_config, authority, config, old.ignore_user_config)def switch(**kwargs):result = switch_model(**kwargs)@@ -144,12 +144,15 @@ async def prepare_model(authority, live, payload, prepared):return dict(prepared, policy=asdict(policy))-def _provider_resolution_config(authority, config):+def _provider_resolution_config(authority, config, bypass=False):"""*config* with the owning profile's CURRENT named providers over its frozen ones, used only toresolve and freeze a pick. Reads this owner's own config.yaml (never another profile's); a- frozen entry the profile no longer declares stays resolvable."""+ frozen entry the profile no longer declares stays resolvable. A session that bypasses the+ profile (``ignore_user_config``, implied by safe mode) resolves only its own frozen config."""from pathlib import Pathfrom gateway.run import _load_gateway_config+ if bypass:+ return configcurrent = _load_gateway_config(Path(authority.db.db_path).resolve().parent / 'config.yaml')if not isinstance(current, dict):return configdiff --git a/tests/gateway/test_session_mutation_model_provider_replacement.py b/tests/gateway/test_session_mutation_model_provider_replacement.pyindex c4b46baea5a..60d52fb36e8 100644--- a/tests/gateway/test_session_mutation_model_provider_replacement.py+++ b/tests/gateway/test_session_mutation_model_provider_replacement.py@@ -89,6 +89,21 @@ async def test_named_provider_replacement_does_not_keep_withdrawn_secrets(tmp_paassert config['providers']['reviewprovider'].get('extra_headers') is None[email protected]('bypass', ['ignore_user_config', 'safe_mode'])+async def test_config_only_pick_does_not_import_profile_provider(tmp_path, monkeypatch, bypass):+ from hermes_state_runtime import RuntimeStoreError+ with peers() as (_a, au, b, bu):+ before = {'model': {'provider':'custom', 'base_url':au,'default':'original'}}+ after = {**before, 'providers': {'reviewprovider':{'base_url':bu,'api_key':'profile-only-key'}}}+ try:+ await pick(tmp_path, monkeypatch, before, after, 'reviewprovider',+ request={bypass: True, 'provider': 'custom', 'base_url': au})+ except RuntimeStoreError as exc:+ assert str(exc) == 'model_resolution_failed'+ assert not b.bearers, 'ignore_user_config session imported profile-only provider'++@pytest.mark.platforms('linux')def test_removed_provider_key_is_not_sent_to_retargeted_endpoint(tmp_path):root = Path(__file__).resolve().parents[2]