From e7ac74aa121af1e721fb2b5f18a666aad02a4c65 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 23:38:11 -0700 Subject: [PATCH] =?UTF-8?q?refactor(hermes=5Fcli):=20relay=5Fshared=5Fmetr?= =?UTF-8?q?ics=20=E2=80=94=20single=20=5Fraw=5Fconfig()=20reader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../observability/relay_shared_metrics.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/hermes_cli/observability/relay_shared_metrics.py b/hermes_cli/observability/relay_shared_metrics.py index 27feb6a28a..265eccb71c 100644 --- a/hermes_cli/observability/relay_shared_metrics.py +++ b/hermes_cli/observability/relay_shared_metrics.py @@ -838,12 +838,23 @@ class _Runtime: return cls._guarded("Hermes shared metrics operation failed", callback, *args, **kwargs) +def _raw_config() -> dict[str, Any]: + """Read-only config snapshot (lazy import: tests patch ``hermes_cli.config``). + + Collection consent is profile-owned: managed overlays cannot opt a profile in or out. + The read-only path matters because this gate runs 2-3x per agent turn and the mutable + read_raw_config() paid a full config deepcopy on every call. + """ + from hermes_cli.config import read_raw_config_readonly + + return read_raw_config_readonly() or {} + + def _resolved_send_config(): """Resolve the opt-in send policy from the read-only config snapshot.""" - from hermes_cli.config import read_raw_config_readonly from hermes_cli.observability.shared_metrics_send_config import resolve_send_config - return resolve_send_config(read_raw_config_readonly() or {}) + return resolve_send_config(_raw_config()) def _reconcile_store_consent(store: SharedMetricsStore, send_enabled: bool) -> None: @@ -859,12 +870,7 @@ def enabled() -> bool: """Return the shared-metrics policy for the active Hermes profile.""" profile_key = relay_runtime.current_profile_key() try: - from hermes_cli.config import read_raw_config_readonly - - # Collection consent is profile-owned: managed overlays cannot opt a profile in or - # out. Read-only fast path — this gate runs 2-3x per agent turn and the mutable - # read_raw_config() paid a full config deepcopy on every call. - config = read_raw_config_readonly() or {} + config: Any = _raw_config() except Exception: logger.debug("Unable to read Hermes shared-metrics policy", exc_info=True) config = None