The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(telemetry): provider_setup Esc is cancelled and Back continues one flow (M12)
teknium1946ae62a895b
diff --git a/hermes_cli/observability/shared_metrics_setup.py b/hermes_cli/observability/shared_metrics_setup.pyindex 8ac46824366..98aa4ba964b 100644--- a/hermes_cli/observability/shared_metrics_setup.py+++ b/hermes_cli/observability/shared_metrics_setup.py@@ -105,11 +105,12 @@ def setup_failure_class(exc: BaseException) -> str:"""Closed class for an exception that ended a setup flow; inert (type checks only)."""from hermes_cli.auth_error_copy import is_cancelled, is_network_error- if is_cancelled(exc):+ names = {cls.__name__ for cls in type(exc).__mro__}+ if is_cancelled(exc) or "_SetupCancelled" in names: # Esc in the setup menusreturn "cancelled"if is_network_error(exc):return "network"- if {cls.__name__ for cls in type(exc).__mro__} & _AUTH_ERROR_TYPES:+ if names & _AUTH_ERROR_TYPES:return "auth"return "other"@@ -312,33 +313,68 @@ def provider_setup_surface(surface: str) -> Iterator[None]:_cli.surface = surfacetry:yield+ except BaseException as exc:+ if not _is_go_back(exc): # a Back replays the wizard section: its flow may resume there+ _close_backed_out()+ raise+ else:+ _close_backed_out()finally:_cli.surface = previous+def _is_go_back(exc: BaseException) -> bool:+ return any(cls.__name__ == "_SetupGoBack" for cls in type(exc).__mro__)+++def _close_backed_out() -> None:+ """The user went Back out of a provider flow and never resumed it: it ends as ``cancelled``."""+ pending, _cli.backed_out = getattr(_cli, "backed_out", None), None+ if pending is not None:+ finish_provider_setup(pending[0], "failed", "cancelled")+++def _resumes(flow: SetupFlow, surface: Any, provider: Any) -> bool:+ try:+ from .shared_metrics_catalog import provider_metric_name++ return provider not in _NOT_A_PROVIDER and (flow.surface, flow.provider) == (surface, provider_metric_name(provider))+ except Exception:+ return False++@contextlib.contextmanagerdef cli_provider_setup(provider: Any) -> Iterator[None]:"""Track one CLI provider flow under the entry point's surface. Without one (fallback picking,tests driving the picker directly) nothing is tracked.Completed when the flow saved a choice or changed the model route; a flow that returns without- either failed with the class it reported, else the user backed out (``cancelled``).+ either failed with the class it reported, else the user backed out (``cancelled``). Back (Left+ arrow) leaves the flow open: the replayed picker re-entering the same provider continues it (one+ ``started``); picking another provider, or leaving the entry point, ends it ``cancelled``."""surface = getattr(_cli, "surface", None)- flow = begin_provider_setup(surface, provider) if surface else None+ pending, _cli.backed_out = getattr(_cli, "backed_out", None), None+ if pending is not None and not _resumes(pending[0], surface, provider):+ finish_provider_setup(pending[0], "failed", "cancelled")+ pending = None+ flow, before = pending or (begin_provider_setup(surface, provider) if surface else None, None)if flow is None:yieldreturn- before = None- with contextlib.suppress(Exception):- before = _model_route()+ if pending is None:+ with contextlib.suppress(Exception):+ before = _model_route()hints: dict[str, Any] = {"saved": False, "failure": None}_cli.hints = hintstry:yieldexcept BaseException as exc:_cli.hints = None- finish_provider_setup(flow, "failed", setup_failure_class(exc))+ if _is_go_back(exc):+ _cli.backed_out = (flow, before)+ else:+ finish_provider_setup(flow, "failed", setup_failure_class(exc))raise_cli.hints = Nonelanded = hints["saved"]diff --git a/tests/hermes_cli/test_shared_metrics_signals.py b/tests/hermes_cli/test_shared_metrics_signals.pyindex cf65adcf01c..8e9f0c8bb61 100644--- a/tests/hermes_cli/test_shared_metrics_signals.py+++ b/tests/hermes_cli/test_shared_metrics_signals.py@@ -204,6 +204,40 @@ def test_cli_flow_classifies_landed_backed_out_failed_and_raised(marks, monkeypasetup_metrics.note_provider_setup_saved() # outside a flow: inert+def test_cli_setup_navigation_esc_cancels_and_back_resumes_one_flow(marks, monkeypatch):+ from hermes_cli.setup import _SetupCancelled, _SetupGoBack++ monkeypatch.setattr(setup_metrics, "_model_route", lambda: ("openrouter", "a", None))++ def attempt(provider, exc=None):+ with setup_metrics.cli_provider_setup(provider):+ if exc is not None:+ raise exc+ setup_metrics.note_provider_setup_saved()++ with setup_metrics.provider_setup_surface("cli_model"):+ with pytest.raises(_SetupCancelled):+ attempt("xai", _SetupCancelled()) # Esc+ with pytest.raises(_SetupGoBack):+ attempt("anthropic", _SetupGoBack(1)) # Back to the provider menu, then the same provider+ attempt("anthropic")+ with pytest.raises(_SetupGoBack):+ attempt("nous", _SetupGoBack(1)) # Back, then another provider+ attempt("gemini")+ with pytest.raises(_SetupGoBack): # a wizard section replay keeps the flow open across the surface+ with setup_metrics.provider_setup_surface("cli_setup"):+ attempt("xai", _SetupGoBack(0))+ with setup_metrics.provider_setup_surface("cli_setup"):+ pass # ...and leaving the entry point without resuming it ends it+ assert _setup_rows(marks.rows) == [+ ("cli_model", "xai", "started", "none"), ("cli_model", "xai", "failed", "cancelled"),+ ("cli_model", "anthropic", "started", "none"), ("cli_model", "anthropic", "completed", "none"),+ ("cli_model", "nous", "started", "none"), ("cli_model", "nous", "failed", "cancelled"),+ ("cli_model", "gemini", "started", "none"), ("cli_model", "gemini", "completed", "none"),+ ("cli_setup", "xai", "started", "none"), ("cli_setup", "xai", "failed", "cancelled"),+ ]++@pytest.mark.parametrize(("sess", "ending"), [({"status": "approved"}, ("completed", "none")),({"status": "expired"}, ("abandoned", "none")),diff --git a/website/docs/developer-guide/relay-shared-metrics.md b/website/docs/developer-guide/relay-shared-metrics.mdindex d3d2447d7cb..5e5773050fc 100644--- a/website/docs/developer-guide/relay-shared-metrics.md+++ b/website/docs/developer-guide/relay-shared-metrics.md@@ -443,7 +443,7 @@ database and the count is not reported.| Metric | Dimensions | Question it answers ||---|---|---|| `hermes.tool_unavailable.count` | provider, model, tool name (shipped built-ins only) | Which toolsets should be on by default: the model called a tool Hermes ships that this session did not enable. Any other unknown name (plugin, MCP, hallucinated) stays a `model_tool_quality` `unknown_tool` issue only. Background reviews and delegated children, whose toolsets are narrowed on purpose, are excluded. |-| `hermes.provider_setup.count` | provider (catalog name; custom endpoints read `custom`), surface (`cli_setup`, `cli_model`, `tui`, `desktop`, `dashboard`), event (`started`, `completed`, `failed`, `abandoned`), failure class (`auth`, `network`, `no_models`, `cancelled`, `other`; `none` unless failed) | Where connecting a provider breaks down. `started` counts once a provider is picked; the flow's end is recorded by the surface that ran it. A flow nobody finished leaves a local marker that the next setup start or Hermes start in the profile reports as `abandoned` (its process is gone, or it has been pending over an hour); an OAuth device code left to expire is also `abandoned`. API keys saved from a form (TUI/Desktop/dashboard) and custom endpoints start and complete in one action. Never a key, token, base URL or error text. Leaving the provider picker before choosing one is not counted. |+| `hermes.provider_setup.count` | provider (catalog name; custom endpoints read `custom`), surface (`cli_setup`, `cli_model`, `tui`, `desktop`, `dashboard`), event (`started`, `completed`, `failed`, `abandoned`), failure class (`auth`, `network`, `no_models`, `cancelled`, `other`; `none` unless failed) | Where connecting a provider breaks down. `started` counts once a provider is picked; the flow's end is recorded by the surface that ran it. In the CLI pickers Esc ends the flow `failed`/`cancelled`; Back (Left arrow) keeps it open, so picking the same provider again continues it (one `started`), while picking another provider or leaving the command ends it `cancelled`. A flow nobody finished leaves a local marker that the next setup start or Hermes start in the profile reports as `abandoned` (its process is gone, or it has been pending over an hour); an OAuth device code left to expire is also `abandoned`. API keys saved from a form (TUI/Desktop/dashboard) and custom endpoints start and complete in one action. Never a key, token, base URL or error text. Leaving the provider picker before choosing one is not counted. || `hermes.feature_adoption.count` | feature (`memory`, `skills_created`, `delegation`, `cron`, `gateway_platform`, `desktop`, `tui`, `mcp`, `plugins`, `browser`, `voice`, `kanban`, `projects`, `bot_mode`, `curator`), days since install (`same_day`, `1d_to_7d`, `7d_to_30d`, `30d_to_90d`, `gte_90d`, `unknown`) | How long after install each major feature is first really used. Once per feature per install, latched in the local database, derived from the counters above (a foreground memory write, a created skill, a successful MCP/plugin/browser/TTS/kanban tool call, a Desktop/TUI/gateway task, a cron run, a curator run) plus direct first-use reports for Bot Mode messages and project creation. The age is the owning profile's (its first session). || `hermes.feature_disabled.count` | kind (`toolset`, `skill`, `plugin`, `platform`, `setting`, `memory`, `curator`, `compression`), name, surface (`cli_tools`, `cli_config`, `cli_slash`, `tui`, `desktop`, `dashboard`), event (`disabled`, `re_enabled`) | What users turn off. Diffed at the config write itself: a default-on toolset removed, a skill or plugin added to its disabled list, a default-`true` setting set false (and each moved back). Names are public only when shipped — toolset key, bundled/catalog skill, bundled/catalog plugin (messaging-platform plugins report as `platform`), `DEFAULT_CONFIG` key path (never a value) — else `custom`. Uninstalling a catalog skill counts as `disabled`. Only user entry points record (`hermes tools` / `config` / `skills` / `plugins`, chat slash commands, TUI/Desktop, dashboard); setup and migrations do not. At most once per (kind, name, event) per day. |<!-- ---- end v5 signals ---- -->