Skip to content

The agent that grows with you

fix(telemetry): relay-stamped turns are gateway messages; a multi-platform connector's unknown chat stays `relay` (M5 part, m9)

teknium18dfdc46067c7
diff --git a/gateway/relay/adapter.py b/gateway/relay/adapter.py
index 2dfa6099c01..d3972923be8 100644
--- a/gateway/relay/adapter.py
+++ b/gateway/relay/adapter.py
@@ -228,6 +228,12 @@ class RelayAdapter(BasePlatformAdapter):
"""The chat's underlying platform as seen inbound, else the primary's."""
return self._platform_by_chat.get(str(chat_id)) or self.descriptor.platform
+ def _metrics_platform(self, chat_id: str) -> Optional[str]:
+ """The platform a chat's shared metrics carry: the inbound's, else the primary's only when this
+ socket fronts one platform (a multi-platform connector's unknown chat stays unlabelled)."""
+ fronted = {p for p, _ in (getattr(self._transport, "_identities", None) or ())}
+ return self._platform_by_chat.get(str(chat_id)) or (self.descriptor.platform if len(fronted) <= 1 else None)
+
def warning_notifications_enabled(self, logical_platform=None, *, chat_id=None, metadata=None) -> bool:
platform = (logical_platform or (metadata or {}).get("_relay_logical_platform")
or self._chat_platform(chat_id))
diff --git a/hermes_cli/observability/shared_metrics_contract.py b/hermes_cli/observability/shared_metrics_contract.py
index 4ef21b9e3c1..d51040c5eb4 100644
--- a/hermes_cli/observability/shared_metrics_contract.py
+++ b/hermes_cli/observability/shared_metrics_contract.py
@@ -147,7 +147,8 @@ TASK_FAILURE_CLASSES = MODEL_ERROR_CLASSES | frozenset({
"repeated_errors", "restart_limit", "session_busy", "shutdown",
})
# Surfaces that are not messaging platforms keep their own execution_surface value.
-_CORE_GATEWAY_PLATFORMS = (frozenset(PLATFORMS) - {"api_server", "cli", "cron"}) | {"none", "plugin"}
+# ``relay``: a connector inbound whose platform neither the inbound nor a single-platform connector names.
+_CORE_GATEWAY_PLATFORMS = (frozenset(PLATFORMS) - {"api_server", "cli", "cron"}) | {"none", "plugin", "relay"}
TOOL_NAMES = BUILTIN_TOOL_NAMES | {"mcp", "plugin", "unknown"}
TOOL_ERROR_CLASSES = frozenset({
"blocked", "contract_violation", "exception", "interrupted", "invalid_arguments", "none",
@@ -1246,6 +1247,8 @@ def skill_provenance(value: Any) -> str:
_SURFACE_ALIASES = {
"api_server": "api",
+ # The relay connector's own platform: an inbound it could not stamp is still a gateway message.
+ "relay": "gateway",
**dict.fromkeys(("cron", "scheduler", "scheduled"), "scheduled_task"),
}
_KNOWN_GATEWAY_PLATFORMS = frozenset({"discord", "email", "slack", "telegram", "teams", "whatsapp"})
diff --git a/hermes_cli/observability/shared_metrics_gateway.py b/hermes_cli/observability/shared_metrics_gateway.py
index c336df037cd..275fef734b9 100644
--- a/hermes_cli/observability/shared_metrics_gateway.py
+++ b/hermes_cli/observability/shared_metrics_gateway.py
@@ -277,11 +277,11 @@ _FRONTING_PLATFORMS = frozenset({"relay"})
def _source_platform(adapter: Any, chat_id: Any) -> Any:
"""The platform a fronting adapter's chat really lives on (the relay connector learned it from
- the inbound, else its primary platform); the adapter's own platform otherwise. Read-only."""
+ the inbound, else the one platform it fronts); the adapter's own platform otherwise. Read-only."""
platform = getattr(adapter, "platform", None)
if str(getattr(platform, "value", platform) or "") not in _FRONTING_PLATFORMS or chat_id in (None, ""):
return adapter
- resolve = getattr(adapter, "_chat_platform", None)
+ resolve = getattr(adapter, "_metrics_platform", None)
try:
return (resolve(str(chat_id)) if callable(resolve) else None) or adapter
except Exception:
diff --git a/tests/gateway/test_relay_source_platform_metrics.py b/tests/gateway/test_relay_source_platform_metrics.py
index 9091c8d0d5e..9b6cf284b2c 100644
--- a/tests/gateway/test_relay_source_platform_metrics.py
+++ b/tests/gateway/test_relay_source_platform_metrics.py
@@ -58,10 +58,26 @@ def test_an_unresolvable_relay_chat_keeps_the_relay_label(rows, chat_platform):
class _Front:
platform = Platform.RELAY
- def _chat_platform(self, chat_id):
+ def _metrics_platform(self, chat_id):
if isinstance(chat_platform, BaseException):
raise chat_platform
return chat_platform
smg._record_delivery(_Front(), SimpleNamespace(success=True), chat_id="c1")
assert rows("hermes.platform.delivery") == [{"failure_class": "none", "outcome": "sent", "platform": "relay"}]
+
+
+def test_an_unstamped_chat_on_a_multiplatform_connector_is_not_labelled_as_its_primary(rows):
+ relay = _relay("discord")
+ relay._transport._identities = [("discord", "bot-a"), ("slack", "bot-b")]
+ event = _inbound(relay, Platform.RELAY, "c7")
+ smg.start_reply_clock(event.source)
+ asyncio.run(relay.send_final_ledgered(event, "k", "final answer", {}, reply_to=None))
+ assert rows("hermes.platform.delivery") == [{"failure_class": "none", "outcome": "sent", "platform": "relay"}]
+
+
+def test_a_relay_stamped_turn_is_a_gateway_message():
+ from hermes_cli.observability.shared_metrics_contract import task_start_fields
+
+ assert task_start_fields({"platform": "relay"}) == {
+ "entrypoint": "gateway_message", "execution_surface": "gateway", "platform": "relay"}
diff --git a/website/docs/developer-guide/relay-shared-metrics.md b/website/docs/developer-guide/relay-shared-metrics.md
index 35fee81b6ac..43c9190b686 100644
--- a/website/docs/developer-guide/relay-shared-metrics.md
+++ b/website/docs/developer-guide/relay-shared-metrics.md
@@ -313,8 +313,10 @@ itself ships.
| `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). |
Replies the relay connector carries report the platform the conversation lives
-on (the inbound's platform, else the platform the connector fronts), never
-`relay`; `relay` remains only when neither is known.
+on (the inbound's platform, else the platform the connector fronts when it
+fronts exactly one), never `relay`; `relay` remains only when neither is known.
+A turn whose inbound the connector did not stamp is still a gateway message
+(`execution_surface=gateway`, task/session `platform=relay`).
| `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. |
| `hermes.startup.latency` | surface (`cli`, `tui`, `desktop_attach`, `gateway_boot`, `serve_boot`), latency bucket (`lt_500ms` … `gte_10s`) | How long each surface takes from launch to usable, so startup regressions show per surface and release. One row per process start: CLI = process start to first rendered prompt (or a `-q` query dispatched; Kanban workers excluded), TUI = Ink process start to gateway ready, Desktop = app start to backend attached, gateway = process start to adapters connected, `hermes serve` = process start to listening. Not counted: a process re-exec'd in place (e.g. `hermes sessions browse` resuming a session) and each dashboard Chat-tab terminal; a TUI/Desktop reconnect to the same backend never re-counts. |
| `hermes.update.run` | kind, outcome, failed_stage, duration_bucket, from_version_age_bucket, apply_mode | Whether updates succeed, how long they take, where they fail, and how stale the version being updated from was. `hermes update` rows are derived from the final update receipt, once per run (`kind` is `desktop` when Desktop's source-checkout hand-off ran it); a run the pre-update interpreter finishes is parked locally with only these fields, only while collection is on, and counted by the next start; Desktop packaged self-updates (`apply_mode=package`) are reported once by the app, after the restart that applies them. |