Skip to content

The agent that grows with you

fix(telemetry): review findings on pre-apply stop reasons

Tekniumb49e2ff2b92a
diff --git a/hermes_cli/main.py b/hermes_cli/main.py
index 7e9ea1efb3e..67adbfe5ee7 100644
--- a/hermes_cli/main.py
+++ b/hermes_cli/main.py
@@ -2330,7 +2330,8 @@ def _update_preflight_handled(args) -> bool:
sys.exit(0)
if is_managed():
managed_error("update Hermes Agent")
- _record_stop("managed_install", without_receipt="refused") # before the lock: a metrics row only
+ if not any(getattr(args, flag, False) for flag in ("plan", "check", "list_venv_holders")):
+ _record_stop("managed_install", without_receipt="refused") # an update attempt: a metrics row only
return True
# --plan is read-only and deployment-kind aware, so it runs BEFORE the
diff --git a/hermes_cli/observability/shared_metrics_contract.py b/hermes_cli/observability/shared_metrics_contract.py
index c774d5a0814..8d4e6f79a7b 100644
--- a/hermes_cli/observability/shared_metrics_contract.py
+++ b/hermes_cli/observability/shared_metrics_contract.py
@@ -464,7 +464,7 @@ EXTENSION_REGISTRY_IDS = frozenset({
})
EXTENSION_REGISTRIES = EXTENSION_REGISTRY_IDS | frozenset({"none", "other", "unresolved"})
# Why a `hermes update` run failed or was refused, derived from the FINAL receipt only
-# (shared_metrics_update.update_failure_class); ``none`` unless outcome is failed/refused.
+# (shared_metrics_update.update_failure_class); ``none`` unless outcome is failed/refused/partial.
UPDATE_FAILURE_CLASSES = frozenset({
"aborted_before_apply", # fallback: exited before the checkout moved with no reason recorded
"build_failed", # the build stage reported failure
@@ -485,7 +485,7 @@ UPDATE_FAILURE_CLASSES = frozenset({
"local_changes_parked", # committed, but the user's stashed changes could not be re-applied (partial)
"permission_denied", # the run ended on a PermissionError
})
-# The exit that stopped a run before it applied anything, recorded at the exit itself as one of
+# The exit that stopped a run before its apply stage mark, recorded at the exit itself as one of
# these tokens (update_receipt.record_stop_reason -> the receipt's ``stop_class``).
UPDATE_STOP_CLASSES = frozenset({
"branch_missing", # the target branch exists neither locally nor on origin
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index f9a4b8f4bcd..e3b5a333377 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -1298,11 +1298,19 @@ def _exit_after_failed_branch_switch(
print(f"✗ Branch '{branch}' does not exist locally or on origin.")
if detail:
print(f" {detail.splitlines()[0]}")
- _record_stop("checkout_move_failed" if any(_resolved_commit(git_cmd, ref) for ref in (
- f"refs/heads/{branch}", f"origin/{branch}")) else "branch_missing")
+ _record_stop(_missing_branch_stop(git_cmd, branch))
sys.exit(1)
+def _missing_branch_stop(git_cmd, branch) -> str:
+ """``branch_missing`` unless the branch resolves (then git refused the switch). Never raises."""
+ try:
+ return "checkout_move_failed" if any(
+ _resolved_commit(git_cmd, ref) for ref in (f"refs/heads/{branch}", f"origin/{branch}")) else "branch_missing"
+ except Exception: # health: allow BLE001 -- metrics only: the exit it names must not change
+ return "checkout_move_failed"
+
+
@dataclass
class _CheckoutPlan:
"""What the pre-pull checkout phase decided (see ``_prepare_checkout_for_update``)."""
diff --git a/hermes_cli/update_receipt.py b/hermes_cli/update_receipt.py
index 7c08283143b..d09e1e81f21 100644
--- a/hermes_cli/update_receipt.py
+++ b/hermes_cli/update_receipt.py
@@ -683,9 +683,12 @@ def _collection_enabled_now() -> Optional[bool]:
return isinstance(config, dict) and config.get("enabled") is True
-#: The leading label of a stop reason the parked copy may keep: an exception type name or a fixed
-#: phrase Hermes writes, plus an errno token; never the message after it.
-_PARKED_REASON_LABEL = re.compile(r"[A-Za-z_][A-Za-z0-9_ ]{0,60}:(?: \[(?:Errno|WinError) \d+\])?")
+#: The leading label of a stop reason the parked copy may keep, exactly what the classifier reads:
+#: an exception type name (plus its errno token) or one of the fixed phrases Hermes writes
+#: (shared_metrics_update._STOP_REASON_PREFIX_CLASSES); never the message after it.
+_PARKED_REASON_LABEL = re.compile(
+ r"(?:[A-Z][A-Za-z0-9_]{0,63}:(?: \[(?:Errno|WinError) \d+\])?"
+ r"|historical takeover preparation failed|Windows gateway recovery failed)")
_STOP_CLASS_TOKEN = re.compile(r"[a-z][a-z0-9_]{0,39}")
diff --git a/tests/hermes_cli/test_shared_metrics_update_stop_reasons.py b/tests/hermes_cli/test_shared_metrics_update_stop_reasons.py
index e45a3313edc..3690f51e103 100644
--- a/tests/hermes_cli/test_shared_metrics_update_stop_reasons.py
+++ b/tests/hermes_cli/test_shared_metrics_update_stop_reasons.py
@@ -60,6 +60,27 @@ def test_a_pre_apply_exit_reads_its_own_class_in_process_and_parked(rows, stop,
parked = update_receipt._metric_receipt(receipt)
assert "/home/alice" not in json.dumps(parked)
assert update_metrics.update_receipt_fields(json.loads(json.dumps(parked)))[0] == run
+ for text in ("alice secret repo: x", "Windows gateway recovery failed: C:\\Users\\alice"):
+ kept = update_receipt._metric_receipt({**receipt, "stop_reason": text})["stop_reason"]
+ assert "alice" not in kept and kept in {"-", "Windows gateway recovery failed"}
+
+
[email protected](("stderr", "argv", "code", "expected"), [
+ ("fatal: Unable to create '/x/.git/index.lock': File exists.", ["git", "merge"], 128, "git_index_locked"),
+ ("git fetch timed out after 300s (a stalled remote)", ["git", "fetch"], 124, "git_timeout"),
+ ("error: No space left on device", ["git", "checkout"], 1, "disk_full"),
+ ("error: could not write index", ["git", "stash", "push"], 1, "local_changes_blocked"),
+ ("fatal: bad object", ["git", "reset", "--hard"], 128, "checkout_move_failed"),
+ ("whatever", ["uv", "pip", "install"], 1, None),
+])
+def test_a_failed_git_call_names_its_class_from_the_argv_and_fixed_phrases(stderr, argv, code, expected):
+ import subprocess
+
+ from hermes_cli.update_cmd_zip import _zip_stop_class
+
+ assert update_receipt.git_error_stop_class(subprocess.CalledProcessError(code, argv, stderr=stderr)) == expected
+ assert _zip_stop_class(OSError(28, "No space left on device"), downloaded=True) == "disk_full"
+ assert _zip_stop_class(ValueError("x"), downloaded=False) == "download_failed"
def test_exits_before_the_receipt_opens_count_once_and_leave_the_holders_receipt_alone(rows, monkeypatch):
diff --git a/website/docs/developer-guide/relay-shared-metrics.md b/website/docs/developer-guide/relay-shared-metrics.md
index 847705a03c0..b963d6c5a7e 100644
--- a/website/docs/developer-guide/relay-shared-metrics.md
+++ b/website/docs/developer-guide/relay-shared-metrics.md
@@ -506,7 +506,7 @@ they failed. Rows recorded before the change keep their old field set and still
| Metric | Dimensions added | Question it answers |
|---|---|---|
| `hermes.extension.install.count` | failure class, registry | Why skill, plugin and MCP installs fail, and which skills-hub source fails. `failure_class` is `none` on success, else a closed name for the failure exit that stopped the install. Skills: `ambiguous`, `auth_rejected`, `fetch_failed`, `invalid_bundle`, `invalid_name`, `not_found`, `rate_limited`, `scan_blocked`, `stale_index`. Plugins: `already_installed`, `clone_failed`, `deps_declined`, `deps_failed`, `git_missing`, `incompatible`, `invalid_source`, `manifest_invalid`, `non_interactive`, `removed_from_catalog`, `scan_blocked`. MCP servers: `auth_required`, `bootstrap_failed`, `clone_failed`, `config_invalid`, `config_rejected`, `connect_failed`, `git_missing`, `missing_credentials`, `server_start_failed`. Every kind may also read `exception`, `filesystem_error`, `network`, `other`, `permission`. A raised error without a named class is classified by its Python type only (`PermissionError` reads `permission`, connection and timeout errors `network`, other `OSError`s `filesystem_error`, anything else `exception`, its type name dropped). `registry` is set on skill rows only: the skills-hub adapter that resolved or served the skill, one of `browse-sh`, `clawhub`, `github`, `hermes-index`, `lobehub`, `official`, `skills-sh`, `url`, `well-known` (the adapter ids `tools/skills_hub_search.py::create_source_router` builds), `unresolved` when no adapter answered, `none` for built-in restores and every plugin/MCP row, `other` otherwise. A row whose `failure_class` is outside its kind's set, is `none` on a failure or set on a success, or that names a registry on a plugin/MCP row is invalid. Never the identifier, URL, error text or path; `name` keeps its existing catalog-or-`custom` rule. |
-| `hermes.update.run` | failure class | Why `hermes update` fails, next to where (`failed_stage`). `none` unless the outcome is `failed`, `refused` or `partial`. Derived from the final update receipt only: `build_failed`, `deps_failed`, `exception`, `fleet_stale`, `fleet_unverified`, `git_failed`, `interrupted`, `lock_held`, `managed_install`, `os_error`, `disk_full`, `permission_denied`, `restart_failed`, `subprocess_failed`, else `other`; Desktop packaged self-updates report `unknown` (their RPC carries a stage, never a reason). An exception that ended the run is read by its type name alone, never its message (a `PermissionError` reads `permission_denied`, an `OSError` whose errno is ENOSPC reads `disk_full`); a failed Windows gateway resume after the update reads `restart_failed`. Every exit that stops a run before it applies anything records one closed token at the exit itself, and the run reads it: `fetch_failed`, `git_timeout` (a network git call hit the updater's time limit), `channel_unresolved`, `git_in_progress` (a merge/rebase/... was already running), `git_index_locked`, `merge_conflict` (local commits on a custom branch), `checkout_move_failed`, `branch_missing`, `parked_branch_blocked`, `detached_head`, `unexpected_branch`, `head_moved` (a ref moved mid-update), `target_unresolved`, `target_syntax_error` (refused before the move), `syntax_rollback` (moved, failed the syntax check, rolled back), `commit_point_refused` (the commit point could not be armed; nothing moved), `venv_foreign_owner`, `local_changes_blocked` (local changes git could not stash, or a dirty tree the ZIP fallback will not overwrite), `stash_restore_rejected`, `not_git_checkout`, `old_version_handoff` (an older updater's hand-off could not finish), `branch_unsupported`, `download_failed`, `zip_failed`, `disk_full`, `lock_held`, `managed_install`. `aborted_before_apply` is now only the fallback for such an exit with no recorded token. The update-lock refusal, the Git-operation refusal and the managed-install refusal fire before the run's receipt opens; they still write no receipt (the receipt store belongs to the update holding the lock) and record one row with that token. A token is read only while the run has no apply mark, so a reason can never outlive the exit that recorded it. A run that committed and then was interrupted, or whose stashed local changes could not be re-applied, reads outcome `partial` (`interrupted` / `local_changes_parked`, `failed_stage` `apply` for the latter), never `failed`; owed follow-ups alone keep the run a `success` (contract C3). A run the pre-update interpreter finishes is parked with the token, the exit code, the stop reason's leading exception label and the restart/user-action flags (never argv, paths or messages), so it classifies exactly as the same run finished in-process. A failed run whose every stage mark passed now reads `failed_stage` `verify` (the post-restart verification wrote `partial`) or `restart` (a skipped restart left the fleet owing one) instead of `other`; a `partial` run with a failed build or restart mark keeps that stage, and its verify stage row is failed only when the fleet has a stale or down row. |
+| `hermes.update.run` | failure class | Why `hermes update` fails, next to where (`failed_stage`). `none` unless the outcome is `failed`, `refused` or `partial`. Derived from the final update receipt only: `build_failed`, `deps_failed`, `exception`, `fleet_stale`, `fleet_unverified`, `git_failed`, `interrupted`, `lock_held`, `managed_install`, `os_error`, `disk_full`, `permission_denied`, `restart_failed`, `subprocess_failed`, else `other`; Desktop packaged self-updates report `unknown` (their RPC carries a stage, never a reason). An exception that ended the run is read by its type name alone, never its message (a `PermissionError` reads `permission_denied`, an `OSError` whose errno is ENOSPC reads `disk_full`); a failed Windows gateway resume after the update reads `restart_failed`. Every exit that stops a run before its apply stage mark records one closed token at the exit itself, and the run reads it (a few of these, `syntax_rollback`, `stash_restore_rejected`, `unexpected_branch`, `head_moved`, fire after git moved the tree and put it back or left it for the next launch to restore): `fetch_failed`, `git_timeout` (a network git call hit the updater's time limit), `channel_unresolved`, `git_in_progress` (a merge/rebase/... was already running), `git_index_locked`, `merge_conflict` (local commits on a custom branch), `checkout_move_failed`, `branch_missing`, `parked_branch_blocked`, `detached_head`, `unexpected_branch`, `head_moved` (a ref moved mid-update), `target_unresolved`, `target_syntax_error` (refused before the move), `syntax_rollback` (moved, failed the syntax check, rolled back), `commit_point_refused` (the commit point could not be armed; nothing moved), `venv_foreign_owner`, `local_changes_blocked` (local changes git could not stash, or a dirty tree the ZIP fallback will not overwrite), `stash_restore_rejected`, `not_git_checkout`, `old_version_handoff` (an older updater's hand-off could not finish), `branch_unsupported`, `download_failed`, `zip_failed`, `disk_full`, `lock_held`, `managed_install`. `aborted_before_apply` is now only the fallback for such an exit with no recorded token. The update-lock refusal, the Git-operation refusal and the managed-install refusal fire before the run's receipt opens; they still write no receipt (the receipt store belongs to the update holding the lock) and record one row with that token. A token is read only while the run has no apply mark, so a reason can never outlive the exit that recorded it. A run that committed and then was interrupted, or whose stashed local changes could not be re-applied, reads outcome `partial` (`interrupted` / `local_changes_parked`, `failed_stage` `apply` for the latter), never `failed`; owed follow-ups alone keep the run a `success` (contract C3). A run the pre-update interpreter finishes is parked with the token, the exit code, the stop reason's leading exception type (or one of Hermes' two fixed phrases) and the restart/user-action flags (never argv, paths or messages), so it classifies exactly as the same run finished in-process. A failed run whose every stage mark passed now reads `failed_stage` `verify` (the post-restart verification wrote `partial`) or `restart` (a skipped restart left the fleet owing one) instead of `other`; a `partial` run with a failed build or restart mark keeps that stage, and its verify stage row is failed only when the fleet has a stale or down row. |
<!-- ---- end iuf c1 ---- -->
<!-- ---- iuf c2 ---- -->
#### Fresh installs