Skip to content

The agent that grows with you

fix(telemetry): an opted-out start purges pending setup and exit markers (m19)

teknium123b5f37d8211
diff --git a/hermes_cli/observability/shared_metrics_process.py b/hermes_cli/observability/shared_metrics_process.py
index 38929d3afda..a0e322b68f6 100644
--- a/hermes_cli/observability/shared_metrics_process.py
+++ b/hermes_cli/observability/shared_metrics_process.py
@@ -14,6 +14,7 @@ import atexit
import json
import logging
import os
+import shutil
import sys
import threading
from pathlib import Path
@@ -75,13 +76,17 @@ def begin_process(kind: str) -> None:
try:
from hermes_constants import get_hermes_home
+ from .shared_metrics_setup import markers_dir as setup_markers_dir
from .shared_metrics_update import _collection_on, purge_pending_updates
if _STATE:
return
_STATE["kind"] = kind # watchdog turn rows name the surface even when this home is off
if not _collection_on():
- purge_pending_updates(get_hermes_home()) # parked while on, never to be counted once off
+ home = get_hermes_home()
+ purge_pending_updates(home) # parked while on, never to be counted once off
+ for directory in (markers_dir(home), setup_markers_dir(home)): # likewise pending exits/setups
+ shutil.rmtree(directory, ignore_errors=True)
return
from gateway.status import get_process_start_time
diff --git a/tests/hermes_cli/test_shared_metrics_reliability.py b/tests/hermes_cli/test_shared_metrics_reliability.py
index 758b8b572dd..39bf3a6fcbf 100644
--- a/tests/hermes_cli/test_shared_metrics_reliability.py
+++ b/tests/hermes_cli/test_shared_metrics_reliability.py
@@ -168,6 +168,19 @@ def test_begin_process_marks_then_stamps_clean_and_crash(marks, monkeypatch):
assert (record["state"], record["crash_class"]) == ("crash", "import_error")
+def test_opted_out_start_purges_markers_left_while_opted_in(marks, monkeypatch):
+ from hermes_cli.observability import shared_metrics_setup as setup_metrics
+
+ left = [process_metrics.markers_dir(marks.home) / "cli-1.json", setup_metrics.markers_dir(marks.home) / "tui-1-1.json"]
+ for marker in left:
+ marker.parent.mkdir(parents=True)
+ marker.write_text(json.dumps({"pid": 1, "started_at": 0, "surface": "tui", "provider": "xai", "state": "running"}))
+ monkeypatch.setattr(process_metrics, "_STATE", {})
+ marks.policy["on"] = False
+ process_metrics.begin_process("cli")
+ assert not any(marker.parent.exists() for marker in left) # nothing reports "abandoned"/"killed" on re-enable
+
+
def test_v3_schema_accepts_exactly_the_contract_values():
from pathlib import Path
diff --git a/website/docs/developer-guide/relay-shared-metrics.md b/website/docs/developer-guide/relay-shared-metrics.md
index 3a5e6f46809..4a0497b4ac0 100644
--- a/website/docs/developer-guide/relay-shared-metrics.md
+++ b/website/docs/developer-guide/relay-shared-metrics.md
@@ -321,7 +321,7 @@ A turn whose inbound the connector did not stamp is still a gateway message
| `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. |
| `hermes.update.stage` | stage, outcome, duration_bucket | Per-stage result and wall time of `hermes update` (plan, snapshot, apply, deps, build, restart, verify), from the receipt's stage timestamps. |
-| `hermes.process.exit` | process_kind, exit_kind, crash_class | How CLI / TUI / gateway / serve / cron-tick processes end (`clean`, `crash` with an exception family only, `killed`, `watchdog`), reported by the next start in the same profile from a local marker. Turns aborted by a turn watchdog also count as `exit_kind=watchdog`. |
+| `hermes.process.exit` | process_kind, exit_kind, crash_class | How CLI / TUI / gateway / serve / cron-tick processes end (`clean`, `crash` with an exception family only, `killed`, `watchdog`), reported by the next start in the same profile from a local marker (a start with collection off deletes these markers, and pending `provider_setup` ones, unreported). Turns aborted by a turn watchdog also count as `exit_kind=watchdog`. |
<!-- ---- v5 desktop ---- -->