Skip to content

The agent that grows with you

fix(web): list, activate and delete legacy custom_providers entries on Custom Endpoints

teknium176c640ff11ea
diff --git a/hermes_cli/config.py b/hermes_cli/config.py
index 3b8533061bd..854d3cf1409 100644
--- a/hermes_cli/config.py
+++ b/hermes_cli/config.py
@@ -1235,11 +1235,11 @@ def _validate_custom_providers(cp: Any, issues: List[ConfigIssue]) -> None:
"warning", "custom_providers[{i}] is not a dict (got {type})",
"Each entry should have at minimum: name, base_url"))
else:
- # get_compatible_custom_providers() returns [] for any non-list: every endpoint vanishes
+ # get_compatible_custom_providers() returns [] for any non-list: the legacy entries vanish
# ("0 endpoints") with nothing naming the cause.
_issue(issues, "error",
f"custom_providers is a {type(cp).__name__} — it must be a YAML list (items prefixed with '-'); "
- "every custom endpoint is ignored until it is", _CP_LIST_HINT)
+ "legacy custom_providers entries are ignored until it is", _CP_LIST_HINT)
def _validate_fallback_model(fb: Any, issues: List[ConfigIssue]) -> None:
diff --git a/hermes_cli/doctor_config.py b/hermes_cli/doctor_config.py
index f7bdba4ffed..d488aebe7a0 100644
--- a/hermes_cli/doctor_config.py
+++ b/hermes_cli/doctor_config.py
@@ -397,8 +397,8 @@ def _drift_legacy_custom_providers(f: Finding, should_fix: bool, config_path) ->
"""Legacy ``custom_providers`` list entries with no ``providers:`` twin (raw-file diagnostic).
The v11→v12 migration (config_migrations._migrate_to_12) moves the list into ``providers:`` ONCE, at
- the version bump; an entry hand-written afterwards is served by the chat picker (dual-read) but has no
- row on the Custom Endpoints settings pages, which list only ``providers:`` — deletable nowhere.
+ the version bump; an entry hand-written afterwards lives on in the retired list store (dual-read by the
+ picker and the Custom Endpoints page) instead of the ``providers:`` map every other surface edits.
"""
from hermes_cli.config import read_user_config_raw
raw_config = read_user_config_raw(config_path)
@@ -412,7 +412,7 @@ def _drift_legacy_custom_providers(f: Finding, should_fix: bool, config_path) ->
continue
label = str(entry.get("name") or "").strip() or _endpoint_url(entry)
check_warn(f"Legacy custom_providers entry '{label}' has no providers: twin",
- "(shown in the model picker, missing from the Custom Endpoints settings page)")
+ "(still read from the retired list store; every other surface edits providers:)")
f.manual_issues.append(
f"Move custom_providers entry '{label}' into config.yaml providers: as `providers.<key>.api: "
f"{_endpoint_url(entry)}` and delete it from the list — the v12 list migration ran once and does not re-fire")
diff --git a/hermes_cli/web_routers/config_env.py b/hermes_cli/web_routers/config_env.py
index d2093083d03..d53b0e421cc 100644
--- a/hermes_cli/web_routers/config_env.py
+++ b/hermes_cli/web_routers/config_env.py
@@ -21,7 +21,8 @@ from hermes_cli.web_server_profiles import (
_approval_mode_of, _broadcast_gateway_session_info, _is_other_profile, _parse_model_ids,
)
from fastapi import HTTPException, Request
-from hermes_cli.config import DEFAULT_CONFIG, OPTIONAL_ENV_VARS, read_raw_config, custom_endpoint_key_env, coerce_provider_id, find_provider_entry, redact_key, _deep_merge
+from hermes_cli.config import DEFAULT_CONFIG, OPTIONAL_ENV_VARS, read_raw_config, custom_endpoint_key_env, coerce_provider_id, find_provider_entry, get_compatible_custom_providers, redact_key, _deep_merge
+from hermes_cli.config_providers import _custom_provider_entry_to_provider_config
from hermes_cli.web_models import ConfigUpdate, EnvVarUpdate, EnvVarDelete, EnvVarReveal, CustomEndpointUpdate
from typing import Any, Dict, List, Optional, Tuple
@@ -433,7 +434,31 @@ def _custom_endpoint_response(cfg: Dict[str, Any]) -> Dict[str, Any]:
raw_entry, _model_names_provider(model_cfg, endpoint_id, raw_entry), "providers",
))
- if current_provider.lower() == "custom" and current_base_url and not any(e["id"] == "custom" for e in endpoints):
+ # Legacy ``custom_providers:`` list entries the migration left behind are
+ # still routed at runtime (get_compatible_custom_providers), so they need a
+ # row too, or the panel hides an endpoint the agent can pick. Entries from
+ # ``providers:`` carry ``provider_key``; the legacy ones do not. A bare
+ # ``provider: custom`` main slot is "current" for the legacy row whose
+ # base_url it points at.
+ is_bare_custom = current_provider.lower() == "custom" and bool(current_base_url)
+ seen_ids = {e["id"] for e in endpoints}
+ for entry in get_compatible_custom_providers(cfg):
+ if entry.get("provider_key"):
+ continue
+ endpoint_id = _custom_endpoint_id(entry["name"])
+ if endpoint_id in seen_ids:
+ continue
+ seen_ids.add(endpoint_id)
+ models = _models_from_custom_endpoint_entry(entry)
+ is_current = is_bare_custom and entry["base_url"].rstrip("/") == current_base_url.rstrip("/")
+ endpoints.append(_endpoint_row(
+ endpoint_id, entry["name"], entry["base_url"],
+ str(entry.get("model") or (models[0] if models else "")), models,
+ entry.get("context_length"), bool(entry.get("discover_models", True)),
+ entry, is_current, "custom_providers",
+ ))
+
+ if is_bare_custom and not any(e["id"] == "custom" or e["is_current"] for e in endpoints):
endpoints.insert(0, _endpoint_row(
"custom", "Custom", current_base_url, current_model, [current_model] if current_model else [],
model_cfg.get("context_length"), True, model_cfg, True, "direct-config",
@@ -447,6 +472,17 @@ def _custom_endpoint_response(cfg: Dict[str, Any]) -> Dict[str, Any]:
}
+def _pop_legacy_custom_provider(cfg: Dict[str, Any], provider_key: str) -> Optional[Dict[str, Any]]:
+ """Remove and return the legacy ``custom_providers:`` list entry whose name slugs to *provider_key*."""
+ legacy = cfg.get("custom_providers")
+ if not isinstance(legacy, list):
+ return None
+ for index, entry in enumerate(legacy):
+ if isinstance(entry, dict) and _custom_endpoint_id(str(entry.get("name") or "")) == provider_key:
+ return legacy.pop(index)
+ return None
+
+
def _detach_main_model_from_provider(cfg: Dict[str, Any], provider_key: str, entry: Optional[Dict[str, Any]] = None) -> None:
"""Drop the main-slot mirror of a provider that no longer exists.
@@ -602,12 +638,23 @@ def activate_custom_endpoint(endpoint_id: str, profile: Optional[str] = None):
cfg = load_config()
stored_key, entry = _resolve_custom_endpoint_entry(cfg.get("providers"), endpoint_id)
if entry is None:
- raise HTTPException(status_code=404, detail="custom endpoint not found")
- provider_key = coerce_provider_id(stored_key)
+ # A legacy ``custom_providers:`` row: the main slot names providers by
+ # key, so promote the entry to ``providers.<key>`` (the v12 shape the
+ # migration would have written) before activating it.
+ provider_key = _custom_endpoint_id(endpoint_id)
+ legacy = _pop_legacy_custom_provider(cfg, provider_key)
+ entry = _custom_provider_entry_to_provider_config(legacy, provider_key=provider_key) if legacy else None
+ if entry is None:
+ raise HTTPException(status_code=404, detail="custom endpoint not found")
+ providers = cfg.get("providers") if isinstance(cfg.get("providers"), dict) else {}
+ providers[provider_key] = entry
+ cfg["providers"] = providers
+ else:
+ provider_key = coerce_provider_id(stored_key)
models = _models_from_custom_endpoint_entry(entry)
- model = str(entry.get("model") or (models[0] if models else "")).strip()
- base_url = str(entry.get("base_url") or "").strip()
+ model = str(entry.get("model") or entry.get("default_model") or (models[0] if models else "")).strip()
+ base_url = str(entry.get("base_url") or entry.get("api") or "").strip()
if not model or not base_url:
raise HTTPException(status_code=400, detail="custom endpoint is incomplete")
@@ -643,11 +690,15 @@ def delete_custom_endpoint(endpoint_id: str, profile: Optional[str] = None):
cfg = load_config()
providers = cfg.get("providers")
stored_key, entry = _resolve_custom_endpoint_entry(providers, endpoint_id)
- if entry is None or not isinstance(providers, dict):
- raise HTTPException(status_code=404, detail="custom endpoint not found")
- provider_key = coerce_provider_id(stored_key)
- providers.pop(stored_key, None)
- cfg["providers"] = providers
+ if entry is not None and isinstance(providers, dict):
+ provider_key = coerce_provider_id(stored_key)
+ providers.pop(stored_key, None)
+ cfg["providers"] = providers
+ else:
+ # A legacy ``custom_providers:`` row is addressed by its slug.
+ provider_key = _custom_endpoint_id(endpoint_id)
+ if _pop_legacy_custom_provider(cfg, provider_key) is None:
+ raise HTTPException(status_code=404, detail="custom endpoint not found")
_detach_main_model_from_provider(cfg, provider_key, entry)
remove_env_value(custom_endpoint_key_env(provider_key))
save_config(cfg)
diff --git a/tests/hermes_cli/test_doctor.py b/tests/hermes_cli/test_doctor.py
index 09748f91d25..fddb011581f 100644
--- a/tests/hermes_cli/test_doctor.py
+++ b/tests/hermes_cli/test_doctor.py
@@ -1535,8 +1535,8 @@ class TestDoctorStaleMaxIterationsDrift:
class TestDoctorLegacyCustomProvidersResidue:
- """A legacy ``custom_providers`` list entry without a ``providers:`` twin is picker-visible but has no
- Custom Endpoints row; doctor must name it and point at the move. Twins (URL modulo trailing slash /
+ """A legacy ``custom_providers`` list entry without a ``providers:`` twin lives on in the retired list
+ store; doctor must name it and point at the move. Twins (URL modulo trailing slash /
case) and non-list values are not this step's business."""
def _run(self, tmp_path, yaml_text):
diff --git a/tests/hermes_cli/test_web_server.py b/tests/hermes_cli/test_web_server.py
index 03bf619425f..3a10de3dc01 100644
--- a/tests/hermes_cli/test_web_server.py
+++ b/tests/hermes_cli/test_web_server.py
@@ -2147,6 +2147,53 @@ class TestWebServerEndpoints:
model_cfg = load_config()["model"]
assert model_cfg["api_key"] == "sk-legacy"
+ def test_legacy_custom_providers_entries_get_a_row_and_can_be_deleted(self):
+ """A post-migration ``custom_providers:`` list entry is still routed by the
+ runtime (``get_compatible_custom_providers``), so Custom Endpoints must show
+ it — and Delete must remove it from the legacy list, not 404 (#114471)."""
+ from hermes_cli.config import load_config, save_config
+
+ cfg = load_config()
+ cfg["providers"] = {
+ "modern": {"name": "Modern", "base_url": "https://llm.modern.com/v1", "model": "m"},
+ }
+ cfg["custom_providers"] = [
+ {"name": "Old Box", "base_url": "http://10.0.0.5:8080/v1", "model": "qwen"},
+ ]
+ save_config(cfg)
+
+ rows = {e["id"]: e for e in self.client.get("/api/providers/custom-endpoints").json()["endpoints"]}
+ assert set(rows) == {"modern", "old-box"}
+ assert rows["old-box"]["source"] == "custom_providers"
+ assert rows["old-box"]["base_url"] == "http://10.0.0.5:8080/v1"
+ assert rows["old-box"]["model"] == "qwen"
+
+ deleted = self.client.request("DELETE", "/api/providers/custom-endpoints/old-box")
+ assert deleted.status_code == 200, deleted.text
+ assert [e["id"] for e in deleted.json()["endpoints"]] == ["modern"]
+ cfg = load_config()
+ assert cfg.get("custom_providers") == []
+ assert "modern" in cfg["providers"]
+
+ def test_activating_a_legacy_custom_providers_entry_promotes_it(self):
+ """Use on a legacy row moves the entry under ``providers:`` (the v12+ shape the
+ main slot names by key) instead of 404ing on a row the list just rendered."""
+ from hermes_cli.config import load_config, save_config
+
+ cfg = load_config()
+ cfg["custom_providers"] = [
+ {"name": "Old Box", "base_url": "http://10.0.0.5:8080/v1", "model": "qwen", "api_key": "sk-old"},
+ ]
+ save_config(cfg)
+
+ activated = self.client.post("/api/providers/custom-endpoints/old-box/activate", json={})
+ assert activated.status_code == 200, activated.text
+ cfg = load_config()
+ assert cfg.get("custom_providers") == []
+ assert cfg["providers"]["old-box"]["api"] == "http://10.0.0.5:8080/v1"
+ assert cfg["model"]["provider"] == "old-box"
+ assert cfg["model"]["default"] == "qwen"
+
def test_get_sessions_rejects_negative_limit(self):
"""limit=-1 must be rejected (422), not passed through to SQLite as
LIMIT -1 (unbounded) — issue #74316."""
diff --git a/website/docs/reference/cli-commands.md b/website/docs/reference/cli-commands.md
index 4804f9a1bee..45f19283fd2 100644
--- a/website/docs/reference/cli-commands.md
+++ b/website/docs/reference/cli-commands.md
@@ -914,7 +914,7 @@ The **API Connectivity** section includes an `IPv6 route` check: it opens one sh
Custom-endpoint config checks (both warn-only; `--fix` does not rewrite them):
- `custom_providers` that is not a YAML list (for example a string left by a bad `config set`) is reported as an error naming the key and the received type — the runtime ignores every custom endpoint until it is a list again.
-- A legacy `custom_providers` list entry with no matching `providers:` entry (same endpoint URL) is reported with the move to make: such an entry shows up in the model picker but has no row on the Custom Endpoints settings page, and the one-shot v12 migration that moved the list into `providers:` does not run again.
+- A legacy `custom_providers` list entry with no matching `providers:` entry (same endpoint URL) is reported with the move to make: such an entry is still served from the retired list store (the model picker and the Custom Endpoints page dual-read it) rather than the `providers:` map every other surface edits, and the one-shot v12 migration that moved the list into `providers:` does not run again.
## `hermes dump`