The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(credential-pool): frozen routes pick pool keys from their frozen provider entry
Tekniumaa71cf9e1f65
diff --git a/agent/credential_pool.py b/agent/credential_pool.pyindex f2d36bac544..c3f323e0354 100644--- a/agent/credential_pool.py+++ b/agent/credential_pool.py@@ -516,16 +516,12 @@ def _pool_keys_for_custom_entry(norm_name: str, entry: dict[str, Any]) -> list[sdef custom_provider_pool_key_candidates(- base_url: Optional[str],- provider_name: Optional[str] = None,+ base_url: Optional[str], provider_name: Optional[str] = None, config: Optional[dict] = None,) -> list[str]:- """Return pool keys to try for a custom endpoint.-- ``hermes auth add <key>`` stores ``providers.<key>`` credentials under the- durable config slug; older rows and legacy ``custom_providers:`` entries- live under ``custom:<display-name>``. Try the slug first, then the legacy- namespace, so a populated pool is not skipped in favour of the- ``no-key-required`` placeholder.+ """Return pool keys to try for a custom endpoint: the durable ``providers.<key>`` slug+ (``hermes auth add <key>``), then legacy ``custom:<display-name>``, so a populated pool is not+ skipped for the ``no-key-required`` placeholder. ``config`` is a frozen route's config: ITS+ entry owns the endpoint, so a live edit of that entry's URL neither drops nor redirects the pool."""if not base_url:return []@@ -533,7 +529,7 @@ def custom_provider_pool_key_candidates(requested_aliases = _requested_custom_name_aliases(provider_name) if provider_name else set()if requested_aliases:- for norm_name, entry in _iter_custom_providers():+ for norm_name, entry in _iter_custom_providers(config):if requested_aliases & _custom_entry_name_aliases(norm_name, entry):# A named pool holds credentials for its configured endpoint only: a launch-# overridden base_url must not inherit them (R2-M1), nor borrow a sibling's by URL.@@ -542,7 +538,7 @@ def custom_provider_pool_key_candidates(return []return _pool_keys_for_custom_entry(norm_name, entry)- for norm_name, entry in _iter_custom_providers():+ for norm_name, entry in _iter_custom_providers(config):entry_url = _norm_url(entry.get("base_url"))if entry_url and entry_url == normalized_url:return _pool_keys_for_custom_entry(norm_name, entry)diff --git a/hermes_cli/runtime_provider_custom.py b/hermes_cli/runtime_provider_custom.pyindex 07ca2a60538..5520121dac1 100644--- a/hermes_cli/runtime_provider_custom.py+++ b/hermes_cli/runtime_provider_custom.py@@ -372,7 +372,10 @@ def _try_resolve_from_custom_pool("""Runtime dict from the first credential pool that owns this custom endpoint, else None."""rp = _rp()try:- raw_keys = list(rp.custom_provider_pool_key_candidates(base_url, provider_name))+ # A frozen route's entry owns the pool, never the live one (a live URL edit would drop it).+ frozen = rp._FROZEN_RUNTIME_CONFIG.get()+ scope = {} if frozen is None else {"config": frozen}+ raw_keys = list(rp.custom_provider_pool_key_candidates(base_url, provider_name, **scope))except Exception:raw_keys = []# Order-preserving dedupe of normalized keys.diff --git a/tests/gateway/test_session_policy.py b/tests/gateway/test_session_policy.pyindex 2db24d626ce..28ea44f1898 100644--- a/tests/gateway/test_session_policy.py+++ b/tests/gateway/test_session_policy.py@@ -280,6 +280,57 @@ def test_frozen_bare_custom_route_keeps_its_endpoint_pool_and_launch_key_wins(tmassert (runtimes[1]['api_key'], runtimes[1]['credential_pool']) == ('sk-launch-explicit', None)+def _frozen_fixture_routes(tmp_path, monkeypatch, *launches):+ """Freeze ``custom_providers: Fixture`` at endpoint A with a pool-only key in auth.json, freeze one+ route per launch ``base_url``, then edit the LIVE entry to endpoint B; return each route's runtime."""+ import json+ from types import SimpleNamespace+ from gateway.session_policy import build_policy, bind_launch_key+ from gateway.run_turn_prepare import GatewayTurnPrepareMixin+ from hermes_cli.config_effective import load_user_config_effective+ home = tmp_path / 'home'+ home.mkdir()+ monkeypatch.setenv('HERMES_HOME', str(home))++ def write(url):+ (home / 'config.yaml').write_text(json.dumps({'model': {'provider': 'fixture', 'default': 'm'},+ 'custom_providers': [{'name': 'Fixture', 'base_url': url}]}))+ write('https://a.fixture.example/v1')+ (home / 'auth.json').write_text(json.dumps({'version': 1, 'providers': {}, 'credential_pool': {'custom:fixture': [+ {'id': 'k1', 'label': 'a', 'auth_type': 'api_key', 'priority': 0, 'source': 'manual',+ 'access_token': 'sk-pool-key-for-endpoint-a'}]}}))+ authority = SimpleNamespace(instance_id='i', epoch=1, profile_id='p', db=None)+ policies = []+ for n, url in enumerate(launches):+ private = {}+ params = {'cwd': str(tmp_path), 'model': 'm', 'provider': 'fixture'} | ({'base_url': url} if url else {})+ policy = build_policy(params, load_user_config_effective(home / 'config.yaml'), private_secrets=private)+ policies.append(bind_launch_key(authority, f's{n}', policy, None, config_secrets=private))+ write('https://b.fixture.example/v1')+ runner = SimpleNamespace(session_authority=authority)+ runtimes = []+ for policy in policies:+ monkeypatch.setattr('gateway.session_policy.policy_for_source', lambda runner, source, p=policy: p)+ runtimes.append(GatewayTurnPrepareMixin._resolve_session_agent_runtime(runner, source=SimpleNamespace())[1])+ return runtimes+++def test_frozen_named_route_keeps_its_pool_after_live_endpoint_edit(tmp_path, monkeypatch):+ """A frozen named route stays on endpoint A after the live entry moves to B; A's pool key goes+ with it (the pool-key lookup reads the FROZEN entry, not live config) instead of no-key-required."""+ (runtime,) = _frozen_fixture_routes(tmp_path, monkeypatch, None)+ assert (runtime['base_url'], runtime['api_key']) == ('https://a.fixture.example/v1', 'sk-pool-key-for-endpoint-a')+ assert runtime['credential_pool'] is not None+++def test_frozen_launch_url_override_never_borrows_the_named_pool(tmp_path, monkeypatch):+ """R2-M1 under a frozen route: a launch ``base_url`` B for the provider frozen at A never borrows+ A's pool key, even after the live entry is edited to B."""+ (runtime,) = _frozen_fixture_routes(tmp_path, monkeypatch, 'https://b.fixture.example/v1')+ assert runtime['base_url'] == 'https://b.fixture.example/v1'+ assert (runtime['api_key'], runtime['credential_pool']) == ('no-key-required', None)++def test_lazy_info_reports_the_free_tier_pinned_model(tmp_path, monkeypatch):"""A not-yet-built session with no launch model/provider runs on ``nous/welcome`` on the freetier (the agent build pins it), so ``session.info`` says so; an explicit launch model stands."""@@ -287,7 +338,7 @@ def test_lazy_info_reports_the_free_tier_pinned_model(tmp_path, monkeypatch):from types import SimpleNamespacefrom gateway.session_local import _lazy_modelfrom gateway.session_policy import build_policy- import hermes_cli.anon_auth as anon_auth+ from hermes_cli import anon_authauthority = SimpleNamespace(runner=None, profile_id='fixture')monkeypatch.setattr(anon_auth, 'free_tier_route', lambda: True)configured = replace(build_policy({'cwd': str(tmp_path)}, {'model': {'default': 'cfg-model'}}), model='cfg-model')