The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(left-core): singularity_in_use reads the managed .env, and process env only for the launch home
Teknium11dd594d0d9f
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.pyindex c084b88f8b3..9c4eeaaf544 100644--- a/hermes_cli/left_core_migration.py+++ b/hermes_cli/left_core_migration.py@@ -27,6 +27,7 @@ to deliver it.from __future__ import annotationsimport logging+import osfrom dataclasses import dataclassfrom pathlib import Pathfrom typing import Callable, Optional@@ -150,9 +151,12 @@ def langfuse_in_use(home: Path, *, process_env: bool = False) -> bool:def singularity_in_use(home: Path, *, process_env: bool = False) -> bool:"""What made core run its Singularity backend for *home*: ``terminal.backend`` (or the legacy``terminal.env_type``) set to ``singularity`` in its config (managed overlay applied, as the bridge- reads it), else ``TERMINAL_ENV=singularity`` in its ``.env``. config.yaml wins over ``.env``, as in- the bridge. *process_env* (the active home at startup only) also counts a ``TERMINAL_ENV`` the- process received from its environment (systemd unit, Docker, shell export)."""+ reads it), else ``TERMINAL_ENV=singularity`` from its dotenv layers in ``load_hermes_dotenv``'s order+ (the home's ``.env``, then the administrator-managed ``.env`` with override). config.yaml wins over+ both, as in the bridge. *process_env* (startup) also counts a ``TERMINAL_ENV`` the process received+ from its environment (systemd unit, Docker, shell export), for the launch home only: ``TERMINAL_*``+ is process-global (``get_secret`` never scopes it), so for any other served home it is the launch+ profile's backend, not this one's."""from gateway import config_loadertry:terminal = config_loader.read_yaml_layers(home).get("terminal")@@ -163,13 +167,13 @@ def singularity_in_use(home: Path, *, process_env: bool = False) -> bool:configured = str(terminal.get("backend") or terminal.get("env_type") or "").strip()if not configured:from agent.secret_scope import load_env_file- configured = str(load_env_file(home / ".env").get("TERMINAL_ENV") or "").strip()+ from hermes_cli.managed_scope import load_managed_env+ dotenv = {**load_env_file(home / ".env"), **load_managed_env()}+ configured = str(dotenv.get("TERMINAL_ENV") or "").strip()if not configured and process_env:- from agent.secret_scope import UnscopedSecretError, get_secret- try:- configured = str(get_secret("TERMINAL_ENV", "") or "").strip()- except UnscopedSecretError: # multiplexed with no profile scope bound: no process value is this home's- configured = ""+ from hermes_constants import get_routing_process_hermes_home, hermes_home_key+ if hermes_home_key(home) == hermes_home_key(get_routing_process_hermes_home()):+ configured = os.environ.get("TERMINAL_ENV", "").strip()return configured.lower() == "singularity"diff --git a/tests/hermes_cli/test_left_core_singularity.py b/tests/hermes_cli/test_left_core_singularity.pyindex dfab8205203..44e39fea118 100644--- a/tests/hermes_cli/test_left_core_singularity.py+++ b/tests/hermes_cli/test_left_core_singularity.py@@ -48,11 +48,28 @@ def test_singularity_in_use_is_the_configured_backend(tmp_path, env, config, in_assert lcm.singularity_in_use(_home(tmp_path, env=env, config=config)) is in_use-def test_process_env_backend_counts_only_for_the_active_home(tmp_path, monkeypatch):- home = _home(tmp_path)- monkeypatch.setenv("TERMINAL_ENV", "singularity")- assert lcm.singularity_in_use(home) is False- assert lcm.singularity_in_use(home, process_env=True) is True[email protected](("home_env", "managed_env", "in_use"), [+ ("TERMINAL_ENV=local\n", "TERMINAL_ENV=singularity\n", True),+ ("TERMINAL_ENV=singularity\n", "TERMINAL_ENV=local\n", False),+ ("", "TERMINAL_ENV=singularity\n", True),+])+def test_the_managed_env_beats_the_homes_env_as_in_load_hermes_dotenv(tmp_path, home_env, managed_env, in_use):+ # load_hermes_dotenv applies the administrator-managed .env last, with override.+ (tmp_path / "managed" / ".env").write_text(managed_env, encoding="utf-8")+ assert lcm.singularity_in_use(_home(tmp_path, env=home_env)) is in_use+++def test_process_env_backend_counts_only_for_the_launch_home(tmp_path, monkeypatch):+ launch = _home(tmp_path)+ secondary = tmp_path / "profiles" / "work"+ secondary.mkdir(parents=True)+ monkeypatch.setenv("HERMES_HOME", str(launch))+ monkeypatch.setenv("TERMINAL_ENV", "singularity") # the launch process's backend (systemd unit, export)+ assert lcm.singularity_in_use(launch) is False+ assert lcm.singularity_in_use(launch, process_env=True) is True+ # Gateway start runs the startup migration for every served home: a secondary with no backend of its+ # own runs `local`, whatever the launch process exported.+ assert lcm.singularity_in_use(secondary, process_env=True) is Falsedef test_a_singularity_home_gets_the_plugin_once(tmp_path):