The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(web): the dashboard's submitted custom endpoint survives the model assignment
kshitijk4poor8c1f8ed64664
diff --git a/hermes_cli/web_server_config.py b/hermes_cli/web_server_config.pyindex b502ab914f9..a33f2171bc2 100644--- a/hermes_cli/web_server_config.py+++ b/hermes_cli/web_server_config.py@@ -3,6 +3,7 @@import loggingimport os+from dataclasses import replacefrom fastapi import HTTPExceptionfrom typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKINGfrom agent.model_metadata import is_local_endpoint@@ -476,6 +477,17 @@ def _validated_main_model_selection(custom_providers=get_compatible_custom_providers(cfg))if not result.success:raise HTTPException(status_code=400, detail=result.error_message or "model switch rejected")+ if is_bare_custom and base_url.strip():+ # The submitted endpoint IS the route this pick asked for; the credential step may have+ # re-resolved the bare target onto an env/config endpoint (CUSTOM_BASE_URL, a stale+ # model.base_url, the OPENROUTER_BASE_URL mirror). Restore the submitted endpoint AND the+ # wire protocol it mandates: ``model.base_url`` and ``model.api_mode`` are persisted+ # together, so a mode derived from the displaced host would route the submitted endpoint+ # over the wrong wire.+ from hermes_cli.providers import determine_api_mode+ url = base_url.strip()+ result = replace(result, base_url=url,+ api_mode=determine_api_mode(result.target_provider, url))return resultdiff --git a/tests/hermes_cli/test_web_server.py b/tests/hermes_cli/test_web_server.pyindex 148909e5877..e768798b509 100644--- a/tests/hermes_cli/test_web_server.py+++ b/tests/hermes_cli/test_web_server.py@@ -5674,3 +5674,32 @@ def test_mount_spa_dynamic_web_dist_recheck(tmp_path, monkeypatch):res2 = client.get("/")assert res2.status_code == 200assert "Test" in res2.text+++class TestSubmittedCustomEndpointSurvivesAssignment:+ """#115661 follow-up: a bare-``custom`` main-slot pick carries the submitted endpoint as the+ current one (see ``_validated_main_model_selection``). Once the switch's credential step+ re-resolves that target, an env endpoint (``CUSTOM_BASE_URL`` / ``OPENROUTER_BASE_URL``) could+ replace what the user typed and had persisted."""++ def test_submitted_custom_endpoint_wins_over_an_env_endpoint(self, monkeypatch):+ from hermes_cli.web_server_config import _apply_main_model_assignment, _validated_main_model_selection++ monkeypatch.setenv("CUSTOM_BASE_URL", "http://127.0.0.1:9999/v1")+ monkeypatch.setattr(+ "hermes_cli.models_validate.validate_requested_model",+ lambda *a, **k: {"accepted": True, "persist": True, "recognized": True, "message": None})+ monkeypatch.setattr("hermes_cli.model_switch.get_model_info", lambda *a, **k: None)+ monkeypatch.setattr("hermes_cli.model_switch.get_model_capabilities", lambda *a, **k: None)++ cfg = {"model": {"provider": "openrouter", "default": "m"}}+ result = _validated_main_model_selection(+ cfg, "custom", "qwen3:8b", "https://api.anthropic.com", "submitted-key")++ assert result.base_url == "https://api.anthropic.com"+ # The wire protocol follows the endpoint that gets persisted, not the displaced env host.+ assert result.api_mode == "anthropic_messages"+ applied = _apply_main_model_assignment(cfg.get("model", {}), result, "submitted-key")+ assert applied["base_url"] == "https://api.anthropic.com"+ assert applied["api_mode"] == "anthropic_messages"+ assert applied["api_key"] == "submitted-key"