The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): delegation routing writes refuse a managed install with a 409
Teknium24e2a2908247
diff --git a/hermes_cli/web_routers/delegation.py b/hermes_cli/web_routers/delegation.pyindex 297596f1471..9c682c89653 100644--- a/hermes_cli/web_routers/delegation.py+++ b/hermes_cli/web_routers/delegation.py@@ -11,6 +11,7 @@ from __future__ import annotationsimport asyncioimport logging+from dataclasses import asdictfrom typing import Any, Callable, Mapping, Optionalfrom fastapi import APIRouter, HTTPException@@ -37,6 +38,13 @@ def _bad_request(detail: str) -> HTTPException:return HTTPException(status_code=400, detail=detail)+def _managed_install(message: str) -> HTTPException:+ """A package-manager-managed install's config.yaml is not ours to write (``save_config`` would skip it and+ report nothing): 409 with core's one-line reason, which the page shows as the error. Not 403, which the+ Desktop transport reads as an auth rejection and answers with a re-login."""+ return HTTPException(status_code=409, detail=" ".join(message.split()))++def _mapping(parent: Any, key: str) -> dict:value = parent.get(key) if isinstance(parent, Mapping) else Nonereturn value if isinstance(value, dict) else {}@@ -57,8 +65,8 @@ def _registered_backends() -> list[dict[str, Any]]:from hermes_cli.plugins import discover_pluginsdiscover_plugins() # idempotent; a plugin enabled after boot loads on the next scan- return [{"name": b.name, "label": b.label, "description": b.description, "available": b.available,- "reason": b.reason, "builtin": b.name == builtin} for b in list_backends()]+ # ``description`` is the provider's ``summary``: the one line a backend picker shows for it.+ return [{**asdict(b), "builtin": b.name == builtin} for b in list_backends()]def _redacted_options(options: Any) -> list[dict[str, Any]]:@@ -121,6 +129,8 @@ async def select_delegation_backend(body: DelegationBackendSelect, profile: Optidiscover_plugins()try:set_global_backend(name)+ except PermissionError as exc:+ raise _managed_install(str(exc)) from excexcept ValueError as exc:raise _bad_request(str(exc)) from exc@@ -182,6 +192,9 @@ def _clean_model_option(index: int, entry: dict, stored: dict[str, dict]) -> dicdef _write_backend_block(profile: Optional[str], backend: str, build: Callable[[dict], dict]) -> dict:+ from hermes_cli.config import format_managed_message, is_managed+ if is_managed():+ raise _managed_install(format_managed_message(f"save delegation.backends.{backend}"))with config_write_scope(profile):config = load_config()blocks = _section(_section(config, "delegation"), "backends")diff --git a/tests/hermes_cli/test_web_delegation_routing.py b/tests/hermes_cli/test_web_delegation_routing.pyindex 39448b4d1c9..31e29bb7f14 100644--- a/tests/hermes_cli/test_web_delegation_routing.py+++ b/tests/hermes_cli/test_web_delegation_routing.py@@ -107,6 +107,23 @@ def test_a_backend_can_only_be_chosen_where_its_plugin_is_registered(client, homassert (root / "config.yaml").read_text(encoding="utf-8") == before[email protected](("path", "body"), [+ ("/api/delegation/backend", {"backend": "default"}),+ ("/api/delegation/backends/model_map", {"options": []}),+ ("/api/delegation/backends/profile_routes", {"profiles": []}),+])+def test_a_managed_install_refuses_every_routing_write_with_the_reason(client, homes, monkeypatch, path, body):+ """config.yaml of a package-manager-managed install is not ours: each write is a 409 naming the manager,+ never a silent ``ok`` over an untouched file."""+ _root, work = homes+ before = (work / "config.yaml").read_text(encoding="utf-8")+ monkeypatch.setenv("HERMES_MANAGED", "nixos")+ resp = client.put(f"{path}?profile=work", json=body)+ assert resp.status_code == 409, resp.text+ assert "managed by nixos" in resp.json()["detail"] and "\n" not in resp.json()["detail"]+ assert (work / "config.yaml").read_text(encoding="utf-8") == before++@pytest.mark.parametrize(("options", "problem"), [([{"name": "a", "description": "x", "provider": "p", "model": "m"},{"name": "a", "description": "y", "provider": "p", "model": "m"}], "unique"),