The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): a pick expands provider refs against the profile's current .env
Tekniuma6f549761c29
diff --git a/gateway/session_mutation_model.py b/gateway/session_mutation_model.pyindex bd4a1e9bdd0..2a004869f0a 100644--- a/gateway/session_mutation_model.py+++ b/gateway/session_mutation_model.py@@ -150,12 +150,13 @@ 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); afrozen 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."""+ profile (``ignore_user_config``, implied by safe mode) resolves only its own frozen config.+ ``${VAR}`` refs expand against the profile's CURRENT ``.env``, not the daemon's start env."""from pathlib import Path- from gateway.run import _load_gateway_config+ from gateway.session_local import load_profile_configif bypass:return config- current = _load_gateway_config(Path(authority.db.db_path).resolve().parent / 'config.yaml')+ current = load_profile_config(Path(authority.db.db_path).resolve().parent)if not isinstance(current, dict):return configresolved = dict(config)diff --git a/tests/gateway/test_session_mutation_model_provider_replacement.py b/tests/gateway/test_session_mutation_model_provider_replacement.pyindex 4b142ea1bc4..03544cd7466 100644--- a/tests/gateway/test_session_mutation_model_provider_replacement.py+++ b/tests/gateway/test_session_mutation_model_provider_replacement.py@@ -146,6 +146,27 @@ async def test_pick_reads_only_the_owning_profiles_config(tmp_path, monkeypatch)assert config['providers']['loop']['base_url'] == bu[email protected]('secondary', [False, True])+async def test_pick_expands_provider_refs_against_the_profiles_current_env(tmp_path, monkeypatch, secondary):+ """A ``providers:`` entry whose ``base_url`` is a ``${VAR}`` ref freezes the value in the owning+ profile's CURRENT ``.env``, not the one the daemon started with (also for a multiplexed+ secondary profile, whose state.db lives under ``profiles/<name>``)."""+ import gateway.run # the daemon is already up: its import-time .env load is done+ home = tmp_path / 'profiles' / 'other' if secondary else tmp_path+ home.mkdir(parents=True, exist_ok=True)+ with peers() as (boot_peer, boot_url, b, bu):+ monkeypatch.setenv('LOOP_URL', boot_url) # the daemon's start-time value+ (home / '.env').write_text(f'LOOP_URL={bu}\n') # the user's edit after startup+ before = {'model': {'provider': 'custom', 'base_url': boot_url, 'default': 'original'}}+ after = {**before, 'providers': {'loop': {'base_url': '${LOOP_URL}', 'api_key': 'loop-key',+ 'models': {'switched': {}}}}}+ config, runtime = await pick(home, monkeypatch, before, after, 'loop', hermes_home=tmp_path)+ assert runtime['base_url'].rstrip('/') == bu+ assert b.bearers == ['Bearer loop-key'] and not boot_peer.bearers+ assert config['providers']['loop']['base_url'] == bu++@pytest.mark.platforms('linux')def test_removed_provider_key_is_not_sent_to_retargeted_endpoint(tmp_path):root = Path(__file__).resolve().parents[2]