Skip to content

The agent that grows with you

fix(local-runtime): machine-scope the runtime — profiles share the engine, models, and server

emozilla82ec5dc419c4
diff --git a/hermes_cli/local_runtime/binaries.py b/hermes_cli/local_runtime/binaries.py
index cfe8b6f089e..d442ef80b60 100644
--- a/hermes_cli/local_runtime/binaries.py
+++ b/hermes_cli/local_runtime/binaries.py
@@ -67,7 +67,15 @@ class AssetPlan:
def runtimes_root() -> Path:
- return get_hermes_home() / "runtimes" / "llamacpp"
+ """Machine-scoped, deliberately NOT profile-scoped. Engine binaries,
+ presets, and server state describe this machine's hardware and its one
+ managed server (stable port) — a second profile re-downloading the
+ engine or fighting over the port would be the bug. Profile-scoped
+ things (which model is the default, enabled) live in each profile's
+ config.yaml as ever."""
+ from hermes_constants import get_default_hermes_root
+
+ return get_default_hermes_root() / "runtimes" / "llamacpp"
def installed_tags() -> list[str]:
diff --git a/hermes_cli/local_runtime/bootstrap.py b/hermes_cli/local_runtime/bootstrap.py
index bd0a0f5e36b..77eb1fc8a93 100644
--- a/hermes_cli/local_runtime/bootstrap.py
+++ b/hermes_cli/local_runtime/bootstrap.py
@@ -18,7 +18,9 @@ import subprocess
import time
from pathlib import Path
-from hermes_constants import get_hermes_home
+from hermes_constants import get_hermes_home # noqa: F401 — config paths
+
+from hermes_cli.local_runtime.binaries import runtimes_root
logger = logging.getLogger(__name__)
@@ -40,7 +42,12 @@ def _detect_gpu_vendor() -> str | None:
def models_dir() -> Path:
- return get_hermes_home() / "models"
+ """Machine-scoped, deliberately NOT profile-scoped: a 20 GB GGUF is a
+ machine asset, and every profile shares the one managed server that
+ serves it. See runtimes_root() for the same rule on the engine."""
+ from hermes_constants import get_default_hermes_root
+
+ return get_default_hermes_root() / "models"
def assets_dir() -> Path:
@@ -211,7 +218,7 @@ def ensure_local_runtime(config: dict, force: bool = False) -> "object | None":
# is freed before the new instance loads anything. Pricing against
# live-free here once pinned a fitting model's weights to CPU
# because the probe saw the predecessor's VRAM as gone.
- preset_path = get_hermes_home() / "runtimes" / "llamacpp" / "presets.ini"
+ preset_path = runtimes_root() / "presets.ini"
try:
entries = generate_presets(mdir, probe_budget(planning=True), preset_path)
for entry in entries:
diff --git a/hermes_cli/local_runtime/growth.py b/hermes_cli/local_runtime/growth.py
index a83001141c6..484f2ff9f50 100644
--- a/hermes_cli/local_runtime/growth.py
+++ b/hermes_cli/local_runtime/growth.py
@@ -22,13 +22,13 @@ from __future__ import annotations
import json
import logging
-from hermes_constants import get_hermes_home
-
logger = logging.getLogger(__name__)
def window_overrides_path():
- return get_hermes_home() / "runtimes" / "llamacpp" / "window_overrides.json"
+ from hermes_cli.local_runtime.binaries import runtimes_root
+
+ return runtimes_root() / "window_overrides.json"
def load_window_overrides() -> dict:
diff --git a/hermes_cli/local_runtime/presets.py b/hermes_cli/local_runtime/presets.py
index 1b7031b731b..6bd7f507abf 100644
--- a/hermes_cli/local_runtime/presets.py
+++ b/hermes_cli/local_runtime/presets.py
@@ -168,9 +168,9 @@ def read_preset_decisions(preset_path: Path | None = None) -> dict[str, PresetEn
import configparser
if preset_path is None:
- from hermes_constants import get_hermes_home
+ from hermes_cli.local_runtime.binaries import runtimes_root
- preset_path = get_hermes_home() / "runtimes" / "llamacpp" / "presets.ini"
+ preset_path = runtimes_root() / "presets.ini"
out: dict[str, PresetEntry] = {}
try:
parser = configparser.ConfigParser()
diff --git a/tests/hermes_cli/test_runtime_machine_scope.py b/tests/hermes_cli/test_runtime_machine_scope.py
new file mode 100644
index 00000000000..d58edebaec9
--- /dev/null
+++ b/tests/hermes_cli/test_runtime_machine_scope.py
@@ -0,0 +1,82 @@
+"""The managed runtime is machine-scoped, not profile-scoped.
+
+Engine binaries, models, presets, and server state are machine assets: a
+second profile must reuse them, never re-download 20 GB of GGUFs or fight
+the running server for its port. Profile-scoped decisions (default model,
+enabled flag) stay in each profile's config.yaml."""
+
+from __future__ import annotations
+
+import importlib
+
+import pytest
+
+
+def profile_home(tmp_path, monkeypatch):
+ """A NAMED-profile HERMES_HOME under <root>/profiles/<name>."""
+ root = tmp_path / ".hermes"
+ profile = root / "profiles" / "coder"
+ profile.mkdir(parents=True)
+ monkeypatch.setenv("HERMES_HOME", str(profile))
+ # hermes_constants memoizes root resolution per (native, env) pair;
+ # reload to make the new env authoritative for this test.
+ import hermes_constants
+
+ importlib.reload(hermes_constants)
+ yield root, profile
+ importlib.reload(hermes_constants)
+
+
+def test_models_and_runtimes_resolve_to_the_shared_root(profile_home):
+ root, profile = profile_home
+ import hermes_cli.local_runtime.binaries as binaries
+ import hermes_cli.local_runtime.bootstrap as bootstrap
+
+ models = bootstrap.models_dir()
+ runtimes = binaries.runtimes_root()
+
+ assert models == root / "models", (
+ f"models dir leaked into the profile: {models}")
+ assert runtimes == root / "runtimes" / "llamacpp", (
+ f"runtimes dir leaked into the profile: {runtimes}")
+ assert "profiles" not in models.parts
+ assert "profiles" not in runtimes.parts
+
+
+def test_all_runtime_state_follows_runtimes_root(profile_home):
+ """Presets, window overrides, server state, and the api key all live
+ under runtimes_root() — one resolver, so profile-scoping bugs cannot
+ come back one file at a time."""
+ root, profile = profile_home
+ from hermes_cli.local_runtime.growth import window_overrides_path
+ from hermes_cli.local_runtime.presets import read_preset_decisions
+ import hermes_cli.local_runtime.binaries as binaries
+
+ shared = root / "runtimes" / "llamacpp"
+ assert window_overrides_path() == shared / "window_overrides.json"
+ # read_preset_decisions' default path must be the shared INI: write a
+ # section there and read it back through the default-path branch.
+ shared.mkdir(parents=True, exist_ok=True)
+ (shared / "presets.ini").write_text("[m1]\nctx-size = 65536\n",
+ encoding="utf-8")
+ assert "m1" in read_preset_decisions()
+
+
+def test_default_profile_paths_unchanged(tmp_path, monkeypatch):
+ """HERMES_HOME at the root itself (default profile) resolves exactly
+ as before the scoping change — no migration for existing installs."""
+ root = tmp_path / ".hermes"
+ root.mkdir()
+ monkeypatch.setenv("HERMES_HOME", str(root))
+ import hermes_constants
+
+ importlib.reload(hermes_constants)
+ try:
+ import hermes_cli.local_runtime.binaries as binaries
+ import hermes_cli.local_runtime.bootstrap as bootstrap
+
+ assert bootstrap.models_dir() == root / "models"
+ assert binaries.runtimes_root() == root / "runtimes" / "llamacpp"
+ finally:
+ importlib.reload(hermes_constants)