The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(telemetry): one cache_break row per cold read; opted-out enabled() skips the global lock (m1, m5)
teknium15c805d648f47
diff --git a/hermes_cli/observability/relay_shared_metrics.py b/hermes_cli/observability/relay_shared_metrics.pyindex 80265da96b2..72e6c2e8a43 100644--- a/hermes_cli/observability/relay_shared_metrics.py+++ b/hermes_cli/observability/relay_shared_metrics.py@@ -967,9 +967,10 @@ class _Runtime:return self._cold_expected.pop(key, False) is Nonedef record_known_cache_break(self, cause: str, route: dict[str, str], session_id: str) -> None:- """Hermes invalidated the prefix itself: count it, and don't recount the cold read it causes."""- self._announce_cold(self._cold_key(session_id))- self._emit_rows(None, [eff.cache_break_row(cause, route)])+ """Hermes invalidated the prefix itself: count it, and don't recount the cold read it causes.+ Several causes before one cold read are one break (the first cause names it)."""+ if self._announce_cold(self._cold_key(session_id)):+ self._emit_rows(None, [eff.cache_break_row(cause, route)])def record_session_tools(self, session_id: str, agent: Any, tools_for_api: list) -> None:session = self._session({"session_id": session_id}) if session_id else None@@ -1262,6 +1263,8 @@ def enabled() -> bool:config = config.get(key) if isinstance(config, dict) else Noneif isinstance(config, dict) and config.get("enabled") is True:return True+ if profile_key not in _RUNTIMES: # the opted-out hot path: nothing to tear down, no lock+ return Falsewith _RUNTIME_LOCK:runtime = _RUNTIMES.pop(profile_key, None)if isinstance(runtime, _Runtime):diff --git a/tests/hermes_cli/test_shared_metrics_efficiency.py b/tests/hermes_cli/test_shared_metrics_efficiency.pyindex e4cd5844955..46e8c9b71bd 100644--- a/tests/hermes_cli/test_shared_metrics_efficiency.py+++ b/tests/hermes_cli/test_shared_metrics_efficiency.py@@ -163,6 +163,16 @@ def test_tool_overhead_and_unused_toolsets_report_once_per_conversation(direct_rassert "acme" not in json.dumps(_stored_values(tmp_path, "hermes.tool_enabled_unused.count"))+def test_several_known_causes_before_one_cold_read_are_one_break(direct_runtime, tmp_path):+ agent = _agent()+ _turn("s1", "t1", {"completed": True}, calls=[_usage(9_000, cache_read=8_000)])+ eff.record_cache_break(agent, "compression")+ eff.record_cache_break(agent, "compression")+ eff.record_cache_break(agent, "model_switch")+ _turn("s1", "t2", {"completed": True}, calls=[_usage(9_000, cache_read=0)])+ assert _rows(tmp_path, "hermes.cache_break.count") == [(_dims(**ROUTE, cause="compression"), 1)]++def test_cache_breaks_count_known_causes_once_and_unannounced_cold_reads_as_misses(direct_runtime, tmp_path,monkeypatch):agent = _agent()