Skip to content

The agent that grows with you

fix(dashboard): an unknown ?profile= answers 404 on PUT /api/env, the learning graph and the plugins hub, not 500

John Paul Solivaf793ccad2d99
diff --git a/hermes_cli/web_routers/config_env.py b/hermes_cli/web_routers/config_env.py
index 4735f76b0ec..d7a36b28e5d 100644
--- a/hermes_cli/web_routers/config_env.py
+++ b/hermes_cli/web_routers/config_env.py
@@ -59,19 +59,17 @@ _CATEGORY_ORDER = [
@contextlib.contextmanager
-def _env_write_errors(log_msg: str, *, http_passthrough: bool):
+def _env_write_errors(log_msg: str):
"""``ValueError`` -> 400 with its message (save/remove_env_value reject
invalid names and denylisted keys — LD_PRELOAD, PATH, PYTHONPATH, …, the
credential lifecycle rejects keys a managed install or administrator pins,
- and the SPA needs the reason, not an opaque 500); anything else is logged
- and becomes 500 "Internal server error"."""
+ and the SPA needs the reason, not an opaque 500); ``HTTPException`` (the
+ profile scope's 404 for an unknown ``?profile=``) passes through; anything
+ else is logged and becomes 500 "Internal server error"."""
try:
yield
except HTTPException:
- if http_passthrough:
- raise
- _log.exception(log_msg)
- raise HTTPException(status_code=500, detail="Internal server error")
+ raise
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
except Exception:
@@ -334,10 +332,9 @@ async def set_env_var(body: EnvVarUpdate, profile: Optional[str] = None):
# auxiliary.*.api_key / custom_providers[*]), so a rotation can't leave a
# stale higher-precedence copy that keeps authenticating with the old key.
# Display-only previews (sentinel or legacy mask) must never gain write authority.
- # Checked before the error mapper: it turns HTTPException into a 500 at this site.
if is_redacted_credential_preview(body.value):
raise HTTPException(status_code=400, detail=REDACTED_CREDENTIAL_WRITE_DETAIL)
- with _env_write_errors("PUT /api/env failed", http_passthrough=False):
+ with _env_write_errors("PUT /api/env failed"):
from hermes_cli.credential_lifecycle import save_provider_env_credential
return await scoped_to_thread(
@@ -999,7 +996,7 @@ async def remove_env_var(body: EnvVarDelete, profile: Optional[str] = None):
# ones kept providers alive in the model picker), the affected providers'
# model-cache rows, and value-matched config.yaml api_key mirrors.
# OAuth/device-code/manual pool entries for the same provider are preserved.
- with _env_write_errors("DELETE /api/env failed", http_passthrough=True):
+ with _env_write_errors("DELETE /api/env failed"):
from hermes_cli.credential_lifecycle import remove_provider_env_credential
result = await scoped_to_thread(
diff --git a/hermes_cli/web_routers/dashboard_ui.py b/hermes_cli/web_routers/dashboard_ui.py
index 63de4d7d6b1..af5b6cb9f5b 100644
--- a/hermes_cli/web_routers/dashboard_ui.py
+++ b/hermes_cli/web_routers/dashboard_ui.py
@@ -159,6 +159,8 @@ async def get_plugins_hub(request: Request, profile: Optional[str] = None):
_require_token(request)
try:
return await config_scoped_to_thread(profile, _merged_plugins_hub)
+ except HTTPException:
+ raise # an unknown ?profile= is the scope's 404, not a hub failure
except Exception as exc:
_log.warning("plugins/hub failed: %s", exc)
raise HTTPException(status_code=500, detail="Failed to build plugins hub.") from exc
diff --git a/hermes_cli/web_routers/status.py b/hermes_cli/web_routers/status.py
index e191bee5162..0e998f1a8a8 100644
--- a/hermes_cli/web_routers/status.py
+++ b/hermes_cli/web_routers/status.py
@@ -677,6 +677,8 @@ async def get_learning_graph(profile: Optional[str] = None):
# _profile_scope takes _SKILLS_PROFILE_LOCK and the graph build reads skills/memories
# from disk — keep it off the event loop.
return await scoped_to_thread(profile, _run)
+ except HTTPException:
+ raise # an unknown ?profile= is the scope's 404, not a graph failure
except Exception:
_log.exception("GET /api/learning/graph failed")
raise HTTPException(status_code=500, detail="Failed to build learning graph")
diff --git a/tests/hermes_cli/test_web_unknown_profile_404.py b/tests/hermes_cli/test_web_unknown_profile_404.py
new file mode 100644
index 00000000000..87283fffa5b
--- /dev/null
+++ b/tests/hermes_cli/test_web_unknown_profile_404.py
@@ -0,0 +1,26 @@
+"""An unknown ``?profile=`` is the profile scope's 404 on every dashboard route,
+never a generic 500 from a handler's catch-all."""
+
+import pytest
+from starlette.testclient import TestClient
+
+
+def client(_isolate_hermes_home):
+ from hermes_cli.web_server import app, _SESSION_HEADER_NAME, _SESSION_TOKEN
+
+ c = TestClient(app, raise_server_exceptions=False)
+ c.headers[_SESSION_HEADER_NAME] = _SESSION_TOKEN
+ return c
+
+
[email protected]("method,path,body", [
+ ("PUT", "/api/env", {"key": "FAKE_PROBE_KEY", "value": "fake-value"}),
+ ("GET", "/api/learning/graph", None),
+ ("GET", "/api/dashboard/plugins/hub", None),
+])
+def test_unknown_profile_is_the_scopes_404(client, method, path, body):
+ resp = client.request(method, path, params={"profile": "no-such-profile"}, json=body)
+
+ assert resp.status_code == 404, resp.text
+ assert "no-such-profile" in resp.json()["detail"]