The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(moa): preserve privacy and retained preset metadata
Tharanee4133dfad2654
diff --git a/hermes_cli/web_routers/models.py b/hermes_cli/web_routers/models.pyindex 53f917f6702..f9c0390652e 100644--- a/hermes_cli/web_routers/models.py+++ b/hermes_cli/web_routers/models.py@@ -327,19 +327,28 @@ def set_moa_models(body: MoaConfigPayload, profile: Optional[str] = None):problems = validate_moa_payload(raw)if problems:raise HTTPException(status_code=422, detail="Invalid MoA config: " + "; ".join(problems))- normalized = normalize_moa_config(raw)# Read the raw profile file because the effective config contains defaults and# ``merge_existing=True`` deep-merges dicts, which resurrects omitted preset names.# Keep unknown MoA keys and sibling sections by rebuilding only the MoA section on# the raw document, while treating the submitted named map as authoritative.raw_cfg = read_raw_config()- moa_section = dict(raw_cfg.get("moa") or {})- moa_section.update(normalized)+ existing_moa = raw_cfg.get("moa")+ if isinstance(existing_moa, dict) and "privacy_filter" in existing_moa:+ # ``privacy_filter`` is emitted by the normalizer but is not declared by+ # MoaConfigPayload; an editor round-trip must not reset it.+ raw["privacy_filter"] = existing_moa["privacy_filter"]+ normalized = normalize_moa_config(raw)+ from hermes_cli import config as config_mod+ updated = config_mod._merge_partial_save(raw_cfg, {"moa": normalized})if body.presets:- moa_section["presets"] = normalized["presets"]- raw_cfg["moa"] = moa_section- save_config(raw_cfg)+ # ``_merge_partial_save`` retains undeclared metadata on surviving presets;+ # filter after that merge so omitted names are authoritative deletions.+ merged_presets = updated["moa"]["presets"]+ updated["moa"]["presets"] = {+ name: merged_presets[name] for name in normalized["presets"]+ }+ save_config(updated)return {"ok": True, **normalized}diff --git a/tests/hermes_cli/test_moa_preset_deletion.py b/tests/hermes_cli/test_moa_preset_deletion.pyindex b3fd320db20..ffc914ad89c 100644--- a/tests/hermes_cli/test_moa_preset_deletion.py+++ b/tests/hermes_cli/test_moa_preset_deletion.py@@ -126,3 +126,32 @@ def test_adding_a_preset_still_works(tmp_path, monkeypatch):presets = _on_disk(home)["moa"]["presets"]assert set(presets) == {"keep_a", "doomed", "keep_b", "fresh"}assert presets["fresh"]["reference_models"][0]["model"] == "gpt-5.9"+++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"+ home.mkdir()+ moa = _three_presets()+ moa.update(+ privacy_filter="full",+ save_traces=True,+ trace_dir="/custom/traces",+ presets={**moa["presets"], "keep_a": {**moa["presets"]["keep_a"], "operator_note": "retain me"}},+ )+ _seed(home, monkeypatch, moa)++ set_moa_models(+ MoaConfigPayload(+ default_preset="keep_a",+ active_preset="",+ presets={"keep_a": _preset("gpt-5.5"), "keep_b": _preset("gpt-5.7")},+ )+ )++ on_disk = _on_disk(home)["moa"]+ assert "doomed" not in on_disk["presets"]+ assert on_disk["privacy_filter"] == "full"+ assert on_disk["save_traces"] is True+ assert on_disk["trace_dir"] == "/custom/traces"+ assert on_disk["presets"]["keep_a"]["operator_note"] == "retain me"