The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(plugins): drop the redundant hook-timeout memo
kshitijk4poorb3f118fa62f6
diff --git a/hermes_cli/plugins.py b/hermes_cli/plugins.pyindex 8e7eb7911dd..63b180025ae 100644--- a/hermes_cli/plugins.py+++ b/hermes_cli/plugins.py@@ -1131,45 +1131,15 @@ for _name, _method in list(vars(PluginContext).items()):del _name, _method-# Keyed by the scope-resolved config path (like `_LOAD_CONFIG_CACHE`) so multiplexed profiles do not-# evict each other. Each value is ONE `(sig, value)` tuple stored with a single dict item assignment-# (atomic under the GIL), so a lock-free reader can never observe a new sig paired with an old value.-_HOOK_TIMEOUT_CACHE: Dict[str, Tuple[Any, float]] = {}--def _resolve_hook_callback_timeout() -> float:"""Effective hook-callback timeout from ``plugins.hook_callback_timeout`` (default 30s; ``<= 0``disables the threaded path; clamped to ``_MAX_HOOK_CALLBACK_TIMEOUT_SECS``).- Memoized on the config file's cache signature. ``invoke_hook`` calls this- once per hook invocation, and a gateway fires hooks on every inbound- message — so this was a full config read per message, on the event loop.- The value only changes when config.yaml does; every other call is a dict- lookup.+ ``invoke_hook`` calls this once per hook invocation; ``load_config_readonly()`` serves cache hits+ without ``_CONFIG_LOCK``, so this is a stat + dict lookup per call and needs no memo of its own."""- try:- from hermes_cli.config import _load_config_cache_sig, get_config_path- config_path = get_config_path()- path_key = str(config_path)- _, sig = _load_config_cache_sig(config_path)- except Exception:- path_key, sig = "", None-- cached = _HOOK_TIMEOUT_CACHE.get(path_key) # one read of the published tuple- if cached is not None and sig is not None and cached[0] == sig:- return cached[1]-- resolved = _resolve_hook_callback_timeout_uncached()- if sig is not None:- _HOOK_TIMEOUT_CACHE[path_key] = (sig, resolved)- return resolved---def _resolve_hook_callback_timeout_uncached() -> float:- """Read + validate ``plugins.hook_callback_timeout``; see the memoized wrapper above."""default = _HOOK_CALLBACK_TIMEOUT_SECStry:- from hermes_cli.config import load_config_readonlyplugins_cfg = (load_config_readonly() or {}).get("plugins")if not isinstance(plugins_cfg, dict) or plugins_cfg.get("hook_callback_timeout") is None:return defaultdiff --git a/tests/hermes_cli/test_config_lock_free_cache_hit.py b/tests/hermes_cli/test_config_lock_free_cache_hit.pyindex 0ab1bfa0587..3ba7bb9ba11 100644--- a/tests/hermes_cli/test_config_lock_free_cache_hit.py+++ b/tests/hermes_cli/test_config_lock_free_cache_hit.py@@ -45,11 +45,6 @@ def config_home(tmp_path, monkeypatch):cfgmod._RAW_CONFIG_CACHE.clear()-def _bump_mtime(path):- st = path.stat()- os.utime(path, ns=(st.st_atime_ns, st.st_mtime_ns + 1_000_000))--def _time_cached_read_under_held_lock(reader):"""Prime ``reader`` (lock-free), then time one more call while another thread holds``_CONFIG_LOCK``. Returns ``(result, elapsed_seconds)``."""@@ -101,35 +96,3 @@ def test_cached_raw_read_completes_while_another_thread_holds_the_config_lock(cof"a cached read_raw_config_readonly() blocked {elapsed:.1f}s behind a held ""_CONFIG_LOCK; cache hits must not serialize against config writers")---def test_hook_timeout_memo_never_pairs_a_new_sig_with_an_old_value(config_home):- """The memo is published as ONE ``(sig, value)`` tuple: with a writer thread flipping the config- between two timeouts, every lock-free read must see sig and value from the SAME publish."""- from hermes_cli import plugins as pluginsmod- from hermes_cli.config import _load_config_cache_sig, get_config_path-- def write(v):- (config_home / "config.yaml").write_text(f"plugins:\n hook_callback_timeout: {v}\n", encoding="utf-8")- _bump_mtime(get_config_path())- return pluginsmod._resolve_hook_callback_timeout(), _load_config_cache_sig(get_config_path())[1]-- sig_of = {}- for v in (5, 7):- value, sig = write(v)- assert value == float(v)- sig_of[sig] = value- stop = threading.Event()-- def writer():- while not stop.is_set():- write(5); write(7)-- t = threading.Thread(target=writer, daemon=True); t.start()- try:- for _ in range(2000):- for sig, value in list(pluginsmod._HOOK_TIMEOUT_CACHE.values()):- if sig in sig_of:- assert sig_of[sig] == value, "memo published a new sig with a stale value"- finally:- stop.set(); t.join(timeout=5)