The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(messaging): keep profile status truthful without credential inheritance
Tekniumd0c90039a7fd
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..dfdda83196a--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1,2 @@+crazyief+# PR #104619 empty credential requirements reviewdiff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..7ac355ad6fd--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1,2 @@+vectorcontext+# PR #104650 profile home salvagediff --git a/hermes_cli/web_routers/messaging.py b/hermes_cli/web_routers/messaging.pyindex f91650b133f..b0fcb430107 100644--- a/hermes_cli/web_routers/messaging.py+++ b/hermes_cli/web_routers/messaging.py@@ -166,32 +166,18 @@ def _platform_enablement(os.environ and would leak the root install's tokens into the profile's state."""required = entry["required_env"]if scoped:+ configured = bool(required) and all(env_on_disk.get(key) for key in required)try:plat_cfg = (load_config().get("platforms") or {}).get(platform_id)plat_cfg = plat_cfg if isinstance(plat_cfg, dict) else {}hc = plat_cfg.get("home_channel")- # Credential fallback mirrors _enable_from_env (gateway/config_env.py): env- # credentials alone enable a platform — `hermes gateway setup` only writes- # .env and never a platforms: entry (#104614) — while an explicit- # enabled: false still wins, exactly like the real gateway config. Only the- # profile's own .env (env_on_disk) is consulted; os.environ would leak the- # root install's credentials into this profile's state. `bool(required)`- # guards the empty-required_env platforms (whatsapp, api_server, webhook,- # ...): `all()` over an empty tuple is True, which would report them- # enabled/configured with nothing set up — the unscoped branch reports- # enabled=False for that shape, so the scoped branch must agree.+ # Setup writes credentials without a platforms entry; explicit disable wins.raw_enabled = plat_cfg.get("enabled")- if raw_enabled is False:- enabled = False- else:- enabled = bool(raw_enabled) or (- bool(required)- and all(env_on_disk.get(key) for key in required)- )+ enabled = False if raw_enabled is False else bool(raw_enabled) or configuredhome_channel = hc if isinstance(hc, dict) else Noneexcept Exception:enabled, home_channel = False, None- return enabled, bool(required) and all(env_on_disk.get(key) for key in required), home_channel+ return enabled, configured, home_channeltry:from gateway.config import Platform, load_gateway_configdiff --git a/hermes_cli/web_server_profiles.py b/hermes_cli/web_server_profiles.pyindex 9f20d081d51..9e1404fafac 100644--- a/hermes_cli/web_server_profiles.py+++ b/hermes_cli/web_server_profiles.py@@ -235,23 +235,15 @@ def _config_profile_scope(profile: Optional[str]):(holding those across an ``await`` lets a concurrent request restore THIS request's diron its ``finally``). None/""/"current" = no override.- A named profile that resolves to the SAME directory as this process's own- HERMES_HOME (e.g. ``profile=default`` on a default-home process — the desktop app- always sends ``default``) is treated as current: the scoped branch derives- enablement from config.yaml only and would report an env-enabled platform as- disabled. Classify by resolved path, not by string: a named-profile process- (``-p worker``) has a different HERMES_HOME, so its ``profile=default`` still- scopes correctly. Issue #104614.+ Explicit names resolving to the process home retain current-profile semantics.+ Still enter the requested home so a nested scope cannot retain another profile."""if _is_current_profile(profile):yield Nonereturnprofile_dir = _resolve_profile_dir(profile.strip())- if profile_dir.resolve() == get_process_hermes_home().resolve():- yield None- returnwith _hermes_home_scope(profile_dir):- yield profile_dir+ yield None if profile_dir.resolve() == get_process_hermes_home().resolve() else profile_dir# Terminal backend picker rows — GUI counterpart of terminal.backend. Keep in sync withdiff --git a/tests/hermes_cli/test_web_server.py b/tests/hermes_cli/test_web_server.pyindex 34146a7fc20..46c89c37adf 100644--- a/tests/hermes_cli/test_web_server.py+++ b/tests/hermes_cli/test_web_server.py@@ -773,48 +773,6 @@ class TestWebServerEndpoints:assert seen["status_path"] == worker_home / "gateway_state.json"assert seen["expected_home"] == worker_home- def test_messaging_platforms_profile_scoped_env_credentials_enable(self, monkeypatch):- """Env credentials alone must enable a platform on the profile-scoped path.-- ``hermes gateway setup`` writes the token to .env and never a ``platforms:``- entry, but the desktop always sends ``?profile=default``; the scoped branch- consulted only config.yaml's ``platforms:`` section, so the Messaging page- showed "Disabled" for a connected bot (#104614). An explicit- ``enabled: false`` must still win, mirroring ``_enable_from_env`` in- gateway/config_env.py.- """- import hermes_cli.web_server as web_server- from hermes_cli import profiles as profiles_mod-- worker_home = profiles_mod.get_profile_dir("worker")- worker_home.mkdir(parents=True)- (worker_home / ".env").write_text("DISCORD_BOT_TOKEN=tok\n", encoding="utf-8")-- monkeypatch.setattr(_gw_status, "get_running_pid_cached", lambda pid_path=None, **kw: None)- monkeypatch.setattr(_gw_status, "get_running_pid", lambda pid_path=None, **kw: None)- monkeypatch.setattr(_gw_status, "read_runtime_status", lambda path=None: None)- monkeypatch.setattr(_gw_status, "get_runtime_status_running_pid", lambda runtime=None, **kw: None)- monkeypatch.setattr(web_server, "_GATEWAY_HEALTH_URL", None)-- resp = self.client.get("/api/messaging/platforms?profile=worker")-- assert resp.status_code == 200- platforms = {p["id"]: p for p in resp.json()["platforms"]}- assert platforms["discord"]["enabled"] is True- assert platforms["discord"]["configured"] is True- assert platforms["discord"]["state"] != "disabled"-- # Explicit platforms.discord.enabled: false wins over the .env credentials.- (worker_home / "config.yaml").write_text(- "platforms:\n discord:\n enabled: false\n", encoding="utf-8"- )- resp = self.client.get("/api/messaging/platforms?profile=worker")-- assert resp.status_code == 200- platforms = {p["id"]: p for p in resp.json()["platforms"]}- assert platforms["discord"]["enabled"] is False- assert platforms["discord"]["state"] == "disabled"-diff --git a/tests/hermes_cli/test_web_server_messaging_profiles.py b/tests/hermes_cli/test_web_server_messaging_profiles.pyindex 2074fa82566..193bb4b219a 100644--- a/tests/hermes_cli/test_web_server_messaging_profiles.py+++ b/tests/hermes_cli/test_web_server_messaging_profiles.py@@ -268,43 +268,40 @@ class TestMultiplexPortBindingGuard:)assert resp.status_code == 200+def test_named_current_home_matches_unscoped(client, isolated_profiles, monkeypatch):+ from hermes_cli.web_server_profiles import _config_profile_scope, _hermes_home_scope+ from hermes_constants import get_hermes_home-class TestProfileDefaultOnDefaultHomeReportsEnvEnabled:- """``profile=default`` on a process whose HERMES_HOME IS the default home must- take the unscoped path, not the profile-scoped one.-- The desktop app always sends ``profile=default``. ``_is_current_profile()`` only- recognized None/""/"current" — NOT "default" — so a single-profile install (the- standard ``hermes gateway setup`` flow: token in ``.env``, no ``platforms:``- section in ``config.yaml``) entered the scoped branch, which derives enablement- from ``config.yaml`` only and never calls ``load_gateway_config()``'s- env-override pass. Result: a platform connected via ``.env`` reported- ``enabled=false, state="disabled"`` while it was actually running. The unscoped- GET (no profile param) correctly reported ``enabled=true``. Issue #104614.- """-- def test_default_profile_param_matches_unscoped_enablement(- self, client, isolated_profiles, monkeypatch- ):- # Simulate the gateway having loaded .env into os.environ at startup- # (load_hermes_dotenv in gateway/run.py): the dashboard process shares- # that environment, so the unscoped load_gateway_config() env-override- # pass sees the token and enables the platform.- monkeypatch.setenv("TELEGRAM_BOT_TOKEN", "root-token")-- # config.yaml has NO platforms: section (isolated_profiles writes "{}"),- # so enablement can ONLY come from the env-override pass — exactly the- # standard setup flow the bug hits.-- unscoped = client.get("/api/messaging/platforms")- assert unscoped.status_code == 200- telegram_unscoped = _telegram(unscoped.json())- assert telegram_unscoped["enabled"] is True-- scoped_default = client.get(- "/api/messaging/platforms", params={"profile": "default"}- )- assert scoped_default.status_code == 200- telegram_scoped = _telegram(scoped_default.json())- assert telegram_scoped["enabled"] is True-+ monkeypatch.setenv("TELEGRAM_BOT_TOKEN", "root-token")+ for scope in (None, "current", "default"):+ response = client.get("/api/messaging/platforms", params={"profile": scope} if scope else {})+ assert response.status_code == 200+ assert _telegram(response.json())["enabled"] is True+ with _hermes_home_scope(isolated_profiles["worker_alpha"]):+ with _config_profile_scope("default") as scoped:+ assert scoped is None+ assert get_hermes_home() == isolated_profiles["default"]+++def test_scoped_enablement_uses_only_own_credentials(client, isolated_profiles, monkeypatch):+ monkeypatch.setenv("TELEGRAM_BOT_TOKEN", "root-token")+ worker = isolated_profiles["worker_alpha"]+ params = {"profile": "worker_alpha"}+ assert _telegram(client.get("/api/messaging/platforms", params=params).json())["enabled"] is False+ (worker / ".env").write_text("TELEGRAM_BOT_TOKEN=worker-token\n", encoding="utf-8")+ payload = client.get("/api/messaging/platforms", params=params).json()+ assert _telegram(payload)["enabled"] is True+ assert _telegram(payload)["configured"] is True+ assert _telegram(payload)["state"] != "disabled"+ from hermes_cli.web_server_messaging import _messaging_platform_catalog+ empty = {entry["id"] for entry in _messaging_platform_catalog() if not entry["required_env"]}+ for platform in payload["platforms"]:+ if platform["id"] in empty:+ assert platform["enabled"] is False+ assert platform["configured"] is False+ for enabled in (False, True):+ (worker / "config.yaml").write_text(yaml.safe_dump({"platforms": {"telegram": {"enabled": enabled}}}), encoding="utf-8")+ platform = _telegram(client.get("/api/messaging/platforms", params=params).json())+ assert platform["enabled"] is enabled+ assert platform["configured"] is True+ assert "root-token" in (isolated_profiles["default"] / ".env").read_text(encoding="utf-8")diff --git a/tests/hermes_cli/test_web_server_scoped_enablement.py b/tests/hermes_cli/test_web_server_scoped_enablement.pydeleted file mode 100644index f976228eba8..00000000000--- a/tests/hermes_cli/test_web_server_scoped_enablement.py+++ /dev/null@@ -1,89 +0,0 @@-"""Regression tests for the scoped messaging enablement fix (#104619).--The scoped credential fallback must NOT report an empty-`required_env`-platform (whatsapp, api_server, webhook) as enabled when nothing-is configured. `all()` over an empty tuple would otherwise evaluate True.-"""--from hermes_cli.web_routers.messaging import _platform_enablement---def _entry(required_env=("DISCORD_BOT_TOKEN",)):- return {"required_env": required_env}---class TestScopedEmptyRequiredEnv:- def test_empty_required_env_with_no_config_is_NOT_enabled(self, monkeypatch):- monkeypatch.setattr(- "hermes_cli.web_routers.messaging.load_config", lambda: {}- )- enabled, configured, _ = _platform_enablement(- "whatsapp", _entry(required_env=()), {}, scoped=True- )- assert enabled is False-- def test_empty_required_env_with_explicit_enabled_false(self, monkeypatch):- monkeypatch.setattr(- "hermes_cli.web_routers.messaging.load_config",- lambda: {"platforms": {"whatsapp": {"enabled": False}}},- )- enabled, _, _ = _platform_enablement(- "whatsapp", _entry(required_env=()), {}, scoped=True- )- assert enabled is False-- def test_empty_required_env_with_explicit_enabled_true(self, monkeypatch):- monkeypatch.setattr(- "hermes_cli.web_routers.messaging.load_config",- lambda: {"platforms": {"whatsapp": {"enabled": True}}},- )- enabled, _, _ = _platform_enablement(- "whatsapp", _entry(required_env=()), {}, scoped=True- )- assert enabled is True---class TestScopedWithCredentials:- def test_env_credentials_alone_enable(self, monkeypatch):- monkeypatch.setattr(- "hermes_cli.web_routers.messaging.load_config", lambda: {}- )- enabled, configured, _ = _platform_enablement(- "discord", _entry(), {"DISCORD_BOT_TOKEN": "tok"}, scoped=True- )- assert enabled is True- assert configured is True-- def test_missing_credentials_stay_disabled(self, monkeypatch):- monkeypatch.setattr(- "hermes_cli.web_routers.messaging.load_config", lambda: {}- )- enabled, configured, _ = _platform_enablement(- "discord", _entry(), {}, scoped=True- )- assert enabled is False- assert configured is False---class TestScopedConfiguredField:- # `configured` came from the same `all()`-over-empty expression, so an- # empty-`required_env` platform with nothing set up also reported- # configured=True; it must stay False for that shape too.- def test_empty_required_env_configured_stays_false(self, monkeypatch):- monkeypatch.setattr(- "hermes_cli.web_routers.messaging.load_config", lambda: {}- )- enabled, configured, _ = _platform_enablement(- "whatsapp", _entry(required_env=()), {}, scoped=True- )- assert enabled is False- assert configured is False-- def test_credentials_report_configured_true(self, monkeypatch):- monkeypatch.setattr(- "hermes_cli.web_routers.messaging.load_config", lambda: {}- )- _, configured, _ = _platform_enablement(- "discord", _entry(), {"DISCORD_BOT_TOKEN": "tok"}, scoped=True- )- assert configured is Truediff --git a/website/docs/user-guide/messaging/index.md b/website/docs/user-guide/messaging/index.mdindex dcbb981f3c4..d86ccd169f7 100644--- a/website/docs/user-guide/messaging/index.md+++ b/website/docs/user-guide/messaging/index.md@@ -14,6 +14,20 @@ For the full voice feature set — including CLI microphone mode, spoken repliesBots need both a model provider and tool providers (TTS, web). A [Nous Portal](/integrations/nous-portal) subscription bundles all of them.:::+## Messaging status in Desktop and the dashboard++Messaging status belongs to the selected profile on the selected machine. Credentials+saved by `hermes gateway setup` can enable a credential-based platform without a+`platforms` entry in `config.yaml`; an explicit `platforms.<name>.enabled: false`+still disables it. A different profile never inherits the server process's credentials.+Platforms without required credential fields are not enabled merely because that list+is empty.++Naming the server's own profile explicitly (for example `profile=default` on a+default-profile server) gives the same status as an unscoped request. **Saved** means+credentials are stored, not that the messaging gateway is running or the platform is+connected. An enabled platform can correctly show **Messaging gateway stopped**.+## Platform Comparison| Platform | Voice | Images | Files | Threads | Reactions | Typing | Streaming |