Skip to content

The agent that grows with you

fix(telemetry): CLI /undo counts friction only when a turn was undone

teknium140ae31bcb9da
diff --git a/hermes_cli/cli_loops_mixin.py b/hermes_cli/cli_loops_mixin.py
index e598a4cfce0..d3844204fbf 100644
--- a/hermes_cli/cli_loops_mixin.py
+++ b/hermes_cli/cli_loops_mixin.py
@@ -214,8 +214,10 @@ class CLILoopsMixin:
else f"This removes the last {_undo_n} user turns from history.")
if self._confirm_destructive_slash("undo", _undo_desc, cmd_original=cmd_original) is None:
return True # confirmation cancelled — command handled, keep REPL alive
- self._record_model_friction("undo")
+ _history = self.conversation_history
self.undo_last(_undo_n)
+ if self.conversation_history is not _history: # only a successful rewind installs a new history
+ self._record_model_friction("undo")
def _cmd_skills(self, cmd_original: str):
with self._busy_command(self._slow_command_status(cmd_original)):
diff --git a/tests/hermes_cli/test_shared_metrics_model_attribution.py b/tests/hermes_cli/test_shared_metrics_model_attribution.py
index adbbd90b3bc..9df7fd6625a 100644
--- a/tests/hermes_cli/test_shared_metrics_model_attribution.py
+++ b/tests/hermes_cli/test_shared_metrics_model_attribution.py
@@ -201,3 +201,44 @@ def test_multiplexed_gateway_switch_records_in_the_owning_profile(direct_runtime
assert not _all_rows(tmp_path / "hermes-home")
assert sorted(name for name, _ in _all_rows(home_b)) == ["hermes.model_friction.count", "hermes.model_switch.count"]
+
+
+def _cli(db):
+ from hermes_cli.cli_loops_mixin import CLILoopsMixin
+ from hermes_cli.cli_session_mixin import CLISessionMixin
+
+ class FakeCLI(CLILoopsMixin, CLISessionMixin):
+ _slash_metrics_surface = "cli"
+
+ def __init__(self):
+ self.conversation_history = [
+ {"role": "user", "content": "hi"}, {"role": "assistant", "content": "hello"}]
+ self._session_db, self.session_id, self.agent = db, "s-cli" if db else None, None
+ self.provider, self.model = "openrouter", PUBLIC
+
+ def _confirm_destructive_slash(self, *a, **k):
+ return True
+
+ def _prefill_input_buffer(self, text):
+ return None
+
+ return FakeCLI()
+
+
+def test_cli_undo_counts_friction_only_when_something_was_undone(direct_runtime, tmp_path):
+ class LeasedDB:
+ def rewind_user_turn(self, *a, **k):
+ raise RuntimeError("active turn lease")
+
+ failed = _cli(LeasedDB())
+ failed._cmd_undo("/undo")
+ _flush()
+ assert len(failed.conversation_history) == 2
+ assert not _stored_values(tmp_path, "hermes.model_friction.count")
+
+ done = _cli(None)
+ done._cmd_undo("/undo")
+ _flush()
+ assert done.conversation_history == []
+ assert _stored_values(tmp_path, "hermes.model_friction.count") == [
+ ({"model": PUBLIC, "provider": "openrouter", "signal": "undo"}, 1)]