The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(telemetry): latch a failed-connect episode only when it was recorded, per real adapter
Teknium19b57f11d6ee
diff --git a/hermes_cli/observability/shared_metrics_gateway.py b/hermes_cli/observability/shared_metrics_gateway.pyindex 16f33c1c0c0..2f1bd40ec94 100644--- a/hermes_cli/observability/shared_metrics_gateway.py+++ b/hermes_cli/observability/shared_metrics_gateway.py@@ -194,9 +194,15 @@ _failing_connects: dict[tuple[str, str], str] = {}def _record_connect(platform: Any, event: str, *, exc: BaseException | None, fatal_code: Any, terminal: bool) -> None:from hermes_constants import get_hermes_home- key, day = (str(get_hermes_home()), _platform(platform)), datetime.now(timezone.utc).date().isoformat()+ from .relay_shared_metrics import enabled++ # Keyed by the real adapter (two custom adapters both emit "plugin"); projected only at emission.+ key = (str(get_hermes_home()), str(getattr(platform, "value", platform)))+ day = datetime.now(timezone.utc).date().isoformat()if event != "connect_failed" or terminal:counted = _failing_connects.pop(key, None) == day+ elif not enabled(): # nothing is recorded, so nothing is latched: opting in mid-outage counts it+ returnelse:counted = _failing_connects.get(key) == day_failing_connects[key] = daydiff --git a/tests/gateway/test_platform_shared_metrics.py b/tests/gateway/test_platform_shared_metrics.pyindex 44ee2780653..0ba4b2dc507 100644--- a/tests/gateway/test_platform_shared_metrics.py+++ b/tests/gateway/test_platform_shared_metrics.py@@ -84,9 +84,13 @@ def test_every_connect_attempt_records_one_health_row_with_a_closed_error_class(]-def test_a_reconnect_backoff_loop_is_one_failed_connect_until_it_recovers(rows):+def test_a_reconnect_backoff_loop_is_one_failed_connect_until_it_recovers(rows, monkeypatch):outage = ConnectionResetError("network down")- assert _connect(_Adapter(connect=outage)) == "ConnectionResetError" # cold start+ monkeypatch.setattr(rsm, "enabled", lambda: False) # collection off: nothing recorded, so nothing latched+ assert _connect(_Adapter(connect=outage)) == "ConnectionResetError"+ smg.drain()+ monkeypatch.setattr(rsm, "enabled", lambda: True)+ assert _connect(_Adapter(connect=outage)) == "ConnectionResetError" # opted in mid-outage: countsfor _ in range(5): # the watcher's backoff retries during the same outageassert _connect(_Adapter(connect=outage), is_reconnect=True) == "ConnectionResetError"assert _connect(_Adapter(platform=Platform.DISCORD, connect=outage)) == "ConnectionResetError"@@ -95,9 +99,13 @@ def test_a_reconnect_backoff_loop_is_one_failed_connect_until_it_recovers(rows):smg.drain()smg._failing_connects.update(dict.fromkeys(smg._failing_connects, "2000-01-01")) # ...still down a day laterassert _connect(_Adapter(connect=outage), is_reconnect=True) == "ConnectionResetError"+ # Two custom adapters both emit "plugin" but are separate outages: beta's recovery leaves alpha's open.+ for name, result in (("alpha", outage), ("beta", outage), ("beta", True), ("alpha", outage)):+ _connect(_Adapter(platform=name, connect=result), is_reconnect=True)assert [(r["event"], r["platform"]) for r in rows("hermes.platform.health")] == [("connect_failed", "telegram"), ("connect_failed", "discord"),("reconnect", "telegram"), ("connect_failed", "telegram"), ("connect_failed", "telegram"),+ ("connect_failed", "plugin"), ("connect_failed", "plugin"), ("reconnect", "plugin"),]diff --git a/website/docs/developer-guide/relay-shared-metrics.md b/website/docs/developer-guide/relay-shared-metrics.mdindex 414c5c8f9f0..6b6e3e7f079 100644--- a/website/docs/developer-guide/relay-shared-metrics.md+++ b/website/docs/developer-guide/relay-shared-metrics.md@@ -348,7 +348,7 @@ itself ships.| `hermes.curator.run.count` | trigger (`scheduled`/`manual`), outcome (`success`/`failed`/`skipped`), archived/merged/patched/created buckets | Does the skill curator run, and does it actually consolidate anything. Dry runs report `skipped`; a scheduled check that finds another process already running the pass records nothing. Never skill names. || `hermes.delegation.run.count` | subagent-count bucket, depth (`1`–`3`, `gte_4`), mode (`foreground`/`background`), outcome (`success`/`partial`/`failed`/`cancelled`) | How wide and deep delegate_task fan-outs go and how often every child finishes. One row per call, however many completion units it splits into. || `hermes.execution_backend.count` | kind (`terminal`/`browser`/`code`), backend, outcome, error class | Which sandboxes carry real work and how reliable each is. Terminal backends are the `terminal.backend` values (else `other`); browser backends are `local`, `lightpanda`, `cdp`, `camofox`, `extension` or a bundled cloud provider (else `other`); execute_code is `local` or `remote`. A command's own nonzero exit is still a backend success, but a foreground command that hits its timeout is `failed`/`timeout`; terminal and execute_code calls a guard refuses before they reach the backend, Hermes' own listings for TUI/Desktop path completion, and calls made by the background review and curator forks are not counted. |-| `hermes.platform.health` | platform, event (`connect_ok`/`connect_failed`/`reconnect`/`disconnect`), error class (`auth`/`network`/`rate_limited`/`config`/`other`) | Which messaging platforms fail to connect or drop, and why. Classified from exception types, HTTP statuses and Hermes's own fatal codes, never error text. |+| `hermes.platform.health` | platform, event (`connect_ok`/`connect_failed`/`reconnect`/`disconnect`), error class (`auth`/`network`/`rate_limited`/`config`/`other`) | Which messaging platforms fail to connect or drop, and why. `connect_failed` counts a failed-connect episode once per profile, platform and UTC day (the reconnect watcher's retries are not new rows; the next success ends the episode, and a platform still failing the next day counts again), with the error class of the episode's first failure. Classified from exception types, HTTP statuses and Hermes's own fatal codes, never error text. || `hermes.platform.delivery` | platform, outcome (`sent`/`failed`), failure class (`rate_limited`/`too_long`/`auth`/`network`/`forbidden`/`other`) | How often replies fail to reach the user per platform (one count per logical reply, retries included). || `hermes.gateway.reply_latency` | platform, first-response bucket (`lt_2s` … `gte_60s`) | Time from an accepted inbound message to the first visible reply text (stream first chunk or final message). || `hermes.cron.run` | outcome (`success`/`failed`/`missed`/`skipped`), delivery kind (`local`/`platform`/`webhook`/`none`/`other`), duration bucket | Do scheduled jobs run, fail, get skipped by a gate or overlap, or get missed while Hermes was down. Job names, prompts, schedules and targets are never included. |