The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(honcho): hold the refresh locks while save_config rewrites honcho.json
Erosika36c98cb5ebb9
diff --git a/plugins/memory/honcho/__init__.py b/plugins/memory/honcho/__init__.pyindex f30b2c3a0d7..dfd82e766ed 100644--- a/plugins/memory/honcho/__init__.py+++ b/plugins/memory/honcho/__init__.py@@ -166,13 +166,15 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):return Falsedef save_config(self, values, hermes_home):- """Merge ``values`` into $HERMES_HOME/honcho.json (Honcho SDK native format); a file that does not parse raises."""+ """Merge ``values`` into $HERMES_HOME/honcho.json (Honcho SDK native format); a file that does not parse raises.+ Holds the token refresh locks so a rotation cannot land between the read and the write."""from pathlib import Pathfrom utils import atomic_json_write- from plugins.memory.honcho.oauth import _read_config_strict+ from plugins.memory.honcho.oauth import _config_refresh_lock, _read_config_strict, _refresh_lockconfig_path = Path(hermes_home) / "honcho.json"- existing = _read_config_strict(config_path)- atomic_json_write(config_path, {**existing, **values}, mode=0o600)+ with _refresh_lock, _config_refresh_lock(config_path):+ existing = _read_config_strict(config_path)+ atomic_json_write(config_path, {**existing, **values}, mode=0o600)def get_config_schema(self):return [diff --git a/tests/test_honcho_client_config.py b/tests/test_honcho_client_config.pyindex 38301f8e9c2..695da505dee 100644--- a/tests/test_honcho_client_config.py+++ b/tests/test_honcho_client_config.py@@ -221,3 +221,36 @@ def test_save_config_merges_into_a_parseable_file(tmp_path):HonchoMemoryProvider().save_config({"api_key": "hc-test-key"}, str(tmp_path))data = json.loads(config_path.read_text())assert data["hosts"]["other"]["apiKey"] == "keep-me" and data["api_key"] == "hc-test-key"+++def test_save_config_holds_the_refresh_locks_so_a_rotation_survives(tmp_path, monkeypatch):+ """A refresh thread that wants the locks while save_config reads must land after its write, not under it."""+ import threading+ from plugins.memory.honcho import oauth+ config_path = tmp_path / "honcho.json"+ config_path.write_text(json.dumps({"hosts": {"hermes": {"apiKey": "hch-at-old", "oauth": {"refreshToken": "hch-rt-old"}}}}))+ rotated = oauth.OAuthCredential("hch-at-new", "hch-rt-new", 10_000, "hermes-desktop", "http://localhost:8000/oauth/token")+ save_read, rotation_done = threading.Event(), threading.Event()+ real_read = oauth._read_config_strict++ def read_then_wait(path):+ raw = real_read(path)+ if not save_read.is_set():+ save_read.set()+ rotation_done.wait(0.5) # the refresh gets this window; only a held lock keeps it out+ return raw++ def rotate():+ save_read.wait(2)+ with oauth._refresh_lock, oauth._config_refresh_lock(config_path):+ oauth._persist_credential(config_path, "hermes", rotated)+ rotation_done.set()++ monkeypatch.setattr(oauth, "_read_config_strict", read_then_wait)+ thread = threading.Thread(target=rotate)+ thread.start()+ HonchoMemoryProvider().save_config({"logging": True}, str(tmp_path))+ thread.join(2)+ assert rotation_done.is_set()+ data = json.loads(config_path.read_text())+ assert data["hosts"]["hermes"]["apiKey"] == "hch-at-new" and data["logging"] is True