fix(dashboard): reclassify profile=default as current when it resolves to the process home

The desktop app always sends profile=default on GET /api/messaging/platforms.
_is_current_profile() recognized only None/""/"current" as the dashboard's
own profile — NOT the string "default" — so a single-profile install (the
standard `hermes gateway setup` flow: token in .env, no platforms: section in
config.yaml) entered the profile-scoped branch of _config_profile_scope().
That branch derives platform enablement from config.yaml only and never calls
load_gateway_config()'s env-override pass (which enables the platform when the
token is in the environment). 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, state="connected".

Fix: classify by resolved path, not by string. After _is_current_profile()
fails, _config_profile_scope() now resolves the requested profile dir and
compares it against get_process_hermes_home().resolve() — the same comparison
_is_other_profile() already uses. When they match (profile=default on a
default-home process), yield None (no override), taking the unscoped path that
calls load_gateway_config(). A named-profile process (`-p worker`) has a
different HERMES_HOME, so its profile=default resolves to a different directory
and still scopes correctly — cross-profile secret isolation is preserved.

The scoped branch's config.yaml-only enablement is DELIBERATE:
load_gateway_config()'s env pass reads os.environ and would leak the root
install's tokens into a genuinely different profile's state. This fix only
reclassifies requests that name the process's OWN home; it does not touch the
scoped branch or gateway/config_env.py.

Refs #104614
This commit is contained in:
vectorcontext
2026-09-06 17:22:34 -07:00
committed by Teknium
parent 9098c9a65a
commit e24f07239f
2 changed files with 53 additions and 1 deletions
+13 -1
View File
@@ -233,11 +233,23 @@ def _config_profile_scope(profile: Optional[str]):
"""Await-safe, config-only profile scope: touches ONLY the task-local HERMES_HOME
contextvar, never the process-global skills-module attributes ``_profile_scope`` swaps
(holding those across an ``await`` lets a concurrent request restore THIS request's dir
on its ``finally``). None/""/"current" = no override."""
on 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.
"""
if _is_current_profile(profile):
yield None
return
profile_dir = _resolve_profile_dir(profile.strip())
if profile_dir.resolve() == get_process_hermes_home().resolve():
yield None
return
with _hermes_home_scope(profile_dir):
yield profile_dir
@@ -268,3 +268,43 @@ class TestMultiplexPortBindingGuard:
)
assert resp.status_code == 200
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