The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): a legacy custom provider renamed in place still runs on cold start
Teknium3e920deab6d5
diff --git a/gateway/session_policy_credentials.py b/gateway/session_policy_credentials.pyindex 555f0cdfd05..f7082f8789e 100644--- a/gateway/session_policy_credentials.py+++ b/gateway/session_policy_credentials.py@@ -305,7 +305,8 @@ def _current_custom_path(frozen, config, path):"""*path* (``custom_providers[i]...``, an index into the frozen list) re-pointed at the profile'sentry of the SAME canonical identity (``custom_provider_slug``), wherever a reorder moved it.An entry the profile no longer declares maps to no index (absent), never to whatever entry now- sits at ``i``. A frozen entry with no name has no identity: its index is all there is."""+ sits at ``i``, unless that entry is the same endpoint renamed in place (the fingerprint then decides,+ as on main). A frozen entry with no name has no identity: its index is all there is."""from hermes_cli.providers import custom_provider_slugdef identity(entry):@@ -323,6 +324,10 @@ def _current_custom_path(frozen, config, path):for index, entry in enumerate(current):if identity(entry) == mine: # the first match, as the runtime's own name lookup takesreturn (path[0], index, *path[2:])+ from hermes_cli.runtime_provider_custom import _entry_url, _normalize_base_url_for_match as url+ if 0 <= path[1] < len(current) and isinstance(current[path[1]], dict) \+ and url(_entry_url(current[path[1]])) == url(_entry_url(held[path[1]])):+ return path # renamed in place: same endpoint at the same index, as main read it (the fingerprint decides)return (path[0], len(current), *path[2:]) # gone: past the end reads as absentdiff --git a/tests/gateway/test_session_mutation_model.py b/tests/gateway/test_session_mutation_model.pyindex 0df0028640c..e43d941a858 100644--- a/tests/gateway/test_session_mutation_model.py+++ b/tests/gateway/test_session_mutation_model.py@@ -484,6 +484,49 @@ async def test_picked_legacy_custom_provider_survives_a_profile_reorder_on_cold_assert refused.value.reason == 'launch_credentials_unavailable'+async def test_probe_rename_keep_url_key(tmp_path, monkeypatch):+ """Review (#141484, MP-17): the picked legacy entry renamed in place (same index, same URL, same+ key) still runs on a cold start, as on main. Renamed AND moved to another index still refuses."""+ from dataclasses import asdict+ from types import SimpleNamespace+ from gateway.run_turn_prepare import _resolve_policy_agent_runtime+ from gateway.session_mutation_model import prepare_model+ from gateway.session_policy import build_policy, restore_policy+ from hermes_state import SessionDB+ from hermes_state_runtime import RuntimeStoreError+ from hermes_cli import model_switch++ other = ' - name: other\n base_url: https://other.example.invalid/v1\n api_key: sk-other\n'+ picked = ' - name: {name}\n base_url: https://inkstone.example.invalid/v1\n api_key: sk-inkstone\n'+ config = tmp_path / 'config.yaml'+ config.write_text('custom_providers:\n' + other + picked.format(name='inkstone'), encoding='utf-8')+ monkeypatch.setattr(model_switch, 'switch_model', lambda **k: model_switch.ModelSwitchResult(+ success=True, new_model='glm-5.3', target_provider='inkstone',+ base_url='https://inkstone.example.invalid/v1', api_mode='chat_completions'))+ with SessionDB(tmp_path / 'state.db') as db:+ def owner(): # a fresh owner: no in-memory secrets, everything re-read from config.yaml+ authority = SimpleNamespace(instance_id='i', epoch=1, profile_id='p', db=db)+ authority.runner = SimpleNamespace(session_authority=authority,+ _resolve_session_agent_runtime=lambda **k: (None, {}))+ return authority+ policy = build_policy({'cwd': str(tmp_path), 'model': 'old'}, {+ 'model': {'provider': 'deepseek', 'default': 'old'}})+ prepared = {'snapshot': {'receipt': {'session_id': 'sid', 'policy': asdict(policy)}}}+ switched = restore_policy((await prepare_model(owner(), SimpleNamespace(source=None, route='r'), {+ 'model': 'glm-5.3', 'provider': 'inkstone'}, prepared))['policy'])++ config.write_text('custom_providers:\n' + other + picked.format(name='Inkstone EU'), encoding='utf-8')+ _, runtime = _resolve_policy_agent_runtime(owner().runner, switched)+ assert runtime['base_url'].rstrip('/') == 'https://inkstone.example.invalid/v1'+ assert runtime['api_key'] == 'sk-inkstone'++ config.write_text('custom_providers:\n' + picked.format(name='Inkstone EU') + other, encoding='utf-8')+ with pytest.raises(RuntimeStoreError) as refused:+ switched.config(owner())+ assert refused.value.reason == 'launch_credentials_unavailable'++@pytest.mark.asyncioasync def test_model_pick_resolves_the_profiles_current_entry_over_a_frozen_one(tmp_path, monkeypatch):"""A pick is an explicit user action: a slug the session froze earlier resolves to the profile's