fix: install-time config loads work from hermes_cli alone; upgrade probe tolerates extras

- load_config's safe-worker snapshot lookup returns None when the agent package is absent:
  main's installer completion step runs from a hermes_cli-only tree, and without agent there
  is no worker policy to consult. Other import failures still raise.
- The upgrade path's import probe skips a HEAD-added module whose missing import is an optional
  extra's SDK (acp_adapter.gateway_server needs acp); a stale finder misses the module itself.
This commit is contained in:
teknium1
2026-09-27 04:02:32 -07:00
parent 493bb4397d
commit d2b1b8989b
2 changed files with 20 additions and 12 deletions

View File

@@ -1938,10 +1938,21 @@ def _raw_config_cache_hit(path_key: str, cache_key: Tuple[Any, ...]) -> Optional
return None
def _read_raw_config_impl(*, want_deepcopy: bool) -> Dict[str, Any]:
from agent.safe_worker_policy import worker_config_snapshot
def _worker_config_snapshot() -> Optional[Dict[str, Any]]:
"""A safe worker's frozen config, or None. Install-time loads run from ``hermes_cli`` alone
(the installer's completion step ships no ``agent`` package), and without ``agent`` there
is no worker policy to consult."""
try:
from agent.safe_worker_policy import worker_config_snapshot
except ModuleNotFoundError as exc:
if exc.name != "agent":
raise
return None
return worker_config_snapshot()
snapshot = worker_config_snapshot()
def _read_raw_config_impl(*, want_deepcopy: bool) -> Dict[str, Any]:
snapshot = _worker_config_snapshot()
if snapshot is not None:
return snapshot
@@ -2024,9 +2035,7 @@ def require_readable_config_before_write(config_path: Optional[Path] = None) ->
non-mapping root — bare-``except`` loaders treat both as ``{}``, so a subsequent write would
replace the recoverable file with only the caller's partial dict. Fails closed."""
if config_path is None:
from agent.safe_worker_policy import worker_config_snapshot
snapshot = worker_config_snapshot()
snapshot = _worker_config_snapshot()
if snapshot is not None:
# A bypass worker's config IS its frozen snapshot; it never reads the profile file.
return copy.deepcopy(snapshot)
@@ -2297,9 +2306,7 @@ def _load_config_cache_hit(path_key: str, cache_sig: Any) -> Optional[Dict[str,
def _load_config_impl(*, want_deepcopy: bool) -> Dict[str, Any]:
from agent.safe_worker_policy import worker_config_snapshot
snapshot = worker_config_snapshot()
snapshot = _worker_config_snapshot()
if snapshot is not None:
return _deep_merge(copy.deepcopy(DEFAULT_CONFIG), snapshot)
@@ -2503,11 +2510,9 @@ def load_env() -> Dict[str, str]:
"""Load ~/.hermes/.env as a dict. Memoised inside ``load_env_file`` (``get_env_value()`` runs
hundreds of times per interactive menu render). Each assignment's value is opaque data for
boundary discovery."""
from agent.safe_worker_policy import worker_config_snapshot
# A frozen-policy worker never opens the profile's files; its secrets arrive
# through the owner-installed scope, so the .env layer is empty here.
if worker_config_snapshot() is not None:
if _worker_config_snapshot() is not None:
return {}
from agent.secret_scope import load_env_file # the one .env tokenizer; also installs profile scopes

View File

@@ -142,6 +142,9 @@ for name in tops + ["hermes_cli.main", "run_agent", "hermes_state"] + added:
try:
mod = importlib.import_module(name)
except BaseException as exc:
missing = (getattr(exc, "name", None) or "").split(".")[0]
if name in added and isinstance(exc, ModuleNotFoundError) and missing and missing not in tops:
continue # an optional extra's SDK (e.g. acp); a stale finder misses the module itself
bad.append(f"{name}: {type(exc).__name__}: {exc}")
continue
where = Path(getattr(mod, "__file__", None) or str(list(getattr(mod, "__path__", [""]))[0])).resolve()