The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(moa): keep explicit preset names authoritative on load
Tharaneed2c96d4ffb0d
diff --git a/hermes_cli/config.py b/hermes_cli/config.pyindex 4b839755a9c..aba0da380a9 100644--- a/hermes_cli/config.py+++ b/hermes_cli/config.py@@ -1878,6 +1878,26 @@ def _canonicalize_config(config: Dict[str, Any]) -> Dict[str, Any]:return _normalize_root_model_keys(_normalize_max_turns_config(config))+def _apply_user_moa_presets(merged: Dict[str, Any], raw: Dict[str, Any]) -> None:+ """Treat an explicit user MoA preset map as authoritative.++ ``moa.presets`` is a named map. Generic default merging must not union the+ schema's built-in names into a user map, because that resurrects presets+ the user deleted. An omitted ``moa.presets`` key still receives defaults;+ an explicit empty map remains empty.+ """+ raw_moa = raw.get("moa") if isinstance(raw, dict) else None+ if not isinstance(raw_moa, dict) or "presets" not in raw_moa:+ return+ raw_presets = raw_moa.get("presets")+ if not isinstance(raw_presets, dict):+ return+ merged_moa = merged.get("moa")+ if not isinstance(merged_moa, dict):+ return+ merged_moa["presets"] = copy.deepcopy(raw_presets)++# Sentinel for an unlimited turn budget. ``sys.maxsize`` survives the str->int round-trip through# the HERMES_MAX_ITERATIONS env bridge, works in every ``<``/``>=``/``max - used`` comparison in# the iteration budget without an "unlimited" special case, and is unreachable in practice.@@ -2292,7 +2312,9 @@ def _last_known_good_fallback(config_path: Path, path_key: str, cache_sig, exc:from hermes_cli.config_backups import load_newest_good_backupraw_good = load_newest_good_backup(config_path)if raw_good is not None:- normalized = _canonicalize_config(_deep_merge(copy.deepcopy(DEFAULT_CONFIG), raw_good))+ merged_good = _deep_merge(copy.deepcopy(DEFAULT_CONFIG), raw_good)+ _apply_user_moa_presets(merged_good, raw_good)+ normalized = _canonicalize_config(merged_good)expanded_good: Dict[str, Any] = _expand_env_vars(normalized) # type: ignore[assignment]lkg, _ = _merge_managed_overlay(expanded_good)fallback = "last-known-good-backup"@@ -2399,6 +2421,7 @@ def _load_config_impl(*, want_deepcopy: bool) -> Dict[str, Any]:user_config.pop("max_turns", None)config = _deep_merge(config, user_config)+ _apply_user_moa_presets(config, user_config)# A copy of the file that just parsed is what a FRESH process falls back to when the# next edit breaks the YAML (see _last_known_good_fallback). backup_config() skips# byte-identical repeats and keeps a bounded count, so steady-state loads cost one stat.diff --git a/tests/hermes_cli/test_moa_preset_deletion.py b/tests/hermes_cli/test_moa_preset_deletion.pyindex ffc914ad89c..235c9b97313 100644--- a/tests/hermes_cli/test_moa_preset_deletion.py+++ b/tests/hermes_cli/test_moa_preset_deletion.py@@ -14,6 +14,12 @@ merge that caused the bug.from __future__ import annotations+import json+import os+import subprocess+import sys+from pathlib import Path+import yamlfrom hermes_cli.web_models import MoaConfigPayload, MoaModelSlot, MoaPresetPayload@@ -128,6 +134,61 @@ def test_adding_a_preset_still_works(tmp_path, monkeypatch):assert presets["fresh"]["reference_models"][0]["model"] == "gpt-5.9"+def test_named_map_does_not_receive_schema_default_on_load(tmp_path, monkeypatch):+ """An explicit named map owns its names; loader defaults must not add ``default``."""+ home = tmp_path / ".hermes"+ home.mkdir()+ _seed(home, monkeypatch, _three_presets())++ from hermes_cli.config import load_config++ loaded = load_config()+ assert set(loaded["moa"]["presets"]) == {"keep_a", "doomed", "keep_b"}+++def test_named_map_stays_authoritative_in_a_fresh_process_and_backup_fallback(tmp_path, monkeypatch):+ """A restart and last-known-good fallback must not reinsert the schema ``default``."""+ home = tmp_path / ".hermes"+ home.mkdir()+ _seed(home, monkeypatch, _three_presets())++ from hermes_cli.config import load_config++ # The first valid load creates the real ``good`` backup used by a fresh process.+ assert set(load_config()["moa"]["presets"]) == {"keep_a", "doomed", "keep_b"}+ (home / "config.yaml").write_text("moa: [unterminated\n", encoding="utf-8")++ probe = (+ "import json; from hermes_cli.config import load_config; "+ "print(json.dumps(sorted(load_config()['moa']['presets'])))"+ )+ result = subprocess.run(+ [sys.executable, "-B", "-c", probe],+ cwd=__import__("pathlib").Path(__file__).resolve().parents[2],+ env={**os.environ, "HERMES_HOME": str(home)},+ capture_output=True,+ text=True,+ check=True,+ timeout=30,+ )+ assert json.loads(result.stdout.splitlines()[-1]) == ["doomed", "keep_a", "keep_b"]+++def test_missing_moa_map_still_receives_schema_defaults(tmp_path, monkeypatch):+ """Without a user MoA map, the built-in default remains available."""+ home = tmp_path / ".hermes"+ home.mkdir()+ monkeypatch.setenv("HERMES_HOME", str(home))+ (home / "config.yaml").write_text("model: {}\n", encoding="utf-8")++ from hermes_cli.config import DEFAULT_CONFIG, load_config+ from hermes_cli.moa_config import normalize_moa_config++ actual = normalize_moa_config(load_config()["moa"])+ expected = normalize_moa_config(DEFAULT_CONFIG["moa"])+ assert actual == expected++def test_deletion_preserves_privacy_filter_and_retained_preset_metadata(tmp_path, monkeypatch):"""A MoA edit must not reset an undeclared privacy policy or metadata."""home = tmp_path / ".hermes"