The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(providers): restore a named custom entry from its own pool, not a URL sibling's
unsupportedpastels7616b172ffc5
diff --git a/agent/custom_entry_pool.py b/agent/custom_entry_pool.pyindex 5b77b7218b9..69c9014dc27 100644--- a/agent/custom_entry_pool.py+++ b/agent/custom_entry_pool.py@@ -73,14 +73,14 @@ def custom_entry_for_endpoint(def load_runtime_pool(provider: Optional[str], base_url: Optional[str], requested_provider: Optional[str] = None) -> Any:"""The pool for a runtime snapshot's identity. A custom runtime (``custom`` or ``custom:<name>``)is the entry's, so it gets the entry-scoped view; a built-in identity loads its whole pool.- Ownership comes from the runtime identity, never from the pool slug, which both share."""- from agent.credential_pool import CUSTOM_POOL_PREFIX, load_pool, resolve_runtime_pool_key- key = resolve_runtime_pool_key(provider, base_url)- if not key:- return None+ Ownership and the pool key come from the runtime identity, never from the pool slug, which both+ share: a ``custom:<name>`` identity keys on its own entry, not the first entry on its URL."""+ from agent.credential_pool import CUSTOM_POOL_PREFIX, _pool_keys_for_custom_entry, load_pool, resolve_runtime_pool_keyidentities = [str(v or "").strip().lower() for v in (provider, requested_provider)]if not any(v == "custom" or v.startswith(CUSTOM_POOL_PREFIX) for v in identities):- return load_pool(key)+ key = resolve_runtime_pool_key(provider, base_url)+ return load_pool(key) if key else Nonename = next((v for v in identities if v.startswith(CUSTOM_POOL_PREFIX)), None)match = custom_entry_for_endpoint(base_url, name)- return entry_scoped_pool(load_pool(key), key, match[1] if match else None)+ key = (_pool_keys_for_custom_entry(*match) or [""])[0] if name and match else resolve_runtime_pool_key(provider, base_url)+ return entry_scoped_pool(load_pool(key), key, match[1] if match else None) if key else Nonediff --git a/tests/hermes_cli/test_custom_entry_shadow_key_env.py b/tests/hermes_cli/test_custom_entry_shadow_key_env.pyindex 5fa25c7109b..18fdb490cc3 100644--- a/tests/hermes_cli/test_custom_entry_shadow_key_env.py+++ b/tests/hermes_cli/test_custom_entry_shadow_key_env.py@@ -310,3 +310,43 @@ def test_persisting_the_entry_view_keeps_the_builtin_rows_and_writes_no_secret(tassert {r["id"] for r in after} == beforeassert any(r["source"] == "env:DEEPSEEK_API_KEY" for r in after)assert BUILTIN_KEY not in text and ENTRY_KEY not in text+++# ── review round 2 ──────────────────────────────────────────────────────────────────────────────++SIBLING_KEY = "sibling-key-C-0123456789"+++def _two_entries_on_one_url(tmp_path, monkeypatch):+ """``alpha`` (with a ``hermes auth add alpha`` row) and ``beta`` share ENDPOINT; beta is the primary."""+ home = _home(tmp_path, monkeypatch, "alpha", "ALPHA_KEY_VAR", entry_extra={"key_env": "ALPHA_KEY_VAR"},+ pool={"alpha": [{"id": "m1", "label": "manual", "auth_type": "api_key", "priority": 0,+ "source": "manual", "access_token": MANUAL_KEY}]})+ cfg = yaml.safe_load((home / "config.yaml").read_text())+ cfg["providers"]["beta"] = {**cfg["providers"]["alpha"], "name": "beta", "key_env": "ENTRY_KEY_VAR"}+ cfg["model"]["provider"] = "custom:beta"+ (home / "config.yaml").write_text(yaml.safe_dump(cfg), encoding="utf-8")+ monkeypatch.setenv("ALPHA_KEY_VAR", SIBLING_KEY)+ return home+++def test_restoring_a_named_entry_never_resumes_on_a_sibling_sharing_its_url(tmp_path, monkeypatch):+ _two_entries_on_one_url(tmp_path, monkeypatch)+ from agent.custom_entry_pool import load_runtime_pool+ from hermes_cli import runtime_provider as rp++ pool = load_runtime_pool("custom", ENDPOINT, "custom:beta")+ assert pool is None or not {e.access_token for e in pool.entries()} & {MANUAL_KEY, SIBLING_KEY}+ initial = rp.resolve_runtime_provider(requested="custom:beta")+ assert initial["api_key"] == ENTRY_KEY+ agent = _restorable_agent({"provider": initial["provider"], "requested_provider": "custom:beta",+ "base_url": ENDPOINT, "api_key": ENTRY_KEY})+ assert agent._restore_primary_runtime() is True+ assert (agent.api_key, agent.base_url) == (ENTRY_KEY, ENDPOINT)+++def test_a_genuinely_bare_custom_snapshot_still_takes_the_first_entry_on_its_url(tmp_path, monkeypatch):+ _two_entries_on_one_url(tmp_path, monkeypatch)+ from agent.custom_entry_pool import load_runtime_pool++ assert MANUAL_KEY in {e.access_token for e in load_runtime_pool("custom", ENDPOINT).entries()}