Skip to content

The agent that grows with you

fix: explicit launch key wins over a named provider's pool; pools stay on their endpoint

Teknium26c5401ad282
diff --git a/agent/credential_pool.py b/agent/credential_pool.py
index d6df1850b9f..b90d1a5a13d 100644
--- a/agent/credential_pool.py
+++ b/agent/credential_pool.py
@@ -558,6 +558,11 @@ def custom_provider_pool_key_candidates(
if requested_aliases:
for norm_name, entry in _iter_custom_providers():
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.
+ entry_url = _norm_url(entry.get("base_url"))
+ if entry_url and entry_url != normalized_url:
+ return []
return _pool_keys_for_custom_entry(norm_name, entry)
for norm_name, entry in _iter_custom_providers():
diff --git a/hermes_cli/runtime_provider_custom.py b/hermes_cli/runtime_provider_custom.py
index 7f7356d4191..0379268085e 100644
--- a/hermes_cli/runtime_provider_custom.py
+++ b/hermes_cli/runtime_provider_custom.py
@@ -487,8 +487,10 @@ def _resolve_direct_alias_runtime(requested_provider: str, explicit_api_key: Opt
rp = _rp()
base_url = explicit_base_url.strip().rstrip("/")
# Pool first — mirrors the named-custom path so bare `provider: custom` with a configured
- # custom_providers entry gets its api_key from the pool instead of env fallbacks.
- pool_result = rp._try_resolve_from_custom_pool(base_url, "custom", None)
+ # custom_providers entry gets its api_key from the pool instead of env fallbacks. An explicit
+ # launch key still wins over the pool (R2-M1).
+ explicit_key = (explicit_api_key or "").strip()
+ pool_result = None if rp.has_usable_secret(explicit_key) else rp._try_resolve_from_custom_pool(base_url, "custom", None)
if pool_result:
pool_result["source"] = "direct-alias"
return pool_result
@@ -550,10 +552,12 @@ def _resolve_named_custom_runtime(*, requested_provider: str, explicit_api_key:
base_url = ((explicit_base_url or "").strip() or custom_provider.get("base_url", "")).rstrip("/")
if not base_url:
return None
+ explicit_key = (explicit_api_key or "").strip()
# The credential pool is the profile's auth store (``hermes auth add``), not config: a frozen
# config snapshot still owes a pooled ``providers:`` entry its keys, or the turn ships the
- # ``no-key-required`` placeholder to a host that wants one (C11 pool rows).
- pool_result = rp._try_resolve_from_custom_pool(
+ # ``no-key-required`` placeholder to a host that wants one (C11 pool rows). An explicit launch
+ # key is the operator's credential for this route and wins over the pool (R2-M1).
+ pool_result = None if rp.has_usable_secret(explicit_key) else rp._try_resolve_from_custom_pool(
base_url, "custom", custom_provider.get("api_mode"),
provider_name=custom_provider.get("provider_key") or custom_provider.get("name"),
)
@@ -561,7 +565,6 @@ def _resolve_named_custom_runtime(*, requested_provider: str, explicit_api_key:
# The pool doesn't know the custom_providers fields — propagate them here too.
_apply_custom_provider_extras(custom_provider, target_model, pool_result)
return pool_result
- explicit_key = (explicit_api_key or "").strip()
candidates = [
explicit_key,
_clean(custom_provider.get("api_key", "")),
diff --git a/tests/hermes_cli/test_keyed_provider_credential_pool.py b/tests/hermes_cli/test_keyed_provider_credential_pool.py
index f1035f7b6e0..bb0d6f93a15 100644
--- a/tests/hermes_cli/test_keyed_provider_credential_pool.py
+++ b/tests/hermes_cli/test_keyed_provider_credential_pool.py
@@ -214,3 +214,33 @@ def test_seed_custom_pool_matches_legacy_named_pool(tmp_path, monkeypatch):
seeded = [e for e in entries if getattr(e, "source", "") == "model_config"]
assert seeded, "legacy-named pool must still seed model_config from model.api_key"
assert getattr(seeded[0], "access_token", "") == "sk-model-config-key"
+
+
+def test_explicit_launch_key_wins_over_named_provider_pool(tmp_path, monkeypatch):
+ """R2-M1: a launch ``--api-key`` is the operator's credential for this route; a saved
+ ``providers.<key>`` pool must not silently replace it (live and frozen-config paths)."""
+ _write_keyed_provider_home(tmp_path, monkeypatch)
+
+ from hermes_cli import runtime_provider as rp
+ from hermes_cli.runtime_provider_custom import _resolve_named_custom_runtime
+
+ frozen = rp.load_config()
+ for resolved in (rp.resolve_runtime_provider(requested="b-ai", explicit_api_key="sk-launch-explicit"),
+ _resolve_named_custom_runtime(requested_provider="b-ai", explicit_api_key="sk-launch-explicit",
+ config=frozen)):
+ assert (resolved["base_url"], resolved["api_key"]) == (ENDPOINT, "sk-launch-explicit")
+
+
+def test_named_provider_pool_requires_matching_endpoint(tmp_path, monkeypatch):
+ """R2-M1: a named provider's pool is bound to its configured endpoint; a launch-overridden
+ base_url must never receive it (trailing slash is the same endpoint)."""
+ _write_keyed_provider_home(tmp_path, monkeypatch)
+
+ from agent.credential_pool import custom_provider_pool_key_candidates
+ from hermes_cli import runtime_provider as rp
+
+ assert custom_provider_pool_key_candidates("https://elsewhere.example/v1", "b-ai") == []
+ assert custom_provider_pool_key_candidates(ENDPOINT + "/", "b-ai")[0] == "b-ai"
+ resolved = rp.resolve_runtime_provider(requested="b-ai", explicit_base_url="https://elsewhere.example/v1")
+ assert resolved["base_url"] == "https://elsewhere.example/v1"
+ assert resolved["api_key"] != POOL_KEY