The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dashboard): close config-RMW gaps left by the off-loop sweep
kshitij4ecdee38a6b9
diff --git a/hermes_cli/web_routers/mcp.py b/hermes_cli/web_routers/mcp.pyindex c07df315439..221db07f541 100644--- a/hermes_cli/web_routers/mcp.py+++ b/hermes_cli/web_routers/mcp.py@@ -87,19 +87,17 @@ async def add_mcp_server(body: MCPServerCreate, profile: Optional[str] = None):except ValueError as exc:raise HTTPException(status_code=400, detail=str(exc)) from exc- def _check_existing():- with _profile_scope(body.profile or profile):- return _get_mcp_servers()-- existing = await asyncio.to_thread(_check_existing)- if name in existing:- raise HTTPException(status_code=409, detail=f"Server '{name}' already exists")-- def _save():+ def _run():with _profile_scope(body.profile or profile):# _save_mcp_server does its own load→mutate→save of config.yaml;# serialize the whole cycle against other off-loop config writers.+ # The duplicate-name check lives under the same lock span so a+ # concurrent add of the same name can't slip between check and save.with _CONFIG_MUTATION_LOCK:+ if name in _get_mcp_servers():+ raise HTTPException(+ status_code=409, detail=f"Server '{name}' already exists"+ )if bearer_token is not None:server_config["headers"] = _save_bearer_auth_token(name, bearer_token)if not _save_mcp_server(name, server_config):@@ -109,7 +107,7 @@ async def add_mcp_server(body: MCPServerCreate, profile: Optional[str] = None):)try:- await asyncio.to_thread(_save)+ await asyncio.to_thread(_run)except HTTPException:raiseexcept Exception as exc:diff --git a/hermes_cli/web_routers/tools.py b/hermes_cli/web_routers/tools.pyindex 0c3e6d2b51a..1ed3ecc1d3e 100644--- a/hermes_cli/web_routers/tools.py+++ b/hermes_cli/web_routers/tools.py@@ -518,36 +518,40 @@ async def select_toolset_provider(if body.capability is not None:response["capability"] = body.capability- # Entitlement check for managed Nous rows — mirrors the gate the CLI- # applies via ensure_nous_portal_access at selection time.- cat = TOOL_CATEGORIES.get(name)- row = None- if cat:- row = next(- (- p- for p in _visible_providers(cat, config, force_fresh=True)- if p.get("name") == body.provider- ),- None,- )- managed_feature = (row or {}).get("managed_nous_feature")- if managed_feature:- features = get_nous_subscription_features(config, force_fresh=True)- acct = features.account_info- category = MANAGED_FEATURE_COVERAGE_CATEGORY.get(managed_feature)- entitled = bool(- acct- and acct.logged_in- and (- acct.tool_gateway_entitled_for(category)- if category- else acct.tool_gateway_entitled- )+ # Entitlement check for managed Nous rows — mirrors the gate the CLI+ # applies via ensure_nous_portal_access at selection time. This hits+ # the network (Portal), so it runs AFTER releasing the mutation lock:+ # holding a process-wide config-write lock across a network fetch+ # would stall every other config writer behind a slow Portal call.+ # Still inside the worker thread + profile scope.+ cat = TOOL_CATEGORIES.get(name)+ row = None+ if cat:+ row = next(+ (+ p+ for p in _visible_providers(cat, config, force_fresh=True)+ if p.get("name") == body.provider+ ),+ None,+ )+ managed_feature = (row or {}).get("managed_nous_feature")+ if managed_feature:+ features = get_nous_subscription_features(config, force_fresh=True)+ acct = features.account_info+ category = MANAGED_FEATURE_COVERAGE_CATEGORY.get(managed_feature)+ entitled = bool(+ acct+ and acct.logged_in+ and (+ acct.tool_gateway_entitled_for(category)+ if category+ else acct.tool_gateway_entitled)- if not entitled:- response["needs_nous_auth"] = True- response["feature"] = managed_feature+ )+ if not entitled:+ response["needs_nous_auth"] = True+ response["feature"] = managed_featurereturn responseresponse = await asyncio.to_thread(_run)diff --git a/hermes_cli/web_server.py b/hermes_cli/web_server.pyindex 00ef6ba7419..197c7c193bc 100644--- a/hermes_cli/web_server.py+++ b/hermes_cli/web_server.py@@ -17287,14 +17287,18 @@ async def put_plugin_providers(request: Request, body: _PluginProvidersPutBody):_save_memory_provider,)- if body.memory_provider is not None:- memory_provider = _normalize_memory_provider_name(body.memory_provider)- _require_memory_provider_ready(memory_provider)- _save_memory_provider(memory_provider)- if body.context_engine is not None:- _save_context_engine(body.context_engine)- _invalidate_plugins_hub_cache()- return {"ok": True}+ def _run():+ with _CONFIG_MUTATION_LOCK:+ if body.memory_provider is not None:+ memory_provider = _normalize_memory_provider_name(body.memory_provider)+ _require_memory_provider_ready(memory_provider)+ _save_memory_provider(memory_provider)+ if body.context_engine is not None:+ _save_context_engine(body.context_engine)+ _invalidate_plugins_hub_cache()+ return {"ok": True}++ return await asyncio.to_thread(_run)@app.post("/api/dashboard/plugins/{name:path}/visibility")